Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add support to op v2 #383

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions lib/stack_master/parameter_resolvers/one_password.rb
Original file line number Diff line number Diff line change
@@ -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

@@ -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)
@@ -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)
@@ -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