getauthtoken 0.4.1 → 0.5.0

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: 36470fd7a5da225e693d83ccd434a83fe5a8a0331633fb7f070b8129bbd95a55
4
- data.tar.gz: 88a34fe8d9e19ff26cac441a5055c3996228bc1d2e5cdfef91634eed37b6e12f
3
+ metadata.gz: 568a05c002733aa012393e484a452ba1377776dd4d227fb781777f339d907fc1
4
+ data.tar.gz: b04ec9d5aa278f0168275a94f8ccded0f181df2d5b77a6281182429e1b843505
5
5
  SHA512:
6
- metadata.gz: 776884e842291b27555eef4268a7f15f6a55a29836f10cca04238937c168d56249d83f496ac0931d70bfbee1c2ce6048e3be39b72f10066fd045733c2181f5aa
7
- data.tar.gz: 3c36a887c504cecd9d7085bcde5f6afff0712f5025427352275997222d006b06b14915365aa98df08570be139ee997ada4aea4dded2dee2396715735ff103488
6
+ metadata.gz: ad0ee84ab0475f32edc67c1f7bb20bea8869faa93eb680b1aafdd4ed1bdc3d32b3fabcb014becc15eaba8b074007bf81be8e6cd3f8c965511321607d2018ddcb
7
+ data.tar.gz: 0e815ce2043bdb8e8e419cd40bc1ae8ac06d93ecd46f63d7d39f9387d2633f93ad78ed5fc96f3f509c213fc2c8730441d759ff1806b6b8969020265a84bdac4c
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- getauthtoken (0.4.0)
4
+ getauthtoken (0.5.0)
5
+ highline (~> 2.0.3)
5
6
  http (~> 4.2.0)
6
7
 
7
8
  GEM
@@ -16,6 +17,7 @@ GEM
16
17
  ffi-compiler (1.0.1)
17
18
  ffi (>= 1.0.0)
18
19
  rake
20
+ highline (2.0.3)
19
21
  http (4.2.0)
20
22
  addressable (~> 2.3)
21
23
  http-cookie (~> 1.0)
