atlas 1.6.0 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d7458c18f82f6db9fb3fd42f6c1191d010d1ac1
4
- data.tar.gz: 1231af2fa78aedc507c897f09386c8b53beb376b
3
+ metadata.gz: 2327ab72bc81334bee756f79d747dbcbb7aaf69e
4
+ data.tar.gz: 82d266882fc5c21eb533f13b89731f630c36aa08
5
5
  SHA512:
6
- metadata.gz: b188e800d63252dd99682ea50802fc59ab9608d6d036c17ab1877fa7ce3992abdd1823cf27b014980f57ce318aa3845d8da605a2fe1cc612a5aaedb73e32b173
7
- data.tar.gz: 1271220ab59f2dfd908793e9a552b2ffd777be6f1ccc7271c8170831998e8e1e46675cea469217532fad9aa47ec0de783d23da6857714bb9278ee8f4e04b88e3
6
+ metadata.gz: a270dac6c5bcbbe5e5f0c5b62706b9ff40c870761ecffe17951bc9983878d153fa4db5631ef509fa36337453843e0b912bec00d661381392bd1ca7bd077abdd4
7
+ data.tar.gz: 83000712484128862ea561ed0fc7ff7fa80aba86390bc08c2dd42e565c646e3bbd2baf6cd7662e2cae9b9edd788a10d694269779bc243cc6c48c19342b2e883c
@@ -1,6 +1,4 @@
1
+ ---
1
2
  language: ruby
2
3
  rvm:
3
4
  - 2.4.1
4
- addons:
5
- code_climate:
6
- repo_token: 17baf936cec8165bd651d58919ddcaa30f2a9d35f23290db4df618ac10a99743
@@ -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
- [![Code Climate](https://codeclimate.com/github/nickcharlton/atlas-ruby/badges/gpa.svg)](https://codeclimate.com/github/nickcharlton/atlas-ruby)
5
- [![Test Coverage](https://codeclimate.com/github/nickcharlton/atlas-ruby/badges/coverage.svg)](https://codeclimate.com/github/nickcharlton/atlas-ruby)
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.access_token = 'token'
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)
@@ -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(access_token: configuration.access_token)
22
+ @client ||= Client.new(token: configuration.token)
21
23
  end
22
24
  end
@@ -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
- :is_private, :current_version, :versions
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['is_private'] = hash['private']
65
- hash['description'] = hash['description_markdown']
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
- response = Atlas.client.post('/boxes', body: body)
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
@@ -7,6 +7,8 @@ module Atlas
7
7
  attr_accessor :name, :original_url, :download_url, :url
8
8
  date_accessor :created_at, :updated_at
9
9
 
10
+ requires :name
11
+
10
12
  # Find a provider by it's tag.
11
13
  #
12
14
  # @param [String] tag the tag of the provider.
@@ -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
- if hash.key? 'description_markdown'
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
@@ -10,7 +10,7 @@ module Atlas
10
10
 
11
11
  def initialize(opts = {})
12
12
  @url = opts[:url] || 'https://app.vagrantup.com/'
13
- @access_token = opts[:access_token]
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
- query.merge!(access_token: @access_token)
33
+ headers["Authorization"] = "Bearer #{token}"
32
34
 
33
35
  connection = Excon.new(@url)
34
36
  response = connection.request(expects: [200, 201], method: method,
@@ -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 :access_token
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 |k, v|
13
- send("#{k}=".to_sym, v)
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
- { access_token: @access_token }
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
@@ -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
@@ -1,8 +1,11 @@
1
- require "date"
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 to_hash
23
- attrs = instance_variables.collect do |v|
24
- %w(@tag @url_builder).include?(v.to_s) ? next : v.to_s.sub(/^@/, '')
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
- Hash[attrs.select { |v| respond_to? v }.map { |v| [v.to_sym, send(v)] }]
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) ? DateTime.parse(date) : date
44
+ date = date.is_a?(String) ? Time.parse(date) : date
40
45
  instance_variable_set("@#{attr}", date)
41
46
  end
42
47
  end
@@ -1,4 +1,4 @@
1
1
  # Version information.
2
2
  module Atlas
3
- VERSION = "1.6.0".freeze
3
+ VERSION = "2.0.0".freeze
4
4
  end
@@ -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: 1.6.0
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: 2017-07-31 00:00:00.000000000 Z
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
@@ -1,13 +0,0 @@
1
- ---
2
- languages:
3
- Ruby: true
4
- engines:
5
- rubocop:
6
- enabled: true
7
- bundler-audit:
8
- enabled: true
9
- ratings:
10
- paths:
11
- - "**.rb"
12
- exclude_paths:
13
- - spec/**/*