Skip to content
Snippets Groups Projects
Verified Commit 8077731a authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Fix rubocop complaints

parent c27920a0
Branches
Tags
No related merge requests found
Pipeline #5428 passed with warnings
......@@ -80,7 +80,7 @@ module Passwordstate
def request(method, api_path, options = {})
uri = URI(server_url + "/#{api_type}/" + api_path)
uri.query = URI.encode_www_form(options.fetch(:query)) if options.key? :query
uri.query = nil if uri.query&.empty?
uri.query = nil unless uri.query&.any?
req_obj = Net::HTTP.const_get(method.to_s.capitalize.to_sym).new uri
if options.key? :body
......
......@@ -46,9 +46,7 @@ module Passwordstate
def self.get(client, object, query = {})
object = object.send(object.class.send(index_field)) if object.is_a? Resource
if query[:_bare]
return new _client: client, index_field => object
end
return new _client: client, index_field => object if query[:_bare]
path = query.fetch(:_api_path, api_path)
query = passwordstateify_hash query.reject { |k| k.to_s.start_with? '_' }
......@@ -57,6 +55,7 @@ module Passwordstate
new data.merge(_client: client)
end
return resp.first if resp.one? || resp.empty?
resp
end
......
......@@ -2,6 +2,7 @@ module Passwordstate
class ResourceList < Array
Array.public_instance_methods(false).each do |method|
next if %i[reject select slice clear inspect].include?(method.to_sym)
class_eval <<-EVAL, __FILE__, __LINE__ + 1
def #{method}(*args)
lazy_load unless @loaded
......@@ -57,6 +58,7 @@ module Passwordstate
return nil unless %i[search all get post put delete].include?(operation)
return false if options.key?(:only) && !options[:only].include?(operation)
return false if options.key?(:except) && options[:except].include?(operation)
!options.fetch("#{operation}_path".to_sym, '').nil?
end
......@@ -66,6 +68,7 @@ module Passwordstate
def create(data)
raise 'Operation not supported' unless operation_supported?(:post)
obj = resource.new options.fetch(:object_data, {}).merge(data).merge(_client: client)
obj.post
obj
......@@ -73,6 +76,7 @@ module Passwordstate
def search(query = {})
raise 'Operation not supported' unless operation_supported?(:search)
api_path = options.fetch(:search_path, resource.api_path)
query = options.fetch(:search_query, {}).merge(query)
......@@ -81,6 +85,7 @@ module Passwordstate
def all(query = {})
raise 'Operation not supported' unless operation_supported?(:all)
api_path = options.fetch(:all_path, resource.api_path)
query = options.fetch(:all_query, {}).merge(query)
......@@ -89,6 +94,7 @@ module Passwordstate
def get(id, query = {})
raise 'Operation not supported' unless operation_supported?(:get)
api_path = options.fetch(:get_path, resource.api_path)
query = options.fetch(:get_query, {}).merge(query)
......@@ -97,6 +103,7 @@ module Passwordstate
def post(data, query = {})
raise 'Operation not supported' unless operation_supported?(:post)
api_path = options.fetch(:post_path, resource.api_path)
query = options.fetch(:post_query, {}).merge(query)
......@@ -105,6 +112,7 @@ module Passwordstate
def put(data, query = {})
raise 'Operation not supported' unless operation_supported?(:put)
api_path = options.fetch(:put_path, resource.api_path)
query = options.fetch(:put_query, {}).merge(query)
......@@ -113,6 +121,7 @@ module Passwordstate
def delete(id, query = {})
raise 'Operation not supported' unless operation_supported?(:delete)
api_path = options.fetch(:delete_path, resource.api_path)
query = options.fetch(:delete_query, {}).merge(query)
......
......@@ -30,6 +30,7 @@ module Passwordstate
def full_path(unix = false)
return tree_path.tr('\\', '/') if unix
tree_path
end
end
......
......@@ -57,6 +57,7 @@ module Passwordstate
def history
raise 'Password history only available on stored passwords' unless stored?
Passwordstate::ResourceList.new client, PasswordHistory,
all_path: "passwordhistory/#{password_id}",
only: :all
......@@ -73,6 +74,7 @@ module Passwordstate
def add_dependency(data = {})
raise 'Password dependency creation only available for stored passwords' unless stored?
client.request :post, 'dependencies', body: self.class.passwordstatify_hash(data.merge(password_id: password_id))
end
......@@ -87,6 +89,7 @@ module Passwordstate
def self.generate(client, options = {})
results = client.request(:get, 'generatepassword', query: options).map { |r| r['Password'] }
return results.first if results.count == 1
results
end
end
......
......@@ -2,15 +2,15 @@ module Passwordstate
module Resources
class Report < Passwordstate::Resource
REPORT_PARAMETERS = {
1 => %i[user_id],
2 => %i[user_id site_id],
3 => %i[user_id duration],
4 => %i[user_id site_id duration],
5 => %i[duration],
6 => %i[],
7 => %i[user_id site_id duration],
8 => %i[],
9 => %i[],
1 => %i[user_id],
2 => %i[user_id site_id],
3 => %i[user_id duration],
4 => %i[user_id site_id duration],
5 => %i[duration],
6 => %i[],
7 => %i[user_id site_id duration],
8 => %i[],
9 => %i[],
10 => %i[duration],
11 => %i[duration],
12 => %i[site_id],
......
......@@ -33,6 +33,7 @@ class String
def find_line(&_block)
raise ArgumentError, 'No block given' unless block_given?
each_line do |line|
return line if yield line
end
......@@ -76,4 +77,4 @@ module Passwordstate
end
end
Net::HTTP.send :prepend, Passwordstate::NetHTTPExtensions unless Net::HTTP.ancestors.include? Passwordstate::NetHTTPExtensions
Net::HTTP.prepend Passwordstate::NetHTTPExtensions unless Net::HTTP.ancestors.include? Passwordstate::NetHTTPExtensions
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment