lg_pod_plugin 1.1.6.5 → 1.1.6.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7af2ac8a760f94c57f82d9005cd1b366a7dc9b51ab09c887e43dff3e0f43b0c4
4
- data.tar.gz: f120886f336ce31ea35dcc38300a24561878a7a49963017484d26b59eb3e671e
3
+ metadata.gz: ad00d26eddca0197af9e74cce63dde7b58620b66694e5c97efeb6c8ca00c451d
4
+ data.tar.gz: 6f67d7bf931020022b87d2bb2de40b74d25716e6a4ef5b1dad0f70b0a7a03e67
5
5
  SHA512:
6
- metadata.gz: e304fe0bbafee6d7ad797c3bc32e60c4fb050109d29a2d04d27d0a22630a7e9abf024820e54891792c16b8953f0574b0876e4df2b67cf27f22e57af7c89a6352
7
- data.tar.gz: 13029c1d8e46a6dc0388fc7de8e78b470dbd6f040834d6554bab1c615a4344d7f8584efbf56714c1429262fb6478ec2fa6792cfedef7570b0ad3cd4b354ddfb4
6
+ metadata.gz: efa9785b96cd87f2d8af38fa907b6df5f036a7d4c6f3caa8c4cf338d07233271d27c78d1a0177fddda2117a760cefd3adb6f9c111045634e35d733131e774198
7
+ data.tar.gz: ee86b67391bafbfc0db8b4b9063935b3f736f38487f181e2a729402d6cc1368806ace7f8acb21850b229a0436307e6e099dde50448e305ffa9d3a3acafe2875d
data/lib/command/init.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'claide'
2
+ require 'json'
2
3
  require_relative 'command'
3
4
 
4
5
  module LgPodPlugin
@@ -7,8 +8,7 @@ module LgPodPlugin
7
8
  self.command = "init"
8
9
  self.abstract_command = false
9
10
  self.summary = '初始化gitlab projects 信息'
10
- attr_accessor :username
11
- attr_accessor :password
11
+ attr_accessor :token
12
12
  attr_accessor :host
13
13
  self.description = <<-DESC
14
14
  Manipulate the download cache for pods, like printing the cache content
@@ -17,16 +17,44 @@ module LgPodPlugin
17
17
 
18
18
  def initialize(argv)
19
19
  self.host = argv.option('host')
20
- self.username = argv.option('username')
21
- self.password = argv.option('password')
20
+ self.token = argv.option('token')
22
21
  super
23
22
  end
24
23
 
25
24
  def run
26
- raise unless self.host
27
- raise unless self.username
28
- raise unless self.password
29
- GitLabAPI.request_gitlab_access_token(self.host, self.username, self.password)
25
+ if self.host.nil? || self.host == ""
26
+ LgPodPlugin.log_red "传入host不能为空"
27
+ return
28
+ end
29
+ if self.token.nil? || self.token == ""
30
+ LgPodPlugin.log_red "传入token不能为空"
31
+ return
32
+ end
33
+ token_vaild = GitLabAPI.request_user_emails(self.host, self.token)
34
+ if token_vaild == "invalid token"
35
+ LgPodPlugin.log_red "无效的access_token, 请检查私人令牌是否在有限期内"
36
+ return
37
+ end
38
+ refresh_token = ""
39
+ expires_in = 7879680
40
+ created_at = Time.now.to_i
41
+ encrypt_access_token = LUtils.encrypt(self.token, "AZMpxzVxzbo3sFDLRZMpxzVxzbo3sFDZ")
42
+ hash = {"access_token": encrypt_access_token}
43
+ hash["token_type"] = "Bearer"
44
+ hash["expires_in"] = expires_in
45
+ hash["scope"] = "api"
46
+ hash["created_at"] = created_at
47
+ hash["refresh_token"] = refresh_token
48
+ db_path = LFileManager.download_director.join("database")
49
+ db_path.mkdir unless db_path.exist?
50
+ token_file = db_path.join("access_token.json")
51
+ str = JSON.generate(hash)
52
+ File.open(token_file.to_path, 'w+') { |f| f.write(str) }
53
+ LSqliteDb.shared.init_database
54
+ user_id = LUserAuthInfo.get_user_id(self.host)
55
+ user_model = LUserAuthInfo.new(user_id, "", "", self.host, self.token, "", (created_at + expires_in))
56
+ LSqliteDb.shared.insert_user_info(user_model)
57
+ LgPodPlugin.log_green "设置私人访问令牌成功"
30
58
  end
