atlas 1.6.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/CHANGELOG.md +26 -0
- data/README.md +8 -3
- data/lib/atlas.rb +3 -1
- data/lib/atlas/box.rb +10 -4
- data/lib/atlas/box_provider.rb +2 -0
- data/lib/atlas/box_version.rb +3 -3
- data/lib/atlas/client.rb +4 -2
- data/lib/atlas/configuration.rb +17 -4
- data/lib/atlas/errors.rb +3 -0
- data/lib/atlas/mixins/validations.rb +33 -0
- data/lib/atlas/resource.rb +12 -7
- data/lib/atlas/version.rb +1 -1
- data/lib/core_ext/hash_replace_key.rb +17 -0
- metadata +4 -3
- data/.codeclimate.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2327ab72bc81334bee756f79d747dbcbb7aaf69e
|
4
|
+
data.tar.gz: 82d266882fc5c21eb533f13b89731f630c36aa08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a270dac6c5bcbbe5e5f0c5b62706b9ff40c870761ecffe17951bc9983878d153fa4db5631ef509fa36337453843e0b912bec00d661381392bd1ca7bd077abdd4
|
7
|
+
data.tar.gz: 83000712484128862ea561ed0fc7ff7fa80aba86390bc08c2dd42e565c646e3bbd2baf6cd7662e2cae9b9edd788a10d694269779bc243cc6c48c19342b2e883c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.0.0 (07/04/2018)
|
4
|
+
|
5
|
+
_**WARNING**: This will be the last major release of this gem. I recommend
|
6
|
+
using [hashicorp/vagrant_cloud](https://github.com/hashicorp/vagrant_cloud) as
|
7
|
+
it's maintained by HashiCorp._
|
8
|
+
|
9
|
+
* Use headers, not query arguments for the token ([#23][]).
|
10
|
+
* Deprecate the `access_token` configuration option ([#23][]).
|
11
|
+
* Refresh cassettes ([#16][], [#17][], [#18][], [#19][], [#20][], [#21][],
|
12
|
+
[#22][]).
|
13
|
+
* Implement validations for required attributes ([#14][]).
|
14
|
+
* Improve `date_accessor` specs ([#13][]).
|
15
|
+
* Rename keys in-place to avoid assigning nil ([#12][]).
|
16
|
+
|
17
|
+
[#12]: https://github.com/nickcharlton/atlas-ruby/pull/12
|
18
|
+
[#13]: https://github.com/nickcharlton/atlas-ruby/pull/13
|
19
|
+
[#14]: https://github.com/nickcharlton/atlas-ruby/pull/14
|
20
|
+
[#16]: https://github.com/nickcharlton/atlas-ruby/pull/16
|
21
|
+
[#17]: https://github.com/nickcharlton/atlas-ruby/pull/17
|
22
|
+
[#18]: https://github.com/nickcharlton/atlas-ruby/pull/18
|
23
|
+
[#19]: https://github.com/nickcharlton/atlas-ruby/pull/19
|
24
|
+
[#20]: https://github.com/nickcharlton/atlas-ruby/pull/20
|
25
|
+
[#21]: https://github.com/nickcharlton/atlas-ruby/pull/21
|
26
|
+
[#22]: https://github.com/nickcharlton/atlas-ruby/pull/22
|
27
|
+
[#23]: https://github.com/nickcharlton/atlas-ruby/pull/23
|
28
|
+
|
3
29
|
## 1.6.0 (31/07/2016)
|
4
30
|
|
5
31
|
* Switch to use the new Atlas API URL ([#11][])
|
data/README.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
# atlas
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/nickcharlton/atlas-ruby.svg?branch=master)](https://travis-ci.org/nickcharlton/atlas-ruby)
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
_**WARNING**: 2.0.0 is the last major release of this gem. [Atlas became
|
6
|
+
Vagrant Cloud on 2017-06-30][announcement], because of this, the name makes
|
7
|
+
less sense than it did. Additionally, HashiCorp have their own gem:
|
8
|
+
[hashicorp/vagrant_cloud](https://github.com/hashicorp/vagrant_cloud)._
|
9
|
+
|
10
|
+
[announcement]: https://www.hashicorp.com/blog/vagrant-cloud-migration-announcement
|
6
11
|
|
7
12
|
Atlas is a Ruby client for [Hashicorp][]'s [Atlas][].
|
8
13
|
|
@@ -29,7 +34,7 @@ Or install it yourself as:
|
|
29
34
|
```ruby
|
30
35
|
# first, login with the token from Atlas
|
31
36
|
Atlas.configure do |config|
|
32
|
-
config.
|
37
|
+
config.token = "test-token"
|
33
38
|
end
|
34
39
|
|
35
40
|
# then you can load in users (creating, updating, etc isn't supported by Atlas)
|
data/lib/atlas.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'excon'
|
2
2
|
require 'json'
|
3
|
+
require "core_ext/hash_replace_key"
|
3
4
|
|
4
5
|
require 'atlas/version'
|
5
6
|
require 'atlas/configuration'
|
6
7
|
require 'atlas/url_builder'
|
7
8
|
require 'atlas/errors'
|
8
9
|
require 'atlas/client'
|
10
|
+
require "atlas/mixins/validations"
|
9
11
|
require 'atlas/resource'
|
10
12
|
require 'atlas/box_provider'
|
11
13
|
require 'atlas/box_version'
|
@@ -17,6 +19,6 @@ module Atlas
|
|
17
19
|
attr_accessor :client
|
18
20
|
|
19
21
|
def self.client
|
20
|
-
@client ||= Client.new(
|
22
|
+
@client ||= Client.new(token: configuration.token)
|
21
23
|
end
|
22
24
|
end
|
data/lib/atlas/box.rb
CHANGED
@@ -11,9 +11,11 @@ module Atlas
|
|
11
11
|
# @attr_accessor [Array] versions versions associated with this box.
|
12
12
|
class Box < Resource
|
13
13
|
attr_accessor :name, :username, :short_description, :description,
|
14
|
-
:
|
14
|
+
:private, :current_version, :versions
|
15
15
|
date_accessor :created_at, :updated_at
|
16
16
|
|
17
|
+
requires :username, :name, :short_description, :description
|
18
|
+
|
17
19
|
# Find a box by it's tag.
|
18
20
|
#
|
19
21
|
# @param [String] tag the tag of the box.
|
@@ -61,8 +63,8 @@ module Atlas
|
|
61
63
|
#
|
62
64
|
# @return [Box] a new box object.
|
63
65
|
def initialize(tag, hash = {})
|
64
|
-
hash
|
65
|
-
hash
|
66
|
+
hash.replace_key!("private", "is_private")
|
67
|
+
hash.replace_key!("description_markdown", "description")
|
66
68
|
|
67
69
|
super(tag, hash)
|
68
70
|
end
|
@@ -106,6 +108,8 @@ module Atlas
|
|
106
108
|
#
|
107
109
|
# @return [Hash] Atlas response object.
|
108
110
|
def save
|
111
|
+
validate!
|
112
|
+
|
109
113
|
body = { box: to_hash }
|
110
114
|
|
111
115
|
# versions are saved seperately
|
@@ -115,7 +119,9 @@ module Atlas
|
|
115
119
|
begin
|
116
120
|
response = Atlas.client.put(url_builder.box_url, body: body)
|
117
121
|
rescue Atlas::Errors::NotFoundError
|
118
|
-
|
122
|
+
body[:box].replace_key!(:private, :is_private)
|
123
|
+
|
124
|
+
response = Atlas.client.post("/boxes", body: body)
|
119
125
|
end
|
120
126
|
|
121
127
|
# trigger the same on versions
|
data/lib/atlas/box_provider.rb
CHANGED
data/lib/atlas/box_version.rb
CHANGED
@@ -12,6 +12,8 @@ module Atlas
|
|
12
12
|
attr_accessor :version, :description, :status, :providers
|
13
13
|
date_accessor :created_at, :updated_at
|
14
14
|
|
15
|
+
requires :version
|
16
|
+
|
15
17
|
# Find a version by it's tag.
|
16
18
|
#
|
17
19
|
# @param [String] tag the tag of the version.
|
@@ -46,9 +48,7 @@ module Atlas
|
|
46
48
|
# @param attr [String] :version The version number.
|
47
49
|
# @param attr [String] :description Description of the box.
|
48
50
|
def initialize(tag, hash = {})
|
49
|
-
|
50
|
-
hash['description'] = hash['description_markdown']
|
51
|
-
end
|
51
|
+
hash.replace_key!("description_markdown", "description")
|
52
52
|
|
53
53
|
super(tag, hash)
|
54
54
|
end
|
data/lib/atlas/client.rb
CHANGED
@@ -10,7 +10,7 @@ module Atlas
|
|
10
10
|
|
11
11
|
def initialize(opts = {})
|
12
12
|
@url = opts[:url] || 'https://app.vagrantup.com/'
|
13
|
-
@
|
13
|
+
@token = opts[:token]
|
14
14
|
end
|
15
15
|
|
16
16
|
%w(get put post delete).each do |m|
|
@@ -21,6 +21,8 @@ module Atlas
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
+
attr_reader :token
|
25
|
+
|
24
26
|
def request(method, path, opts = {}) # rubocop:disable AbcSize, MethodLength
|
25
27
|
body, query, headers = parse_opts(opts)
|
26
28
|
|
@@ -28,7 +30,7 @@ module Atlas
|
|
28
30
|
headers.merge!(DEFAULT_HEADERS)
|
29
31
|
|
30
32
|
# set the access token
|
31
|
-
|
33
|
+
headers["Authorization"] = "Bearer #{token}"
|
32
34
|
|
33
35
|
connection = Excon.new(@url)
|
34
36
|
response = connection.request(expects: [200, 201], method: method,
|
data/lib/atlas/configuration.rb
CHANGED
@@ -2,21 +2,27 @@ module Atlas
|
|
2
2
|
# Configuration handling for Atlas.
|
3
3
|
class Configuration
|
4
4
|
# Access token for Atlas
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :token
|
6
6
|
|
7
7
|
# Create a new Configuration instance
|
8
8
|
#
|
9
9
|
# This also allows providing a hash of configuration values, which calls
|
10
10
|
# the accessor methods to full in the values.
|
11
11
|
def initialize(opts = {})
|
12
|
-
opts.each do |
|
13
|
-
|
12
|
+
opts.each do |key, value|
|
13
|
+
if key.eql?(:access_token)
|
14
|
+
key = "token"
|
15
|
+
warn "WARNING: Setting the `:access_token` option is " \
|
16
|
+
"deprecated, use `:token` instead"
|
17
|
+
end
|
18
|
+
|
19
|
+
send("#{key}=".to_sym, value)
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
17
23
|
# Hash representation of the configuration object.
|
18
24
|
def to_h
|
19
|
-
{
|
25
|
+
{ token: @token }
|
20
26
|
end
|
21
27
|
|
22
28
|
# String representation of the configuration.
|
@@ -24,6 +30,13 @@ module Atlas
|
|
24
30
|
objects = to_h.collect { |k, v| "#{k}=#{v}" }.join(' ')
|
25
31
|
"#<#{self.class.name}:#{object_id} #{objects}"
|
26
32
|
end
|
33
|
+
|
34
|
+
def access_token=(access_token)
|
35
|
+
warn "WARNING: Setting the `:access_token` option is " \
|
36
|
+
"deprecated, use `:token` instead"
|
37
|
+
|
38
|
+
@token = access_token
|
39
|
+
end
|
27
40
|
end
|
28
41
|
|
29
42
|
class << self
|
data/lib/atlas/errors.rb
CHANGED
@@ -4,6 +4,9 @@ module Atlas
|
|
4
4
|
# Base error for all other gem errors.
|
5
5
|
class AtlasError < StandardError; end
|
6
6
|
|
7
|
+
# Raised when a resource cannot be validated.
|
8
|
+
class InvalidResourceError < AtlasError; end
|
9
|
+
|
7
10
|
# Raised when incorrect arguments are provided to a method.
|
8
11
|
class ArgumentError < AtlasError; end
|
9
12
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Atlas
|
2
|
+
module Validations
|
3
|
+
def self.included(base)
|
4
|
+
base.send(:include, InstanceMethods)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def validate!
|
10
|
+
missing = self.class.required_attributes[self.class.name].reject do |k|
|
11
|
+
to_hash.include?(k) && !to_hash[k].nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
if missing.any?
|
15
|
+
raise Atlas::Errors::InvalidResourceError,
|
16
|
+
"Missing attributes: #{missing.join(', ')}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
@@required_attributes = {}
|
23
|
+
|
24
|
+
def requires(*args)
|
25
|
+
args.each { |attr| (@@required_attributes[name] ||= []) << attr }
|
26
|
+
end
|
27
|
+
|
28
|
+
def required_attributes
|
29
|
+
@@required_attributes
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/atlas/resource.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
require "
|
1
|
+
require "time"
|
2
2
|
|
3
3
|
module Atlas
|
4
|
-
# Base class for representing resources.
|
5
4
|
class Resource
|
5
|
+
include Validations
|
6
|
+
|
7
|
+
INTERNAL_ATTRIBUTE_KEYS = %w(@tag @url_builder).freeze
|
8
|
+
|
6
9
|
attr_accessor :tag, :url_builder
|
7
10
|
|
8
11
|
def initialize(tag, hash = {})
|
@@ -19,12 +22,14 @@ module Atlas
|
|
19
22
|
response.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
20
23
|
end
|
21
24
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
+
def attributes
|
26
|
+
instance_variables.map do |v|
|
27
|
+
INTERNAL_ATTRIBUTE_KEYS.include?(v.to_s) ? next : v.to_s.sub(/^@/, "")
|
25
28
|
end.compact!
|
29
|
+
end
|
26
30
|
|
27
|
-
|
31
|
+
def to_hash
|
32
|
+
Hash[attributes.map { |v| [v.to_sym, send(v)] }]
|
28
33
|
end
|
29
34
|
|
30
35
|
def inspect
|
@@ -36,7 +41,7 @@ module Atlas
|
|
36
41
|
def date_writer(*args)
|
37
42
|
args.each do |attr|
|
38
43
|
define_method("#{attr}=".to_sym) do |date|
|
39
|
-
date = date.is_a?(String) ?
|
44
|
+
date = date.is_a?(String) ? Time.parse(date) : date
|
40
45
|
instance_variable_set("@#{attr}", date)
|
41
46
|
end
|
42
47
|
end
|
data/lib/atlas/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module HashReplaceKey
|
2
|
+
def replace_key(original, replacement)
|
3
|
+
dup.replace_key!(original, replacement)
|
4
|
+
end
|
5
|
+
|
6
|
+
def replace_key!(original, replacement)
|
7
|
+
return self unless has_key?(original)
|
8
|
+
|
9
|
+
self[replacement] = delete(original)
|
10
|
+
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Hash
|
16
|
+
include HashReplaceKey
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atlas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Charlton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -87,7 +87,6 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- ".codeclimate.yml"
|
91
90
|
- ".gitignore"
|
92
91
|
- ".ruby-version"
|
93
92
|
- ".travis.yml"
|
@@ -107,10 +106,12 @@ files:
|
|
107
106
|
- lib/atlas/client.rb
|
108
107
|
- lib/atlas/configuration.rb
|
109
108
|
- lib/atlas/errors.rb
|
109
|
+
- lib/atlas/mixins/validations.rb
|
110
110
|
- lib/atlas/resource.rb
|
111
111
|
- lib/atlas/url_builder.rb
|
112
112
|
- lib/atlas/user.rb
|
113
113
|
- lib/atlas/version.rb
|
114
|
+
- lib/core_ext/hash_replace_key.rb
|
114
115
|
homepage: https://github.com/nickcharlton/atlas-ruby
|
115
116
|
licenses:
|
116
117
|
- MIT
|