cocoapods-cache-proxy 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 314ee2e85d24d3f0cdb7decd9b1507a810b715197d095ed9b8bb522a5e14d561
4
- data.tar.gz: 74015ad447d10595a45bfa2fdd939c0eb9495acd67e90fff57e320acd193e915
3
+ metadata.gz: c2641c3f7994f3e378c9a6090965052d64af6bef57404fe1cd87dfb99758e114
4
+ data.tar.gz: afa86ca8923a5f2484ef41cb139935481993aef5fe4cc1cb160b2f583902f208
5
5
  SHA512:
6
- metadata.gz: '049e7d8f29245475de4808681557ca09dc94b19c2e1fd1dc0d1febd6f846aadf9c9640f64c79cc12a87928b12fcdd197c0f57891ab43be034e337e4e6a84eec3'
7
- data.tar.gz: c089b4c51f24d2e6e4b830e9058394b117008c931d11010890708193c682b428f11ef9a7fa441dcde51817323b1df5b0a1c0687deee2d8199a8f00a6cc67ea15
6
+ metadata.gz: 90c4d464bee0db56bcfefc35bda43837613cdb9e07bf3775dc343be778d0038e136c4f86238f3b4415f2cb01a2906b77daa3509e3545f6fbe84fd8c59115d1a3
7
+ data.tar.gz: ff4e33e69d73a2f0fd4fe03ae7f2fa8f0df9904be5d0e743f0f8add1bd33bbf01af28fdf18e0f5b56da724d8b2fe13ea40595e993f67ca6d612b03670ea27504
@@ -6,16 +6,18 @@ module Pod
6
6
  class Proxy < Cache
7
7
 
8
8
  require 'cocoapods-cache-proxy/command/cache_proxy/add'
9
+ require 'cocoapods-cache-proxy/command/cache_proxy/update'
9
10
  require 'cocoapods-cache-proxy/command/cache_proxy/remove'
10
- # require 'cocoapods-cache-proxy/command/cache_proxy/update'
11
11
  require 'cocoapods-cache-proxy/command/cache_proxy/list'
12
+
13
+ require 'cocoapods-cache-proxy/command/cache_proxy/auth/auth'
12
14
 
13
15
  self.abstract_command = true
14
16
  self.version = CocoapodsCacheProxy::VERSION
15
- self.description = '代理缓存服务'\
17
+ self.description = '缓存代理服务'\
16
18
  "\n v#{CocoapodsCacheProxy::VERSION}\n"
17
19
  self.summary = <<-SUMMARY
18
- 代理缓存
20
+ 缓存代理服务
19
21
  SUMMARY
20
22
 
21
23
  self.default_subcommand = 'list'
@@ -3,7 +3,7 @@ require 'cocoapods-cache-proxy/helper/helper'
3
3
  module Pod
4
4
  class Command
5
5
  class Cache < Command
6
- class Proxy
6
+ class Proxy < Cache
7
7
  class Add < Proxy
8
8
  self.summary = '添加缓存代理'
9
9
 
@@ -14,8 +14,8 @@ module Pod
14
14
  self.arguments = [
15
15
  CLAide::Argument.new('NAME', true),
16
16
  CLAide::Argument.new('URL', true),
17
- CLAide::Argument.new('USER', false),
18
- CLAide::Argument.new('PASSWORD', false)
17
+ CLAide::Argument.new('USER', true),
18
+ CLAide::Argument.new('PASSWORD', true)
19
19
  ]
20
20
 
21
21
  def initialize(argv)
@@ -34,10 +34,10 @@ module Pod
34
34
  end
35
35
 
36
36
  def run
37
- raise Pod::Informative.exception "`#{@name}` 已经存在" if CPSH.check_cache_proxy_source_conf_exists(@name)
38
- raise Pod::Informative.exception "官方源不存在, 请先添加官方源" unless Pod::Config.instance.sources_manager.master_repo_functional?
37
+ raise Pod::Informative.exception "`#{@name}` 已经存在" if CPSH.check_source_conf_exists(@name)
38
+ #raise Pod::Informative.exception "官方源不存在, 请先添加官方源" unless Pod::Config.instance.sources_manager.master_repo_functional?
39
39
 
40
- UI.section("Add proxy server config `#{@url}` into local spec repo `#{@name}`") do
40
+ UI.section("Add proxy server config `#{@url}` into local spec repo `#{@name}`".green) do
41
41
  CPSH.init_cache_proxy_source(@name, @url, @user, @password)
42
42
  end
43
43
  end
