ecs-rails 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c315c2e992cf5b44e419f99fbca24d590b67bde002ff99c87eace906039d479
4
- data.tar.gz: eea04176308d22f38e5c4ae44ce4bf9fff10f5e45f33ac5a1904b794e602791f
3
+ metadata.gz: dfe4933e3eb4620330076f2125af1d6cb0d618f06f52ebf7594e09bd96ee814d
4
+ data.tar.gz: 504edec780c9ac72495e47a62a9ba947a2cb5f5c54efe0168d4c97ae3983eb59
5
5
  SHA512:
6
- metadata.gz: bd23d26514639ac9f015bb8af4b82491a0896e670c10b701f642981d8a2872b1230c009f570c5dc6a9a7f787842c7972b2573762de69b7b3ac62289a5c7a8142
7
- data.tar.gz: e6f6e8043df16a541c81cdba7cf316c301e8a850082de85a694b0b7c1b8e3c27064e29431857fd66764de7ffeaa01c1f7c6983c9e755fdc32e21ffd4e75df244
6
+ metadata.gz: 468eeaa07559226e3cb18e7445d4fe087823b5152efb1b2b436d12b21d351728931cfeba4ee90118a090c611495e2cdefce799f77b6c378224702c0913d6fcc8
7
+ data.tar.gz: 1830eaff6a0e8852e2b563efb5cace637eed17a5169fd63de2c960c5cbfa9bf9e7d484e75b9c96f581da091d2b037eda60db702e27de35d5fd4102778daec5db
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ gemspec
6
6
 
7
7
  gem 'byebug'
8
8
  gem 'rspec', '~> 3.0'
9
+ gem 'activesupport', '> 5.2'
data/bin/ecs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'byebug'
4
4
  require 'optparse'
5
+
5
6
  require_relative '../lib/ecs-rails'
6
7
 
7
8
  options = {}
@@ -15,8 +16,22 @@ OptionParser.new do |opts|
15
16
  opts.on("-s", "--service SERVICE_STRING", "Give a substring present in your service name. Ex: 'ecs console -c prod -s app' to connect to service webapp-app-prod-7c7cad7") do |c|
16
17
  options[:service] = c
17
18
  end
19
+
20
+ opts.on("-f", "--file-path FILE_PATH", "file path to yaml config file") do |c|
21
+ options[:config_file] = c
22
+ end
23
+
18
24
  end.parse!
19
25
 
20
26
  command_keyword = ARGV[0]
21
27
 
28
+ if !options[:config_file].nil?
29
+ EcsRails.load_settings(options[:config_file])
30
+ else
31
+ EcsRails.aws_region = ENV['AWS_REGION']
32
+ EcsRails.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
33
+ EcsRails.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
34
+ EcsRails.container_name = ENV['CONTAINER_NAME'] || 'webapp'
35
+ end
36
+
22
37
  EcsRails::CommandExecutor.call(command_keyword, options)
data/ecs-rails.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency "aws-sdk-ecs", "~> 1.132", "> 1.132"
25
25
  s.add_runtime_dependency "aws-sdk-ec2", "~> 1.425", "> 1.425"
26
26
  s.add_runtime_dependency "tty-prompt", "~> 0.23", "> 0.23"
27
+ s.add_runtime_dependency "activesupport", "> 5.2"
27
28
  end
@@ -1,21 +1,37 @@
1
+ require 'yaml'
2
+ require 'singleton'
3
+
1
4
  module EcsRails
2
5
  class EcsRailsConfiguration
6
+ include Singleton
7
+
3
8
  attr_accessor :aws_region
4
9
  attr_accessor :aws_access_key_id
5
10
  attr_accessor :aws_secret_access_key
6
11
  attr_accessor :container_name
7
12
 
8
- def self.setup
9
- new.tap do |config|
10
- yield config if block_given?
11
- end
13
+ def self.delegated
14
+ public_instance_methods - superclass.public_instance_methods - Singleton.instance_methods
12
15
  end
13
16
 
14
17
  def initialize
15
- @aws_region = ENV['AWS_REGION'] || 'us-east-1'
16
- @aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
17
- @aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
18
- @container_name = ENV['CONTAINER_NAME'] || 'webapp'
18
+ @aws_region = 'us-east-1'
19
+ @aws_access_key_id = nil
20
+ @aws_secret_access_key = nil
21
+ @container_name = 'webapp'
22
+ end
23
+
24
+ def load_settings(file_path=nil)
25
+ file_path ||= default_settings_file_path
26
+ yaml = YAML.load_file(file_path)
27
+ yaml_settings = yaml['settings']
28
+ yaml_settings.each do |key, value|
29
+ send("#{key}=", value)
30
+ end
31
+ end
32
+
33
+ def aws_region
34
+ @aws_region
19
35
  end
