New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added unlock_keychain action #580
Changes from 2 commits
d76aa81
d18db95
08108cc
1da0d3e
50f27df
499e52e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
module Fastlane | ||
module Actions | ||
class UnlockKeychainAction < Action | ||
def self.run(params) | ||
@keychain_path = params[:path] | ||
add_to_search_list = params[:add_to_search_list] | ||
|
||
if !keychainfile_exists? | ||
raise "Could not find the keychain file: #{@keychain_path}".red | ||
end | ||
|
||
# add to search list if not already added | ||
if add_to_search_list | ||
add_keychain_to_search_list | ||
end | ||
|
||
escaped_path = @keychain_path.shellescape | ||
escaped_password = params[:password].shellescape | ||
|
||
commands = [] | ||
# unlock given keychain and disable lock and timeout | ||
commands << Fastlane::Actions.sh("security unlock-keychain -p #{escaped_password} #{escaped_path}", log: false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [119/80] |
||
commands << Fastlane::Actions.sh("security set-keychain-settings #{escaped_path}", log: false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [102/80] |
||
commands | ||
end | ||
|
||
def self.add_keychain_to_search_list | ||
escaped_path = @keychain_path.shellescape | ||
|
||
result = Fastlane::Actions.sh("security list-keychains", log: false) | ||
|
||
# add the keychain to the keychains list | ||
# the basic strategy is to open the keychain file it with Keychain Access | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [81/80] |
||
if !result.include?(@keychain_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can switch to |
||
commands = [] | ||
commands << Fastlane::Actions.sh("open #{escaped_path}") | ||
commands | ||
end | ||
end | ||
|
||
def self.keychainfile_exists? | ||
possible_locations = [] | ||
possible_locations << @keychain_path | ||
possible_locations << "~/Library/Keychains/#{@keychain_path}" | ||
possible_locations << "~/Library/Keychains/#{@keychain_path}.keychain" | ||
|
||
possible_locations.each do |location| | ||
expaded_location = File.expand_path(location) | ||
if File.exist?(expaded_location) | ||
@keychain_path = expaded_location | ||
return true | ||
end | ||
end | ||
end | ||
|
||
##################################################### | ||
# @!group Documentation | ||
##################################################### | ||
|
||
def self.description | ||
"Unlock a keychain" | ||
end | ||
|
||
def self.details | ||
"Unlocks the give keychain file and it adds it to the keychain search list." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [84/80] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate |
||
end | ||
|
||
def self.available_options | ||
[ | ||
FastlaneCore::ConfigItem.new(key: :path, | ||
env_name: "FL_UNLOCK_KEYCHAIN_PATH", | ||
description: "Path to the Keychain file", | ||
optional: false), | ||
FastlaneCore::ConfigItem.new(key: :password, | ||
env_name: "FL_UNLOCK_KEYCHAIN_PASSWORD", | ||
description: "Keychain password", | ||
optional: false), | ||
FastlaneCore::ConfigItem.new(key: :add_to_search_list, | ||
env_name: "FL_UNLOCK_KEYCHAIN_ADD_TO_SEARCH_LIST", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [89/80] |
||
description: "Add to keychain search list", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [82/80] |
||
is_string: false, | ||
default_value: true) | ||
|
||
] | ||
end | ||
|
||
def self.authors | ||
["xfreebird"] | ||
end | ||
|
||
def self.is_supported?(platform) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename |
||
platform == :ios | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to use
@keychain_path
? You could pass the keychain path from therun
method to the other methods, right?I'd prefer to not store anything in the action itself.