Class: LgPodPlugin::LConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/lg_pod_plugin/config/l_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLConfig

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_tokenObject

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_urlObject

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

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/lg_pod_plugin/config/l_config.rb', line 8

def host
  @host
end

#projectObject

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_nameObject

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_tokenObject

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)
   = LSqliteDb.shared.(user_id)
  # 用户授权 token 不存在, 提示用户输入用户名密码
  unless 
     = GitLabAPI.get_gitlab_access_token_input(uri, user_id, nil, nil)
    return nil unless 
  end
  time_now = Time.now.to_i
  # 判断 token 是否失效
  if .expires_in <= time_now
    # 刷新 token 失败时, 通过已经保存的用户名密码来刷新 token
     = GitLabAPI.refresh_gitlab_access_token uri.hostname, .refresh_token
    if .nil?
      username = .username
      password = .password
       = GitLabAPI.get_gitlab_access_token_input(uri, user_id, username, password)
      return nil unless 
    else
       = 
    end
  end

  config = LConfig.new
  config.host = uri.hostname
  config.access_token = .access_token
  config.refresh_token = .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