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

.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
# 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

  new_password = FastlaneCore::Helper.ask_password(message: "New passphrase for Git Repo: ", confirm: true)

  # Choose the right storage and encryption implementations
  storage = Storage.from_params(params)
  storage.download

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

  encryption.clear_password
  encryption.store_password(new_password)

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