Skip to content

Commit

Permalink
add hacky support to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
gpavelar committed Mar 22, 2024
1 parent 523062e commit 308eaee
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/stack_master/parameter_resolvers/one_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class OnePassword < Resolver
OnePasswordNotAbleToAuthenticate = Class.new(StandardError)
OnePasswordBinaryNotFound = Class.new(StandardError)
OnePasswordInvalidResponse = Class.new(StandardError)
OnePasswordInvalidVersion = Class.new(StandardError)

array_resolver

Expand Down Expand Up @@ -49,8 +50,9 @@ def login_item(data)

def op_get_item(item, vault)
validate_op_installed?
item = %x(op get item --vault='#{vault}' '#{item}' 2>&1)
item if validate_response?(item)

get_item(item, vault, get_version)

end

def create_struct(title, vault)
Expand All @@ -69,7 +71,13 @@ def get_password(title, vault)
end

def get_secure_note(title, vault)
create_struct(title, vault).details.notesPlain
version = get_version
if version.start_with?("1")
return create_struct(title, vault).details.notesPlain
end
if version.start_with?("2")
create_struct(title, vault).fields.first.value
end
end

def get_items(params)
Expand All @@ -80,6 +88,21 @@ def get_items(params)
return get_secure_note(params['title'], params['vault'])
end
end

def get_version
%x(op --version).strip
end

def get_item(item, vault, version)
case version
when version.start_with?("1")
%x(op get item --vault='#{vault}' '#{item}' 2>&1)
when version.start_with?("2")
%x(op item get --vault='#{vault}' '#{item}' --format json 2>&1)
else
raise OnePasswordInvalidVersion, "Unsupported version of 1Password: #{version}"
end
end
end
end
end

0 comments on commit 308eaee

Please sign in to comment.