Class: LgPodPlugin::LConfig

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLConfig

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_tokenObject

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_urlObject

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

#hostObject

Returns the value of attribute host.



11
12
13
# File 'lib/lg_pod_plugin/l_config.rb', line 11

def host
  @host
end

#projectObject

Returns the value of attribute project.



16
17
18
# File 'lib/lg_pod_plugin/l_config.rb', line 16

def project
  @project
end

#project_nameObject

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_tokenObject

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)
   = LSqliteDb.shared.(user_id)
  unless 
    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  = LSqliteDb.shared.(user_id)
  end

  time = Time.now.to_i
  # 判断 token 是否失效
  if .expires_in <= time
     = GitLabAPI.refresh_gitlab_access_token(host, .refresh_token)
    unless 
      username = .username
      password = .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  = LSqliteDb.shared.(user_id)
    end

    config = LConfig.new
    config.host = host
    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)
    return config
  else
    config = LConfig.new
    config.host = host
    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)
    return config
  end

end