feefi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ #in case i do something stupid
20
+ feefi.yml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in feefi.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Hank Beaver
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Feefi (alpha)
2
+ Feefi, a not-so-giant sized CLI for AWS Elastic Beanstalk
3
+
4
+ ## Installation
5
+
6
+ ```
7
+ $ gem install feefi
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ 1. Create a the skeleton config directory and file.
13
+
14
+ ```
15
+ $ feefi setup
16
+ ```
17
+
18
+ 2. Edit ~/.feefi/feefi.conf and add your own Beanstalk apps(s) and AWS credentials
19
+ for each.
20
+
21
+ 3. You'll have to manage your own SSH keys for the moment using ssh-add
22
+ or an agent for deploys and logging into systems.
23
+
24
+ 4. Start using it!
25
+
26
+ $ feefi help
27
+
28
+
29
+ ## TODO
30
+
31
+ 0. TESTS!
32
+ 1. Add interactive add/delete of apps and credentials
33
+ 2. Install git hooks into current repo
34
+ 3. pem/key management
35
+ 4. delete versions
36
+ 5. zero-downtime deploy: create environment using template, incremnent
37
+ name-number +1, deploy.
38
+ 6. zero-downtime cut over - with DNS plugin too?
39
+
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
48
+
49
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/feefi ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.expand_path("../../lib", __FILE__)
3
+ require 'feefi/cli'
4
+
5
+ if File.exists? Feefi::FEEFI_CONFIG_FILE
6
+ Feefi::Config.config = Hashie::Mash.new YAML.load(File.open(Feefi::FEEFI_CONFIG_FILE).read)
7
+ elsif ARGV[0] == 'setup'
8
+ #pass on by, this is hack for now
9
+ else
10
+ puts "You need to run 'setup'!"
11
+ exit
12
+ end
13
+
14
+ Feefi::Cli.start
data/feefi.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'feefi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "feefi"
8
+ spec.version = Feefi::VERSION
9
+ spec.authors = ["Hank Beaver"]
10
+ spec.email = ["hbeaver@gmail.com"]
11
+ spec.description = %q{Elastic Beanstalk CLI to tame the behemoth of ways to interact with Beanstalk}
12
+ spec.summary = %q{}
13
+ spec.homepage = "http://www.github.com/blasterpal/feefi"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+
26
+ spec.add_dependency "thor"
27
+ spec.add_dependency "fog"
28
+ spec.add_dependency 'hashie'
29
+
30
+
31
+ end
data/feefi.yml.example ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ :apps:
3
+ - :name: my_beanstalk_app
4
+ :aws_config: {}
5
+ :aws_id: ASADFADFSDF
6
+ :aws_secret: '!@#$!@#!@$'
7
+ :environments:
8
+ - staging
9
+ - production
10
+
11
+ - :name:
12
+ :aws_config: {}
13
+ :aws_id: ASADFADFSDF
14
+ :aws_secret: '!@#$!@#!@$'
15
+ :environments:
16
+ - staging
17
+ - production
18
+
data/lib/feefi.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "feefi/version"
2
+ require 'thor'
3
+
4
+ # dev gems
5
+ begin
6
+ require 'pry'
7
+ rescue LoadError
8
+ end
9
+
10
+ module Feefi
11
+ # Your code goes here...
12
+ FEEFI_CONFIG_PATH = File.expand_path "~/.feefi"
13
+ FEEFI_CONFIG_FILE = File.join(FEEFI_CONFIG_PATH,"feefi.yml")
14
+ end
data/lib/feefi/aws.rb ADDED
File without changes
@@ -0,0 +1,55 @@
1
+ module Feefi::AWS
2
+ class Beanstalk
3
+ include Feefi::Helpers
4
+
5
+ attr_accessor :aws, :config
6
+ def initialize(aws,config)
7
+ @aws = aws
8
+ @beanstalk_connection = aws.beanstalk_connection
9
+ @ec2_connection = aws.ec2_connection
10
+ @config = config
11
+ end
12
+
13
+ # Obtains a list of configuration templates for the current beanstalk app
14
+ def list_templates
15
+ @beanstalk_connection.templates.map(&:name)
16
+ end
17
+
18
+ def delete_template(name)
19
+ @beanstalk_connection.templates.get( @config.name, name).destroy
20
+ end
21
+
22
+ # gets the current EB OS Environment variables for the deployed app on a
23
+ # current eb environment, overloaded term. eb environments are
24
+ # arbitrary and are loosely similar to a Rails env.
25
+ def list_variables(eb_env_name)
26
+ begin
27
+ body = @aws.beanstalk_connection.describe_configuration_settings("ApplicationName" => @config.name, "EnvironmentName" => eb_env_name).body
28
+ current_env_variables = body['DescribeConfigurationSettingsResult']['ConfigurationSettings'].first['OptionSettings'].select \
29
+ {|ea| ea['Namespace'] == ENV_NAMESPACE}
30
+ rescue Fog::AWS::ElasticBeanstalk::InvalidParameterError => e
31
+ puts "An error occurred connecting to Beanstalk. Check your options!"
32
+ puts e
33
+ exit
34
+ end
35
+ end
36
+
37
+ # List it out all environments for an application
38
+ def eb_environments
39
+ @aws.beanstalk_connectoin
40
+ binding.pry
41
+ end
42
+
43
+ # Uses EC2 and the tags to get a list of EC2 instances associated with this app and Beanstalk environment
44
+ # Technically the eb_env is merely a filter and will match using Array#include? in the env_env varianble.
45
+ def servers(eb_env)
46
+ @aws.ec2_connection.servers.select do |server|
47
+ if server.tags && server.tags["elasticbeanstalk:environment-name"]
48
+ server.tags["elasticbeanstalk:environment-name"].include? eb_env
49
+ else
50
+ nil
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,16 @@
1
+ require 'fog'
2
+ module Feefi::AWS
3
+ class Connection
4
+ ENV_NAMESPACE = 'aws:elasticbeanstalk:application:environment'
5
+ attr_accessor :config, :ec2_connection, :beanstalk_connection
6
+ def initialize(config)
7
+ @config = config
8
+ @ec2_connection = Fog::Compute.new({:provider => 'AWS',
9
+ :aws_access_key_id => @config.aws_id,
10
+ :aws_secret_access_key => @config.aws_secret })
11
+ @beanstalk_connection = Fog::AWS::ElasticBeanstalk.new({
12
+ :aws_access_key_id => @config.aws_id,
13
+ :aws_secret_access_key => @config.aws_secret })
14
+ end
15
+ end
16
+ end
data/lib/feefi/cli.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'feefi'
2
+ require 'feefi/config'
3
+ require 'feefi/setup'
4
+ require 'feefi/helpers'
5
+ require 'feefi/aws/connection'
6
+ require 'feefi/aws/beanstalk'
7
+
8
+
9
+ class Feefi::Cli < Thor
10
+
11
+ include Feefi::Helpers
12
+ include Thor::Actions
13
+
14
+ desc "setup", "Setup your feefi, creates ~/.feefi and writes config"
15
+ def setup
16
+ Feefi::Setup.create_feefi_config
17
+ end
18
+
19
+ desc "apps", "List apps"
20
+ def apps
21
+ Feefi::Helpers.preamble "Your apps"
22
+ puts Feefi::Config.apps.map(&:name)
23
+ end
24
+
25
+ desc "servers", "List servers for EB app environment "
26
+ method_option :app_name, :type => :string, :required => true
27
+ method_option :env, :type => :string, :required => true
28
+ def servers
29
+ s = beanstalk.servers options[:env]
30
+ end
31
+
32
+ desc "manage configurations templates", "Manage saved configuration templates for an app and environment"
33
+ method_option :app_name, :type => :string, :required => true
34
+ method_option :env, :type => :string, :required => true
35
+ method_option :list, :type => :boolean
36
+ method_option :delete, :type => :boolean
37
+ method_option :name, :type => :string
38
+ def templates
39
+ unless options[:list] || options[:delete]
40
+ puts "No action specified, supply --list or --delete"
41
+ exit
42
+ end
43
+ if options[:list]
44
+ preamble "#{options[:app_name]} | #{options[:env]} Configuration Templates"
45
+ puts beanstalk.list_templates
46
+ elsif options[:delete]
47
+ if yes? "Are you sure you want to delete #{options[:name]}?"
48
+ beanstalk.delete_template options[:name]
49
+ end
50
+ end
51
+ end
52
+
53
+ private
54
+ def connection
55
+ @connection ||= Feefi::AWS::Connection.new app_config
56
+ end
57
+
58
+ def beanstalk
59
+ @beanstalk ||= Feefi::AWS::Beanstalk.new connection, app_config
60
+ end
61
+
62
+ end
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+ require 'hashie'
3
+ module Feefi
4
+ class Config
5
+ class << self
6
+ attr_accessor :config
7
+ def app_config(app_name)
8
+ config.apps.select {|ea| ea.name == app_name}.first
9
+ end
10
+ def method_missing(method_name)
11
+ config.send method_name.to_sym
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Feefi
2
+ module Helpers
3
+ def preamble(message)
4
+ puts "#{message}"
5
+ puts "-----------"
6
+ end
7
+ # presumed to be used within method
8
+ def app_config
9
+ Feefi::Config.app_config options[:app_name]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,49 @@
1
+ module Feefi
2
+ class Setup
3
+ class << self
4
+ def create_feefi_config()
5
+ puts "Setting up #{Feefi::FEEFI_CONFIG_FILE} ..."
6
+ # does directory exist?
7
+ unless Dir.exists? Feefi::FEEFI_CONFIG_PATH
8
+ Dir.mkdir(Feefi::FEEFI_CONFIG_PATH) #unless
9
+ end
10
+
11
+ if File.exist?(Feefi::FEEFI_CONFIG_FILE)
12
+ puts "Config file: #{Feefi::FEEFI_CONFIG_FILE} already exists!"
13
+ else
14
+ content =
15
+ {:apps => [{
16
+ :name => 'my_beanstalk_app',
17
+ :beanstalk_config => {},
18
+ :aws_id => 'ASADFADFSDF',
19
+ :aws_secret => '!@#$!@#!@$',
20
+ :environments => ['staging','production']},
21
+
22
+ {
23
+ :name => 'my_beanstalk_app2',
24
+ :beanstalk_config => {},
25
+ :aws_id => 'ASADFADFSDF',
26
+ :aws_secret => '!@#$!@#!@$',
27
+ :environments => ['staging','production']}
28
+
29
+ ]
30
+ }.to_yaml
31
+ File.open(Feefi::FEEFI_CONFIG_FILE,'w') do |f|
32
+ f << content
33
+ end
34
+ end
35
+ end
36
+ def upsert_app(app_name,aws_id,aws_secret)
37
+
38
+ end
39
+ protected
40
+ def read_config
41
+ TOML.load_file(Feefi::FEEFI_CONFIG_FILE )
42
+ end
43
+
44
+ def write_config(config_hash)
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Feefi
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: feefi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hank Beaver
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: thor
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: fog
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: hashie
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Elastic Beanstalk CLI to tame the behemoth of ways to interact with Beanstalk
127
+ email:
128
+ - hbeaver@gmail.com
129
+ executables:
130
+ - feefi
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/feefi
140
+ - feefi.gemspec
141
+ - feefi.yml.example
142
+ - lib/feefi.rb
143
+ - lib/feefi/aws.rb
144
+ - lib/feefi/aws/beanstalk.rb
145
+ - lib/feefi/aws/connection.rb
146
+ - lib/feefi/cli.rb
147
+ - lib/feefi/config.rb
148
+ - lib/feefi/helpers.rb
149
+ - lib/feefi/setup.rb
150
+ - lib/feefi/version.rb
151
+ homepage: http://www.github.com/blasterpal/feefi
152
+ licenses:
153
+ - MIT
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ segments:
165
+ - 0
166
+ hash: 4133757758499919753
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ segments:
174
+ - 0
175
+ hash: 4133757758499919753
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 1.8.22
179
+ signing_key:
180
+ specification_version: 3
181
+ summary: ''
182
+ test_files: []