credentials_manager 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26653ecd3f629c5c898c14974f86a934afc79039
4
+ data.tar.gz: b798286e071ca660f0feefca1a0e06656637108d
5
+ SHA512:
6
+ metadata.gz: e39574838aa27694de859188d15a286f4c8e359a966ec6f49f46234414965452225cf97d5d3800780c6798bded68767a376e695d6281cfcefd65f3234dc05d03
7
+ data.tar.gz: f08c8eee8e42848150e8687d37a8a93873f45d648f493399062e88b8cd7a9735082dac6e55bb624514e9bbac550b1b3110d9932bf32726e1d93274686b09cc97
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Felix Krause
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ ```CredentialsManager``` is used by most of the tools part of the [fastlane.tools](https://fastlane.tools) Toolchain.
2
+
3
+ To get more information about how your credentials are stored in the Mac OS Keychain, check out the description of [fastlane](https://github.com/KrauseFx/fastlane).
4
+
5
+ # License
6
+ This project is licensed under the terms of the MIT license. See the LICENSE file.
7
+
8
+ # Contributing
9
+
10
+ 1. Create an issue to discuss about your idea
11
+ 2. Fork it (https://github.com/KrauseFx/CredentialsManager/fork)
12
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
13
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
14
+ 5. Push to the branch (`git push origin my-new-feature`)
15
+ 6. Create a new Pull Request
@@ -0,0 +1,46 @@
1
+ module CredentialsManager
2
+ # Access the content of the app file (e.g. app identifier and Apple ID)
3
+ class AppfileConfig
4
+
5
+ def self.try_fetch_value(key)
6
+ if self.default_path
7
+ return self.new.data[key]
8
+ end
9
+ nil
10
+ end
11
+
12
+ def self.default_path
13
+ ["./fastlane/Appfile", "./Appfile"].each do |current|
14
+ return current if File.exists?current
15
+ end
16
+ nil
17
+ end
18
+
19
+
20
+
21
+ def initialize(path = nil)
22
+ path ||= self.class.default_path
23
+
24
+ raise "Could not find Appfile at path '#{path}'".red unless File.exists?(path)
25
+
26
+ full_path = File.expand_path(path)
27
+ Dir.chdir(File.expand_path('..', path)) do
28
+ eval(File.read(full_path))
29
+ end
30
+ end
31
+
32
+ def data
33
+ @data ||= {}
34
+ end
35
+
36
+ def app_identifier(value)
37
+ value ||= yield if block_given?
38
+ data[:app_identifier] = value if value
39
+ end
40
+
41
+ def apple_id(value)
42
+ value ||= yield if block_given?
43
+ data[:apple_id] = value if value
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,111 @@
1
+ require 'security'
2
+ require 'highline/import' # to hide the entered password
3
+
4
+ module CredentialsManager
5
+ # Handles reading out the password from the keychain or asking for login data
6
+ class PasswordManager
7
+ # @return [String] The username / email address of the currently logged in user
8
+ attr_accessor :username
9
+ # @return [String] The password of the currently logged in user
10
+ attr_accessor :password
11
+
12
+ HOST = "deliver" # there might be a string appended, if user has multiple accounts
13
+ private_constant :HOST
14
+
15
+ # A singleton object, which also makes sure, to use the correct Apple ID
16
+ # @param id_to_use (String) The Apple ID email address which should be used
17
+ def self.shared_manager(id_to_use = nil)
18
+ @@instance ||= PasswordManager.new(id_to_use)
19
+ end
20
+
21
+ # A new instance of PasswordManager.
22
+ #
23
+ # This already check the Keychain if there is a username and password stored.
24
+ # If that's not the case, it will ask for login data via stdin
25
+ # @param id_to_use (String) Apple ID (e.g. steve@apple.com) which should be used for this upload.
26
+ # if given, only the password will be asked/loaded.
27
+ def initialize(id_to_use = nil)
28
+
29
+ self.username ||= ENV["DELIVER_USER"] || id_to_use || AppfileConfig.try_fetch_value(:apple_id) || load_from_keychain[0]
30
+ self.password ||= ENV["DELIVER_PASSWORD"] || load_from_keychain[1]
31
+
32
+ if (self.username || '').length == 0 or (self.password || '').length == 0
33
+ puts "No username or password given. You can set environment variables:"
34
+ puts "DELIVER_USER, DELIVER_PASSWORD"
35
+
36
+ ask_for_login
37
+ end
38
+ end
39
+
40
+ # This method is called, when the iTunes backend returns that the login data is wrong
41
+ # This will ask the user, if he wants to re-enter the password
42
+ def password_seems_wrong
43
+ return false if Helper.is_test?
44
+
45
+ puts "It seems like the username or password for the account '#{self.username}' is wrong.".red
46
+ reenter = agree("Do you want to re-enter your username and password? (y/n)", true)
47
+ if reenter
48
+ remove_from_keychain
49
+
50
+ @username = nil
51
+ @password = nil
52
+
53
+ puts "You will have to re-run the recent command to use the new username/password.".yellow
54
+ return true
55
+ else
56
+ return false
57
+ end
58
+ end
59
+
60
+ private
61
+ def ask_for_login
62
+ puts "---------------------------------------------------------------------------".green
63
+ puts "The login information you enter now will be stored in your keychain ".green
64
+ puts "More information about that on GitHub: https://github.com/krausefx/fastlane".green
65
+ puts "---------------------------------------------------------------------------".green
66
+
67
+ username_was_there = self.username
68
+
69
+ while (self.username || '').length == 0
70
+ self.username = ask("Username: ")
71
+ end
72
+
73
+ self.password ||= load_from_keychain[1] # maybe there was already something stored in the keychain
74
+
75
+ if (self.password || '').length > 0
76
+ return true
77
+ else
78
+ while (self.password || '').length == 0
79
+ text = "Password: "
80
+ text = "Password (for #{self.username}): " if username_was_there
81
+ self.password = ask(text) { |q| q.echo = "*" }
82
+ end
83
+
84
+ # Now we store this information in the keychain
85
+ # Example usage taken from https://github.com/nomad/cupertino/blob/master/lib/cupertino/provisioning_portal/commands/login.rb
86
+ if Security::InternetPassword.add(hostname, self.username, self.password)
87
+ return true
88
+ else
89
+ Helper.log.error "Could not store password in keychain".red
90
+ return false
91
+ end
92
+ end
93
+ end
94
+
95
+ def remove_from_keychain
96
+ Helper.log.info "removing keychain item: #{hostname}".yellow
97
+ Security::InternetPassword.delete(:server => hostname)
98
+ end
99
+
100
+ def load_from_keychain
101
+ pass = Security::InternetPassword.find(:server => hostname)
102
+
103
+ return [pass.attributes['acct'], pass.password] if pass
104
+ return [nil, nil]
105
+ end
106
+
107
+ def hostname
108
+ [HOST, self.username].join('.')
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ module CredentialsManager
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'credentials_manager/password_manager'
2
+
3
+ # Third Party code
4
+ require 'colored'
5
+
6
+ module CredentialsManager
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: credentials_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Felix Krause
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.21
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.21
27
+ - !ruby/object:Gem::Dependency
28
+ name: colored
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: security
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ description: Password manager used in Fastlane.tools
98
+ email:
99
+ - krausefx@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE
105
+ - README.md
106
+ - lib/credentials_manager.rb
107
+ - lib/credentials_manager/appfile_config.rb
108
+ - lib/credentials_manager/password_manager.rb
109
+ - lib/credentials_manager/version.rb
110
+ homepage: http://fastlane.tools
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: 2.0.0
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.2.2
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Password manager used in Fastlane.tools
134
+ test_files: []