passwordstate 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2548f3e172e66faaa1d3a80f2e366161a61694a1874bffa97e68246d0bfbc091
4
- data.tar.gz: 273d810d08aafd3849a42ff5397f4d6e123b1557f33f17590106758ee17773dc
3
+ metadata.gz: 8339c30925359da2d1fb10918796945cb5bdc4ad56beff7e99af39781bdfae96
4
+ data.tar.gz: 6d9c0c54ce250813c874fa7007c63e8378c9c20ac4a6b9df887b6fe74b5939b9
5
5
  SHA512:
6
- metadata.gz: c515ecce21af9bdd9e6c72b85041bd979cd23c3d3bb0927c17f665cd7077834a239daaa5f3001a2251d6fa6914e884f39941ab91c9cc33926f9fa194529f84dd
7
- data.tar.gz: e087dc037ce713911d626876677a9aacc818261a717a3e867524fb3aece1d4a28f2dde71329c3896fcda2afbde808021b729f3ec7121800e29d5cb5df3fa2500
6
+ metadata.gz: 7cbe2c67683aa901f0d4b3fc4c9991115c59f93ecef0b1b8436e78c0f752abcf71c60a2f8151df7714e0d872d9620402a2fc1273d30875f70648916f8f5459ab
7
+ data.tar.gz: 5feb809a4426576eb901a18c137f0d70337a692ef7cfdc633122ca1d0042d7b59f1727841f8b32ff68186ff0cc93cf4fa895de21622b250d5d9c92341d44a709
data/.gitlab-ci.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- image: "ruby:2.7"
2
+ image: "ruby"
3
3
 
4
4
  # Cache gems in between builds
5
5
  cache:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## v0.1.2 2025-08-26
2
+
3
+ - Improved performance when working with large lists
4
+
5
+ ## v0.1.1 2024-03-27
6
+
7
+ - Add Client#open_timeout=
8
+ - Add Resource#modified?
9
+
1
10
  ## v0.1.0 2022-12-05
2
11
 
3
12
  - Reduced data transferred for regular queries
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json'
4
+ require 'pp' # rubocop:disable Lint/RedundantRequireStatement - required for pretty_print_inspect
4
5
 
5
6
  module Passwordstate
6
7
  class Client
@@ -12,10 +12,14 @@ module Passwordstate
12
12
  @code = code.to_i
13
13
  @request = request
14
14
  @response = response
15
+
16
+ if errors.count == 1 && errors.first.is_a?(Hash) && errors.first.key?('errors')
17
+ errors = errors.first['errors']
18
+ end
15
19
  @errors = errors
16
20
 
17
21
  errorstr = errors.map { |err| err['message'] || err['phrase'] || err['error'] }.join('; ')
18
- super "Passwordstate responded with an error to the request:\n#{errorstr}"
22
+ super("Passwordstate responded with an error to the request:\n#{errorstr}")
19
23
  end
20
24
 
21
25
  def self.new_by_code(code, req, res, errors = [])
@@ -34,8 +34,7 @@ module Passwordstate
34
34
 
35
35
  def initialize(data)
36
36
  @client = data.delete :_client
37
- set! data, store_old: false
38
- old
37
+ set! data
39
38
  end
40
39
 
41
40
  # Is the object stored on the Passwordstate server
@@ -126,7 +125,7 @@ module Passwordstate
126
125
  nil_as_string = opts.fetch(:nil_as_string, self.class.nil_as_string)
127
126
  (self.class.send(:accessor_field_names) + self.class.send(:read_field_names) + self.class.send(:write_field_names)).to_h do |field|
128
127
  redact = self.class.send(:field_options)[field]&.fetch(:redact, false) && !ignore_redact
129
- at_field = "@#{field}".to_sym
128
+ at_field = :"@#{field}"
130
129
  field = at_field if atify
131
130
  value = instance_variable_get(at_field) unless redact
132
131
  value = '[ REDACTED ]' if redact
@@ -164,16 +163,11 @@ module Passwordstate
164
163
  end
165
164
 
166
165
  def modified
167
- attribs = attributes
168
- attribs.reject { |field| old[field] == attribs[field] }
166
+ @modified ||= {}
169
167
  end
170
168
 
171
- def old
172
- @old ||= attributes.dup
173
- end
174
-
175
- def set!(data, store_old: true)
176
- @old = attributes.dup if store_old
169
+ def set!(data, reset_modified = true)
170
+ @modified = {} if reset_modified
177
171
  data = data.attributes if data.is_a? Passwordstate::Resource
178
172
  data.each do |key, value|
179
173
  field = self.class.passwordstate_to_ruby_field(key)
@@ -190,7 +184,7 @@ module Passwordstate
190
184
  parsed_value = convert.call(value, direction: :from)
191
185
  end
192
186
 
193
- instance_variable_set "@#{field}".to_sym, parsed_value || value
187
+ instance_variable_set :"@#{field}", parsed_value || value
194
188
  end
195
189
  self
196
190
  end
@@ -274,7 +268,8 @@ module Passwordstate
274
268
  fields.each do |field|
275
269
  if field.is_a? Symbol
276
270
  accessor_field_names << field
277
- attr_accessor field
271
+ attr_reader field
272
+ build_writer_method field
278
273
  else
279
274
  field_options[accessor_field_names.last] = field
280
275
  end
@@ -296,12 +291,24 @@ module Passwordstate
296
291
  fields.each do |field|
297
292
  if field.is_a? Symbol
