@@ -4,14 +4,14 @@ class OnePassword
44 OP_CLI_VERSION = '2.32.1' . freeze
55 OP_CLI_DOWNLOAD_URL_AMD64 = "https://cache.agilebits.com/dist/1P/op2/pkg/v#{ OP_CLI_VERSION } /op_linux_amd64_v#{ OP_CLI_VERSION } .zip" . freeze
66 OP_CLI_DOWNLOAD_URL_ARM64 = "https://cache.agilebits.com/dist/1P/op2/pkg/v#{ OP_CLI_VERSION } /op_linux_arm64_v#{ OP_CLI_VERSION } .zip" . freeze
7- STDIO_TRUNCATE = 2000 . freeze
7+ STDIO_TRUNCATE = 2000
88
99 def self . op_whoami ( type = 'auto' )
1010 cli = op_cli
1111 env = op_environment ( type )
1212
1313 command = "#{ cli } whoami"
14- run_shellout ( command , env : env , type : type , event : 'op_whoami' , log_stdout : true ) . stdout . strip
14+ run_shellout ( command , :env => env , :type => type , :event => 'op_whoami' , :log_stdout => true ) . stdout . strip
1515 end
1616
1717 def self . op_read ( reference , type = 'auto' )
@@ -21,20 +21,22 @@ def self.op_read(reference, type = 'auto')
2121 # 1Password Connect Server does not support `op user get --me`
2222 if [ 'auto' , 'service_account' ] . include? ( type )
2323 command = "#{ cli } user get --me"
24- run_shellout ( command , env : env , type : type , event : 'op_user_get_me' , log_stdout : true )
24+ run_shellout ( command , :env => env , :type => type , :event => 'op_user_get_me' , :log_stdout => true )
2525 else
26- Chef ::Log . debug ( "boxcutter_onepassword[op_read]: skipping `op user get --me` for type=#{ type . inspect } (connect_server)" )
26+ Chef ::Log . debug (
27+ "boxcutter_onepassword[op_read]: skipping `op user get --me` for type=#{ type . inspect } (connect_server)" ,
28+ )
2729 end
2830
2931 command = "#{ cli } read '#{ reference } '"
3032 # IMPORTANT: Do not log stdout (secret contents)
3133 run_shellout (
3234 command ,
33- env : env ,
34- type : type ,
35- event : 'op_read' ,
36- extra : { reference : reference } ,
37- log_stdout : false
35+ :env => env ,
36+ :type => type ,
37+ :event => 'op_read' ,
38+ :extra => { :reference => reference } ,
39+ :log_stdout => false
3840 ) . stdout . strip
3941 end
4042
@@ -48,18 +50,17 @@ def self.op_document_get(item, vault, type = 'auto')
4850 # Documents may be secrets too; default: no stdout logging.
4951 run_shellout (
5052 command ,
51- env : env ,
52- type : type ,
53- event : 'op_document_get' ,
54- extra : { item : item , vault : vault } ,
53+ :env => env ,
54+ :type => type ,
55+ :event => 'op_document_get' ,
56+ :extra => { :item => item , :vault => vault } ,
5557 log_stdout : false
5658 ) . stdout . strip
5759 end
5860
5961 def self . op_environment ( type )
60- # Determine which auth mode we’ ll use, and log clearly (without secrets).
62+ # Determine which auth mode we' ll use, and log clearly (without secrets).
6163 requested = type
62- chosen = nil
6364
6465 if op_connect_server_token_found? && [ 'auto' , 'connect_server' ] . include? ( requested )
6566 chosen = 'connect_server'
@@ -71,7 +72,7 @@ def self.op_environment(type)
7172
7273 Chef ::Log . info (
7374 "boxcutter_onepassword[op_environment]: using auth=#{ chosen } requested=#{ requested . inspect } " \
74- "env_keys=#{ env . keys . sort . inspect } sources=#{ summarize_token_sources ( env ) } "
75+ "env_keys=#{ env . keys . sort . inspect } sources=#{ summarize_token_sources ( env ) } " ,
7576 )
7677 return env
7778 end
@@ -81,20 +82,21 @@ def self.op_environment(type)
8182 env = {
8283 'OP_SERVICE_ACCOUNT_TOKEN' => token_from_env_or_file (
8384 'OP_SERVICE_ACCOUNT_TOKEN' ,
84- op_service_account_token_path
85+ op_service_account_token_path ,
8586 ) ,
8687 }
8788
8889 Chef ::Log . info (
8990 "boxcutter_onepassword[op_environment]: using auth=#{ chosen } requested=#{ requested . inspect } " \
90- "env_keys=#{ env . keys . sort . inspect } sources=#{ summarize_token_sources ( env ) } "
91+ "env_keys=#{ env . keys . sort . inspect } sources=#{ summarize_token_sources ( env ) } " ,
9192 )
9293 return env
9394 end
9495
9596 Chef ::Log . error (
9697 "boxcutter_onepassword[op_environment]: no usable auth found requested=#{ requested . inspect } " \
97- "connect_server_present=#{ op_connect_server_token_found? } service_account_present=#{ op_service_account_token_found? } "
98+ "connect_server_present=#{ op_connect_server_token_found? } " \
99+ "service_account_present=#{ op_service_account_token_found? } " ,
98100 )
99101 fail "boxcutter_onepassword[op_environment]: 1Password token not found (type=#{ requested . inspect } )"
100102 end
@@ -110,7 +112,7 @@ def self.bootstrap_op_cli
110112
111113 def self . op_cli
112114 unless ::File . exist? ( '/usr/bin/op' )
113- Chef ::Log . warn ( " boxcutter_onepassword[op_cli]: /usr/bin/op not found; bootstrapping op cli at compile time" )
115+ Chef ::Log . warn ( ' boxcutter_onepassword[op_cli]: /usr/bin/op not found; bootstrapping op cli at compile time' )
114116 install_bootstrap_op_cli
115117 return bootstrap_op_cli
116118 end
@@ -138,15 +140,19 @@ def self.install_bootstrap_op_cli
138140
139141 uri = URI . parse ( url )
140142
141- Chef ::Log . info ( "boxcutter_onepassword[install_bootstrap_op_cli]: downloading op cli arch=#{ architecture } to #{ tmp_path } (basename=#{ ::File . basename ( url ) } )" )
143+ Chef ::Log . info (
144+ "boxcutter_onepassword[install_bootstrap_op_cli]: downloading op cli " \
145+ "arch=#{ architecture } to #{ tmp_path } (basename=#{ ::File . basename ( url ) } )" ,
146+ )
142147
143148
144149 # Open a connection and download the file
145150 Net ::HTTP . start ( uri . host , uri . port , :use_ssl => uri . scheme == 'https' ) do |http |
146151 request = Net ::HTTP ::Get . new ( uri )
147152 http . request ( request ) do |response |
148153 if response . code . to_i >= 400
149- fail "boxcutter_onepassword[install_bootstrap_op_cli]: failed download http=#{ response . code } url_basename=#{ ::File . basename ( url ) } "
154+ fail "boxcutter_onepassword[install_bootstrap_op_cli]: failed download " \
155+ "http=#{ response . code } url_basename=#{ ::File . basename ( url ) } "
150156 end
151157
152158 # Write the file to disk
@@ -168,7 +174,9 @@ def self.install_bootstrap_op_cli
168174 end
169175
170176 def self . unzip_file ( zip_file , filename , destination )
171- Chef ::Log . debug ( "boxcutter_onepassword[unzip_file]: extracting #{ filename . inspect } from #{ zip_file } to #{ destination } " )
177+ Chef ::Log . debug (
178+ "boxcutter_onepassword[unzip_file]: extracting #{ filename . inspect } from #{ zip_file } to #{ destination } " ,
179+ )
172180
173181 Zip ::File . open ( zip_file ) do |zip |
174182 entry = zip . find_entry ( filename )
@@ -193,12 +201,11 @@ def self.op_connect_host_path
193201 op_connect_host_path = '/etc/cinc/op_connect_host'
194202 if ::File . exist? ( op_connect_host_path )
195203 Chef ::Log . debug ( "boxcutter_onepassword: using #{ op_connect_host_path } for op_connect_host_path" )
196- op_connect_host_path
197204 else
198205 op_connect_host_path = '/etc/chef/op_connect_host'
199206 Chef ::Log . debug ( "boxcutter_onepassword: using #{ op_connect_host_path } for op_connect_host_path" )
200- op_connect_host_path
201207 end
208+ op_connect_host_path
202209 end
203210
204211 def self . op_connect_token_path
@@ -232,13 +239,16 @@ def self.op_connect_server_token_found?
232239 def self . op_service_account_token_path
233240 op_service_account_token_path = '/etc/cinc/op_service_account_token'
234241 if ::File . exist? ( op_service_account_token_path )
235- Chef ::Log . debug ( "boxcutter_onepassword: using #{ op_service_account_token_path } for op_service_account_token_path" )
236- op_service_account_token_path
242+ Chef ::Log . debug (
243+ "boxcutter_onepassword: using #{ op_service_account_token_path } for op_service_account_token_path" ,
244+ )
237245 else
238246 op_service_account_token_path = '/etc/chef/op_service_account_token'
239- Chef ::Log . debug ( "boxcutter_onepassword: using #{ op_service_account_token_path } for op_service_account_token_path" )
240- op_service_account_token_path
247+ Chef ::Log . debug (
248+ "boxcutter_onepassword: using #{ op_service_account_token_path } for op_service_account_token_path"
249+ )
241250 end
251+ op_service_account_token_path
242252 end
243253
244254 def self . op_service_account_token_found?
0 commit comments