carthage_cache 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36686ab2b139da674ecef72174dd975af74eed4d
4
- data.tar.gz: 65fd75b822f1d83364c26c4e8334a49138cbcf78
3
+ metadata.gz: 66392e9c9f8b79620a85307d4c543f3f6ff4204c
4
+ data.tar.gz: 04ca97e2e59edeb04445c9ae7a36abcb972e667d
5
5
  SHA512:
6
- metadata.gz: 71851859f37b05838859c9929dabee63a28d2f99be4604d5141140bdfddf716dd23e94c1ef03c3268a6f2ed0f9ba394bab57a952c04ff280ae5c3fc404acc74c
7
- data.tar.gz: 18139e8c8c077d7767c5ec8d0c5fadf7c089dc99d5aea04772fe7ebb3cb4a767f2d17477bf6d4edae9472b0e734693a6b734699bf6814b6e1ddc88babab29094
6
+ metadata.gz: 4a39c50a039f20336f3e4b6aa8c07a5e46a93da7dffd40ee5198fc79b41feb3edec343ff34dbb33d481625a05c8106e8e98f0464c5d39de7f05d963f63dace33
7
+ data.tar.gz: 715a6a13f71f284a854051a24fb64624b265b6c09c0b7e5acbe758129205fb3211bee9f945df60443c8e84c19f386fe2ea03796880c1ec13ced910f7354ffa09
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .DS_Store
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
data/README.md CHANGED
@@ -48,6 +48,11 @@ You can also set your credentials using the following environmental variables
48
48
  * `AWS_ACCESS_KEY_ID`
49
49
  * `AWS_SECRET_ACCESS_KEY`
50
50
 
51
+ Or if you prefer using [AWS Named Profiles](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-multiple-profiles), you can use the following environmental variables instead
52
+
53
+ * `AWS_REGION`
54
+ * `AWS_PROFILE`
55
+
51
56
  ### AWS S3 bucket
52
57
 
53
58
  CarthageCache will assume there is a bucket named `carthage-cache`. You can change the bucket to be used by using the option `-b` or `--bucket-name`.
@@ -85,7 +90,7 @@ Create a policy with the following permisions:
85
90
  ]
86
91
  }
87
92
  ```
88
- Don't forget to attach the policy to the group.
93
+ Don't forget to attach the policy to the group and make sure to replace `autogenerated-id` with an ID that should be unique. You can generate a new policy using AWS policy generator and replace the content with the previous snippet keeping the SID field.
89
94
 
90
95
  ## Usage
91
96
 
@@ -145,6 +150,37 @@ For more information run the help command
145
150
  carthage_cache help
146
151
  ```
147
152
 
153
+ ### OSS project
154
+
155
+ In an OSS project you wouldn't store AWS credentials anywhere since anyone can have access, even if you have a build like travis that supports for encrypted variables but these are not available in your contributors pull requests build.
156
+
157
+ In order allow your build to run in these circumstances, you can avoid defining these variables
158
+
159
+ * `AWS_ACCESS_KEY_ID`
160
+ * `AWS_SECRET_ACCESS_KEY`
161
+ * `AWS_PROFILE`
162
+
163
+ And **carthage_cache** will work in read-only mode, you wont be able to publish new items but your build will still be able to fetch the cached dependencies.
164
+
165
+ The only requirement is to make the action `s3:GetObject` avaible for any anonymous user in your S3 Bucket
166
+
167
+ ```
168
+ {
169
+ "Version":"2012-10-17",
170
+ "Statement":[
171
+ {
172
+ "Sid":"AddPerm",
173
+ "Effect":"Allow",
174
+ "Principal": "*",
175
+ "Action":["s3:GetObject"],
176
+ "Resource":["arn:aws:s3:::examplebucket/*"]
177
+ }
178
+ ]
179
+ }
180
+ ```
181
+
182
+ > Please know that this will make all your dependencies **PUBLIC** and accessible for anyone, so if you have sensitive information or propietary code there you should avoid this configuration.
183
+
148
184
  ### Project's root directory
149
185
 
150
186
  The `carthage_cache` command assumes that the project's root directory is the current working directory and that the `Cartfile.resolved` file is located in the project's root directory. All `carthage_cache` accept an optional argument to set the project's root directory. For example
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "pry"
31
31
  spec.add_development_dependency "codeclimate-test-reporter"
32
32
 
33
- spec.add_dependency "aws-sdk", "~> 2.2.3"
33
+ spec.add_dependency "aws-sdk", "~> 2.0"
34
34
  spec.add_dependency "commander", "~> 4.3"
35
35
  end
@@ -12,11 +12,12 @@ module CarthageCache
12
12
  attr_reader :project
13
13
  attr_reader :config
14
14
 
15
- def initialize(project_path, verbose, config, repository: Repository, terminal: Terminal, swift_version_resolver: SwiftVersionResolver)
15
+ def initialize(project_path, verbose, config, repository: AWSRepository, terminal: Terminal, swift_version_resolver: SwiftVersionResolver)
16
16
  @terminal = terminal.new(verbose)
17
17
  @archiver = Archiver.new
18
18
  @config = Configurator.new(@terminal, project_path, config).config
19
- @repository = repository.new(@config.bucket_name, @config.hash_object[:aws_s3_client_options])
19
+ clazz = @config.read_only? ? HTTPRepository : repository
20
+ @repository = clazz.new(@config.bucket_name, @config.hash_object[:aws_s3_client_options])
20
21
  @project = Project.new(project_path, CACHE_DIR_NAME, @terminal, @config.tmpdir, swift_version_resolver.new)