data/README.md CHANGED
@@ -1,35 +1,49 @@
1
1
  # getauthtoken
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/getauthtoken.svg)](https://badge.fury.io/rb/getauthtoken)
4
+
3
5
  `getauthtoken` is a small command line utility to acquire an authorization token from [Xaptum](https://dev.xaptum.io). It's intended to speed up the process of testing API's, since an authorization token is required as a header in every request and new tokens are generated every four hours.
4
6
 
5
7
  Running `getauthtoken` from your command line after installation (see below) will always give the current token.
6
8
 
7
9
  ## Installation
8
10
 
9
- First, install the gem from [Ruby Gems](https://rubygems.org). You may need to `sudo gem install` here.
11
+ First, install the gem from [Ruby Gems](https://rubygems.org).
10
12
 
11
13
  ```shell
12
14
  $ gem install getauthtoken
13
15
  ```
14
16
 
15
- Second, we'll need to create a JSON file `.xaptum_credentials.json` that stores your Xaptum credentials. `getauthtoken` will always use the credentials in this file to acquire your auth token.
17
+ Alternatively, if you've already installed `getauthtoken`, update the gem to the latest version.
18
+
19
+ ```shell
20
+ $ gem update getauthtoken
21
+ ```
22
+
23
+ _Note that for the above commands you may need to use `sudo gem`._
16
24
 
17
- In your `$HOME` directory, create the file `.xaptum_credentials.json` with the following structure:
25
+ Second, we'll need to create a JSON file `.xaptum_config.json` that stores your Xaptum configurations. `getauthtoken` will always use the configurations in this file to acquire your auth token.
26
+
27
+ In your `$HOME` directory, create the file `.xaptum_config.json` with the following structure:
18
28
 
19
29
  ```json
20
30
  {
21
31
  "username": "<YOUR_USERNAME>",
22
- "password": "<YOUR_PASSWORD>"
32
+ "host": "<YOUR_HOST>"
23
33
  }
24
34
  ```
25
35
 
36
+ `<YOUR_HOST>` should normally be `https://xaptum.io` or `https://dev.xaptum.io`.
37
+
26
38
  ## Usage
27
39
 
28
- Simply run `getauthtoken` from the command line. The token should then appear and get copied to your clipboard.
40
+ Simply run `getauthtoken` from the command line. You will then be prompted for your Xaptum account password. If the password is correct, your token should appear and get copied to your clipboard.
29
41
 
30
42
  ```shell
31
43
  $ getauthtoken
32
44
  Authenticating with Xaptum...
45
+ Enter Password
46
+
33
47
  Your token is <TOKEN>. It has been copied to the clipboard.
34
48
  ```
35
49
 
@@ -46,11 +60,14 @@ $ bundle install
46
60
  Write tests, pass tests, bump version, pull request.
47
61
 
48
62
  - **Write tests:** Write all tests in `test/getauthtoken_test.rb`.
49
- - **Pass tests:** Write code in `lib/getauthtoken.rb` to pass the tests. You can run tests with `$ rake test`.
63
+ - **Pass tests:** Write code in `lib/getauthtoken.rb` to pass the tests. You can run tests with `rake test`.
50
64
  - **Bump version:** The current version of the gem is in `lib/getauthtoken/version.rb`. After you've made your changes, update this version by following the format `MAJOR.MINOR.PATCH`.
65
+ - **Test locally:** Running `bundle exec rake build` will build a new version of the gem that you can run and test locally by installing with `gem install pkg/getauthtoken-<VERSION>` and then running `getauthtoken`.
51
66
  - **Pull request:** Open a PR! One of the maintainers will review your changes and work with you to get them merged.
52
67
 
53
- For maintainers: building new gem version and pushing to Github and Ruby Gems
68
+ ### For Maintainers
69
+
70
+ Build a new gem version, pushing to Github (along with a tag), and add the new version to Ruby Gems
54
71
 
55
72
  ```shell
56
73
  $ bundle exec rake release
@@ -1,7 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'getauthtoken'
3
+ require 'highline/import'
4
+
5
+ def get_password(prompt = "Enter Password")
6
+ ask(prompt) {|q| q.echo = false}
7
+ end
3
8
 
4
9
  puts "Authenticating with Xaptum..."
5
- token = Getauthtoken::authenticate()
10
+ password = get_password()
11
+ token = Getauthtoken::authenticate(password)
6
12
  Getauthtoken::pbcopy(token)
7
13
  puts "Your token is #{token}. It has been copied to the clipboard."
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_dependency "http", "~> 4.2.0"
32
+ spec.add_dependency "highline", "~> 2.0.3"
32
33
 
33
34
  spec.add_development_dependency "bundler", "~> 2.0"
34
35
  spec.add_development_dependency "rake", "~> 10.0"
@@ -3,25 +3,25 @@ require "json"
3
3
  require "http"
4
4
 
5
5
  module Getauthtoken
6
- BASE_URL = 'https://dev.xaptum.io/api/xcr/v2/xauth'
6
+ AUTH_PATH = '/api/xcr/v2/xauth'
7
7
 
8
- def self.authenticate()
9
- credentials = get_credentials()
10
- post_credentials(credentials)
8
+ def self.authenticate(password)
9
+ config = get_config()
10
+ post_credentials(config, password)
11
11
  end
12
12
 
13
- def self.get_credentials()
14
- file = File.open(File.expand_path("~/.xaptum_credentials.json"))
13
+ def self.get_config()
14
+ file = File.open(File.expand_path("~/.xaptum_config.json"))
15
15
  data = JSON.load file
16
16
  file.close
17
17
  data
18
18
  end
19
19
 
20
- def self.post_credentials(credentials)
21
- hash = { "username" => credentials["username"], "token" => credentials["password"]}
20
+ def self.post_credentials(config, password)
21
+ hash = { "username" => config["username"], "token" => password}
22
22
  json = JSON.generate(hash)
23
23
  response = HTTP.headers("Content-Type": "application/json", "Accept": "application/json")
24
- .post(BASE_URL, body: json)
24
+ .post(config["host"] + AUTH_PATH, body: json)
25
25
 
26
26
  response.code == 200 ? JSON.parse(response)["data"][0]["token"] : nil
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module Getauthtoken
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getauthtoken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Irlbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-15 00:00:00.000000000 Z
11
+ date: 2019-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.3
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement