docker_cloud 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +43 -0
  5. data/.travis.yml +4 -0
  6. data/CODE_OF_CONDUCT.md +49 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +81 -0
  10. data/Rakefile +6 -0
  11. data/docker_cloud.gemspec +31 -0
  12. data/lib/docker_cloud.rb +107 -0
  13. data/lib/docker_cloud/api/api.rb +57 -0
  14. data/lib/docker_cloud/api/availability_zone_api.rb +23 -0
  15. data/lib/docker_cloud/api/container_api.rb +38 -0
  16. data/lib/docker_cloud/api/external_repository_api.rb +34 -0
  17. data/lib/docker_cloud/api/node_api.rb +27 -0
  18. data/lib/docker_cloud/api/node_cluster_api.rb +46 -0
  19. data/lib/docker_cloud/api/node_type_api.rb +23 -0
  20. data/lib/docker_cloud/api/provider_api.rb +19 -0
  21. data/lib/docker_cloud/api/region_api.rb +24 -0
  22. data/lib/docker_cloud/api/registry_api.rb +19 -0
  23. data/lib/docker_cloud/api/service_api.rb +53 -0
  24. data/lib/docker_cloud/api/stack_api.rb +53 -0
  25. data/lib/docker_cloud/availability_zone.rb +19 -0
  26. data/lib/docker_cloud/container.rb +204 -0
  27. data/lib/docker_cloud/external_repository.rb +20 -0
  28. data/lib/docker_cloud/helpers.rb +33 -0
  29. data/lib/docker_cloud/node.rb +99 -0
  30. data/lib/docker_cloud/node_cluster.rb +67 -0
  31. data/lib/docker_cloud/node_type.rb +38 -0
  32. data/lib/docker_cloud/provider.rb +31 -0
  33. data/lib/docker_cloud/region.rb +28 -0
  34. data/lib/docker_cloud/registry.rb +27 -0
  35. data/lib/docker_cloud/service.rb +235 -0
  36. data/lib/docker_cloud/stack.rb +42 -0
  37. data/lib/docker_cloud/type.rb +19 -0
  38. data/lib/docker_cloud/version.rb +3 -0
  39. metadata +193 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59c2aefec9011edee7b419eff4d029878d02a2ce