20
36
 
21
37
  def aws_region=(region)
@@ -34,5 +50,11 @@ module EcsRails
34
50
  @container_name = container_name
35
51
  end
36
52
 
53
+ private
54
+
55
+ def default_settings_file_path
56
+ File.join(Dir.pwd, 'config', 'ecs-rails.yml')
57
+ end
58
+
37
59
  end
38
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EcsRails
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.5'
5
5
  end
data/lib/ecs-rails.rb CHANGED
@@ -24,21 +24,19 @@ require_relative 'ecs-rails/console'
24
24
  require_relative 'ecs-rails/bash'
25
25
  require_relative 'ecs-rails/null_command'
26
26
 
27
+ # delegate
28
+ require 'active_support/core_ext/module/delegation'
27
29
 
28
30
  # prompt
29
31
  require "tty-prompt"
30
32
 
31
33
  module EcsRails
32
34
 
33
- @configuration = EcsRails::EcsRailsConfiguration.setup
34
-
35
35
  class << self
36
- extend Forwardable
37
-
38
- def_delegators :@configuration, :aws_region, :aws_region=
39
- def_delegators :@configuration, :aws_access_key_id, :aws_access_key_id=
40
- def_delegators :@configuration, :aws_secret_access_key, :aws_secret_access_key=
41
- def_delegators :@configuration, :container_name, :container_name=
36
+ def config
37
+ EcsRails::EcsRailsConfiguration.instance
38
+ end
39
+ delegate(*EcsRails::EcsRailsConfiguration.delegated, to: :config)
42
40
  end
43
41
 
44
42
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe EcsRails::EcsRailsConfiguration do
4
+
5
+
6
+ describe '#default' do
7
+
8
+ it 'sets region to us-east-1' do
9
+ expect(EcsRails.aws_region).to eq('us-east-1')
10
+ end
11
+ end
12
+
13
+ describe 'set aws region' do
14
+ describe 'directly' do
15
+ it 'sets region to us-west-2' do
16
+ EcsRails.aws_region = 'us-west-2'
17
+ expect(EcsRails.aws_region).to eq('us-west-2')
18
+ end
19
+ end
20
+ describe 'via configuration file' do
21
+ it 'sets region to us-west-2' do
22
+ EcsRails.load_settings('spec/fixtures/ecs-rails.yml')
23
+ expect(EcsRails.aws_region).to eq('us-west-2')
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ end
@@ -0,0 +1,2 @@
1
+ settings:
2
+ aws_region: 'us-west-2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck D'agostini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-11 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -104,6 +104,20 @@ dependencies:
104
104
  - - ">"
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0.23'
107
+ - !ruby/object:Gem::Dependency
108
+ name: activesupport
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">"
112
+ - !ruby/object:Gem::Version
113
+ version: '5.2'
114
+ type: :runtime
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">"
119
+ - !ruby/object:Gem::Version
120
+ version: '5.2'
107
121
  description: Connect to your AWS ECS tasks
108
122
  email: franck.dagostini@gmail.com
109
123
  executables:
@@ -130,7 +144,8 @@ files:
130
144
  - lib/ecs-rails/service_selector.rb
131
145
  - lib/ecs-rails/task_selector.rb
132
146
  - lib/ecs-rails/version.rb
133
- - spec/bin/ecs_spec.rb
147
+ - spec/ecs-rails/ecs_rails_configuration_spec.rb
148
+ - spec/fixtures/ecs-rails.yml
134
149
  - spec/spec_helper.rb
135
150
  homepage: https://rubygems.org/gems/ecs-rails
136
151
  licenses:
data/spec/bin/ecs_spec.rb DELETED
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Ecs binary' do
4
-
5
- context 'without arguments' do
6
- it 'should run ecs help' do
7
- output = EcsRails::CommandExecutor.call('', {})
8
- expect(output).to include('You must specify a command')
9
- end
10
- end
11
-
12
- context 'with console command argument' do
13
- it 'calls the command factory with correct command keyword' do
14
- command_factory_instance = double('command_factory_instance')
15
-
16
- expect(EcsRails::CommandFactory).to receive(:new).with('console', {}).and_return(command_factory_instance)
17
-
18
- command_instance = double('command_instance')
19
-
20
- expect(command_factory_instance).to receive(:command).and_return(command_instance)
21
- expect(command_instance).to receive(:call)
22
-
23
- EcsRails::CommandExecutor.call('bash', {})
24
- end
25
- end
26
- end