syspass-client 0.1.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 +7 -0
- data/lib/syspass.rb +78 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 85e9ed08b81692698b11ebbff753a23aa68fa3c688ec0f50437837d0f56abccc
|
4
|
+
data.tar.gz: da92cef070faaaf0f9e084b8eb6e269ff7c9075eca69c7903a223425d8e3d17e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc5d77801ef5a665c8d0d656f9a3d2fede6d49b77cfa12259472aa9fc35f767f410de6930c1a403034cce758e0bfa2a6fc7fcb36208eb1d0f3e8a7fc5dec7258
|
7
|
+
data.tar.gz: 7b1190f8218023c749ad5a202aae3dce9ffb5ee40951701754c834a0e0886baca74f1918baadb6e4349e4295c7300d3cc28474e136af63854ed0b92169501fcc
|
data/lib/syspass.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
class Syspass
|
7
|
+
class Method
|
8
|
+
@@json_rcp_version = '2.0'
|
9
|
+
@@json_rcp_request_id = 1
|
10
|
+
@@headers = { 'Content-Type' => 'application/json-rpc' }
|
11
|
+
|
12
|
+
def initialize(prefix, connection)
|
13
|
+
@prefix = prefix
|
14
|
+
@connection = connection
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(method_name, *args)
|
18
|
+
validate_args(args)
|
19
|
+
method = "#{@prefix}/#{method_name}"
|
20
|
+
params = args[0] || {}
|
21
|
+
|
22
|
+
query(method, @connection.options, params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def query(method, options, params)
|
26
|
+
jsonquery = {
|
27
|
+
:jsonrpc => @@json_rcp_version,
|
28
|
+
:method => method,
|
29
|
+
:params => params.merge!(options),
|
30
|
+
:id => @@json_rcp_request_id,
|
31
|
+
}
|
32
|
+
sslmode = @connection.url.scheme == 'https'
|
33
|
+
http = Net::HTTP.new(@connection.url.host, @connection.url.port)
|
34
|
+
|
35
|
+
if sslmode
|
36
|
+
http.use_ssl = sslmode
|
37
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
38
|
+
end
|
39
|
+
|
40
|
+
request = Net::HTTP::Post.new(@connection.url.path, @@headers)
|
41
|
+
request.body = jsonquery.to_json
|
42
|
+
response = http.request(request)
|
43
|
+
json_response = JSON.parse(response.body)
|
44
|
+
|
45
|
+
if json_response['error']
|
46
|
+
raise "error handling: #{json_response['error']}"
|
47
|
+
end
|
48
|
+
json_response['result']
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate_args(args)
|
52
|
+
unless args.is_a?(Array)
|
53
|
+
raise TypeError, "Wrong argument: #{args.inspect} (expected an Array)"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_reader :url, :options
|
59
|
+
|
60
|
+
def initialize(url, options = {})
|
61
|
+
validate_options(options)
|
62
|
+
@url = URI.parse(url)
|
63
|
+
@options = options
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_options(options)
|
67
|
+
unless options.key?(:authToken)
|
68
|
+
raise ArgumentError, "Expected :authToken in options. Got: #{options.inspect}"
|
69
|
+
end
|
70
|
+
unless options.key?(:tokenPass)
|
71
|
+
warn("WARNING: Some queries require :tokenPass and you didn't set it.")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def method_missing(method_name)
|
76
|
+
Syspass::Method.new(method_name, self)
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: syspass-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeferson Catarina
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple client of sysPass API
|
14
|
+
email: catarinajeferson@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/syspass.rb
|
20
|
+
homepage: https://github.com/JeferCatarina/syspass-client
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.7.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Simple client of sysPass API
|
44
|
+
test_files: []
|