Class: Match::ChangePassword

Inherits:
Object
  • Object
show all
Defined in:
match/lib/match/change_password.rb

Overview

These functions should only be used while in (UI.) interactive mode

Class Method Summary collapse

Class Method Details

.ask_password(message: "Passphrase for Git Repo: ", confirm: nil) ⇒ Object

This method is called from both here, and from ‘openssl.rb`



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'match/lib/match/change_password.rb', line 48

def self.ask_password(message: "Passphrase for Git Repo: ", confirm: nil)
  ensure_ui_interactive
  loop do
    password = UI.password(message)
    if confirm
      password2 = UI.password("Type passphrase again: ")
      if password == password2
        return password
      end
    else
      return password
    end
    UI.error("Passphrases differ. Try again")
  end
end

.update(params: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'match/lib/match/change_password.rb', line 9

def self.update(params: nil)
  if params[:storage_mode] != "git"
    # Only git supports changing the password
    # All other storage options will most likely use more advanced
    # ways to encrypt files
    UI.user_error!("Only git-based match allows you to change your password, current `storage_mode` is #{params[:storage_mode]}")
  end

  ensure_ui_interactive

  to = ChangePassword.ask_password(message: "New passphrase for Git Repo: ", confirm: true)

  # Choose the right storage and encryption implementations
  storage = Storage.for_mode(params[:storage_mode], {
    git_url: params[:git_url],
    shallow_clone: params[:shallow_clone],
    skip_docs: params[:skip_docs],
    git_branch: params[:git_branch],
    git_full_name: params[:git_full_name],
    git_user_email: params[:git_user_email],
    clone_branch_directly: params[:clone_branch_directly]
  })
  storage.download

  encryption = Encryption.for_storage_mode(params[:storage_mode], {
    git_url: params[:git_url],
    working_directory: storage.working_directory
  })
  encryption.decrypt_files

  encryption.clear_password
  encryption.store_password(to)

  message = "[fastlane] Changed passphrase"
  files_to_commit = encryption.encrypt_files
  storage.save_changes!(files_to_commit: files_to_commit, custom_message: message)
end