Class: LgPodPlugin::LConfig
- Inherits:
-
Object
- Object
- LgPodPlugin::LConfig
- Defined in:
- lib/lg_pod_plugin/l_config.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#host ⇒ Object
Returns the value of attribute host.
-
#project ⇒ Object
Returns the value of attribute project.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ LConfig
constructor
A new instance of LConfig.
Constructor Details
#initialize ⇒ LConfig
Returns a new instance of LConfig.
18 19 |
# File 'lib/lg_pod_plugin/l_config.rb', line 18 def initialize end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
14 15 16 |
# File 'lib/lg_pod_plugin/l_config.rb', line 14 def access_token @access_token end |
#base_url ⇒ Object
Returns the value of attribute base_url.
12 13 14 |
# File 'lib/lg_pod_plugin/l_config.rb', line 12 def base_url @base_url end |
#host ⇒ Object
Returns the value of attribute host.
11 12 13 |
# File 'lib/lg_pod_plugin/l_config.rb', line 11 def host @host end |
#project ⇒ Object
Returns the value of attribute project.
16 17 18 |
# File 'lib/lg_pod_plugin/l_config.rb', line 16 def project @project end |
#project_name ⇒ Object
Returns the value of attribute project_name.
13 14 15 |
# File 'lib/lg_pod_plugin/l_config.rb', line 13 def project_name @project_name end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
15 16 17 |
# File 'lib/lg_pod_plugin/l_config.rb', line 15 def refresh_token @refresh_token end |
Class Method Details
.getConfig(git) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lg_pod_plugin/l_config.rb', line 22 def self.getConfig(git) return nil if git.include?("github.com") || git.include?("gitee.com") || git.include?("coding.net") || git.include?("code.aliyun.com") ip_address = LRequest.shared.net_ping.ip network_ok = LRequest.shared.net_ping.network_ok return nil unless ip_address && network_ok if git.include?("ssh") || git.include?("git@gitlab") || git.include?("git@") host = "http://" + ip_address else uri = LRequest.shared.net_ping.uri host = uri ? ("#{uri.scheme}://" + ip_address) : ("http://" + ip_address) end user_id = LUserAuthInfo.get_user_id(host) user_info = LSqliteDb.shared.query_user_info(user_id) unless user_info LgPodPlugin.log_yellow "请输入 `#{uri}` 的用户名" username = STDIN.gets.chomp LgPodPlugin.log_yellow "请输入 `#{uri}` 的密码" password = STDIN.noecho(&:gets).chomp GitLabAPI.request_gitlab_access_token(host, username, password) return nil unless user_info = LSqliteDb.shared.query_user_info(user_id) end time = Time.now.to_i # 判断 token 是否失效 if user_info.expires_in <= time new_user_info = GitLabAPI.refresh_gitlab_access_token(host, user_info.refresh_token) unless new_user_info username = user_info.username password = user_info.password unless username && password LgPodPlugin.log_yellow "请输入 `#{uri}` 的用户名" username = STDIN.gets.chomp LgPodPlugin.log_yellow "请输入 `#{uri}` 的密码" password = STDIN.noecho(&:gets).chomp end GitLabAPI.request_gitlab_access_token(host, username, password) return nil unless new_user_info = LSqliteDb.shared.query_user_info(user_id) end config = LConfig.new config.host = host config.access_token = new_user_info.access_token config.refresh_token = new_user_info.refresh_token config.base_url = LUtils.get_gitlab_base_url(git) config.project_name = LUtils.get_git_project_name(git) config.project = LSqliteDb.shared.query_project_info(config.project_name, git) return config else config = LConfig.new config.host = host config.access_token = user_info.access_token config.refresh_token = user_info.refresh_token config.base_url = LUtils.get_gitlab_base_url(git) config.project_name = LUtils.get_git_project_name(git) config.project = LSqliteDb.shared.query_project_info(config.project_name, git) return config end end |