Class: Match::Encrypt
- Inherits:
-
Object
- Object
- Match::Encrypt
- Defined in:
- lib/match/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) ⇒ Object
- #encrypt_repo(path: nil, git_url: nil) ⇒ 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/match/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) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/match/encrypt.rb', line 48 def decrypt_repo(path: nil, git_url: nil, manual_password: nil) iterate(path) do |current| begin crypt(path: current, password: manual_password || password(git_url), encrypt: false) rescue UI.error "Couldn't decrypt the repo, please make sure you enter the right password!" UI.user_error!("Invalid password passed via 'MATCH_PASSWORD'") if ENV["MATCH_PASSWORD"] clear_password(git_url) decrypt_repo(path: path, git_url: git_url) 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) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/match/encrypt.rb', line 38 def encrypt_repo(path: nil, git_url: nil) iterate(path) do |current| crypt(path: current, password: password(git_url), encrypt: true) UI.success "🔒 Encrypted '#{File.basename(current)}'" if $verbose end UI.success "🔒 Successfully encrypted certificates repo" end |
#password(git_url) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/match/encrypt.rb', line 9 def password(git_url) password = ENV["MATCH_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 certificates" 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 match on a different machine" while password.to_s.length == 0 password = ask("Passphrase for Git Repo: ".yellow) { |q| q.echo = "*" } end store_password(git_url, password) end return password end |
#server_name(git_url) ⇒ Object
5 6 7 |
# File 'lib/match/encrypt.rb', line 5 def server_name(git_url) ["match", git_url].join("_") end |
#store_password(git_url, password) ⇒ Object
29 30 31 |
# File 'lib/match/encrypt.rb', line 29 def store_password(git_url, password) Security::InternetPassword.add(server_name(git_url), "", password) end |