298
293
  write_field_names << field
299
- attr_writer field
294
+ build_writer_method field
300
295
  else
301
296
  field_options[write_field_names.last] = field
302
297
  end
303
298
  end
304
299
  end
300
+
301
+ private
302
+
303
+ def build_writer_method(field)
304
+ field = field.to_s.to_sym unless field.is_a? Symbol
305
+ define_method(:"#{field}=") do |arg|
306
+ return arg if send(field) == arg
307
+
308
+ instance_variable_set "@#{field}", arg
309
+ modified[field] = arg
310
+ end
311
+ end
305
312
  end
306
313
  end
307
314
  # rubocop:enable Metrics/ClassLength
@@ -317,7 +324,7 @@ module Passwordstate
317
324
  autoload :PasswordList, 'passwordstate/resources/password_list'
318
325
  autoload :PasswordListPermission, 'passwordstate/resources/password_list'
319
326
  autoload :PasswordHistory, 'passwordstate/resources/password'
320
- autoload :PasswordPermission, 'passwordstate/resources/password_list'
327
+ autoload :PasswordPermission, 'passwordstate/resources/password'
321
328
  autoload :PrivilegedAccount, 'passwordstate/resources/privileged_account'
322
329
  autoload :PrivilegedAccountPermission, 'passwordstate/resources/privileged_account'
323
330
  autoload :Permission, 'passwordstate/resources/permission'
@@ -62,11 +62,11 @@ module Passwordstate
62
62
  end
63
63
 
64
64
  def operation_supported?(operation)
65
- return nil unless %i[search all get post put delete].include?(operation)
65
+ return false unless %i[search all get post put delete].include?(operation)
66
66
  return false if options.key?(:only) && !options[:only].include?(operation)
67
67
  return false if options.key?(:except) && options[:except].include?(operation)
68
68
 
69
- !options.fetch("#{operation}_path".to_sym, '').nil?
69
+ !options.fetch(:"#{operation}_path", '').nil?
70
70
  end
71
71
 
72
72
  def new(data)
@@ -13,7 +13,7 @@ module Passwordstate
13
13
  alias title document_name
14
14
 
15
15
  def self.all(client, store, **query)
16
- super client, query.merge(_api_path: "#{api_path}/#{validate_store! store}")
16
+ super(client, query.merge(_api_path: "#{api_path}/#{validate_store! store}"))
17
17
  end
18
18
 
19
19
  def self.search(client, store, **options)
@@ -21,19 +21,19 @@ module Passwordstate
21
21
  end
22
22
 
23
23
  def self.get(client, store, object)
24
- super client, object, _api_path: "#{api_path}/#{validate_store! store}"
24
+ super(client, object, _api_path: "#{api_path}/#{validate_store! store}")
25
25
  end
26
26
 
27
27
  def self.post(client, store, data, **query)
28
- super client, data, query.merge(_api_path: "#{api_path}/#{validate_store! store}")
28
+ super(client, data, query.merge(_api_path: "#{api_path}/#{validate_store! store}"))
29
29
  end
30
30
 
31
31
  def self.put(client, store, data, **query)
32
- super client, data, query.merge(_api_path: "#{api_path}/#{validate_store! store}")
32
+ super(client, data, query.merge(_api_path: "#{api_path}/#{validate_store! store}"))
33
33
  end
34
34
 
35
35
  def self.delete(client, store, object, **query)
36
- super client, object, query.merge(_api_path: "#{api_path}/#{validate_store! store}")
36
+ super(client, object, query.merge(_api_path: "#{api_path}/#{validate_store! store}"))
37
37
  end
38
38
 
39
39
  class << self
@@ -112,11 +112,13 @@ module Passwordstate
112
112
  end
113
113
 
114
114
  def self.all(client, **query)
115
- super client, **{ query_all: true }.merge(query)
115
+ query = { query_all: true }.merge(query)
116
+ super(client, **query)
116
117
  end
117
118
 
118
119
  def self.search(client, **query)
119
- super client, **{ _api_path: 'searchpasswords' }.merge(query)
120
+ query = { _api_path: 'searchpasswords' }.merge(query)
121
+ super(client, **query)
120
122
  end
121
123
 
122
124
  def self.generate(client, **options)
@@ -70,7 +70,7 @@ module Passwordstate
70
70
  alias title password_list
71
71
 
72
72
  def self.search(client, **query)
73
- super client, **query.merge(_api_path: 'searchpasswordlists')
73
+ super(client, **query.merge(_api_path: 'searchpasswordlists'))
74
74
  end
75
75
 
76
76
  def passwords
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Passwordstate
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/passwordstate.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'logging'
4
- require 'pp'
5
4
  require 'passwordstate/version'
6
5
  require 'passwordstate/client'
7
6
  require 'passwordstate/errors'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passwordstate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Olofsson
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-03-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: logging
@@ -173,7 +172,6 @@ licenses:
173
172
  - MIT
174
173
  metadata:
175
174
  rubygems_mfa_required: 'true'
176
- post_install_message:
177
175
  rdoc_options: []
178
176
  require_paths:
179
177
  - lib
@@ -188,8 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
186
  - !ruby/object:Gem::Version
189
187
  version: '0'
190
188
  requirements: []
191
- rubygems_version: 3.5.3
192
- signing_key:
189
+ rubygems_version: 3.6.9
193
190
  specification_version: 4
194
191
  summary: A ruby API client for interacting with a passwordstate server
195
192
  test_files: []