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 all 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,97 @@ | ||
module Fastlane | ||
module Actions | ||
class UnlockKeychainAction < Action | ||
def self.run(params) | ||
keychain_path = self.expand_keychain_path(params[:path]) | ||
add_to_search_list = params[:add_to_search_list] | ||
|
||
if keychain_path.empty? | ||
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(keychain_path) | ||
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(keychain_path) | ||
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 with Keychain Access | ||
unless result.include?(keychain_path) | ||
commands = [] | ||
commands << Fastlane::Actions.sh("open #{escaped_path}") | ||
commands | ||
end | ||
end | ||
|
||
def self.expand_keychain_path(keychain_path) | ||
possible_locations = [] | ||
possible_locations << keychain_path | ||
possible_locations << "~/Library/Keychains/#{keychain_path}" | ||
possible_locations << "~/Library/Keychains/#{keychain_path}.keychain" | ||
|
||
possible_locations.each do |location| | ||
expanded_location = File.expand_path(location) | ||
if File.exist?(expanded_location) | ||
return expanded_location | ||
end | ||
end | ||
|
||
return "" | ||
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. Redundant |
||
end | ||
|
||
##################################################### | ||
# @!group Documentation | ||
##################################################### | ||
|
||
def self.description | ||
"Unlock a keychain" | ||
end | ||
|
||
def self.details | ||
"Unlocks the give keychain file and 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. [81/80] |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe Fastlane do | ||
describe Fastlane::FastFile do | ||
describe "Unlock keychain Integration" do | ||
|
||
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. Extra empty line detected at block body beginning. |
||
it "works with path and password and existing keychain" do | ||
keychain_path = Tempfile.new('foo').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. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
|
||
result = Fastlane::FastFile.new.parse("lane :test do | ||
unlock_keychain ({ | ||
path: '#{keychain_path}', | ||
password: 'testpassword', | ||
}) | ||
end").runner.execute(:test) | ||
|
||
expect(result.size).to eq 2 | ||
expect(result[0]).to eq "security unlock-keychain -p testpassword #{keychain_path}" | ||
expect(result[1]).to eq "security set-keychain-settings #{keychain_path}" | ||
end | ||
end | ||
end | ||
end | ||
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. Final newline missing. |
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.
Redundant
self
detected.