atlas_peering_ctl 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f0e6276fc86d3e404bdbab2a2d21679f3bbe28c
4
+ data.tar.gz: 00d355e314d2c4db4cb0c50ed4b1c7d56b796190
5
+ SHA512:
6
+ metadata.gz: 1d1ef9b873ea0db0d5a94c36d88ac11d89d0e6e0cbe68c69515f0767c75f5b5bd64aa5e696f243ae462068802f0391e2fdce75cc8b70e7cc246053825a8809f4
7
+ data.tar.gz: 920020559a4618dcb84d11feb558b164324cd55c6a331820c33ff22ee40b1e25f06cadd537da9be7057ec3385bc52d76068ff13a196a86aac1b7135029080c62
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ config/*.yaml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ Lint/UnusedMethodArgument:
2
+ Exclude:
3
+ - 'lib/atlas/peering/proxy.rb'
4
+
5
+ Lint/Void:
6
+ Exclude:
7
+ - 'lib/atlas/client.rb'
8
+
9
+ Style/RaiseArgs:
10
+ EnforcedStyle: compact
11
+
12
+ Metrics/AbcSize:
13
+ Max: 25
14
+
15
+ Metrics/MethodLength:
16
+ Max: 50
17
+
18
+ Metrics/LineLength:
19
+ Max: 132
20
+
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 7
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.0
4
+ before_install: gem install bundler -v '1.16'
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Javier Juarez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Atlas Peering Control
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/atlas_peering_ctl`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'atlas_peering_ctl'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install atlas_peering_ctl
22
+
23
+ ## Usage
24
+
25
+ You can discover by yourself the easy use of this application, just type atlas_peering_ctl --help
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jjuarez/atlas_peering_ctl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RuboCop::RakeTask.new(:rubocop) do |t|
8
+ t.options = ['--display-cop-names', '--display-style-guide']
9
+ end
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
13
+ task default: :spec
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'atlas'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'atlas_peering_ctl'
9
+ spec.version = ::Atlas::VERSION
10
+ spec.authors = ['Javier Juarez']
11
+ spec.email = ['javier.juarez@gmail.com']
12
+
13
+ spec.summary = 'This cli helps to handle peering connectons with MongoDB Atlas service.'
14
+ spec.description = 'This cli helps to handle peering connectons with MongoDB Atlas service.'
15
+ spec.homepage = 'https://github.com/jjuarez/atlas_peering_ctl'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_runtime_dependency 'httparty', '0.16.0'
27
+ spec.add_runtime_dependency 'json', '2.1.0'
28
+ spec.add_runtime_dependency 'thor', '0.20.0'
29
+
30
+ spec.add_development_dependency 'awesome_print'
31
+ spec.add_development_dependency 'bundler', '~> 1.15'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.52'
35
+ spec.add_development_dependency 'wirble'
36
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'atlas'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+ set -vx
6
+
7
+ bundle install
8
+
9
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ ---
2
+ username: 'phil@example.com'
3
+ apiKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
4
+ groupId: '59d4e3760bd66b3b619ef1d0'
5
+ vpcId: 'vpc-xxxxx'
6
+ awsAccountId: 'xxxxx'
7
+ routeTableCidrBlock: '10.0.0.0/16'
8
+ containerId: 'xxxx'
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ begin
5
+ lib = File.expand_path('../../lib', __dir__)
6
+
7
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
+ require 'atlas'
9
+ rescue StandardError => e
10
+ raise("We can not handle this LOAD_PATH properly(#{e.message})")
11
+ end
12
+
13
+ Process.setproctitle('atlas_peering_ctl')
14
+ Atlas::Peering.start(ARGV)
data/lib/atlas.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'atlas/cli'
4
+
5
+ module Atlas
6
+ VERSION = '0.3.1'
7
+ end
data/lib/atlas/cli.rb ADDED
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'thor'
5
+ require 'atlas/config'
6
+ require 'atlas/client'
7
+
8
+ module Atlas
9
+ DEFAULT_ERROR_CODE = 1
10
+ LIST_ERROR_CODE = 2
11
+ CREATE_ERROR_CODE = 3
12
+ DELETE_ERROR_CODE = 4
13
+
14
+ ##
15
+ # class: Atlas::CLI: The command line interface class
16
+ class Peering < ::Thor
17
+ no_commands do
18
+ def handle_exit(response, exit_code = DEFAULT_ERROR_CODE)
19
+ if response.keys.include?('error')
20
+ exit(exit_code)
21
+ else
22
+ exit(0)
23
+ end
24
+ end
25
+
26
+ def out(response)
27
+ STDOUT.puts(::JSON.pretty_generate(response))
28
+ end
29
+
30
+ def die(exception, error_code)
31
+ STDERR.puts(exception.backtrace)
32
+ exit(error_code)
33
+ end
34
+ end
35
+
36
+ class_option :config, type: :string, aliases: ['-f'], desc: 'The configuration file'
37
+
38
+ desc 'version', 'Atlas peering CTL version'
39
+ def version
40
+ puts Atlas::VERSION
41
+ end
42
+
43
+ desc 'list', 'List all the Atlas MongoDB peerings for the configuration given'
44
+ def list
45
+ Config.configure(options[:config])
46
+
47
+ client = Client.new(Config.user_name, Config.api_key, Config.group_id)
48
+ response = client.list(Config).parsed_response
49
+ out(response)
50
+ handle_exit(response)
51
+ rescue StandardError => exception
52
+ die(exception, LIST_ERROR_CODE)
53
+ end
54
+
55
+ desc 'create', 'Create a new Atlas MongoDB peering connection based on the configuration given'
56
+ def create
57
+ Config.configure(options[:config])
58
+
59
+ client = Client.new(Config.user_name, Config.api_key, Config.group_id)
60
+ response = client.create(Config).parsed_response
61
+ out(response)
62
+ handle_exit(response)
63
+ rescue StandardError => exception
64
+ die(exception, CREATE_ERROR_CODE)
65
+ end
66
+
67
+ desc 'delete', 'Delete a Atlas MongoDB peering connection based on the configuration given'
68
+ def delete(id)
69
+ Config.configure(options[:config])
70
+ Config.configure { |c| c.id = id }
71
+
72
+ client = Client.new(Config.user_name, Config.api_key, Config.group_id)
73
+ response = client.delete(Config).parsed_response
74
+ handle_exit(response)
75
+ rescue StandardError => exception
76
+ die(exception, DELETE_ERROR_CODE)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'json'
5
+
6
+ module Atlas
7
+ ##
8
+ # class: Atlas::Client: The Atlas Mclient interface
9
+ class Client
10
+ DEFAULT_ATLAS_URL = 'https://cloud.mongodb.com/api/atlas/v1.0'
11
+ HEADERS = {
12
+ 'Content-Type' => 'application/json',
13
+ 'User-Agent' => 'Httparty'
14
+ }.freeze
15
+
16
+ def initialize(user_name, api_key, group_id)
17
+ @headers = HEADERS
18
+ @user_name = user_name
19
+ @api_key = api_key
20
+ @peers_endpoint = "#{DEFAULT_ATLAS_URL}/groups/#{group_id}/peers"
21
+
22
+ self
23
+ end
24
+
25
+ def basic_options
26
+ {
27
+ headers: @headers,
28
+ digest_auth: { username: @user_name, password: @api_key }
29
+ }
30
+ end
31
+
32
+ def list(_data = {})
33
+ HTTParty.get(@peers_endpoint, basic_options)
34
+ end
35
+
36
+ def create(data)
37
+ call_options = basic_options
38
+ call_options[:body] = {
39
+ "vpcId": data.vpc_id,
40
+ "awsAccountId": data.aws_account_id,
41
+ "routeTableCidrBlock": data.route_table_cidr_block,
42
+ "containerId": data.container_id
43
+ }.to_json
44
+
45
+ HTTParty.post(@peers_endpoint, call_options)
46
+ end
47
+
48
+ def delete(data)
49
+ HTTParty.delete("#{@peers_endpoint}/#{data.id}", basic_options)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Atlas
6
+ ##
7
+ # class: Atlas::Config: This class helps to handle configuration from YAML files
8
+ module Config
9
+ @config = nil
10
+
11
+ def self.config
12
+ @config ||= {}
13
+ end
14
+
15
+ def self.configure(source = nil)
16
+ config
17
+
18
+ case source
19
+ when /\.(yml|yaml)$/i then
20
+ raise StandardError.new("The configuration file: #{config_file} does not exist") unless File.exist?(source)
21
+
22
+ @config = ::YAML.safe_load(File.read(source))
23
+ else
24
+ yield self if block_given?
25
+ end
26
+
27
+ self
28
+ end
29
+
30
+ def self.inspect
31
+ config
32
+ @config.inspect
33
+ end
34
+
35
+ def self.[](key)
36
+ @config || Config.init
37
+ @config[key]
38
+ end
39
+
40
+ def self.fetch(key, default_value = nil)
41
+ config
42
+ if @config.keys.include?(key)
43
+ @config[key]
44
+ else
45
+ default_value
46
+ end
47
+ end
48
+
49
+ def self.respond_to_missing?
50
+ true
51
+ end
52
+
53
+ def self.method_missing(method, *arguments, &block)
54
+ config
55
+
56
+ method_str = method.to_s
57
+
58
+ case method_str
59
+ when /(.+)=$/ then
60
+ key = method_str.delete('=').to_sym
61
+ @config[key] = arguments.size == 1 ? arguments[0] : arguments
62
+ when /(.+)\?$/ then
63
+ key = method_str.delete('?').to_sym
64
+ @config.keys.include?(key)
65
+ else
66
+ if @config.keys.include?(method)
67
+ @config[method]
68
+ elsif @config.keys.include?(method_str)
69
+ @config[method_str]
70
+ else
71
+ super
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atlas_peering_ctl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Javier Juarez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.16.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.16.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.20.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.20.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.15'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.15'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.52'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.52'
125
+ - !ruby/object:Gem::Dependency
126
+ name: wirble
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: This cli helps to handle peering connectons with MongoDB Atlas service.
140
+ email:
141
+ - javier.juarez@gmail.com
142
+ executables:
143
+ - atlaspeeringctl
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".travis.yml"
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - atlas_peering_ctl.gemspec
156
+ - bin/console
157
+ - bin/setup
158
+ - config/my_config.yaml.example
159
+ - exe/atlaspeeringctl
160
+ - lib/atlas.rb
161
+ - lib/atlas/cli.rb
162
+ - lib/atlas/client.rb
163
+ - lib/atlas/config.rb
164
+ homepage: https://github.com/jjuarez/atlas_peering_ctl
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.6.14
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: This cli helps to handle peering connectons with MongoDB Atlas service.
188
+ test_files: []