@@ -0,0 +1,45 @@
1
+ require 'cocoapods-cache-proxy/helper/helper'
2
+
3
+ module Pod
4
+ class Command
5
+ class Cache < Command
6
+ class Proxy < Cache
7
+ class Auth < Proxy
8
+ class Add < Auth
9
+ self.summary = '添加缓存代理授权配置'
10
+
11
+ self.description = <<-DESC
12
+ 添加缓存代理授权配置
13
+ DESC
14
+
15
+ self.arguments = [
16
+ CLAide::Argument.new('HOST', true),
17
+ CLAide::Argument.new('TOKEN', true),
18
+ ]
19
+
20
+ def initialize(argv)
21
+ init
22
+ @host, @token = argv.shift_argument, argv.shift_argument
23
+ @silent = argv.flag?('silent', false)
24
+ super
25
+ end
26
+
27
+ def validate!
28
+ super
29
+ help! 'This command requires both a auth host.' unless @host
30
+ help! 'This command requires both a auth token.' unless @token
31
+ end
32
+
33
+ def run
34
+ raise Pod::Informative.exception "`#{@host}` 已经存在" if CPSH.check_auth_conf_exists(@host)
35
+
36
+ UI.section("Add proxy auth config `#{@host}`".green) do
37
+ CPSH.init_cache_proxy_auth(@host, @token)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ require 'cocoapods-cache-proxy/gem_version'
2
+ require 'cocoapods-cache-proxy/command/cache_proxy'
3
+
4
+ module Pod
5
+ class Command
6
+ class Cache < Command
7
+ class Proxy < Cache
8
+ class Auth < Proxy
9
+
10
+ require 'cocoapods-cache-proxy/command/cache_proxy/auth/add'
11
+ require 'cocoapods-cache-proxy/command/cache_proxy/auth/update'
12
+ require 'cocoapods-cache-proxy/command/cache_proxy/auth/remove'
13
+ require 'cocoapods-cache-proxy/command/cache_proxy/auth/list'
14
+
15
+ self.abstract_command = true
16
+ self.version = CocoapodsCacheProxy::VERSION
17
+ self.description = '缓存代理授权配置'\
18
+ "\n v#{CocoapodsCacheProxy::VERSION}\n"
19
+ self.summary = <<-SUMMARY
20
+ 缓存代理授权配置
21
+ SUMMARY
22
+
23
+ self.default_subcommand = 'list'
24
+
25
+ def init
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ require 'cocoapods-cache-proxy/helper/helper'
2
+ require 'cocoapods-cache-proxy/native/cache_proxy_auth'
3
+
4
+ module Pod
5
+ class Command
6
+ class Cache < Command
7
+ class Proxy < Cache
8
+ class Auth < Proxy
9
+ class List < Auth
10
+ self.summary = '列出缓存代理授权配置'
11
+
12
+ self.description = <<-DESC
13
+ 列出缓存代理授权配置
14
+ DESC
15
+
16
+ def initialize(argv)
17
+ init
18
+ @silent = argv.flag?('silent', false)
19
+ super
20
+ end
21
+
22
+ def validate!
23
+ super
24
+ end
25
+
26
+ def run
27
+ auths = CPSH.get_all_auths
28
+ print_auths(auths)
29
+ end
30
+
31
+ def print_auth(auth)
32
+ if auth.is_a?(Pod::CacheProxyAuth)
33
+ UI.puts "- Host: #{auth.host}"
34
+ UI.puts "- Token: #{auth.token}"
35
+ end
36
+ end
37
+
38
+ def print_auths(auths)
39
+ auths.each_with_index do |auth, index|
40
+ if auth.is_a?(Pod::CacheProxyAuth)
41
+ UI.title "auth config: #{index + 1}" do
42
+ UI.puts "- Host: #{auth.host}"
43
+ UI.puts "- Token: #{auth.token}"
44
+ end
45
+ end
46
+ end
47
+ UI.puts "\n"
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,43 @@
1
+ require 'cocoapods-cache-proxy/helper/helper'
2
+
3
+ module Pod
4
+ class Command
5
+ class Cache < Command
6
+ class Proxy < Cache
7
+ class Auth < Proxy
8
+ class Remove < Auth
9
+ self.summary = '移除缓存代理授权配置'
10
+
11
+ self.description = <<-DESC
12
+ 移除缓存代理授权配置
13
+ DESC
14
+
15
+ self.arguments = [
16
+ CLAide::Argument.new('HOST', true),
17
+ ]
18
+
19
+ def initialize(argv)
20
+ init
21
+ @host = argv.shift_argument
22
+ @silent = argv.flag?('silent', false)
23
+ super
24
+ end
25
+
26
+ def validate!
27
+ super
28
+ help! 'This command requires both a auth host.' unless @host
29
+ end
30
+
31
+ def run
32
+ raise Pod::Informative.exception "`#{@host}` 不存在" unless CPSH.check_auth_conf_exists(@host)
33
+
34
+ UI.section("remove cache proxy auth `#{@host}`".green) do
35
+ CPSH.remove_cache_proxy_auth(@host)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ require 'cocoapods-cache-proxy/helper/helper'
2
+
3
+ module Pod
4
+ class Command
5
+ class Cache < Command
6
+ class Proxy < Cache
7
+ class Auth < Proxy
8
+ class Update < Auth
9
+ self.summary = '更新缓存代理授权配置'
10
+
11
+ self.description = <<-DESC
12
+ 更新缓存代理授权配置
13
+ DESC
14
+
15
+ self.arguments = [
16
+ CLAide::Argument.new('HOST', true),
17
+ CLAide::Argument.new('TOKEN', true),
18
+ ]
19
+
20
+ def initialize(argv)
21
+ init
22
+ @host, @token = argv.shift_argument, argv.shift_argument
23
+ @silent = argv.flag?('silent', false)
24
+ super
25
+ end
26
+
27
+ def validate!
28
+ super
29
+ help! 'This command requires both a auth host.' unless @host
30
+ help! 'This command requires both a auth token.' unless @token
31
+ end
32
+
33
+ def run
34
+ raise Pod::Informative.exception "`#{@host}` 不存在" unless CPSH.check_auth_conf_exists(@host)
35
+
36
+ UI.section("Update proxy auth config `#{@host}`".green) do
37
+ CPSH.init_cache_proxy_auth(@host, @token)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -4,7 +4,7 @@ require 'cocoapods-cache-proxy/native/cache_proxy_source'
4
4
  module Pod
5
5
  class Command
6
6
  class Cache < Command
7
- class Proxy
7
+ class Proxy < Cache
8
8
  class List < Proxy
9
9
  self.summary = '列出缓存代理'
10
10
 
@@ -23,14 +23,14 @@ module Pod
23
23
  end
24
24
 
25
25
  def run
26
- sources = CPSH.get_all_cache_proxy_source_conf()
26
+ sources = CPSH.get_all_sources
27
27
  print_sources(sources)
