Skip to content

Commit 308eaee

Browse files
committed
add hacky support to v2
1 parent 523062e commit 308eaee

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

lib/stack_master/parameter_resolvers/one_password.rb

+26-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class OnePassword < Resolver
55
OnePasswordNotAbleToAuthenticate = Class.new(StandardError)
66
OnePasswordBinaryNotFound = Class.new(StandardError)
77
OnePasswordInvalidResponse = Class.new(StandardError)
8+
OnePasswordInvalidVersion = Class.new(StandardError)
89

910
array_resolver
1011

@@ -49,8 +50,9 @@ def login_item(data)
4950

5051
def op_get_item(item, vault)
5152
validate_op_installed?
52-
item = %x(op get item --vault='#{vault}' '#{item}' 2>&1)
53-
item if validate_response?(item)
53+
54+
get_item(item, vault, get_version)
55+
5456
end
5557

5658
def create_struct(title, vault)
@@ -69,7 +71,13 @@ def get_password(title, vault)
6971
end
7072

7173
def get_secure_note(title, vault)
72-
create_struct(title, vault).details.notesPlain
74+
version = get_version
75+
if version.start_with?("1")
76+
return create_struct(title, vault).details.notesPlain
77+
end
78+
if version.start_with?("2")
79+
create_struct(title, vault).fields.first.value
80+
end
7381
end
7482

7583
def get_items(params)
@@ -80,6 +88,21 @@ def get_items(params)
8088
return get_secure_note(params['title'], params['vault'])
8189
end
8290
end
91+
92+
def get_version
93+
%x(op --version).strip
94+
end
95+
96+
def get_item(item, vault, version)
97+
case version
98+
when version.start_with?("1")
99+
%x(op get item --vault='#{vault}' '#{item}' 2>&1)
100+
when version.start_with?("2")
101+
%x(op item get --vault='#{vault}' '#{item}' --format json 2>&1)
102+
else
103+
raise OnePasswordInvalidVersion, "Unsupported version of 1Password: #{version}"
104+
end
105+
end
83106
end
84107
end
85108
end

0 commit comments

Comments
 (0)