Class: LgPodPlugin::LConfig
- Inherits:
-
Object
- Object
- LgPodPlugin::LConfig
- Defined in:
- lib/lg_pod_plugin/config/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.
15 16 |
# File 'lib/lg_pod_plugin/config/l_config.rb', line 15 def initialize end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
11 12 13 |
# File 'lib/lg_pod_plugin/config/l_config.rb', line 11 def access_token @access_token end |
#base_url ⇒ Object
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/lg_pod_plugin/config/l_config.rb', line 9 def base_url @base_url end |
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/lg_pod_plugin/config/l_config.rb', line 8 def host @host end |
#project ⇒ Object
Returns the value of attribute project.
13 14 15 |
# File 'lib/lg_pod_plugin/config/l_config.rb', line 13 def project @project end |
#project_name ⇒ Object
Returns the value of attribute project_name.
10 11 12 |
# File 'lib/lg_pod_plugin/config/l_config.rb', line 10 def project_name @project_name end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
12 13 14 |
# File 'lib/lg_pod_plugin/config/l_config.rb', line 12 def refresh_token @refresh_token end |
Class Method Details
.get_config(git, uri) ⇒ Object
19 20 21 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 |
# File 'lib/lg_pod_plugin/config/l_config.rb', line 19 def self.get_config(git, uri) return nil unless uri&.host return nil unless LUtils.is_gitlab_uri(git, uri.hostname) user_id = LUserAuthInfo.get_user_id(uri.hostname) user_info = LSqliteDb.shared.query_user_info(user_id) # 用户授权 token 不存在, 提示用户输入用户名密码 unless user_info user_info = GitLabAPI.get_gitlab_access_token_input(uri, user_id, nil, nil) return nil unless user_info end time_now = Time.now.to_i # 判断 token 是否失效 if user_info.expires_in <= time_now # 刷新 token 失败时, 通过已经保存的用户名密码来刷新 token new_user_info = GitLabAPI.refresh_gitlab_access_token uri.hostname, user_info.refresh_token if new_user_info.nil? username = user_info.username password = user_info.password user_info = GitLabAPI.get_gitlab_access_token_input(uri, user_id, username, password) return nil unless user_info else user_info = new_user_info end end config = LConfig.new config.host = uri.hostname 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) unless config.project config.project = GitLabAPI.request_project_info(config.host, config.project_name, config.access_token, git) end return config end |