31
59
 
32
60
  end
@@ -23,23 +23,11 @@ module LgPodPlugin
23
23
  user_info = LSqliteDb.shared.query_user_info(user_id)
24
24
  # 用户授权 token 不存在, 提示用户输入用户名密码
25
25
  unless user_info
26
- user_info = GitLabAPI.get_gitlab_access_token_input(uri, user_id,nil ,nil )
26
+ user_info = GitLabAPI.get_gitlab_access_token(uri, user_id)
27
27
  return nil unless user_info
28
28
  end
29
- time_now = Time.now.to_i
30
- # 判断 token 是否失效
31
- if user_info.expires_in <= time_now
32
- # 刷新 token 失败时, 通过已经保存的用户名密码来刷新 token
33
- new_user_info = GitLabAPI.refresh_gitlab_access_token uri.hostname, user_info.refresh_token
34
- if new_user_info.nil?
35
- username = user_info.username
36
- password = user_info.password
37
- user_info = GitLabAPI.get_gitlab_access_token_input(uri, user_id, username, password)
38
- return nil unless user_info
39
- else
40
- user_info = new_user_info
41
- end
42
- end
29
+ user_info = GitLabAPI.check_gitlab_access_token_valid(uri, user_info)
30
+ return nil unless user_info
43
31
  config = LConfig.new
44
32
  config.host = uri.hostname
45
33
  config.access_token = user_info.access_token
@@ -42,8 +42,8 @@ module LgPodPlugin
42
42
  self.commit = commit
43
43
  end
44
44
 
45
- def self.get_pod_id(name, git)
46
- key = name + git
45
+ def self.get_pod_id(name, git, branch)
46
+ key = name + git + branch
47
47
  return Digest::MD5.hexdigest(key)
48
48
  end
49
49
 
@@ -221,7 +221,7 @@ module LgPodPlugin
221
221
  end
222
222
 
223
223
  def insert_pod_refs(name, git, branch, tag, commit)
224
- id = LPodLatestRefs.get_pod_id(name, git)
224
+ id = LPodLatestRefs.get_pod_id(name, git, branch)
225
225
  pod = LPodLatestRefs.new(id, name, git, branch, tag, commit)
226
226
  if self.query_pod_refs(id) != nil
