atlas 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +22 -0
- data/atlas.gemspec +30 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/lib/atlas.rb +21 -0
- data/lib/atlas/box.rb +126 -0
- data/lib/atlas/box_provider.rb +75 -0
- data/lib/atlas/box_version.rb +114 -0
- data/lib/atlas/client.rb +47 -0
- data/lib/atlas/configuration.rb +42 -0
- data/lib/atlas/resource.rb +35 -0
- data/lib/atlas/url_builder.rb +42 -0
- data/lib/atlas/user.rb +27 -0
- data/lib/atlas/version.rb +4 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b556974cf8d489ffb377369aaa4ebc950bb56aa2
|
4
|
+
data.tar.gz: c502bf03db82b80088e13d03d9edfbb46e96813c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e41edd08e181ecd43b7373240850f624d21375a96f711423261de20a05f08a050de711e006f2cbb2fcc75e63652bb27f3efba551fe1fcb05135859f98de5ad58
|
7
|
+
data.tar.gz: 4cf2d46a3bcbf72f6d4c5084cbfa47a857b7b9c033554dd99c2490bcc64c2b7520b0d8eb07cc38f125bf0c498bae963d7cc0846ea912eadf979460312b6941c1
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Nick Charlton
|
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,60 @@
|
|
1
|
+
# atlas
|
2
|
+
|
3
|
+
Atlas is a Ruby client for [Hashicorp][]'s [Atlas][].
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'atlas'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install atlas
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
`atlas` uses an approach similar ActiveRecord:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# first, login with the token from Atlas
|
27
|
+
Atlas.configure do |config|
|
28
|
+
config.access_token = 'token'
|
29
|
+
end
|
30
|
+
|
31
|
+
# then you can load in users (creating, updating, etc isn't supported by Atlas)
|
32
|
+
user = Atlas::User.find('nickcharlton')
|
33
|
+
#=> <Atlas::User username=nickcharlton...>
|
34
|
+
|
35
|
+
# or access boxes, their versions and providers
|
36
|
+
box = Atlas::Box.find('nickcharlton/example-box')
|
37
|
+
#=> <Atlas::Box name=example-box'...>
|
38
|
+
|
39
|
+
# or create a new version
|
40
|
+
version = box.create(version: '1.0.0', description: 'A new box version.')
|
41
|
+
```
|
42
|
+
|
43
|
+
It aims to support most of the functionality listed in the [Atlas API
|
44
|
+
Documentation][].
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it ( https://github.com/nickcharlton/atlas-ruby/fork )
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create a new Pull Request
|
53
|
+
|
54
|
+
## Author
|
55
|
+
|
56
|
+
Copyright (c) 2015 Nick Charlton <nick@nickcharlton.net>
|
57
|
+
|
58
|
+
[Hashicorp]: https://www.hashicorp.com
|
59
|
+
[Atlas]: https://atlas.hashicorp.com
|
60
|
+
[Atlas API Documentation]: https://atlas.hashicorp.com/docs
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'bundler/gem_tasks'
|
10
|
+
|
11
|
+
##
|
12
|
+
# Configure the test suite.
|
13
|
+
##
|
14
|
+
require 'rspec/core'
|
15
|
+
require 'rspec/core/rake_task'
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new
|
18
|
+
|
19
|
+
##
|
20
|
+
# By default, just run the tests.
|
21
|
+
##
|
22
|
+
task default: :spec
|
data/atlas.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'atlas/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'atlas'
|
8
|
+
spec.version = Atlas::VERSION
|
9
|
+
spec.authors = ['Nick Charlton']
|
10
|
+
spec.email = ['nick@nickcharlton.net']
|
11
|
+
|
12
|
+
spec.summary = 'A client for Hashicorp\'s Atlas.'
|
13
|
+
spec.description = 'A client for Hashicorp\'s Atlas.'
|
14
|
+
spec.homepage = 'https://github.com/nickcharlton/atlas'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'excon', '~> 0.45'
|
23
|
+
spec.add_dependency 'json', '~> 1.8'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'vcr', '~> 2.9'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
end
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/atlas.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'atlas/version'
|
5
|
+
require 'atlas/configuration'
|
6
|
+
require 'atlas/url_builder'
|
7
|
+
require 'atlas/client'
|
8
|
+
require 'atlas/resource'
|
9
|
+
require 'atlas/box_provider'
|
10
|
+
require 'atlas/box_version'
|
11
|
+
require 'atlas/box'
|
12
|
+
require 'atlas/user'
|
13
|
+
|
14
|
+
# Toolkit for working with Hashicorp's Atlas.
|
15
|
+
module Atlas
|
16
|
+
attr_accessor :client
|
17
|
+
|
18
|
+
def self.client
|
19
|
+
@client ||= Client.new(access_token: configuration.access_token)
|
20
|
+
end
|
21
|
+
end
|
data/lib/atlas/box.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
module Atlas
|
2
|
+
# Representation and handling of Box objects.
|
3
|
+
#
|
4
|
+
# @attr_accessor [String] name The name of the box
|
5
|
+
# @attr_accessor [String] username The owner of the box
|
6
|
+
# @attr_accessor [String] short_description A short version of the
|
7
|
+
# description.
|
8
|
+
# @attr_accessor [String] description Markdown text used to describe it.
|
9
|
+
# @attr_accessor [Boolean] is_private A boolean if the box is private.
|
10
|
+
# @attr_accessor [Version] current_version the current version of this box.
|
11
|
+
# @attr_accessor [Array] versions versions associated with this box.
|
12
|
+
class Box < Resource
|
13
|
+
attr_accessor :name, :username, :short_description, :description,
|
14
|
+
:is_private, :current_version, :versions
|
15
|
+
|
16
|
+
# Find a box by it's tag.
|
17
|
+
#
|
18
|
+
# @param [String] tag the tag of the box.
|
19
|
+
#
|
20
|
+
# @return [Box] a representation of the box.
|
21
|
+
def self.find(tag)
|
22
|
+
url_builder = UrlBuilder.new tag
|
23
|
+
response = Atlas.client.get(url_builder.box_url)
|
24
|
+
|
25
|
+
new(tag, JSON.parse(response.body))
|
26
|
+
end
|
27
|
+
|
28
|
+
# Create a new Box.
|
29
|
+
#
|
30
|
+
# @param [Hash] attr attributes to create the box with
|
31
|
+
# @param attr [String] :name The name of the box, used to identify it.
|
32
|
+
# @option attr [String] :username The username to assign the box to.
|
33
|
+
# @option attr [String] :short_description The short description is used on
|
34
|
+
# small box previews.
|
35
|
+
# @option attr [String] :description Markdown text used as a full-length and
|
36
|
+
# in-depth description of the box.
|
37
|
+
# @option attr [Boolean] :is_private A boolean if the box should be private
|
38
|
+
# or not.
|
39
|
+
#
|
40
|
+
# @return [Box] a newly created box.
|
41
|
+
def self.create(attr = {})
|
42
|
+
tag = "#{attr.fetch(:username, '')}/#{attr[:name]}"
|
43
|
+
box = new(tag, attr)
|
44
|
+
box.save
|
45
|
+
box
|
46
|
+
end
|
47
|
+
|
48
|
+
# Initialize a box from a tag and object hash.
|
49
|
+
#
|
50
|
+
# @param [String] tag the tag which represents the origin of the box.
|
51
|
+
# @param [Hash] hash the attributes for the box
|
52
|
+
# @param hash [String] :name The name of the box, used to identify it.
|
53
|
+
# @option hash [String] :username The username to assign the box to.
|
54
|
+
# @option hash [String] :short_description The short description is used on
|
55
|
+
# small box previews.
|
56
|
+
# @option hash [String] :description Markdown text used as a full-length and
|
57
|
+
# in-depth description of the box.
|
58
|
+
# @option hash [Boolean] :is_private A boolean if the box should be private
|
59
|
+
# or not.
|
60
|
+
#
|
61
|
+
# @return [Box] a new box object.
|
62
|
+
def initialize(tag, hash = {})
|
63
|
+
hash['is_private'] = hash['private']
|
64
|
+
hash['description'] = hash['description_markdown']
|
65
|
+
|
66
|
+
super(tag, hash)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Assign the current version.
|
70
|
+
#
|
71
|
+
# @note This is intended to be used to assign the response object, not
|
72
|
+
# calling directly. Calling `release` will set the `current_version`.
|
73
|
+
#
|
74
|
+
# @param [Hash] attr a response hash of a `BoxVersion`.
|
75
|
+
def current_version=(attr)
|
76
|
+
if attr.is_a? Hash
|
77
|
+
@current_version = BoxVersion.new("#{tag}/#{attr['version']}", attr)
|
78
|
+
else
|
79
|
+
@current_version = attr
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Assign the versions of this box.
|
84
|
+
#
|
85
|
+
# @note This is intended to be used to assign the response object, not
|
86
|
+
# calling directly. You could do something unexpected by replacing this.
|
87
|
+
#
|
88
|
+
# @param [Array] attr an array of responses hashes.
|
89
|
+
def versions=(attr)
|
90
|
+
@versions = attr.collect do |v|
|
91
|
+
BoxVersion.new("#{tag}/#{v['version']}", v)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Save the box.
|
96
|
+
#
|
97
|
+
# @return [Hash] Atlas response object.
|
98
|
+
def save
|
99
|
+
body = { box: to_hash }
|
100
|
+
|
101
|
+
# versions are saved seperately
|
102
|
+
body[:box].delete(:versions)
|
103
|
+
|
104
|
+
# update or create the box
|
105
|
+
begin
|
106
|
+
response = Atlas.client.put(url_builder.box_url, body: body)
|
107
|
+
rescue Excon::Errors::NotFound
|
108
|
+
response = Atlas.client.post('/boxes', body: body)
|
109
|
+
end
|
110
|
+
|
111
|
+
# trigger the same on versions
|
112
|
+
versions.each(&:save) if versions
|
113
|
+
|
114
|
+
update_with_response(response.body, [:versions])
|
115
|
+
end
|
116
|
+
|
117
|
+
# Delete the box.
|
118
|
+
#
|
119
|
+
# @return [Hash] response body from Atlas.
|
120
|
+
def delete
|
121
|
+
response = Atlas.client.delete(url_builder.box_url)
|
122
|
+
|
123
|
+
JSON.parse(response.body)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Atlas
|
2
|
+
# Representation and handling of Box Provider objects.
|
3
|
+
#
|
4
|
+
# @attr_accessor [String] name The name of the provider.
|
5
|
+
# @attr_accessor [String] download_url The url to download from.
|
6
|
+
class BoxProvider < Resource
|
7
|
+
attr_accessor :name, :download_url
|
8
|
+
|
9
|
+
# Find a provider by it's tag.
|
10
|
+
#
|
11
|
+
# @param [String] tag the tag of the provider.
|
12
|
+
#
|
13
|
+
# @return [Provider] a representation of the provider.
|
14
|
+
def self.find(tag)
|
15
|
+
url_builder = UrlBuilder.new tag
|
16
|
+
response = Atlas.client.get(url_builder.box_provider_url)
|
17
|
+
|
18
|
+
new(tag, JSON.parse(response.body))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Create a new Provider.
|
22
|
+
#
|
23
|
+
# @param [String] box_version_tag the box version tag to create the provider
|
24
|
+
# under.
|
25
|
+
# @param [String] tag the tag which represents the origin on the provider.
|
26
|
+
# @param [Hash] hash the attributes for the box
|
27
|
+
# @param hash [String] :name The name of the provider.
|
28
|
+
# @param hash [String] :url An HTTP URL to the box file. Omit if uploading
|
29
|
+
# with Atlas.
|
30
|
+
def self.create(box_version_tag, attr = {})
|
31
|
+
tag = "#{box_version_tag}/#{attr[:name]}"
|
32
|
+
provider = new(tag, attr)
|
33
|
+
provider.save
|
34
|
+
provider
|
35
|
+
end
|
36
|
+
|
37
|
+
# Initialize a provider from a tag and object hash.
|
38
|
+
#
|
39
|
+
# @param [String] tag the tag which represents the origin on the provider.
|
40
|
+
# @param [Hash] hash the attributes for the box
|
41
|
+
# @param hash [String] :name The name of the provider.
|
42
|
+
# @param hash [String] :url An HTTP URL to the box file. Omit if uploading
|
43
|
+
# with Atlas.
|
44
|
+
def initialize(tag, hash = {})
|
45
|
+
hash[:url] = hash[:download_url]
|
46
|
+
|
47
|
+
super(tag, hash)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Save the provider.
|
51
|
+
#
|
52
|
+
# @return [Hash] Atlas response object.
|
53
|
+
def save
|
54
|
+
body = { provider: to_hash }
|
55
|
+
|
56
|
+
begin
|
57
|
+
response = Atlas.client.put(url_builder.box_provider_url, body: body)
|
58
|
+
rescue Excon::Errors::NotFound
|
59
|
+
response = Atlas.client.post("#{url_builder.box_version_url}/providers",
|
60
|
+
body: body)
|
61
|
+
end
|
62
|
+
|
63
|
+
update_with_response(response.body)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Delete the provider.
|
67
|
+
#
|
68
|
+
# @return [Hash] Atlas response object.
|
69
|
+
def delete
|
70
|
+
response = Atlas.client.delete(url_builder.box_provider_url)
|
71
|
+
|
72
|
+
JSON.parse(response.body)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Atlas
|
2
|
+
# Representation and handling of Box Version objects.
|
3
|
+
#
|
4
|
+
# @attr_accessor [String] version The version number.
|
5
|
+
# @attr_accessor [String] description Markdown test used as a full-length and
|
6
|
+
# in-depth description of the version.
|
7
|
+
# @attr_accessor [String] status The status of the version
|
8
|
+
# (unreleased/releases) (cannot be set directly)
|
9
|
+
# @attr_accessor [Array] providers The providers associated with this version.
|
10
|
+
class BoxVersion < Resource
|
11
|
+
# Properties of the version.
|
12
|
+
attr_accessor :version, :description, :status, :providers
|
13
|
+
|
14
|
+
# Find a version by it's tag.
|
15
|
+
#
|
16
|
+
# @param [String] tag the tag of the version.
|
17
|
+
#
|
18
|
+
# @return [Version] a representation of the version.
|
19
|
+
def self.find(tag)
|
20
|
+
url_builder = UrlBuilder.new tag
|
21
|
+
response = Atlas.client.get(url_builder.box_version_url)
|
22
|
+
|
23
|
+
new(tag, JSON.parse(response.body))
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create a new version.
|
27
|
+
#
|
28
|
+
# @param [String] box_tag the box tag to create the version under.
|
29
|
+
# @param [Hash] attr attributes to create the version with.
|
30
|
+
# @param attr [String] :version The version number.
|
31
|
+
# @param attr [String] :description Description of the box.
|
32
|
+
#
|
33
|
+
# @return [Version] a newly created version.
|
34
|
+
def self.create(box_tag, attr = {})
|
35
|
+
tag = "#{box_tag}/#{attr[:version]}"
|
36
|
+
version = new(tag, attr)
|
37
|
+
version.save
|
38
|
+
version
|
39
|
+
end
|
40
|
+
|
41
|
+
# Initialize a version from a versiontag and object hash.
|
42
|
+
#
|
43
|
+
# @param [String] tag the tag which represents the origin of the version.
|
44
|
+
# @param [Hash] hash the attributes for the version.
|
45
|
+
# @param attr [String] :version The version number.
|
46
|
+
# @param attr [String] :description Description of the box.
|
47
|
+
def initialize(tag, hash = {})
|
48
|
+
hash['description'] = hash['description_markdown']
|
49
|
+
|
50
|
+
super(tag, hash)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Assign the providers of this version.
|
54
|
+
#
|
55
|
+
# @note This is intended to be used to assign the response object, not
|
56
|
+
# calling directly.
|
57
|
+
#
|
58
|
+
# @param [Array] attr an array of response hashes.
|
59
|
+
def providers=(attr)
|
60
|
+
@providers = attr.collect do |v|
|
61
|
+
BoxProvider.new("#{tag}/#{v['name']}", v)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Save the version.
|
66
|
+
#
|
67
|
+
# @return [Hash] Atlas response object.
|
68
|
+
def save # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
69
|
+
body = { version: to_hash }
|
70
|
+
|
71
|
+
# providers are saved seperately
|
72
|
+
body[:version].delete(:providers)
|
73
|
+
|
74
|
+
begin
|
75
|
+
response = Atlas.client.put(url_builder.box_version_url, body: body)
|
76
|
+
rescue Excon::Errors::NotFound
|
77
|
+
response = Atlas.client.post("#{url_builder.box_url}/versions",
|
78
|
+
body: body)
|
79
|
+
end
|
80
|
+
|
81
|
+
# trigger the same on the providers
|
82
|
+
providers.each(&:save) if providers
|
83
|
+
|
84
|
+
update_with_response(response.body, [:providers])
|
85
|
+
end
|
86
|
+
|
87
|
+
# Release the version.
|
88
|
+
#
|
89
|
+
# @return [Hash] Atlas response object.
|
90
|
+
def release
|
91
|
+
response = Atlas.client.put("#{url_builder.box_version_url}/release")
|
92
|
+
|
93
|
+
update_with_response(response.body)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Revoke the version.
|
97
|
+
#
|
98
|
+
# @return [Hash] Atlas response object.
|
99
|
+
def revoke
|
100
|
+
response = Atlas.client.put("#{url_builder.box_version_url}/revoke")
|
101
|
+
|
102
|
+
update_with_response(response.body)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Delete the version.
|
106
|
+
#
|
107
|
+
# @return [Hash] Atlas response object.
|
108
|
+
def delete
|
109
|
+
response = Atlas.client.delete(url_builder.box_version_url)
|
110
|
+
|
111
|
+
JSON.parse(response.body)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/atlas/client.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Atlas
|
2
|
+
# Client for interacting with the Atlas API.
|
3
|
+
class Client
|
4
|
+
DEFAULT_HEADERS = { 'User-Agent' => "Atlas-Ruby/#{Atlas::VERSION}",
|
5
|
+
'Content-Type' => 'application/json' }
|
6
|
+
|
7
|
+
attr_accessor :url
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
@url = opts[:url] || 'https://atlas.hashicorp.com'
|
11
|
+
@access_token = opts[:access_token]
|
12
|
+
end
|
13
|
+
|
14
|
+
%w(get put post delete).each do |m|
|
15
|
+
define_method m do |path, opts = {}|
|
16
|
+
request(m.to_sym, path, opts)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def request(method, path, opts = {})
|
23
|
+
body, query, headers = parse_opts(opts)
|
24
|
+
|
25
|
+
# set the default headers
|
26
|
+
headers.merge!(DEFAULT_HEADERS)
|
27
|
+
|
28
|
+
# set the access token
|
29
|
+
query.merge!(access_token: @access_token)
|
30
|
+
|
31
|
+
connection = Excon.new(@url)
|
32
|
+
connection.request(expects: [200, 201], method: method,
|
33
|
+
path: "/api/v1#{path}", body: body, query: query,
|
34
|
+
headers: headers)
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_opts(opts)
|
38
|
+
body = opts.fetch(:body, nil)
|
39
|
+
body = JSON.dump(body) if body && body.is_a?(Hash)
|
40
|
+
|
41
|
+
query = opts.fetch(:query, {})
|
42
|
+
headers = opts.fetch(:headers, {})
|
43
|
+
|
44
|
+
[body, query, headers]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Atlas
|
2
|
+
# Configuration handling for Atlas.
|
3
|
+
class Configuration
|
4
|
+
# Access token for Atlas
|
5
|
+
attr_accessor :access_token
|
6
|
+
|
7
|
+
# Create a new Configuration instance
|
8
|
+
#
|
9
|
+
# This also allows providing a hash of configuration values, which calls
|
10
|
+
# the accessor methods to full in the values.
|
11
|
+
def initialize(opts = {})
|
12
|
+
opts.each do |k, v|
|
13
|
+
send("#{k}=".to_sym, v)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Hash representation of the configuration object.
|
18
|
+
def to_h
|
19
|
+
{ access_token: @access_token }
|
20
|
+
end
|
21
|
+
|
22
|
+
# String representation of the configuration.
|
23
|
+
def to_s
|
24
|
+
objects = to_h.collect { |k, v| "#{k}=#{v}" }.join(' ')
|
25
|
+
"#<#{self.class.name}:#{object_id} #{objects}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
attr_accessor :configuration
|
31
|
+
end
|
32
|
+
|
33
|
+
# Support for a configuration block.
|
34
|
+
def self.configure
|
35
|
+
yield configuration if block_given?
|
36
|
+
end
|
37
|
+
|
38
|
+
# The default configuration object.
|
39
|
+
def self.configuration
|
40
|
+
@configuration ||= Configuration.new
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Atlas
|
2
|
+
# Base class for representing resources.
|
3
|
+
class Resource
|
4
|
+
attr_accessor :tag, :url_builder
|
5
|
+
|
6
|
+
def initialize(tag, hash = {})
|
7
|
+
@tag = tag
|
8
|
+
@url_builder = UrlBuilder.new tag
|
9
|
+
|
10
|
+
hash.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_with_response(o, except_keys = [])
|
14
|
+
hash = JSON.parse(o)
|
15
|
+
|
16
|
+
# remove keys that shouldn't be included
|
17
|
+
except_keys.each { |k| hash.delete(k) }
|
18
|
+
|
19
|
+
hash.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
attrs = instance_variables.collect do |v|
|
24
|
+
%w(@tag @url_builder).include?(v.to_s) ? next : v.to_s.sub(/^@/, '')
|
25
|
+
end.compact!
|
26
|
+
|
27
|
+
Hash[attrs.select { |v| respond_to? v }.map { |v| [v.to_sym, send(v)] }]
|
28
|
+
end
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
objects = to_hash.map { |k, v| "#{k}=#{v.inspect}" }.join(' ')
|
32
|
+
"#<#{self.class.name}:#{object_id} #{objects}>"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Atlas
|
2
|
+
# A class which takes (and extends) Atlas tags and builds URLs from them.
|
3
|
+
#
|
4
|
+
# This allows us to refer to items using the same identifiers as Vagrant, with
|
5
|
+
# a few extras.
|
6
|
+
class UrlBuilder
|
7
|
+
attr_reader :tag
|
8
|
+
|
9
|
+
def self.url_for(user = nil, box = nil, version = nil, provider = nil)
|
10
|
+
url = ''
|
11
|
+
|
12
|
+
if user && !box
|
13
|
+
return "/user/#{user}"
|
14
|
+
else
|
15
|
+
url << "/box/#{user}"
|
16
|
+
end
|
17
|
+
|
18
|
+
url << "/#{box}" if box
|
19
|
+
url << "/version/#{version}" if version
|
20
|
+
url << "/provider/#{provider}" if provider
|
21
|
+
|
22
|
+
url
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(tag)
|
26
|
+
user, box, version, provider = tag.split(%r{\/})
|
27
|
+
|
28
|
+
@tag = { user: user, box: box, version: version, provider: provider }
|
29
|
+
end
|
30
|
+
|
31
|
+
{ user: [:user],
|
32
|
+
box: [:user, :box],
|
33
|
+
box_version: [:user, :box, :version],
|
34
|
+
box_provider: [:user, :box, :version, :provider] }.each do |m, a|
|
35
|
+
define_method "#{m}_url" do
|
36
|
+
a.each { |e| return nil unless tag[e] }
|
37
|
+
|
38
|
+
UrlBuilder.url_for(*tag.values_at(*a))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/atlas/user.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Atlas
|
2
|
+
# Representation and handling of User objects.
|
3
|
+
class User < Resource
|
4
|
+
attr_accessor :username, :avatar_url, :profile
|
5
|
+
|
6
|
+
def self.find(tag)
|
7
|
+
url_builder = UrlBuilder.new(tag)
|
8
|
+
response = Atlas.client.get(url_builder.user_url)
|
9
|
+
|
10
|
+
new(tag, JSON.parse(response.body))
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(tag, hash = {})
|
14
|
+
hash['profile'] = hash['profile_markdown']
|
15
|
+
|
16
|
+
super(tag, hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
def boxes
|
20
|
+
@boxes ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
def boxes=(hash)
|
24
|
+
@boxes = hash.collect { |v| Box.new("#{username}/#{v['name']}", v) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: atlas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Charlton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.45'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.45'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A client for Hashicorp's Atlas.
|
112
|
+
email:
|
113
|
+
- nick@nickcharlton.net
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- CODE_OF_CONDUCT.md
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- atlas.gemspec
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- lib/atlas.rb
|
128
|
+
- lib/atlas/box.rb
|
129
|
+
- lib/atlas/box_provider.rb
|
130
|
+
- lib/atlas/box_version.rb
|
131
|
+
- lib/atlas/client.rb
|
132
|
+
- lib/atlas/configuration.rb
|
133
|
+
- lib/atlas/resource.rb
|
134
|
+
- lib/atlas/url_builder.rb
|
135
|
+
- lib/atlas/user.rb
|
136
|
+
- lib/atlas/version.rb
|
137
|
+
homepage: https://github.com/nickcharlton/atlas
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.4.5
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: A client for Hashicorp's Atlas.
|
161
|
+
test_files: []
|