xlogin-apiclient 0.2.5 → 0.2.6
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/bin/xloginapi +6 -0
- data/lib/xlogin/apiclient.rb +3 -2
- data/lib/xlogin/apiclient/cli.rb +58 -1
- data/lib/xlogin/apiclient/version.rb +2 -2
- data/xlogin-apiclient.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba7acd60107439028cb9f8c6a77afd5dfaf6c1cf74c2232b529678b8888b6053
|
4
|
+
data.tar.gz: 32b07f46ca25f31ee09cadf2de19c5a0284bd1bb5c0a92b1d9a62b6af8a0b261
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f985e16fe2d94d2daee92e2d060aab4007deb0cda7d7aa56338f6e0f57c86907e8ec2299860d3cf2495f1f1c92b2ab35f84b6e24ecf08a7a711ac6c6238f8b3
|
7
|
+
data.tar.gz: d8bf59fae7037c02f2488c7b2115a84a40349a5909a31b3e6ea6995fc981ec60ffba990e1575c8c206a6c938799fd6555b674eab3513d7a52a336366f134cdaa
|
data/bin/xloginapi
ADDED
data/lib/xlogin/apiclient.rb
CHANGED
@@ -29,12 +29,13 @@ module Xlogin
|
|
29
29
|
|
30
30
|
def cmd(args, &block)
|
31
31
|
params = {driver: @type, target: @args, command: args}
|
32
|
-
request(**params.transform_keys(&:to_sym), &block)
|
32
|
+
request(:cmd, **params.transform_keys(&:to_sym), &block)
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
36
|
-
def request(**params, &block)
|
36
|
+
def request(endpoint, **params, &block)
|
37
37
|
uri = @uri.dup
|
38
|
+
uri.path = File.join(uri.path, endpoint.to_s)
|
38
39
|
uri.query = "q=#{URI.encode_www_form_component(JSON.generate(params))}"
|
39
40
|
|
40
41
|
if block
|
data/lib/xlogin/apiclient/cli.rb
CHANGED
@@ -1,8 +1,38 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'singleton'
|
3
|
+
require 'xlogin/apiclient'
|
2
4
|
|
3
5
|
|
6
|
+
XLOGIN_API_URL = ENV.fetch('XLOGIN_API_URL', 'http://127.0.0.1:8080')
|
7
|
+
|
4
8
|
module Xlogin
|
5
|
-
|
9
|
+
class APIClient
|
10
|
+
|
11
|
+
class Factory
|
12
|
+
include Singleton
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@inventory = Hash.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_hostinfo(name, **opts)
|
19
|
+
@inventory[name] = (get_hostinfo(name) || {name: name}).merge(opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_hostinfo(name)
|
23
|
+
@inventory[name]
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(method_name, *args, **opts, &block)
|
27
|
+
super unless args.size == 2 && Addressable::URI::URIREGEX =~ args[1]
|
28
|
+
|
29
|
+
name = args[0]
|
30
|
+
uri = args[1]
|
31
|
+
type = method_name.to_s.downcase
|
32
|
+
set_hostinfo(name.to_s, type: type, uri: uri, **opts)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
6
36
|
class CLI
|
7
37
|
|
8
38
|
def self.run(args = ARGV)
|
@@ -10,6 +40,33 @@ module Xlogin
|
|
10
40
|
end
|
11
41
|
|
12
42
|
def run(args)
|
43
|
+
config = {api: XLOGIN_API_URL}
|
44
|
+
parser = OptionParser.new
|
45
|
+
parser.banner = "#{File.basename($0)} HOST [Options]"
|
46
|
+
parser.version = Xlogin::APIClient::VERSION
|
47
|
+
|
48
|
+
parser.on('-a API', '--api', String, 'The Xlogin API URL.') { |v| config[:api] = v }
|
49
|
+
parser.on('-t TYPE', '--type', String, 'The TYPE of the device.') { |v| config[:type] = v }
|
50
|
+
parser.on('-i PATH', '--inventory', String, 'The PATH to the inventory file..') { |v| config[:inventory] = v }
|
51
|
+
parser.on('-e COMMAND', '--exec', String, 'Execute commands and quit.') { |v| config[:exec] = v }
|
52
|
+
|
53
|
+
args = parser.parse!(args)
|
54
|
+
host = args.shift
|
55
|
+
hostinfo = if config[:inventory]
|
56
|
+
factory = Factory.instance
|
57
|
+
factory.instance_eval(IO.read(config[:inventory]))
|
58
|
+
factory.get_hostinfo(host) || {}
|
59
|
+
else
|
60
|
+
{type: config[:type], uri: host}
|
61
|
+
end
|
62
|
+
|
63
|
+
raise "Argument error - type='#{hostinfo[:type]}' uri='#{hostinfo[:uri]}'" unless hostinfo[:type] && hostinfo[:uri]
|
64
|
+
|
65
|
+
APIClient.base_url = config[:api]
|
66
|
+
client = APIClient.new(**hostinfo)
|
67
|
+
client.cmd(config[:exec]) { |c| $stdout.print c }
|
68
|
+
rescue => e
|
69
|
+
$stderr.puts e, '', parser
|
13
70
|
end
|
14
71
|
|
15
72
|
end
|
data/xlogin-apiclient.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "xlogin/apiclient/version"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "xlogin-apiclient"
|
8
|
-
spec.version = Xlogin::
|
8
|
+
spec.version = Xlogin::APIClient::VERSION
|
9
9
|
spec.authors = ["haccht"]
|
10
10
|
spec.email = ["haccht@users.noreply.github.com"]
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlogin-apiclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- bin/console
|
83
83
|
- bin/setup
|
84
|
+
- bin/xloginapi
|
84
85
|
- lib/xlogin/apiclient.rb
|
85
86
|
- lib/xlogin/apiclient/cli.rb
|
86
87
|
- lib/xlogin/apiclient/version.rb
|