Class: Fastlane::Cryptex::Runner
- Inherits:
-
Object
- Object
- Fastlane::Cryptex::Runner
- Defined in:
- lib/fastlane/plugin/cryptex/runner.rb
Instance Attribute Summary collapse
-
#git_changed ⇒ Object
Returns the value of attribute git_changed.
Instance Method Summary collapse
- #delete_file(params) ⇒ Object
- #export_env(params) ⇒ Object
- #export_file(params) ⇒ Object
- #import_env(params) ⇒ Object
- #import_file(params) ⇒ Object
- #nuke_all(params) ⇒ Object
- #run(params) ⇒ Object
Instance Attribute Details
#git_changed ⇒ Object
Returns the value of attribute git_changed.
4 5 6 |
# File 'lib/fastlane/plugin/cryptex/runner.rb', line 4 def git_changed @git_changed end |
Instance Method Details
#delete_file(params) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/fastlane/plugin/cryptex/runner.rb', line 62 def delete_file(params) UI.user_error!("No key file supplied") if params[:key].to_s.length.zero? path = "#{params[:workspace]}/#{params[:key]}.crypt" UI.user_error!("Wrong key file supplied.") unless File.exist? path FileUtils.rm path @git_changed = true end |
#export_env(params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fastlane/plugin/cryptex/runner.rb', line 28 def export_env(params) UI.user_error!("No key file supplied") if params[:key].to_s.length.zero? env_world_file = "#{params[:workspace]}/#{params[:key]}_env_world.crypt" UI.user_error!("Wrong key file supplied.") unless File.exist? env_world_file world_data = File.read(env_world_file) world_data_parsed = JSON.parse(world_data) ret_json = {} world_data_parsed.keys.each do |el| next unless !params[:hash] || (params[:hash] && params[:hash].keys.include?(el)) ret_json[el] = world_data_parsed[el] if params[:set_env] ENV[el] = world_data_parsed[el] end end return world_data_parsed end |
#export_file(params) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fastlane/plugin/cryptex/runner.rb', line 71 def export_file(params) UI.user_error!("No key file supplied") if params[:key].to_s.length.zero? path = "#{params[:workspace]}/#{params[:key]}.crypt" UI.user_error!("Wrong key file supplied.") unless File.exist? path outfile = params[:out] unless params[:out].to_s.length.zero? outfile ||= File.basename(params[:key]) outfile = File.(outfile) require "fileutils" FileUtils.mkdir_p(File.dirname(outfile)) File.write(outfile, File.read(path)) end |
#import_env(params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fastlane/plugin/cryptex/runner.rb', line 6 def import_env(params) UI.user_error!("No input hash supplied") if params[:hash].to_s.length.zero? UI.user_error!("No key file supplied") if params[:key].to_s.length.zero? env_world_file = "#{params[:workspace]}/#{params[:key]}_env_world.crypt" if params[:hash].kind_of?(String) begin params[:hash] = JSON.parse(params[:hash]) rescue StandardError # might contain sensitive informatio UI.user_error!("Supplied :hash isn't in json format") end end if params[:hash].kind_of?(Hash) json = params[:hash].to_json else UI.user_error!("Not really sure what to do with :hash param of type #{params[:hash].class}") end File.write(env_world_file, json) @git_changed = true end |
#import_file(params) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fastlane/plugin/cryptex/runner.rb', line 47 def import_file(params) UI.user_error!("No input file supplied") if params[:in].to_s.length.zero? in_path = File.(params[:in]) UI.user_error!("File to import at `#{in_path}` not found") unless File.exist? in_path file = params[:key] unless params[:key].to_s.length.zero? file ||= File.basename(params[:in]) require "fileutils" FileUtils.mkdir_p(File.dirname("#{params[:workspace]}/#{file}")) File.write("#{params[:workspace]}/#{file}.crypt", File.read(in_path)) @git_changed = true end |
#nuke_all(params) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/fastlane/plugin/cryptex/runner.rb', line 86 def nuke_all(params) Encrypt.new.iterate(params[:workspace]) do |item| FileUtils.rm_f item end @git_changed = true end |
#run(params) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fastlane/plugin/cryptex/runner.rb', line 93 def run(params) FastlaneCore::PrintTable.print_values(config: params, hide_keys: [], title: "Summary for cryptex #{Cryptex::VERSION}") @git_changed = false params[:workspace] = GitHelper.clone(params[:git_url], params[:shallow_clone], skip_docs: params[:skip_docs], branch: params[:git_branch], digest: params[:digest]) @params = params if params[:type] == "import_env" return import_env(params) end if params[:type] == "export_env" return export_env(params) end if params[:type] == "import" import_file(params) return end if params[:type] == "delete" delete_file(params) return end if params[:type] == "export" export_file(params) return end if params[:type] == "nuke" nuke_all(params) return end ensure if git_changed = GitHelper.(params) GitHelper.commit_changes(params[:workspace], , params[:git_url], params[:git_branch], digest: params[:digest]) end GitHelper.clear_changes end |