28
28
  end
29
29
 
30
30
  def print_source(source)
31
31
  if source.is_a?(Pod::CacheProxySource)
32
32
  UI.puts "- URL: #{source.baseURL}"
33
- UI.puts "- Path: #{CPSH.get_cache_proxy_source_root_dir(source.name)}"
33
+ UI.puts "- Path: #{CPSH.get_source_root_dir(source.name)}"
34
34
  end
35
35
  end
36
36
 
@@ -39,7 +39,7 @@ module Pod
39
39
  if source.is_a?(Pod::CacheProxySource)
40
40
  UI.title source.name do
41
41
  UI.puts "- URL: #{source.baseURL}"
42
- UI.puts "- Path: #{CPSH.get_cache_proxy_source_root_dir(source.name)}"
42
+ UI.puts "- Path: #{CPSH.get_source_root_dir(source.name)}"
43
43
  end
44
44
  end
45
45
  end
@@ -3,7 +3,7 @@ require 'cocoapods-cache-proxy/helper/helper'
3
3
  module Pod
4
4
  class Command
5
5
  class Cache < Command
6
- class Proxy
6
+ class Proxy < Cache
7
7
  class Remove < Proxy
8
8
  self.summary = '移除缓存代理'
9
9
 
@@ -24,15 +24,13 @@ module Pod
24
24
 
25
25
  def validate!
26
26
  super
27
- unless @name
28
- help! 'This command requires both a repo name.'
29
- end
27
+ help! 'This command requires both a repo name.' unless @name
30
28
  end
31
29
 
32
30
  def run
33
- raise Pod::Informative.exception "`#{@name}` 不存在" unless CPSH.check_cache_proxy_source_conf_exists(@name)
31
+ raise Pod::Informative.exception "`#{@name}` 不存在" unless CPSH.check_source_conf_exists(@name)
34
32
 
35
- UI.section("remove cache proxy repo `#{@name}`") do
33
+ UI.section("Remove cache proxy repo `#{@name}`".green) do
36
34
  CPSH.remove_cache_proxy_source(@name)
37
35
  end
38
36
  end
@@ -3,7 +3,7 @@ require 'cocoapods-cache-proxy/helper/helper'
3
3
  module Pod
4
4
  class Command
5
5
  class Cache < Command
6
- class Proxy
6
+ class Proxy < Cache
7
7
  class Update < Proxy
8
8
  self.summary = '更新缓存代理'
9
9
 
@@ -14,8 +14,8 @@ module Pod
14
14
  self.arguments = [
15
15
  CLAide::Argument.new('NAME', true),
16
16
  CLAide::Argument.new('URL', true),
17
- CLAide::Argument.new('USER', false),
18
- CLAide::Argument.new('PASSWORD', false)
17
+ CLAide::Argument.new('USER', true),
18
+ CLAide::Argument.new('PASSWORD', true)
19
19
  ]
20
20
 
21
21
  def initialize(argv)
@@ -34,9 +34,9 @@ module Pod
34
34
  end
35
35
 
36
36
  def run
37
- raise Pod::Informative.exception "`#{@name}` 不存在" unless CPSH.check_cache_proxy_source_conf_exists(@name)
37
+ raise Pod::Informative.exception "`#{@name}` 不存在" unless CPSH.check_source_conf_exists(@name)
38
38
 
39
- UI.section("update cache proxy repo `#{@name}`") do
39
+ UI.section("Update cache proxy repo `#{@name}`".green) do
40
40
  CPSH.init_cache_proxy_source(@name, @url, @user, @password)
41
41
  end
42
42
  end
@@ -1,5 +1,5 @@
1
1
  module CocoapodsCacheProxy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2".freeze
3
3
  end
4
4
 
5
5
  module Pod
@@ -6,33 +6,91 @@ require 'yaml'
6
6
  require 'uri'
7
7
  require 'pathname'
8
8
  require 'cocoapods-cache-proxy/native/cache_proxy_source'
9
+ require 'cocoapods-cache-proxy/native/cache_proxy_auth'
9
10
 
10
11
  module Pod
11
12
  class CacheProxySource
12
13
  class CacheProxySourceHelper
13
14
 
14
- def self.get_cache_proxy_root_dir()
15
+ # @return [String]
16
+ def self.get_cache_proxy_root_dir
15
17
  "#{Pod::Config.instance.home_dir}/cache-proxy"
16
18
  end
17
19
 
18
- def self.get_cache_proxy_source_root_dir(source_name)
20
+ # @param [String] source_name
21
+ # @return [String]
22
+ def self.get_source_root_dir(source_name)
19
23
  "#{Pod::Config.instance.home_dir}/cache-proxy/#{source_name}"
20
24
  end
21
25
 
22
- def self.get_cache_proxy_source_conf_file_name()
26
+
27
+ # @return [String]
28
+ def self.get_auth_root_dir
29
+ "#{Pod::Config.instance.home_dir}/cache-proxy-auth"
30
+ end
31
+
32
+
33
+ # @return [String]
34
+ def self.get_auth_conf_file_name
35
+ ".auth_conf.yml"
36
+ end
37
+
38
+
39
+ # @param [String] host
40
+ # @return [String]
41
+ def self.get_auth_conf_path(host)
42
+ uri = URI.parse(host)
43
+ "#{get_auth_root_dir}/#{uri.host}/#{get_auth_conf_file_name}"
44
+ end
45
+
46
+ # @param [String] host
47
+ # @return [TrueClass, FalseClass]
48
+ def self.check_auth_conf_exists(host)
49
+ File.exist?(get_auth_conf_path(host))
50
+ end
51
+
52
+ # @param [String] host
53
+ # @return [Hash]
54
+ def self.load_auth_conf_host(host)
55
+ path = get_auth_conf_path(host)
56
+ if File.exist?(path)
57
+ YAML.load_file(path)
58
+ else
59
+ nil
60
+ end
61
+ end
62
+
63
+ # @param [String] path
64
+ # @return [Hash]
65
+ def self.load_auth_conf_path(path)
66
+ if File.exist?(path)
67
+ YAML.load_file(path)
68
+ else
69
+ nil
70
+ end
71
+ end
72
+
73
+ # @@return [String]
74
+ def self.get_source_conf_file_name
23
75
  ".cache_proxy_conf.yml"
