passwordstate 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +11 -0
- data/CHANGELOG.md +9 -0
- data/README.md +2 -0
- data/lib/passwordstate/client.rb +6 -3
- data/lib/passwordstate/errors.rb +37 -2
- data/lib/passwordstate/resource_list.rb +4 -2
- data/lib/passwordstate/resources/document.rb +2 -0
- data/lib/passwordstate/resources/folder.rb +7 -0
- data/lib/passwordstate/resources/password.rb +11 -11
- data/lib/passwordstate/resources/password_list.rb +10 -2
- data/lib/passwordstate/version.rb +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: e3e65ba47af619efcf537b2636eb297ac1cbe7a1c423c323e44a0126f27a5e2e
|
4
|
+
data.tar.gz: 5829c7ee7bf3af1d9098246e16f53f06f29d2002683cf8aed15b87a900e50bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96b62d8b3701e7779c035f7bdb05cf4b6ab5540fa74749742169bde51e093ccbe2d255c50309965c3f056bd5081fb24e438dd3f04e096a55cee12e3301b755a1
|
7
|
+
data.tar.gz: 5ed0bc2e7d0c7f922cb1ceee760d3a090381afda9a952d9fb98919eaedc1eee7cb1fecd5d18d3e65f28f6be5564a3eda13f35a8cd0e6a5f25ef8e10b26671b24
|
data/.gitlab-ci.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
## v0.0.2 2018-08-14
|
2
|
+
|
3
|
+
- Add title and full_path fields to the appropriate resources - almost every resource should now have an obvious human-readable name
|
4
|
+
- Fix password searching in password lists
|
5
|
+
- Improved exception handling
|
6
|
+
|
7
|
+
## v0.0.1 2018-07-31
|
8
|
+
|
9
|
+
- Initial release
|
data/README.md
CHANGED
data/lib/passwordstate/client.rb
CHANGED
@@ -88,7 +88,8 @@ module Passwordstate
|
|
88
88
|
if data
|
89
89
|
return data if res_obj.is_a? Net::HTTPSuccess
|
90
90
|
data = data&.first
|
91
|
-
|
91
|
+
|
92
|
+
raise Passwordstate::HTTPError.new_by_code(res_obj.code, req_obj, res_obj, data&.fetch('errors', []) || [])
|
92
93
|
else
|
93
94
|
return res_obj.body if options.fetch(:allow_html, false)
|
94
95
|
raise Passwordstate::PasswordstateError, 'Response was not parseable as JSON'
|
@@ -110,7 +111,7 @@ module Passwordstate
|
|
110
111
|
@http.start
|
111
112
|
end
|
112
113
|
|
113
|
-
def print_http(http)
|
114
|
+
def print_http(http, truncate = true)
|
114
115
|
return unless logger.debug?
|
115
116
|
|
116
117
|
if http.is_a? Net::HTTPRequest
|
@@ -132,7 +133,9 @@ module Passwordstate
|
|
132
133
|
else
|
133
134
|
clean_body = http.body
|
134
135
|
end
|
135
|
-
|
136
|
+
|
137
|
+
clean_body = clean_body.slice(0..2000) + "... [truncated, #{clean_body.length} Bytes total]" if truncate && clean_body.length > 2000
|
138
|
+
logger.debug "#{dir} #{clean_body}" if clean_body
|
136
139
|
end
|
137
140
|
end
|
138
141
|
end
|
data/lib/passwordstate/errors.rb
CHANGED
@@ -2,10 +2,12 @@ module Passwordstate
|
|
2
2
|
class PasswordstateError < RuntimeError; end
|
3
3
|
|
4
4
|
class HTTPError < PasswordstateError
|
5
|
-
attr_reader :code, :errors
|
5
|
+
attr_reader :code, :request, :response, :errors
|
6
6
|
|
7
|
-
def initialize(code, errors = [])
|
7
|
+
def initialize(code, request, response, errors = [])
|
8
8
|
@code = code.to_i
|
9
|
+
@request = request
|
10
|
+
@response = response
|
9
11
|
@errors = errors
|
10
12
|
|
11
13
|
super <<-ERRMSG
|
@@ -13,5 +15,38 @@ Passwordstate responded with an error to the request;
|
|
13
15
|
#{errors.map { |err| err['message'] || err['phrase'] }.join(', ')}
|
14
16
|
ERRMSG
|
15
17
|
end
|
18
|
+
|
19
|
+
def self.new_by_code(code, req, res, errors = [])
|
20
|
+
code_i = code.to_i
|
21
|
+
|
22
|
+
errtype = nil
|
23
|
+
errtype ||= NotFoundError if code_i == 404
|
24
|
+
errtype ||= ClientError if code_i >= 400 && code_i < 500
|
25
|
+
errtype ||= ServerError if code_i >= 500 && code_i < 600
|
26
|
+
|
27
|
+
errtype ||= HTTPError
|
28
|
+
errtype.new(code_i, req, res, errors)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# 4xx
|
33
|
+
class ClientError < HTTPError
|
34
|
+
def initialize(code, req, res, errors = [])
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# 404
|
40
|
+
class NotFoundError < ClientError
|
41
|
+
def initialize(code, req, res, errors = [])
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# 5xx
|
47
|
+
class ServerError < HTTPError
|
48
|
+
def initialize(code, req, res, errors = [])
|
49
|
+
super
|
50
|
+
end
|
16
51
|
end
|
17
52
|
end
|
@@ -47,8 +47,10 @@ module Passwordstate
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def load(entries)
|
50
|
-
clear && entries.
|
51
|
-
|
50
|
+
clear && entries.tap do |loaded|
|
51
|
+
loaded.sort! { |obj| obj.send(obj.class.index_field) } if options.fetch(:sort, true)
|
52
|
+
end.each { |obj| self << obj }
|
53
|
+
self
|
52
54
|
end
|
53
55
|
|
54
56
|
def operation_supported?(operation)
|
@@ -13,6 +13,8 @@ module Passwordstate
|
|
13
13
|
:site_id, { name: 'SiteID' },
|
14
14
|
:site_location
|
15
15
|
|
16
|
+
alias title folder_name
|
17
|
+
|
16
18
|
def password_lists
|
17
19
|
Passwordstate::ResourceList.new client, Passwordstate::Resources::PasswordList,
|
18
20
|
search_query: { tree_path: tree_path },
|
@@ -20,6 +22,11 @@ module Passwordstate
|
|
20
22
|
all_query: { tree_path: tree_path },
|
21
23
|
object_data: { nest_undef_folder_id: folder_id }
|
22
24
|
end
|
25
|
+
|
26
|
+
def full_path(unix = false)
|
27
|
+
return tree_path.tr('\\', '/') if unix
|
28
|
+
tree_path
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
@@ -10,16 +10,16 @@ module Passwordstate
|
|
10
10
|
:host_name,
|
11
11
|
:user_name,
|
12
12
|
:description,
|
13
|
-
:generic_field_1,
|
14
|
-
:generic_field_2,
|
15
|
-
:generic_field_3,
|
16
|
-
:generic_field_4,
|
17
|
-
:generic_field_5,
|
18
|
-
:generic_field_6,
|
19
|
-
:generic_field_7,
|
20
|
-
:generic_field_8,
|
21
|
-
:generic_field_9,
|
22
|
-
:generic_field_10,
|
13
|
+
:generic_field_1, { name: 'GenericField1' },
|
14
|
+
:generic_field_2, { name: 'GenericField2' },
|
15
|
+
:generic_field_3, { name: 'GenericField3' },
|
16
|
+
:generic_field_4, { name: 'GenericField4' },
|
17
|
+
:generic_field_5, { name: 'GenericField5' },
|
18
|
+
:generic_field_6, { name: 'GenericField6' },
|
19
|
+
:generic_field_7, { name: 'GenericField7' },
|
20
|
+
:generic_field_8, { name: 'GenericField8' },
|
21
|
+
:generic_field_9, { name: 'GenericField9' },
|
22
|
+
:generic_field_10, { name: 'GenericField10' },
|
23
23
|
:account_type_id, { name: 'AccountTypeID' },
|
24
24
|
:account_type,
|
25
25
|
:notes,
|
@@ -75,7 +75,7 @@ module Passwordstate
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def self.search(client, query = {})
|
78
|
-
super client,
|
78
|
+
super client, { _api_path: 'searchpasswords' }.merge(query)
|
79
79
|
end
|
80
80
|
|
81
81
|
def self.generate(client, options = {})
|
@@ -38,6 +38,12 @@ module Passwordstate
|
|
38
38
|
:generator_name,
|
39
39
|
:policy_name
|
40
40
|
|
41
|
+
alias title password_list
|
42
|
+
|
43
|
+
def self.search(client, query = {})
|
44
|
+
super client, query.merge(_api_path: 'searchpasswordlists')
|
45
|
+
end
|
46
|
+
|
41
47
|
def passwords
|
42
48
|
Passwordstate::ResourceList.new client, Passwordstate::Resources::Password,
|
43
49
|
all_path: "passwords/#{password_list_id}",
|
@@ -46,8 +52,10 @@ module Passwordstate
|
|
46
52
|
object_data: { password_list_id: password_list_id }
|
47
53
|
end
|
48
54
|
|
49
|
-
def
|
50
|
-
|
55
|
+
def full_path(unix = false)
|
56
|
+
[tree_path, password_list].compact.join('\\').tap do |full|
|
57
|
+
full.tr!('\\', '/') if unix
|
58
|
+
end
|
51
59
|
end
|
52
60
|
end
|
53
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passwordstate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Olofsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logging
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- ".gitignore"
|
105
105
|
- ".gitlab-ci.yml"
|
106
106
|
- ".rubocop.yml"
|
107
|
+
- CHANGELOG.md
|
107
108
|
- Gemfile
|
108
109
|
- LICENSE.txt
|
109
110
|
- README.md
|