4
+ data.tar.gz: 1c1e8e87a55587968b446d21e8d692cb748ec82a
5
+ SHA512:
6
+ metadata.gz: 16fd776a797fa45301fb0d48b04421bf969be06d4db2b07b0c04df84eb16bb4ca7d539a18f5cb292f7e43f4d0e18428bbd8b75b26c91328cf96783acc2ae8c94
7
+ data.tar.gz: 6434be0c98ded603d0c0a472cb1eeb38131f4faab64d1176b81a2a7017922d92ecddbd44fbdd4589883293449f0c2c9c5cc298e8cb0fdf0244c6578db7f8b9a0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,43 @@
1
+ AllCops:
2
+ Exclude:
3
+ - tmp/**/*
4
+ - db/**/*
5
+ - vendor/**/*
6
+ - bin/**
7
+ - Guardfile
8
+
9
+ Rails:
10
+ Enabled: true
11
+
12
+ ClassLength:
13
+ Max: 300
14
+
15
+ MethodLength:
16
+ Max: 50
17
+
18
+ Documentation:
19
+ Enabled: false
20
+
21
+ Metrics/LineLength:
22
+ Enabled: false
23
+
24
+ Metrics/AbcSize:
25
+ Max: 38
26
+
27
+ Style/IfUnlessModifier:
28
+ Enabled: false
29
+
30
+ Rails/HasAndBelongsToMany:
31
+ Enabled: false
32
+
33
+ GuardClause:
34
+ Enabled: false
35
+
36
+ Style/AlignParameters:
37
+ EnforcedStyle: with_fixed_indentation
38
+
39
+ Style/ClosingParenthesisIndentation:
40
+ Enabled: false
41
+
42
+ Style/StringLiterals:
43
+ EnforcedStyle: single_quotes
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at tullo_jillian@bah.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docker_cloud.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 jillianntulloADM
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,81 @@
1
+ # DockerCloud
2
+
3
+ This gem is a ruby implementation of the [Docker Cloud HTTP REST API](https://docs.docker.com/apidocs/docker-cloud/#introduction).
4
+
5
+ DockerCloud is not compatible with the TutumAPI. Credit to [ruby-tutum](https://github.com/tutumcloud/ruby-tutum) which much of this
6
+ code has been based off of.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'docker_cloud'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install docker_cloud
23
+
24
+ ## Usage
25
+
26
+ Getting Started:
27
+ ```ruby
28
+ # Authenticate your ruby client with a usernamme and api_key
29
+ client = DockerCloud::Client.new(username, api_key)
30
+
31
+ # Providers
32
+ provider = client.providers
33
+
34
+ # List all providers
35
+ provider.all
36
+
37
+ # Get a provider by name
38
+ provider.get('digitalocean')
39
+
40
+ # Regions
41
+ regions = client.regions
42
+
43
+ # List all regions
44
+ regions.all
45
+
46
+ # Get a particular region
47
+ # regions.get(<provider_name>, <region_name>)
48
+ # example:
49
+ regions.get('softlayer', 'ams03')
50
+
51
+ # Availability Zones
52
+ az = client.availability_zones
53
+
54
+ # List all AZ
55
+ az.all
56
+
57
+ # Get a particular AZ
58
+ # az.get(<provider name>, <region name>, <az name>)
59
+ # example:
60
+ az.get('softlayer', 'ams03', 'ap-northeast-1a')
61
+
62
+ # Node Types
63
+ node_types = client.node_types
64
+
65
+ # List all Node Types
66
+ node_types.all
67
+
68
+ # Get a node type
69
+ # node_types.get(<provider_name>, <name>)
70
+ node_types.get('softlayer', '1x2.0GHzCore-2GB')
71
+ ```
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jntullo/ruby-docker-cloud. 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.
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
81
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -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 'docker_cloud/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'docker_cloud'
8
+ spec.version = DockerCloud::VERSION
9
+ spec.authors = ['Jillian Tullo']
10
+ spec.email = ['jillian.tullo@gmail.com']
11
+
12
+ spec.summary = 'Ruby wrapper for the Docker Cloud HTTP REST API'
13
+ spec.description = 'Ruby implementation of the HTTP REST API'
14
+ spec.homepage = 'https://github.com/jntullo/ruby-docker-cloud'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'rest-client', '~> 1.8.0'
23
+ spec.add_runtime_dependency 'json', '~> 1.8.1'
24
+
25
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.1'
26
+ spec.add_development_dependency 'rspec', '~> 3.1.0'
27
+ spec.add_development_dependency 'rake', '~> 10.3.2'
28
+ spec.add_development_dependency 'wrong', '~> 0.7.1'
29
+ spec.add_development_dependency 'pry', '~> 0.10.1'
30
+ spec.add_development_dependency 'webmock', '~> 1.21'
31
+ end
@@ -0,0 +1,107 @@
1
+ # types
2
+ require 'docker_cloud/helpers'
3
+ require 'docker_cloud/type'
4
+ require 'docker_cloud/availability_zone'
5
+ require 'docker_cloud/version'
6
+ require 'docker_cloud/container'
7
+ require 'docker_cloud/provider'
8
+ require 'docker_cloud/region'
9
+ require 'docker_cloud/node_type'
10
+ require 'docker_cloud/external_repository'
11
+ require 'docker_cloud/registry'
12
+ require 'docker_cloud/stack'
13
+ require 'docker_cloud/node'
14
+ require 'docker_cloud/node_cluster'
15
+ require 'docker_cloud/service'
16
+
17
+ # api clients
18
+ require 'docker_cloud/api/api'
19
+ require 'docker_cloud/api/provider_api'
20
+ require 'docker_cloud/api/region_api'
21
+ require 'docker_cloud/api/availability_zone_api'
22
+ require 'docker_cloud/api/node_type_api'
23
+ require 'docker_cloud/api/node_cluster_api'
24
+ require 'docker_cloud/api/node_api'
25
+ require 'docker_cloud/api/external_repository_api'
26
+ require 'docker_cloud/api/service_api'
27
+ require 'docker_cloud/api/container_api'
28
+ require 'docker_cloud/api/stack_api'
29
+ require 'docker_cloud/api/registry_api'
30
+
31
+ module DockerCloud
32
+ class Client
33
+ attr_reader :username
34
+
35
+ class ApiType
36
+ INFRASTRUCTURE = 'infra'.freeze
37
+ REPOSITORY = 'repo'.freeze
38
+ APPLICATION = 'app'.freeze
39
+ end
40
+
41
+ def initialize(username, api_key)
42
+ @username = username
43
+ @api_key = api_key
44
+ end
45
+
46
+ def headers
47
+ {
48
+ 'Authorization' => authorization,
49
+ 'Accept' => 'application/json',
50
+ 'Content-Type' => 'application/json'
51
+ }
52
+ end
53
+
54
+ def providers
55
+ @providers ||= DockerCloud::ProviderAPI.new(headers, ApiType::INFRASTRUCTURE, self)
56
+ end
57
+
58
+ def regions
59
+ @regions ||= DockerCloud::RegionAPI.new(headers, ApiType::INFRASTRUCTURE, self)
60
+ end
61
+
62
+ def availability_zones
63
+ @availability_zones ||= DockerCloud::AvailabilityZoneAPI.new(headers, ApiType::INFRASTRUCTURE, self)
64
+ end
65
+
66
+ def node_types
67
+ @node_types ||= DockerCloud::NodeTypeAPI.new(headers, ApiType::INFRASTRUCTURE, self)
68
+ end
69
+
70
+ def node_clusters
71
+ @node_clusters ||= DockerCloud::NodeClusterAPI.new(headers, ApiType::INFRASTRUCTURE, self)
72
+ end
73
+
74
+ def nodes
75
+ @nodes ||= DockerCloud::NodeAPI.new(headers, ApiType::INFRASTRUCTURE, self)
76
+ end
77
+
78
+ def registries
79
+ @registries ||= DockerCloud::RegistryAPI.new(headers, ApiType::REPOSITORY, self)
80
+ end
81
+
82
+ def external_repositories
83
+ @repositories ||=
84
+ DockerCloud::ExternalRepositoryAPI.new(headers, ApiType::REPOSITORY, self)
85
+ end
86
+
87
+ def stacks
88
+ @stacks ||= DockerCloud::StackAPI.new(headers, ApiType::APPLICATION, self)
89
+ end
90
+
91
+ def services
92
+ @services ||= DockerCloud::ServiceAPI.new(headers, ApiType::APPLICATION, self)
93
+ end
94
+
95
+ def containers
96
+ @containers ||= DockerCloud::ContainerAPI.new(headers, ApiType::APPLICATION, self)
97
+ end
98
+
99
+ private
100
+
101
+ attr_reader :api_key
102
+
103
+ def authorization
104
+ @auth ||= "Basic #{Base64.strict_encode64(@username + ':' + api_key)}"
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,57 @@
1
+ require 'rest-client'
2
+
3
+ module DockerCloud
4
+ class API
5
+ include DockerCloud::Helpers
6
+ attr_reader :headers, :type, :client
7
+
8
+ BASE_API_PATH = 'https://cloud.docker.com/api'.freeze
9
+ API_VERSION = 'v1'.freeze
10
+
11
+ def initialize(headers, type, client)
12
+ @headers = headers
13
+ @type = type
14
+ @client = client
15
+ end
16
+
17
+ def url(path)
18
+ BASE_API_PATH + '/' + @type + '/' + API_VERSION + path
19
+ end
20
+
21
+ def http_get(path, params = {})
22
+ query = '?' + params.map { |k, v| "#{k}=#{v}" }.join('&')
23
+ full_path = path
24
+ full_path += query unless params.empty?
25
+ response = RestClient.get(url(full_path), headers)
26
+ parse(response)
27
+ end
28
+
29
+ def http_post(path, content = {})
30
+ response = RestClient.post(url(path), content.to_json, headers)
31
+ parse(response)
32
+ end
33
+
34
+ def http_patch(path, content = {})
35
+ response = RestClient.patch(url(path), content.to_json, headers)
36
+ parse(response)
37
+ end
38
+
39
+ def http_delete(path)
40
+ response = RestClient.delete(url(path), headers)
41
+ parse(response)
42
+ end
43
+
44
+ def parse(response)
45
+ hash = JSON.parse(response, symbolize_names: true)
46
+ hash.delete(:meta)
47
+ hash[:objects].nil? ? hash : hash[:objects]
48
+ end
49
+
50
+ def get_from_uri(uri)
51
+ uri = BASE_API_PATH + uri.split('/api')[1]
52
+ response = RestClient.get(uri, headers)
53
+ response = parse(response)
54
+ format_object(response, self.class::TYPE)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ module DockerCloud
2
+ class AvailabilityZoneAPI < DockerCloud::API
3
+ TYPE = 'AvailabilityZone'.freeze
4
+ def resource_url(zone = '')
5
+ "/az/#{zone}"
6
+ end
7
+
8
+ # Lists all availability zones from all regions of supported cloud providers
9
+ # Returns a list of Availability Zone objects
10
+ def all(params = {})
11
+ response = http_get(resource_url, params)
12
+ format_object(response, TYPE)
13
+ end
14
+
15
+ # Gets all the details of a specific region for a specific provider
16
+ # Returns a Region object
17
+ def get(provider_name, region_name, az_name)
18
+ provider_az = "#{provider_name}/#{region_name}/#{az_name}"
19
+ response = http_get(resource_url(provider_az))
20
+ format_object(response, TYPE)
21
+ end
22
+ end
23
+ end