Class: Fastlane::Cryptex::Encrypt
- Inherits:
-
Object
- Object
- Fastlane::Cryptex::Encrypt
- Defined in:
- lib/fastlane/plugin/cryptex/encrypt.rb
Instance Method Summary collapse
-
#clear_password(git_url) ⇒ Object
removes the password from the keychain again.
- #decrypt_repo(path: nil, git_url: nil, manual_password: nil, digest: nil) ⇒ Object
- #encrypt_repo(path: nil, git_url: nil, digest: nil) ⇒ Object
- #iterate(source_path) ⇒ Object
- #password(git_url) ⇒ Object
- #server_name(git_url) ⇒ Object
- #store_password(git_url, password) ⇒ Object
Instance Method Details
#clear_password(git_url) ⇒ Object
removes the password from the keychain again
34 35 36 |
# File 'lib/fastlane/plugin/cryptex/encrypt.rb', line 34 def clear_password(git_url) Security::InternetPassword.delete(server: server_name(git_url)) end |
#decrypt_repo(path: nil, git_url: nil, manual_password: nil, digest: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fastlane/plugin/cryptex/encrypt.rb', line 49 def decrypt_repo(path: nil, git_url: nil, manual_password: nil, digest: nil) iterate(path) do |current| begin crypt(path: current, password: manual_password || password(git_url), encrypt: false, digest: digest) rescue StandardError UI.error "Couldn't decrypt the repo, please make sure you enter the right password!" UI.user_error!("Invalid password passed via 'CRYPTEX_PASSWORD'") if ENV["CRYPTEX_PASSWORD"] clear_password(git_url) decrypt_repo(path: path, git_url: git_url, digest: digest) return end UI.success "🔓 Decrypted '#{File.basename(current)}'" if $verbose end UI.success "🔓 Successfully decrypted certificates repo" end |
#encrypt_repo(path: nil, git_url: nil, digest: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fastlane/plugin/cryptex/encrypt.rb', line 38 def encrypt_repo(path: nil, git_url: nil, digest: nil) iterate(path) do |current| crypt(path: current, password: password(git_url), encrypt: true, digest: digest) UI.success "🔒 Encrypted '#{File.basename(current)}'" if $verbose end UI.success "🔒 Successfully encrypted certificates repo" end |
#iterate(source_path) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/fastlane/plugin/cryptex/encrypt.rb', line 68 def iterate(source_path) Dir[File.join(source_path, "**", "*.{crypt}")].each do |path| next if File.directory?(path) yield(path) end end |
#password(git_url) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fastlane/plugin/cryptex/encrypt.rb', line 11 def password(git_url) password = ENV["CRYPTEX_PASSWORD"] unless password item = Security::InternetPassword.find(server: server_name(git_url)) password = item.password if item end unless password UI.important "Enter the passphrase that should be used to encrypt/decrypt your repository" UI.important "This passphrase is specific per repository and will be stored in your local keychain" UI.important "Make sure to remember the password, as you'll need it when you run cryptex on a different machine" password = ChangePassword.ask_password(confirm: true) store_password(git_url, password) end return password end |
#server_name(git_url) ⇒ Object
7 8 9 |
# File 'lib/fastlane/plugin/cryptex/encrypt.rb', line 7 def server_name(git_url) ["cryptex", git_url].join("_") end |
#store_password(git_url, password) ⇒ Object
29 30 31 |
# File 'lib/fastlane/plugin/cryptex/encrypt.rb', line 29 def store_password(git_url, password) Security::InternetPassword.add(server_name(git_url), "", password) end |