firim 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/firim/account_manager.rb +98 -0
- data/lib/firim/commands_generator.rb +50 -1
- data/lib/firim/detect_values.rb +8 -1
- data/lib/firim/options.rb +4 -0
- data/lib/firim/runner.rb +1 -1
- data/lib/firim/version.rb +1 -1
- data/lib/firim.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d0731d7d2b35bf81f320244a6a7c62a947f6a67
|
4
|
+
data.tar.gz: 5dbebf6ca5a24c7db39816a3ae229a1cc8caeede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 851d13bbbdcf11e988d82eb972d130fe9c13874abdd2ffe058ade87ab5967673d307c4aa709d165f0848c1a4c294d661a0b58a980b4df4363a7f708da1506a56
|
7
|
+
data.tar.gz: 3a3c9dbbf0e6f9c438aafe4ad5de0283e69f42e350de429fcade6a795d0130b8e0f8ae517df49b429d979ace458661d1127d5da3ed7fc3fb00574d3466fed3f7
|
data/README.md
CHANGED
@@ -36,6 +36,17 @@ You can specify the app infomations in `Firimfile`, To get a list of available o
|
|
36
36
|
Upload with icon ***NOTICE: Icon must be jpg format***
|
37
37
|
|
38
38
|
firim -i [your_ipa_path] -l [your_icon_path]
|
39
|
+
|
40
|
+
# Assgin API Token
|
41
|
+
|
42
|
+
There are three ways to assgin Firim API Token
|
43
|
+
|
44
|
+
1. Set `FIRIM_TOKEN` environment variables
|
45
|
+
2. Add `token` to `macOS Keychain`
|
46
|
+
3. Set in `Firimfile`
|
47
|
+
|
48
|
+
`Firim` will check the value from 1 to 3. Run `Firim` will add `token` to `keychain` in interactive shell. Also can use `firim addtoken` and `firim removetoken` to add or remove `token`.
|
49
|
+
|
39
50
|
|
40
51
|
# Need help?
|
41
52
|
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'security'
|
2
|
+
require 'highline/import' # to hide the entered password
|
3
|
+
|
4
|
+
module Firim
|
5
|
+
class AccountManager
|
6
|
+
DEFAULT_PREFIX = "firim"
|
7
|
+
DEFAULT_USERNAME = "default"
|
8
|
+
# @param prefix [String] Very optional, is used for the
|
9
|
+
# prefix on keychain
|
10
|
+
# @param note [String] An optional note that will be shown next
|
11
|
+
# to the token and token prompt
|
12
|
+
def initialize(user: nil, token: nil, prefix: nil, note: nil)
|
13
|
+
@prefix = prefix || DEFAULT_PREFIX
|
14
|
+
|
15
|
+
@user = user
|
16
|
+
@token = token
|
17
|
+
@note = note
|
18
|
+
end
|
19
|
+
|
20
|
+
# Is the prefix default prefix "firim"
|
21
|
+
def default_prefix?
|
22
|
+
@prefix == DEFAULT_PREFIX
|
23
|
+
end
|
24
|
+
|
25
|
+
def fetch_token_from_env
|
26
|
+
ENV["FIRIM_TOKEN"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def token(ask_if_missing: true)
|
30
|
+
@token ||= fetch_token_from_env
|
31
|
+
|
32
|
+
unless @token
|
33
|
+
item = Security::InternetPassword.find(server: server_name)
|
34
|
+
@token ||= item.password if item
|
35
|
+
end
|
36
|
+
ask_for_token while ask_if_missing && @token.to_s.length == 0
|
37
|
+
return @token
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_to_keychain
|
41
|
+
Security::InternetPassword.add(server_name, @user, token)
|
42
|
+
end
|
43
|
+
|
44
|
+
def remove_from_keychain
|
45
|
+
Security::InternetPassword.delete(server: server_name)
|
46
|
+
@token = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def server_name
|
50
|
+
"#{@prefix}.#{user_or_defualt}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def user_or_defualt
|
54
|
+
if @user.to_s.length == 0
|
55
|
+
return DEFAULT_USERNAME
|
56
|
+
end
|
57
|
+
@user
|
58
|
+
end
|
59
|
+
|
60
|
+
def ask_for_token
|
61
|
+
puts "-------------------------------------------------------------------------------------".green
|
62
|
+
puts "Please provide your Firim Token".green
|
63
|
+
puts "The Token you enter will be stored in your macOS Keychain".green
|
64
|
+
if default_prefix?
|
65
|
+
# We don't want to show this message, if we ask for the application specific token
|
66
|
+
# which has a different prefix
|
67
|
+
puts "You can also pass the token using the `FIRIM_TOKEN` environment variable".green
|
68
|
+
end
|
69
|
+
puts "Or fill in Firimfile `firim_api_token`".green
|
70
|
+
puts "-------------------------------------------------------------------------------------".green
|
71
|
+
|
72
|
+
if @user.to_s.length == 0
|
73
|
+
raise "running in non-interactive shell" if $stdout.isatty == false
|
74
|
+
prompt_text = "Username(not necessary)"
|
75
|
+
prompt_text += " (#{@note})" if @note
|
76
|
+
prompt_text += ": "
|
77
|
+
@user = ask(prompt_text)
|
78
|
+
end
|
79
|
+
|
80
|
+
while @token.to_s.length == 0
|
81
|
+
raise "Missing Token for #{user_or_defualt}, and running in non-interactive shell" if $stdout.isatty == false
|
82
|
+
note = @note + " " if @note
|
83
|
+
@token = ask("Token (#{note}for #{user_or_defualt}): ") { |q| q.echo = "*" }
|
84
|
+
end
|
85
|
+
|
86
|
+
return true if (/darwin/ =~ RUBY_PLATFORM).nil? # mac?, since we don't have access to the helper here
|
87
|
+
|
88
|
+
# Now we store this information in the keychain
|
89
|
+
if add_to_keychain
|
90
|
+
return true
|
91
|
+
else
|
92
|
+
puts "Could not store token in keychain".red
|
93
|
+
return false
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -19,7 +19,7 @@ module Firim
|
|
19
19
|
program :version, Firim::VERSION
|
20
20
|
program :description, 'fir.im command tool'
|
21
21
|
program :help, 'Author', 'Hailong Wang <whlsxl+g@gmail.com>'
|
22
|
-
program :help, 'GitHub', 'https://github.com/
|
22
|
+
program :help, 'GitHub', 'https://github.com/whlsxl/firim'
|
23
23
|
program :help_formatter, :compact
|
24
24
|
|
25
25
|
FastlaneCore::CommanderGenerator.new.generate(Firim::Options.available_options)
|
@@ -60,9 +60,58 @@ module Firim
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
command :addtoken do |c|
|
64
|
+
c.syntax = 'firim addtoken'
|
65
|
+
c.description = 'Add a firim api token to keychain. username is not necessary, Just a sign for multiple api token.'
|
66
|
+
|
67
|
+
c.option '--username username', String, 'Username to add(not necessary).'
|
68
|
+
c.option '--token token', String, 'API token to add'
|
69
|
+
|
70
|
+
c.action do |args, options|
|
71
|
+
username = options.username || ask('Username(not necessary): ')
|
72
|
+
token = options.token || ask('Password: ') { |q| q.echo = '*'}
|
73
|
+
|
74
|
+
add(username, token)
|
75
|
+
|
76
|
+
puts "Token #{username || '`default`'}: #{'*' * token.length} added to keychain."
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Command to remove credential from Keychain
|
81
|
+
command :removetoken do |c|
|
82
|
+
c.syntax = 'firim removetoken'
|
83
|
+
c.description = 'Removes a firim token from the keychain.'
|
84
|
+
|
85
|
+
c.option '--username username', String, 'Username to remove(or default).'
|
86
|
+
|
87
|
+
c.action do |args, options|
|
88
|
+
username = options.username || ask('Username: ')
|
89
|
+
|
90
|
+
remove(username)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
63
94
|
default_command :run
|
64
95
|
|
65
96
|
run!
|
66
97
|
end
|
98
|
+
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
# Add entry to Apple Keychain
|
103
|
+
def add(username, token)
|
104
|
+
Firim::AccountManager.new(
|
105
|
+
user: username,
|
106
|
+
token: token
|
107
|
+
).add_to_keychain
|
108
|
+
end
|
109
|
+
|
110
|
+
# Remove entry from Apple Keychain using AccountManager
|
111
|
+
def remove(username)
|
112
|
+
Firim::AccountManager.new(
|
113
|
+
user: username
|
114
|
+
).remove_from_keychain
|
115
|
+
end
|
67
116
|
end
|
68
117
|
end
|
data/lib/firim/detect_values.rb
CHANGED
@@ -34,7 +34,14 @@ module Firim
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def find_firim_api_token(options)
|
37
|
-
|
37
|
+
option_token = options[:firim_api_token]
|
38
|
+
keychain_token = Firim::AccountManager.new(user: options[:firim_username])
|
39
|
+
token = keychain_token.token(ask_if_missing: option_token == nil)
|
40
|
+
if token
|
41
|
+
options[:firim_api_token] = token
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
38
45
|
options[:firim_api_token] ||= UI.input("The API Token of fir.im: ")
|
39
46
|
end
|
40
47
|
end
|
data/lib/firim/options.rb
CHANGED
@@ -8,7 +8,11 @@ module Firim
|
|
8
8
|
# firim info
|
9
9
|
FastlaneCore::ConfigItem.new(key: :firim_api_token,
|
10
10
|
short_option: "-a",
|
11
|
+
optional: true,
|
11
12
|
description: "fir.im user api token"),
|
13
|
+
FastlaneCore::ConfigItem.new(key: :firim_username,
|
14
|
+
optional: true,
|
15
|
+
description: "fir.im username, a sign for identify different token"),
|
12
16
|
|
13
17
|
# Content path
|
14
18
|
FastlaneCore::ConfigItem.new(key: :ipa,
|
data/lib/firim/runner.rb
CHANGED
@@ -51,7 +51,7 @@ module Firim
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def validation_response response_data
|
54
|
-
error_code = response_data['
|
54
|
+
error_code = response_data['code'].to_i rescue 0
|
55
55
|
if error_code == 100020
|
56
56
|
UI.user_error!("Firim API Token(#{options[:firim_api_token]}) not correct")
|
57
57
|
end
|
data/lib/firim/version.rb
CHANGED
data/lib/firim.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- whlsxl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fastlane
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- bin/firim
|
115
115
|
- lib/assets/FirimfileDefault
|
116
116
|
- lib/firim.rb
|
117
|
+
- lib/firim/account_manager.rb
|
117
118
|
- lib/firim/commands_generator.rb
|
118
119
|
- lib/firim/detect_values.rb
|
119
120
|
- lib/firim/options.rb
|