24
76
  end
25
77
 
26
- def self.get_cache_proxy_source_conf_path(source_name)
27
- "#{get_cache_proxy_source_root_dir(source_name)}/#{get_cache_proxy_source_conf_file_name()}"
78
+ # @param [String] source_name
79
+ # @return [String]
80
+ def self.get_source_conf_path(source_name)
81
+ "#{get_source_root_dir(source_name)}/#{get_source_conf_file_name}"
28
82
  end
29
83
 
30
- def self.check_cache_proxy_source_conf_exists(source_name)
31
- File.exist?(get_cache_proxy_source_conf_path(source_name))
84
+ # @param [String] source_name
85
+ # @return [Void]
86
+ def self.check_source_conf_exists(source_name)
87
+ File.exist?(get_source_conf_path(source_name))
32
88
  end
33
89
 
34
- def self.load_conf(source_name)
35
- path = get_cache_proxy_source_conf_path(source_name)
90
+ # @param [String] source_name
91
+ # @return [Hash]
92
+ def self.load_source_conf(source_name)
93
+ path = get_source_conf_path(source_name)
36
94
  if File.exist?(path)
37
95
  YAML.load_file(path)
38
96
  else
@@ -40,8 +98,90 @@ module Pod
40
98
  end
41
99
  end
42
100
 