227
227
  self.db.execute_batch(
@@ -125,7 +125,7 @@ module LgPodPlugin
125
125
  if branch
126
126
  new_commit, _ = GitLabAPI.request_github_refs_heads git, branch, self.net_ping.uri
127
127
  unless new_commit
128
- id = LPodLatestRefs.get_pod_id(name, git)
128
+ id = LPodLatestRefs.get_pod_id(name, git, branch)
129
129
  pod_info = LSqliteDb.shared.query_pod_refs(id)
130
130
  new_commit = pod_info ? pod_info.commit : nil
131
131
  return [branch, new_commit]
@@ -137,14 +137,14 @@ module LgPodPlugin
137
137
  else
138
138
  new_commit, new_branch = GitLabAPI.request_github_refs_heads git, nil, self.net_ping.uri
139
139
  unless new_commit
140
- id = LPodLatestRefs.get_pod_id(name, git)
140
+ id = LPodLatestRefs.get_pod_id(name, git, "HEAD")
141
141
  pod_info = LSqliteDb.shared.query_pod_refs(id)
142
142
  new_commit = pod_info ? pod_info.commit : nil
143
143
  new_branch = pod_info ? pod_info.branch : nil
144
144
  return [new_branch, new_commit]
145
145
  end
146
146
  if new_commit
147
- LSqliteDb.shared.insert_pod_refs(name, git, new_branch, nil, new_commit)
147
+ LSqliteDb.shared.insert_pod_refs(name, git, "HEAD", nil, new_commit)
148
148
  end
149
149
  [new_branch, new_commit]
150
150
  end
@@ -7,6 +7,33 @@ module LgPodPlugin
7
7
 
8
8
  class GitLabAPI
9
9
 
10
+ # 通过读取本地文件获取 access_token
11
+ def self.get_gitlab_access_token(uri, user_id)
12
+ text = LUtils.encrypt("AzfAjh-xTzyRBXmYuGBr", "AZMpxzVxzbo3sFDLRZMpxzVxzbo3sFDZ")
13
+ db_path = LFileManager.download_director.join("database")
14
+ db_path.mkdir unless db_path.exist?
15
+ token_file = db_path.join("access_token.json")
16
+ return self.get_gitlab_access_token_input(uri, user_id, nil, nil) unless token_file.exist?
17
+ json = JSON.parse(File.read("#{token_file.to_path}"))
18
+ encrypt_access_token = json["access_token"]
19
+ return self.get_gitlab_access_token_input(uri, user_id, nil, nil) if encrypt_access_token.nil?
20
+ access_token = LUtils.decrypt(encrypt_access_token, "AZMpxzVxzbo3sFDLRZMpxzVxzbo3sFDZ")
21
+ token_vaild = GitLabAPI.request_user_emails(uri.hostname, access_token)
22
+ if token_vaild == "invalid token"
23
+ FileUtils.rm_rf token_file
24
+ return self.get_gitlab_access_token_input(uri, user_id, nil, nil) if encrypt_access_token.nil?
25
+ end
26
+ user_id = LUserAuthInfo.get_user_id(uri.hostname)
27
+ refresh_token = json["refresh_token"]
28
+ expires_in = json["expires_in"] ||= 7879680
29
+ created_at = json["created_at"] ||= Time.now.to_i
30
+ user_model = LUserAuthInfo.new(user_id, "", "", uri.hostname, access_token, refresh_token, (created_at + expires_in))
31
+ LSqliteDb.shared.insert_user_info(user_model)
32
+ LgPodPlugin.log_green "请求成功: `access_token` => #{access_token}, expires_in => #{expires_in}"
33
+ return user_model
34
+ end
35
+
36
+ # 通过输入用户名和密码 获取 access_token
10
37
  def self.get_gitlab_access_token_input(uri, user_id, username = nil, password = nil)
11
38
  unless username && password
12
39
  LgPodPlugin.log_yellow "请输入 `#{uri.to_s}` 的用户名"
@@ -18,6 +45,40 @@ module LgPodPlugin
18
45
  user_info = LSqliteDb.shared.query_user_info(user_id)
19
46
  return user_info
20
47
  end
48
+ # 检查 token 是否在有效期内
49
+ def self.check_gitlab_access_token_valid(uri, user_info)
50
+ time_now = Time.now.to_i
51
+ # 判断 token 是否失效
52
+ if user_info.expires_in <= time_now
53
+ refresh_token = user_info.refresh_token
54
+ if refresh_token.nil? || refresh_token == "" # 使用本地令牌访问
55
+ project_name = LUtils.get_git_project_name(uri.to_s)
56
+ token_vaild = GitLabAPI.request_user_emails(uri.hostname, user_info.access_token)
57
+ if token_vaild == "success"
58
+ new_user_info = LUserAuthInfo.new(user_info.id, "", "", uri.hostname, user_info.access_token, nil, (time_now + 7879680))
59
+ LSqliteDb.shared.insert_user_info(user_info)
60
+ return new_user_info
61
+ else
62
+ token_file = LFileManager.download_director.join("database").join("access_token.json")
63
+ FileUtils.rm_rf token_file if token_file.exist?
64
+ return self.get_gitlab_access_token_input(uri, user_info.id, nil, nil)
65
+ end
66
+ else
67
+ # 刷新 token 失败时, 通过已经保存的用户名密码来刷新 token
68
+ new_user_info = GitLabAPI.refresh_gitlab_access_token uri.hostname, refresh_token
69
+ if new_user_info.nil?
70
+ username = user_info.username
71
+ password = user_info.password
72
+ user_info = GitLabAPI.get_gitlab_access_token_input(uri, user_info.user_id, username, password)
73
+ return nil unless user_info
74
+ else
75
+ user_info = new_user_info
76
+ end
77
+ end
78
+ else
79
+ return user_info
80
+ end
81
+ end
21
82
 
22
83
  public
23
84
  # 获取 GitLab access_token
@@ -228,6 +289,31 @@ module LgPodPlugin
228
289
  end
229
290
  end
230
291
 
292
+ # 通过名称搜索项目信息
293
+ public
294
+ def self.request_user_emails(host, access_token)
295
+ begin
296
+ hash_map = {"access_token": access_token}
297
+ uri = URI("#{host}/api/v4/user/emails")
298
+ uri.query = URI.encode_www_form(hash_map)
299
+ res = Net::HTTP.get_response(uri)
300
+ if res.body
301
+ array = JSON.parse(res.body)
302
+ else
303
+ array = []
304
+ end
305
+ if array.is_a?(Array)
306
+ return "success"
307
+ elsif array.is_a?(Hash)
308
+ return "invalid token"
309
+ else
310
+ return "invalid token"
311
+ end
312
+ rescue
313
+ return "invalid token"
314
+ end
315
+ end
316
+
231
317
  end
232
318
 
233
319
  end
@@ -30,13 +30,6 @@ module LgPodPlugin
30
30
  end
31
31
  return if origin_uri.nil?
32
32
  @uri = origin_uri
33
- # redirect_url = LProject.shared.redirect_url_hash[origin_uri.host]
34
- # if redirect_url
35
- # @uri = redirect_url
36
- # else
37
- # @uri = URI(get_redirect_url(origin_uri.scheme + "://" + origin_uri.host))
38
- # LProject.shared.redirect_url_hash[origin_uri.host] = @uri
39
- # end
40
33
  @host = @uri.host
41
34
  @scheme = @uri.scheme ||= "https"
42
35
  @hostname = @scheme + "://" + @host
@@ -3,20 +3,20 @@ require 'resolv'
3
3
  require "ipaddr"
4
4
  require 'base64'
5
5
  require 'fileutils'
6
- # require_relative 'aes-crypt'
6
+ require_relative 'aes-crypt'
7
7
 
8
8
  module LgPodPlugin
9
9
 
10
10
  class LUtils
11
11
 
12
- # def self.encrypt(message, password)
13
- # encrypted_data = AESCrypt.encrypt(message, password)
14
- # encrypted_data.tr("\n", "")
15
- # end
16
- #
17
- # def self.decrypt(message, password)
18
- # AESCrypt.decrypt message, password
19
- # end
12
+ def self.encrypt(message, password)
13
+ encrypted_data = AESCrypt.encrypt(message, password)
14
+ encrypted_data.tr("\n", "")
15
+ end
16
+
17
+ def self.decrypt(message, password)
18
+ AESCrypt.decrypt message, password
19
+ end
20
20
 
21
21
  def self.md5(text)
22
22
  return "" unless text
@@ -1,3 +1,3 @@
1
1
  module LgPodPlugin
2
- VERSION = "1.1.6.5"
2
+ VERSION = "1.1.6.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lg_pod_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6.5
4
+ version: 1.1.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - dongzb01
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-15 00:00:00.000000000 Z
11
+ date: 2023-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -160,6 +160,7 @@ files:
160
160
  - lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/2.7/sqlite3_native.bundle
161
161
  - lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/3.0/sqlite3_native.bundle
162
162
  - lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/3.1/sqlite3_native.bundle
163
+ - lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/3.2/sqlite3_native.bundle
163
164
  - lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/constants.rb
164
165
  - lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/database.rb
165
166
  - lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/errors.rb
@@ -215,6 +216,7 @@ files:
215
216
  - lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/2.7/sqlite3_native.bundle
216
217
  - lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/3.0/sqlite3_native.bundle
217
218
  - lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/3.1/sqlite3_native.bundle
219
+ - lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/3.2/sqlite3_native.bundle
218
220
  - lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/constants.rb
219
221
  - lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/database.rb
220
222
  - lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/errors.rb
@@ -262,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
264
  - !ruby/object:Gem::Version
263
265
  version: '0'
264
266
  requirements: []
265
- rubygems_version: 3.3.7
267
+ rubygems_version: 3.4.13
266
268
  signing_key:
267
269
  specification_version: 4
268
270
  summary: 封装了自定义podfile 中pod 方法