21
22
  end
22
23
 
@@ -31,8 +31,14 @@ module CarthageCache
31
31
 
32
32
  def download_archive
33
33
  archive_path = File.join(project.tmpdir, project.archive_filename)
34
- terminal.puts "Downloading archive with key '#{archive_path}'."
35
- repository.download(project.archive_filename, archive_path)
34
+
35
+ if File.exist?(archive_path)
36
+ terminal.puts "Archive with key '#{archive_path}' already downloaded in local cache."
37
+ else
38
+ terminal.puts "Downloading archive with key '#{archive_path}'."
39
+ repository.download(project.archive_filename, archive_path)
40
+ end
41
+
36
42
  archive_path
37
43
  end
38
44
 
@@ -16,6 +16,10 @@ module CarthageCache
16
16
  ConfigurationValidator.new(config).valid?
17
17
  end
18
18
 
19
+ def self.read_only?(config)
20
+ ConfigurationValidator.new(config).read_only?
21
+ end
22
+
19
23
  def self.parse(str)
20
24
  new(YAML.load(str))
21
25
  end
@@ -25,9 +29,10 @@ module CarthageCache
25
29
  aws_s3_client_options: {
26
30
  region: ENV['AWS_REGION'],
27
31
  access_key_id: ENV['AWS_ACCESS_KEY_ID'],
28
- secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
32
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
33
+ profile: ENV['AWS_PROFILE']
29
34
  },
30
- tmpdir: Dir.tmpdir
35
+ tmpdir: File.join(Dir.home, 'Library', 'Caches')
31
36
  })
32
37
  end
33
38
 
@@ -35,6 +40,7 @@ module CarthageCache
35
40
  config_key :aws_region
36
41
  config_key :aws_access_key_id
37
42
  config_key :aws_secret_access_key
43
+ config_key :aws_profile
38
44
  config_key :tmpdir
39
45
 
40
46
  attr_reader :hash_object
@@ -51,6 +57,10 @@ module CarthageCache
51
57
  self.class.valid?(self)
52
58
  end
53
59
 
60
+ def read_only?
61
+ self.class.read_only?(self)
62
+ end
63
+
54
64
  def merge(c)
55
65
  if c.is_a?(Hash)
56
66
  @hash_object = hash_object.merge(c)
@@ -69,16 +69,30 @@ module CarthageCache
69
69
  validate.valid?
70
70
  end
71
71
 
72
+ def read_only?
73
+ (config.aws_access_key_id.nil? || config.aws_secret_access_key.nil?) && config.aws_profile.nil?
74
+ end
75
+
72
76
  def validate
73
77
  return missing_bucket_name unless has_bucket_name?
74
78
  return missing_aws_region unless has_aws_region?
75
- return missing_aws_access_key_id unless has_aws_access_key_id?
76
- return missing_aws_secret_access_key unless has_aws_secret_access_key?
79
+
80
+ return missing_aws_access_key_id if is_missing_aws_access_key_id?
81
+ return missing_aws_secret_access_key if is_missing_aws_secret_access_key?
82
+
77
83
  ValidationResult.valid
78
84
  end
79
85
 
80
86
  private
81
87
 
88
+ def is_missing_aws_access_key_id?
89
+ !has_aws_profile? && !has_aws_access_key_id? && has_aws_secret_access_key?
90
+ end
91
+
92
+ def is_missing_aws_secret_access_key?
93
+ !has_aws_profile? && has_aws_access_key_id? && !has_aws_secret_access_key?
94
+ end
95
+
82
96
  def has_bucket_name?
83
97
  config.bucket_name
84
98
  end
@@ -95,6 +109,10 @@ module CarthageCache
95
109
  config.aws_secret_access_key
96
110
  end
97
111
 
112
+ def has_aws_profile?
113
+ config.aws_profile
114
+ end
115
+
98
116
  def missing_bucket_name
99
117
  ValidationResult.invalid(MissingConfigurationKey.missing_bucket_name)
100
118
  end
@@ -2,7 +2,7 @@ require "aws-sdk"
2
2
 
3
3
  module CarthageCache
4
4
 
5
- class Repository
5
+ class AWSRepository
6
6
 
7
7
  attr_reader :client
8
8
  attr_reader :bucket_name
@@ -31,4 +31,28 @@ module CarthageCache
31
31
 
32
32
  end
33
33
 
34
+ class HTTPRepository
35
+
36
+ attr_reader :base_url
37
+
38
+ def initialize(bucket_name, client_options = {})
39
+ region = client_options[:region]
40
+ bucket_name = bucket_name
41
+ @base_url = "https://s3-#{region}.amazonaws.com/#{bucket_name}"
42
+ end
43
+
44
+ def archive_exist?(archive_filename)
45
+ system "wget", "--method=HEAD", "#{base_url}/#{archive_filename}", "-q"
46
+ end
47
+
48
+ def download(archive_filename, destination_path)
49
+ system "wget", "--output-document=#{destination_path}", "#{base_url}/#{archive_filename}", "-q"
50
+ end
51
+
52
+ def upload(archive_filename, archive_path)
53
+ raise "carthage_cache is working in read-only mode. Please configure AWS credentials first"
54
+ end
55
+
56
+ end
57
+
34
58
  end
@@ -1,3 +1,3 @@
1
1
  module CarthageCache
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carthage_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guido Marucci Blas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 2.2.3
89
+ version: '2.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 2.2.3
96
+ version: '2.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: commander
99
99
  requirement: !ruby/object:Gem::Requirement