43
- def self.create_cache_proxy_source_conf(source_name, url, user, password)
44
- path = get_cache_proxy_source_conf_path(source_name)
101
+ # @param [String] host
102
+ # @param [String] token
103
+ # @return [Void]
104
+ def self.save_cache_proxy_auth_conf(host, token)
105
+ path = get_auth_conf_path(host)
106
+ auth = {
107
+ 'host' => host,
108
+ 'token' => token,
109
+ }
110
+
111
+ conf = File.new(path, "wb")
112
+ conf << auth.to_yaml
113
+ conf.close
114
+ end
115
+
116
+ # @param [String] host
117
+ # @param [String] token
118
+ # @return [Void]
119
+ def self.init_cache_proxy_auth(host, token)
120
+ begin
121
+
122
+ show_output = Pod::Config.instance.verbose?
123
+ pn = Pathname(get_auth_conf_path(host))
124
+
125
+ FileUtils.mkdir_p(pn.parent) unless Dir.exist?(pn.parent)
126
+
127
+ Pod::UI.message "Generating auth conf .....".yellow if show_output
128
+ save_cache_proxy_auth_conf(host, token)
129
+ Pod::UI.message "Successfully added auth #{host} ".green if show_output
130
+
131
+ rescue Exception => e
132
+ Pod::UI.message "发生异常,清理文件 .....".yellow if show_output
133
+ pn = Pathname(get_auth_conf_path(host))
134
+ FileUtils.rm_rf(pn.parent) if Dir.exist?(pn.parent)
135
+ Pod::UI.message e.message.yellow if show_output
136
+ Pod::UI.message e.backtrace.inspect.yellow if show_output
137
+ raise e
138
+ end
139
+ end
140
+
141
+ # @param [String] host
142
+ # @return [Void]
143
+ def self.remove_cache_proxy_auth(host)
144
+ show_output = Pod::Config.instance.verbose?
145
+ path = Pathname(get_auth_conf_path(host))
146
+ FileUtils.rm_rf(path.parent) if Dir.exist?(path.parent)
147
+
148
+ Pod::UI.message "Successfully remove auth #{host}".green if show_output
149
+ end
150
+
151
+ # @param [String] host
152
+ # @return [Pod::CacheProxyAuth]
153
+ def self.get_cache_proxy_auth_conf_host(host)
154
+ return nil unless (cnf = load_auth_conf_host(host))
155
+ Pod::CacheProxyAuth.new(cnf['host'], cnf['token'])
156
+ end
157
+
158
+ # @param [String] path
159
+ # @return [Pod::CacheProxyAuth]
160
+ def self.get_cache_proxy_auth_conf_path(path)
161
+ return nil unless (cnf = load_auth_conf_path(path))
162
+ Pod::CacheProxyAuth.new(cnf['host'], cnf['token'])
163
+ end
164
+
165
+ # @return [Array<Pod::CacheProxyAuth>]
166
+ def self.get_all_auths
167
+ return [] unless Dir.exist?(get_auth_root_dir)
168
+ list = []
169
+ Find.find(get_auth_root_dir) do |path|
170
+ next unless File.file?(path) && path.end_with?(get_auth_conf_file_name)
171
+ next unless (conf = get_cache_proxy_auth_conf_path(path))
172
+ next if conf.host.blank? || conf.token.blank?
173
+ list << conf
174
+ end
175
+ list
176
+ end
177
+
178
+ # @param [String] source_name
179
+ # @param [String] url
180
+ # @param [String] user
181
+ # @param [String] password
182
+ # @return [Void]
183
+ def self.save_cache_proxy_source_conf(source_name, url, user, password)
184
+ path = get_source_conf_path(source_name)
45
185
  info = {
46
186
  'name' => source_name,
47
187
  'url' => url,
@@ -49,26 +189,31 @@ module Pod
49
189
 
50
190
  info['user'] = user unless user.blank?
51
191
  info['password'] = password unless password.blank?
52
-
192
+
53
193
  conf = File.new(path, "wb")
54
194
  conf << info.to_yaml
55
195
  conf.close
56
-
196
+
57
197
  end
58
198
 
59
199
 
200
+ # @param [String] cache_source_name
201
+ # @param [String] cache_source_url
202
+ # @param [String] user
203
+ # @param [String] password
204
+ # @return [Void]
60
205
  def self.init_cache_proxy_source(cache_source_name, cache_source_url, user, password)
61
206
  begin
62
207
  show_output = Pod::Config.instance.verbose?
63
208
 
64
- cache_source_root_path = "#{get_cache_proxy_source_root_dir(cache_source_name)}"
209
+ cache_source_root_path = "#{get_source_root_dir(cache_source_name)}"
65
210
 
66
211
  FileUtils.rm_rf(cache_source_root_path) if Dir.exist?(cache_source_root_path)
67
212
 
68
213
  FileUtils.mkdir_p(cache_source_root_path)
69
214
 
70
215
  Pod::UI.message "Generating source conf .....".yellow if show_output
71
- create_cache_proxy_source_conf(cache_source_name, cache_source_url, user, password)
216
+ save_cache_proxy_source_conf(cache_source_name, cache_source_url, user, password)
72
217
  Pod::UI.message "Successfully added repo #{cache_source_name}".green if show_output
73
218
 
74
219
  rescue Exception => e
@@ -80,31 +225,36 @@ module Pod
80
225
  end
81
226
  end
82
227
 
228
+ # @param [String] cache_source_name
229
+ # @return [Void]
83
230
  def self.remove_cache_proxy_source(cache_source_name)
84
231
  show_output = Pod::Config.instance.verbose?
85
232
 
86
- cache_source_root_path = "#{get_cache_proxy_source_root_dir(cache_source_name)}"
233
+ cache_source_root_path = "#{get_source_root_dir(cache_source_name)}"
87
234
  FileUtils.rm_rf(cache_source_root_path) if Dir.exist?(cache_source_root_path)
88
235
 
89
236
  Pod::UI.message "Successfully remove repo #{cache_source_name}".green if show_output
90
237
  end
91
238
 
239
+ # @param [String] cache_source_name
240
+ # @return [Pod::CacheProxySource]
92
241
  def self.get_cache_proxy_source_conf(cache_source_name)
93
- return nil unless (hash = load_conf(cache_source_name))
94
- Pod::CacheProxySource.new(hash['name'], hash['url'], hash['user'], hash['password'])
242
+ return nil unless (cnf = load_source_conf(cache_source_name))
243
+ Pod::CacheProxySource.new(cnf['name'], cnf['url'], cnf['user'], cnf['password'])
95
244
  end
96
245
 
97
- def self.get_all_cache_proxy_source_conf()
98
- return [] unless Dir.exist?(get_cache_proxy_root_dir())
99
- confs = []
100
- Find.find(get_cache_proxy_root_dir()) do |path|
101
- next unless File.file?(path) && path.end_with?(".cache_proxy_conf.yml")
246
+ # @return [Array<Pod::CacheProxySource>]
247
+ def self.get_all_sources
248
+ return [] unless Dir.exist?(get_cache_proxy_root_dir)
249
+ list = []
250
+ Find.find(get_cache_proxy_root_dir) do |path|
251
+ next unless File.file?(path) && path.end_with?(get_source_conf_file_name)
102
252
  pn = Pathname.new(path)
103
253
  source_name = pn.dirname.basename
104
254
  next unless (conf = get_cache_proxy_source_conf(source_name))
105
- confs << conf
255
+ list << conf
106
256
  end
107
- confs
257
+ list
108
258
  end
109
259
  end
110
260
  end
@@ -0,0 +1,20 @@
1
+ module Pod
2
+ class CacheProxyAuth
3
+
4
+ # @param [String] host
5
+ # @param [String] token
6
+ def initialize(host, token)
7
+ @host = host
8
+ @token = token
9
+ end
10
+
11
+ # @return [String]
12
+ def host
13
+ @host
14
+ end
15
+
16
+ def token
17
+ @token
18
+ end
19
+ end
20
+ end
@@ -1,9 +1,15 @@
1
+ require 'cocoapods-cache-proxy/helper/helper'
2
+ require 'cocoapods-cache-proxy/native/cache_proxy_auth'
3
+ require 'uri'
4
+
1
5
  module Pod
2
6
  class CacheProxySource
3
- # @param [String] proxy_source The name of the repository
4
- #
5
- # @param [String] url see {#url}
6
- #
7
+
8
+
9
+ # @param [String] name
10
+ # @param [String] baseURL
11
+ # @param [String] user
12
+ # @param [String] password
7
13
  def initialize(name, baseURL, user, password)
8
14
  @name = name
9
15
  @baseURL = baseURL
@@ -11,6 +17,8 @@ module Pod
11
17
  @password = password
12
18
  end
13
19
 
20
+
21
+ # @return [String]
14
22
  def name
15
23
  @name
16
24
  end
@@ -27,8 +35,28 @@ module Pod
27
35
  @password
28
36
  end
29
37
 
38
+ # @param [String] pod pod name
39
+ # @param [String] git repo address
40
+ # @param [String] tag repo tag
41
+ # @param [String] submodules need update submodules
42
+ # @return [String] full download url
30
43
  def build_proxy_source(pod, git, tag, submodules = false)
31
- "#{@baseURL}/#{pod}?git=#{git}&tag=#{tag}&submodules=#{submodules}"
44
+ auth_cnf = CPSH.get_cache_proxy_auth_conf_host(git)
45
+ if auth_cnf.nil?
46
+ uri = URI.parse("#{@baseURL}/#{pod}?git=#{git}&tag=#{tag}&submodules=#{submodules}&cache_proxy=1")
47
+ uri.user = @user
48
+ uri.password = @password
49
+ uri.to_s
50
+ else
51
+ uri = URI.parse(git)
52
+ uri.user = "oauth2"
53
+ uri.password = auth_cnf.token
54
+ url = uri.to_s
55
+ uri = URI.parse("#{@baseURL}/#{pod}?git=#{url}&tag=#{tag}&submodules=#{submodules}&cache_proxy=1")
56
+ uri.user = @user
57
+ uri.password = @password
58
+ uri.to_s
59
+ end
32
60
  end
33
61
  end
34
62
  end
@@ -5,16 +5,24 @@ module Pod
5
5
  class Config
6
6
  attr_reader :cache_proxy_source
7
7
 
8
+ # @param [String] name
9
+ # @return [Pod::CacheProxySource]
8
10
  def set_cache_proxy_source(name)
9
11
  return if name.blank?
10
12
  return unless (cnf = CPSH.get_cache_proxy_source_conf(name))
11
13
  @cache_proxy_source = cnf
12
14
  end
13
15
 
14
- def cache_proxy_source()
16
+ # @return [Pod::CacheProxySource]
17
+ def cache_proxy_source
15
18
  @cache_proxy_source
16
19
  end
17
20
 
21
+ # @return [TrueClass, FalseClass]
22
+ def cache_proxy_source_available
23
+ !@cache_proxy_source.nil?
24
+ end
25
+
18
26
  # def remove_cache_proxy_source(name)
19
27
  # return if name.blank? || @cache_proxy_source.nil? || @cache_proxy_source.empty?
20
28
  # @cache_proxy_source.delete_if { |cnf| cnf.name == name }
@@ -36,19 +36,10 @@ module Pod
36
36
  alias_method :orig_download_file, :download_file
37
37
 
38
38
  def download_file(full_filename)
39
- Pod::UI.message "full_filename: #{full_filename}" if Pod::Config.instance.verbose?
40
-
41
- proxy_source = Pod::Config.instance.cache_proxy_source
42
39
  download_uri = URI(url)
43
- proxy_source_uri = URI(proxy_source.baseURL)
44
-
45
- Pod::UI.message "url: #{download_uri.path}" if Pod::Config.instance.verbose?
46
- Pod::UI.message "proxy_source baseURL: #{proxy_source.baseURL}" if Pod::Config.instance.verbose?
47
- if download_uri.path.start_with?(proxy_source_uri.path)
48
- curl_options = []
49
- curl_options.concat(["-u", "#{proxy_source.user}:#{proxy_source.password}"]) unless proxy_source.user.blank? && proxy_source.password.blank?
50
- curl_options.concat(["-f", "-L", "-o", full_filename, url, "--create-dirs"])
51
- Pod::UI.message "curl_options: #{curl_options.join(" ")}" if Pod::Config.instance.verbose?
40
+
41
+ if !download_uri.query.blank? && download_uri.query.include?("git=") && download_uri.query.include?("tag=") && download_uri.query.include?("cache_proxy=1")
42
+ curl_options = ["-f", "-L", "-o", full_filename, url, "--create-dirs"]
52
43
  curl! curl_options
53
44
  else
54
45
  orig_download_file(full_filename)
@@ -3,9 +3,8 @@ require 'cocoapods-core'
3
3
  module Pod
4
4
  class Podfile
5
5
  module DSL
6
-
6
+
7
7
  def ignore_cache_proxy_pods!(pods = [])
8
- Pod::UI.puts "current_target_definition: #{current_target_definition}" if Pod::Config.instance.verbose?
9
8
  current_target_definition.set_ignore_cache_proxy_pods(pods) if !pods.blank? && !current_target_definition.nil?
10
9
  end
11
10
  end
@@ -15,49 +14,122 @@ end
15
14
 
16
15
  module Pod
17
16
  class Podfile
17
+
18
+ class IgnorePodProxy
19
+ def self.keyword
20
+ :ignore_cache_proxy
21
+ end
22
+ end
23
+
24
+ class UsedPodProxySource
25
+ def self.keyword
26
+ :cache_proxy_source
27
+ end
28
+ end
29
+
18
30
  class TargetDefinition
19
31
  attr_reader :ignore_cache_proxy
32
+ attr_reader :cache_proxy_source
20
33
 
21
- alias_method :orig_store_pod, :store_pod
22
- def store_pod(name, *requirements)
23
- Pod::UI.message "store_pod requirements: #{requirements}" if Pod::Config.instance.verbose?
24
- parse_ignore_cache_proxy(name, requirements)
25
- orig_store_pod(name, *requirements)
26
- end
34
+ #alias_method :orig_store_pod, :store_pod
35
+ #def store_pod(name, *requirements)
36
+ # Pod::UI.message "store_pod requirements: #{requirements}" if Pod::Config.instance.verbose?
37
+ # #parse_ignore_cache_proxy(name, requirements)
38
+ # options = requirements.last
39
+ # if options.is_a?(Hash) and options.has_key?(:ignore_cache_proxy)
40
+ # Pod::UI.message "ignore_cache_proxy name: #{name}"
41
+ # options.delete(:ignore_cache_proxy)
42
+ # requirements.pop if options.empty?
43
+ # end
44
+ # Pod::UI.message "store_pod 2 requirements: #{requirements}" if Pod::Config.instance.verbose?
45
+ # orig_store_pod(name, *requirements)
46
+ #end
47
+
48
+ # ---- patch method ----
49
+ # We want modify `store_pod` method, but it's hard to insert a line in the
50
+ # implementation. So we patch a method called in `store_pod`.
51
+ alias_method :orig_parse_inhibit_warnings, :parse_inhibit_warnings
52
+ def parse_inhibit_warnings(name, requirements)
53
+ options = requirements.last
27
54
 
28
- def parse_ignore_cache_proxy(name, requirements)
29
- requirements.each do |options|
30
- next unless options.is_a?(Hash)
31
- Pod::UI.message "parse_ignore_cache_proxy: #{options}" if Pod::Config.instance.verbose?
32
- set_ignore_cache_proxy_pods([name]) if options.has_key?(:git)
55
+ if options.is_a?(Hash)
56
+ if options.has_key?(Pod::Podfile::IgnorePodProxy.keyword)
57
+ ignore = options[Pod::Podfile::IgnorePodProxy.keyword]
58
+ options.delete(Pod::Podfile::IgnorePodProxy.keyword)
59
+ set_ignore_cache_proxy_pods([name]) if ignore
60
+ end
61
+
62
+ if options.has_key?(Pod::Podfile::UsedPodProxySource.keyword)
63
+ source_name = options[Pod::Podfile::UsedPodProxySource.keyword]
64
+ options.delete(Pod::Podfile::UsedPodProxySource.keyword)
65
+ unless source_name.blank?
66
+ raise Pod::Informative.exception "cache proxy source: `#{source_name}` source does not exist." unless (source = CPSH.get_cache_proxy_source_conf(source_name))
67
+ @cache_proxy_source = Hash.new if @cache_proxy_source.nil?
68
+ @cache_proxy_source[name] = source
69
+ end
70
+ end
71
+ requirements.pop if options.empty?
33
72
  end
73
+ orig_parse_inhibit_warnings(name, requirements)
34
74
  end
35
75
 
76
+ # 参考 https://github.com/leavez/cocoapods-binary/blob/9f40c5df4149598b03b44c01d33b04e78ff38772/lib/cocoapods-binary/helper/podfile_options.rb#L52-L60
77
+ # ---- patch method ----
78
+ # We want modify `store_pod` method, but it's hard to insert a line in the
79
+ # implementation. So we patch a method called in `store_pod`.
80
+ #old_method = instance_method(:parse_inhibit_warnings)
81
+ #
82
+ #define_method(:parse_inhibit_warnings) do |name, requirements|
83
+ # Pod::UI.message "parse_inhibit_warnings requirements: #{requirements}" if Pod::Config.instance.verbose?
84
+ # options = requirements.last
85
+ # if options.is_a?(Hash) and options.has_key?(:ignore_cache_proxy)
86
+ # Pod::UI.message "ignore_cache_proxy name: #{name}"
87
+ # options.delete(:ignore_cache_proxy)
88
+ # requirements.pop if options.empty?
89
+ # set_ignore_cache_proxy_pods([name])
90
+ # end
91
+ # Pod::UI.message "parse_inhibit_warnings requirements: #{requirements}" if Pod::Config.instance.verbose?
92
+ # old_method.bind(self).(name, requirements)
93
+ #end
94
+
95
+ #def parse_ignore_cache_proxy(name, requirements)
96
+ # requirements.each do |options|
97
+ # next unless options.is_a?(Hash)
98
+ # Pod::UI.message "parse_ignore_cache_proxy: #{options}" if Pod::Config.instance.verbose?
99
+ # set_ignore_cache_proxy_pods([name]) if options.has_key?(:git)
100
+ # end
101
+ #end
102
+
103
+ # @param [Array<String>] pods
36
104
  def set_ignore_cache_proxy_pods(pods)
37
105
  return if pods.blank?
38
106
  @ignore_cache_proxy = [] if @ignore_cache_proxy.nil?
39
107
  pods.uniq.each do |pod|
40
108
  @ignore_cache_proxy << pod unless @ignore_cache_proxy.include?(pod)
41
109
  end
42
- Pod::UI.message "set_ignore_cache_proxy_pods name: #{@ignore_cache_proxy}" if Pod::Config.instance.verbose?
43
110
  end
44
111
 
45
- def get_ignore_cache_proxy_pods()
46
- if @ignore_cache_proxy.nil?
47
- []
48
- else
49
- @ignore_cache_proxy.uniq
50
- end
112
+ # @return [Array<String>]
113
+ def get_ignore_cache_proxy_pods
114
+ @ignore_cache_proxy.nil? ? [] : @ignore_cache_proxy.uniq
51
115
  end
52
116
 
117
+ # @param [String] pod
118
+ # @return [TrueClass, FalseClass]
53
119
  def check_ignore_cache_proxy_pod(pod)
54
120
  return false if pod.blank?
55
121
  ignores = []
56
- ignores.concat(get_ignore_cache_proxy_pods())
57
- ignores.concat(root.get_ignore_cache_proxy_pods()) if !root?
58
- ignores.concat(parent.get_ignore_cache_proxy_pods()) unless parent.nil?
59
- Pod::UI.message "check_ignore_cache_proxy_pod #{name}: #{ignores} #{ignores.uniq.include?(pod)}" if Pod::Config.instance.verbose?
60
- return ignores.uniq.include?(pod)
122
+ ignores.concat(get_ignore_cache_proxy_pods)
123
+ ignores.concat(root.get_ignore_cache_proxy_pods) unless root.nil?
124
+ ignores.concat(parent.get_ignore_cache_proxy_pods) unless parent.nil?
125
+ ignores.uniq.include?(pod)
126
+ end
127
+
128
+ # @param [String] pod
129
+ # @return [CacheProxySource]
130
+ def proxy_source_for_pod(pod)
131
+ return nil if @cache_proxy_source.blank?
132
+ @cache_proxy_source[pod]
61
133
  end
62
134
  end
63
135
  end
@@ -7,31 +7,29 @@ module Pod
7
7
  class Resolver
8
8
 
9
9
  alias_method :orig_resolver_specs_by_target, :resolver_specs_by_target
10
- def resolver_specs_by_target()
11
- specs_by_target = orig_resolver_specs_by_target()
12
- proxy_source = Pod::Config.instance.cache_proxy_source
13
- return specs_by_target if proxy_source.nil?
10
+ def resolver_specs_by_target
11
+ specs_by_target = orig_resolver_specs_by_target
14
12
 
15
- show_output = Pod::Config.instance.verbose?
16
- specs_by_target.each do |target, rspecs|
17
- rspecs.each do |spec|
13
+ return specs_by_target unless Pod::Config.instance.cache_proxy_source_available
14
+ root_proxy_source = Pod::Config.instance.cache_proxy_source
15
+
16
+ specs_by_target.each do |target, specs|
17
+ specs.each do |spec|
18
18
  root_spec = spec.spec.root
19
19
  source = root_spec.source
20
- UI.message "spec name: #{root_spec.name}" if show_output
21
- UI.message "spec source: #{source}" if show_output
22
- UI.message "spec version: #{root_spec.version}" if show_output
23
20
  next unless !source.blank? && source.has_key?(:git) && source.has_key?(:tag)
24
- UI.message "ignore_cache_proxy_pod: #{target.name} #{root_spec.name}" if show_output; next if target.check_ignore_cache_proxy_pod(root_spec.name)
25
-
21
+ next if target.check_ignore_cache_proxy_pod(root_spec.name)
22
+
26
23
  git = source[:git]
27
24
  tag = source[:tag]
28
25
  submodules = source.has_key?(:submodules) ? source[:submodules] : false
29
- new_url = proxy_source.build_proxy_source(root_spec.name, git, tag, submodules)
26
+
27
+ proxy_source = target.proxy_source_for_pod(root_spec.name)
28
+ new_url = (proxy_source.nil? ? root_proxy_source : proxy_source).build_proxy_source(root_spec.name, git, tag, submodules)
30
29
  source = {
31
30
  :http => new_url,
32
31
  :type => "tgz",
33
32
  }
34
- UI.message "spec new source: #{source}" if show_output
35
33
  root_spec.source = source
36
34
  end
37
35
  end
@@ -1,3 +1,2 @@
1
1
  require 'cocoapods-cache-proxy/command'
2
- require 'hook'
3
-
2
+ require 'hook'
@@ -11,7 +11,7 @@ Pod::HooksManager.register('cocoapods-cache-proxy', :source_provider) do |contex
11
11
  Pod::UI.message 'cocoapods-cache-proxy received source_provider hook' if show_output
12
12
 
13
13
  return unless (proxy_name = options['proxy'])
14
- raise Pod::Informative.exception "cache proxy source: `#{proxy_name}` does not exist." unless CPSH.check_cache_proxy_source_conf_exists(proxy_name)
14
+ raise Pod::Informative.exception "cache proxy source: `#{proxy_name}` source does not exist." unless CPSH.check_source_conf_exists(proxy_name)
15
15
  Pod::UI.message "proxy_name: #{proxy_name}" if show_output
16
16
  Pod::Config.instance.set_cache_proxy_source(proxy_name)
17
17
  end
metadata CHANGED
@@ -1,72 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-cache-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1306a94'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: cocoapods-core
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '1.5'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '1.3'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '1.3'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - ">="
45
+ - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '0'
47
+ version: '12.0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - ">="
52
+ - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '0'
69
- description: A short description of cocoapods-cache-proxy.
54
+ version: '12.0'
55
+ description: Pod library source file cache proxy
70
56
  email:
71
57
  - 0x1306a94@gmail.com
72
58
  executables: []
@@ -77,12 +63,18 @@ files:
77
63
  - lib/cocoapods-cache-proxy/command.rb
78
64
  - lib/cocoapods-cache-proxy/command/cache_proxy.rb
79
65
  - lib/cocoapods-cache-proxy/command/cache_proxy/add.rb
66
+ - lib/cocoapods-cache-proxy/command/cache_proxy/auth/add.rb
67
+ - lib/cocoapods-cache-proxy/command/cache_proxy/auth/auth.rb
68
+ - lib/cocoapods-cache-proxy/command/cache_proxy/auth/list.rb
69
+ - lib/cocoapods-cache-proxy/command/cache_proxy/auth/remove.rb
70
+ - lib/cocoapods-cache-proxy/command/cache_proxy/auth/update.rb
80
71
  - lib/cocoapods-cache-proxy/command/cache_proxy/list.rb
81
72
  - lib/cocoapods-cache-proxy/command/cache_proxy/remove.rb
82
73
  - lib/cocoapods-cache-proxy/command/cache_proxy/update.rb
83
74
  - lib/cocoapods-cache-proxy/gem_version.rb
84
75
  - lib/cocoapods-cache-proxy/helper/cache_proxy_source_helper.rb
85
76
  - lib/cocoapods-cache-proxy/helper/helper.rb
77
+ - lib/cocoapods-cache-proxy/native/cache_proxy_auth.rb
86
78
  - lib/cocoapods-cache-proxy/native/cache_proxy_source.rb
87
79
  - lib/cocoapods-cache-proxy/native/config.rb
88
80
  - lib/cocoapods-cache-proxy/native/downloader.rb
@@ -115,5 +107,5 @@ rubyforge_project:
115
107
  rubygems_version: 2.7.9
116
108
  signing_key:
117
109
  specification_version: 4
118
- summary: A longer description of cocoapods-cache-proxy.
110
+ summary: Pod library source file cache proxy
119
111
  test_files: []