getauthtoken 0.4.1 → 0.5.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 +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +24 -7
- data/bin/getauthtoken +7 -1
- data/getauthtoken.gemspec +1 -0
- data/lib/getauthtoken.rb +9 -9
- data/lib/getauthtoken/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 568a05c002733aa012393e484a452ba1377776dd4d227fb781777f339d907fc1
|
4
|
+
data.tar.gz: b04ec9d5aa278f0168275a94f8ccded0f181df2d5b77a6281182429e1b843505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad0ee84ab0475f32edc67c1f7bb20bea8869faa93eb680b1aafdd4ed1bdc3d32b3fabcb014becc15eaba8b074007bf81be8e6cd3f8c965511321607d2018ddcb
|
7
|
+
data.tar.gz: 0e815ce2043bdb8e8e419cd40bc1ae8ac06d93ecd46f63d7d39f9387d2633f93ad78ed5fc96f3f509c213fc2c8730441d759ff1806b6b8969020265a84bdac4c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
getauthtoken (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
|
+
[](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).
|
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
|
-
|
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
|
-
|
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
|
-
"
|
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.
|
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
|
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
|
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
|
data/bin/getauthtoken
CHANGED
@@ -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
|
-
|
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."
|
data/getauthtoken.gemspec
CHANGED
@@ -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"
|
data/lib/getauthtoken.rb
CHANGED
@@ -3,25 +3,25 @@ require "json"
|
|
3
3
|
require "http"
|
4
4
|
|
5
5
|
module Getauthtoken
|
6
|
-
|
6
|
+
AUTH_PATH = '/api/xcr/v2/xauth'
|
7
7
|
|
8
|
-
def self.authenticate()
|
9
|
-
|
10
|
-
post_credentials(
|
8
|
+
def self.authenticate(password)
|
9
|
+
config = get_config()
|
10
|
+
post_credentials(config, password)
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.
|
14
|
-
file = File.open(File.expand_path("~/.
|
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(
|
21
|
-
hash = { "username" =>
|
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(
|
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
|
data/lib/getauthtoken/version.rb
CHANGED
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
|
+
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-
|
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
|