module GHI::Authorization
Public Class Methods
password()
click to toggle source
# File lib/ghi/authorization.rb, line 74 def password return @password if defined? @password @password = GHI.config 'github.password' end
token()
click to toggle source
# File lib/ghi/authorization.rb, line 13 def token return @token if defined? @token @token = GHI.config 'ghi.token' end
username()
click to toggle source
# File lib/ghi/authorization.rb, line 69 def username return @username if defined? @username @username = GHI.config 'github.user' end
Private Class Methods
security(command = nil, username = nil, password = nil)
click to toggle source
# File lib/ghi/authorization.rb, line 123 def security command = nil, username = nil, password = nil if command.nil? && username.nil? && password.nil? return system 'which security >/dev/null' end run = [ 'security', "#{command}-internet-password", "-a #{username}", '-s github.com', "-l 'ghi token'" ] run << %(-w#{" #{password}" if password}) unless password.nil? run << '>/dev/null 2>&1' unless command == 'find' run.join ' ' end
store_token!(username, token, local)
click to toggle source
# File lib/ghi/authorization.rb, line 81 def store_token! username, token, local if security run = [] run << security('delete', username) run << security('add', username, token) find = security 'find', username, false run << %(git config#{' --global' unless local} ghi.token "!#{find}") system run.join ' ; ' puts "✔︎ Token saved to keychain." return end command = "git config#{' --global' unless local} ghi.token #{token}" system command unless local at_exit do warn <<EOF Your ~/.gitconfig has been modified by way of: #{command} #{bright { blink { 'Do not check this change into public source control!' } }} You can increase security by storing the token in a secure place that can be fetched from the command line. E.g., on OS X: git config --global ghi.token \\ "!security -a #{username} -s github.com -l 'ghi token' -w" Alternatively, set the following env var in a private dotfile: export GHI_TOKEN="#{token}" EOF end end end