aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2018-06-01 18:23:38 +0100
committerChristopher Baines <mail@cbaines.net>2018-06-01 18:47:00 +0100
commit1135f97d58c9978e3da074c60ec073a42545289c (patch)
tree97fb32ca848e0e895aee7034e1ffa1cf18b0e8f0
parent03b1ffc1a0576f707b323f821597770d66eaae1e (diff)
downloadgovuk-mini-environment-admin-1135f97d58c9978e3da074c60ec073a42545289c.tar
govuk-mini-environment-admin-1135f97d58c9978e3da074c60ec073a42545289c.tar.gz
Add a read_json_file utility to the GovukGuix:Job class
This will be useful when reading data from the store, including from remote machines.
-rw-r--r--app/jobs/govuk_guix/job.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/jobs/govuk_guix/job.rb b/app/jobs/govuk_guix/job.rb
index 2a028d6..342eb9d 100644
--- a/app/jobs/govuk_guix/job.rb
+++ b/app/jobs/govuk_guix/job.rb
@@ -44,6 +44,25 @@ class GovukGuix::Job < Que::Job
end
end
+ def read_json_file(filename, from_remote_host: nil)
+ if from_remote_host
+ command = [
+ 'ssh',
+ from_remote_host,
+ 'cat',
+ filename
+ ]
+
+ stdout_str, status = Open3.capture2(*command)
+
+ puts "STATUS: #{status}"
+
+ stdout_str
+ else
+ JSON.parse(File.read(filename))
+ end
+ end
+
def hash_to_arguments(hash)
hash.map do |(key, value)|
transformed_key = key.tr('_', '-')