purest 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39e177ed2d3cf0ba903e3fb03b415ec27e010df415a1a967257f1af13b9f007e
4
- data.tar.gz: 4e8a9a979354ed87f239c7185fffed070d9c548a568f4e2436f95ec63b1faf75
3
+ metadata.gz: a5c41b5fe331d93426a8a7e3f56f5d765452827522d1122fef6a4d79963b9291
4
+ data.tar.gz: 10111924a912e812272e6ce29f96279a3bca91b27e02c9e5f34b8df69a60946a
5
5
  SHA512:
6
- metadata.gz: 7143346aa454306f0e471e0eb0cb6b55dc1f4742d2d15b8873f68b029aaf740e8097dae0e8c9b4e4e08a430357e2785870867cfbe6989c770e841bb44840b497
7
- data.tar.gz: 87de96a184585d1d533baa7ed77792081f2ff886e1a7125ab21d8c4bc58dd2b0e1b721f3d630161bc35ec2c4b195265a776259e1d959882a0e7511595d1eedfb
6
+ metadata.gz: 01a855b24f60d9e7ab59aecb66d4d1e9dabb4c40ec5110e9ec3b9e8a5545081c9fef8849e157e29ba8ab5e3ac72efb9c184aa3c9811fc131d7a61e8c63d6e0e7
7
+ data.tar.gz: 86568cbbc8e91481508a74c5fced2b5e31460e1bd7de0794ddc299e5b3def37702ca7053ebe73a8a421ad1fcc8d0ab991e664d1b2e08ea42829f267fd0c74a0c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Purest (or Pure Rest, if you will) -- a simple gem for interacting with Pure Storage's REST API
1
+ # Purest (or Pure Rest, if you will) -- a simple gem for interacting with Pure Storage's FlashArray REST API
2
2
 
3
- A simple to use library for Ruby, inspired by the WeAreFarmGeek's Diplomat gem (seriously, those guys are awesome), allowing for easy interaction with Pure Storage's REST API.
3
+ A simple to use library for Ruby, inspired by the WeAreFarmGeek's Diplomat gem (seriously, those guys are awesome), allowing for easy interaction with Pure Storage's FlashArray REST API.
4
4
 
5
5
  ## Disclaimer
6
6
  This started as sort of a labor of love/learning exercise, and sort of blossomed into this. That being said, it means a few things:
@@ -51,25 +51,45 @@ This library requires you use Ruby 2.3 or above.
51
51
  gem install purest
52
52
  ```
53
53
 
54
+ ## Authentication
55
+ Purest allows you to authenticate using two different methods, either username and password OR using your API key (you don't need both). See "Configration" below for examples.
56
+
54
57
  ## Configuration
58
+ There are now two ways to configure Purest, the first is directly in your ruby code like so:
55
59
  ```rb
56
60
  require 'purest'
57
61
 
58
62
  Purest.configure do |config|
59
- config.url = "https://purehost.yourdomain.com"
63
+ config.api_key = '1234-567-89'
64
+ config.api_version = '1.14'
60
65
  config.options = {ssl: { verify: true }}
61
- config.api_version = '1.11'
62
- config.username = 'api-enabled-user'
63
66
  config.password = 'password'
67
+ config.url = "https://purehost.yourdomain.com"
68
+ config.username = 'api-enabled-user'
64
69
  end
65
70
  ```
66
71
 
72
+ The second method is to create a .purest.yaml file in your home directory (~/.purest.yaml) that looks like this:
73
+ ```yaml
74
+ ---
75
+ api_key: '1234-567-89'
76
+ api_version: '1.14'
77
+ password: 'password'
78
+ url: 'https://purehost.yourdomain.com'
79
+ username: 'api-enabled-user'
80
+ options:
81
+ ssl:
82
+ verify: true
83
+ ```
84
+
85
+ This yaml file is loaded in when your code is executed and the values can be individually or wholesale overridden during runtime by using the first configuration method, if you so desire.
86
+
67
87
  ## API options
68
- First: Authentication and session management are handled behind the scenes, you just need to supply your username/password in the configuration block (as shown in the example above). That's it.
88
+ First: Authentication and session management are handled behind the scenes, you just need to supply your username/password or API key in the configuration block or YAML file (as shown in the example above). That's it.
69
89
 
70
90
  Second: The various class methods of this gem turn the provided options into HTTP parameters, and are
71
91
  named accordingly. For instance, ```Purest::Volume.get({:snap: true})``` translates
72
- to http://purehost.yourdomain.com/api/1.11/volume?snap=true. For a full list
92
+ to http://purehost.yourdomain.com/api/1.14/volume?snap=true. For a full list
73
93
  of options for a given class, Pure provides good documentation at:
74
94
  https://purehost.yourdomain.com/static/0/help/rest/.
75
95
 
@@ -3,7 +3,7 @@
3
3
  module Purest
4
4
  # Methods for configuring Purest
5
5
  class Configuration
6
- attr_accessor :api_version, :url, :username, :password, :options
6
+ attr_accessor :api_key, :api_version, :url, :username, :password, :options
7
7
 
8
8
  # Override defaults for configuration
9
9
  # @param api_version [String] the API version to interact with
@@ -11,12 +11,31 @@ module Purest
11
11
  # @param username [String] username to authenticate with
12
12
  # @param password [String] password to authenticate with
13
13
  # @param options [Hash] extra options to configure Faraday::Connection
14
- def initialize(api_version = '1.11', url = nil, username = nil, password = nil, options = {})
15
- @api_version = api_version
16
- @url = url
17
- @username = username
18
- @password = password
19
- @options = options
14
+ def initialize(api_key = nil, api_version = nil, url = nil, username = nil, password = nil, options = {})
15
+ load_yaml
16
+ if load_yaml
17
+ @api_key = load_yaml['api_key']
18
+ @api_version = load_yaml['api_version']
19
+ @options = load_yaml['options']
20
+ @password = load_yaml['password']
21
+ @url = load_yaml['url']
22
+ @username = load_yaml['username']
23
+ else
24
+ @api_key = api_key
25
+ @api_version = api_version
26
+ @options = options
27
+ @password = password
28
+ @url = url
29
+ @username = username
30
+ end
31
+ end
32
+
33
+ def load_yaml
34
+ begin
35
+ Psych.load_file(ENV['HOME'] + '/.purest.yaml')
36
+ rescue Errno::ENOENT
37
+ false
38
+ end
20
39
  end
21
40
  end
22
41
  end
@@ -86,10 +86,11 @@ module Purest
86
86
  end
87
87
 
88
88
  def create_session
89
+ token = Purest.configuration.api_key || get_token
89
90
  raw_resp = @conn.post do |req|
90
91
  req.url "/api/#{Purest.configuration.api_version}/auth/session"
91
92
  req.params = {
92
- "api_token": get_token
93
+ "api_token": token
93
94
  }
94
95
  end
95
96
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Purest
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean McKinley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-11 00:00:00.000000000 Z
11
+ date: 2018-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber