serverlessgems 0.1.4 → 0.2.0

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: 801c924a1a3b4c3308e4637a26d849d7423322f579c9985c2197a1ae64b6b98d
4
- data.tar.gz: d567760d50e0f0c095a4d6ece3bb659a31a351898bb6827266c9bbc0bef0a27a
3
+ metadata.gz: 17849f420754066145243aefd213033867f4926967d1bfd0e530ac183731ebca
4
+ data.tar.gz: 358170e435dea0015b7440c8016be0e715dd5f111276334bd3c17ad51c49ef2d
5
5
  SHA512:
6
- metadata.gz: 723634152694aebb484c1693c1cbf49466195b0e84424e72a8f46cce75216211fcf138bd5fd36ac4b75fc3c3dbd79f75703964ebac8b1bfc4704e0fef93b76c4
7
- data.tar.gz: cceb728e1d0bf62c2ced97d31059ab8ff0c155338c540572bbf70c72238b81365392eea49fcc66e2c0ada09c862d4cd152fd5e77b3375e13282af712ad37e6f8
6
+ metadata.gz: c4618ff2e516a104d98f56ce0edd5a93229f48d7d14565a289712f7edf28c484a7052c36eb5e2dae060c43852d4664d7e3d91c290713d1a6a5b67caff2f7c969
7
+ data.tar.gz: 4ab7918973479151b2200636a30547d67a9cc5eecb6fd6e178fc7000c93c837ec3801e45c796a2d11ce1d747fa65a45467399eed65220b1d76e0e7038a3a255f
data/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [0.2.0] - 2022-07-02
7
+ - provide gems available info
8
+
9
+ ## [0.1.6] - 2021-11-11
10
+ - [#5](https://github.com/boltops-tools/serverlessgems/pull/5) fix gem regexp detection for 2021 macbook m1 chip
11
+
12
+ ## [0.1.5] - 2021-08-31
13
+ - [#4](https://github.com/boltops-tools/serverlessgems/pull/4) Don't create a file if the download fails
14
+
6
15
  ## [0.1.4] - 2021-07-15
7
16
  - [#3](https://github.com/boltops-tools/serverlessgems/pull/3) gems/registered api
8
17
 
@@ -1,3 +1,5 @@
1
+ require "aws-sdk-core"
2
+
1
3
  class Jets::Gems::Api
2
4
  module Core
3
5
  extend Memoist
@@ -23,6 +25,7 @@ class Jets::Gems::Api
23
25
 
24
26
  def set_headers!(req)
25
27
  req['Authorization'] = token if token
28
+ req['x-account'] = account if account
26
29
  req['Content-Type'] = "application/vnd.api+json"
27
30
  end
28
31
 
@@ -77,5 +80,15 @@ class Jets::Gems::Api
77
80
  def delete(path, data={})
78
81
  request(Net::HTTP::Delete, path, data)
79
82
  end
83
+
84
+ def account
85
+ sts.get_caller_identity.account rescue nil
86
+ end
87
+ memoize :account
88
+
89
+ def sts
90
+ Aws::STS::Client.new
91
+ end
92
+ memoize :sts
80
93
  end
81
94
  end
@@ -26,7 +26,8 @@ module Jets::Gems
26
26
  compiled_gems.each do |gem_name|
27
27
  puts "Checking #{gem_name}..." if @options[:verbose]
28
28
  exist = Jets::Gems::Exist.new
29
- @missing_gems << gem_name unless exist.check(gem_name)
29
+ data = exist.check(gem_name)
30
+ @missing_gems << data unless data["exist"]
30
31
  end
31
32
 
32
33
  if exit_early && !@missing_gems.empty?
@@ -34,7 +35,8 @@ module Jets::Gems
34
35
  # Better to error now than deploy a broken package to AWS Lambda.
35
36
  # Provide users with message about using their own serverlessgems source.
36
37
  puts missing_message
37
- Report.new(@options).report(@missing_gems) if agree.yes?
38
+ names = @missing_gems.map {|i| i['gem_name']}
39
+ Report.new(@options).report(names) if agree.yes?
38
40
  exit 1
39
41
  end
40
42
 
@@ -48,10 +50,11 @@ module Jets::Gems
48
50
  def missing_message
49
51
  template = <<-EOL
50
52
  Your project requires compiled gems that are not currently available. Unavailable pre-compiled gems:
51
- <% missing_gems.each do |gem| %>
52
- * <%= gem -%>
53
+ <% missing_gems.each do |missing_gem|
54
+ available = missing_gem['available'].reject { |v| missing_gem['gem_name'].include?(v) }
55
+ %>
56
+ * Unavailable: <%= missing_gem['gem_name'] -%> Available versions: <%= available.join(' ') %>
53
57
  <% end %>
54
-
55
58
  Your current serverlessgems source: #{gems_source}
56
59
 
57
60
  Jets is unable to build a deployment package that will work on AWS Lambda without the required pre-compiled gems. To remedy this, you can:
@@ -148,9 +151,13 @@ EOL
148
151
  # /tmp/jets/demo/stage/opt/ruby/gems/2.7.0/gems/nokogiri-1.11.1-x86_64-darwin
149
152
  # /tmp/jets/demo/stage/opt/ruby/gems/2.7.0/gems/nokogiri-1.11.1-x86_64-linux
150
153
  #
154
+ # On new 2021 macbook with m1 chip: the gems are being saved in a folder like so:
155
+ # nokogiri-1.12.5-arm64-darwin
156
+ # The GEM_REGEXP accounts for this case.
157
+ GEM_REGEXP = /-(arm|x)\d+.*-(darwin|linux)/
151
158
  def other_compiled_gems
152
159
  paths = Dir.glob("#{Jets.build_root}/stage/opt/ruby/gems/#{Jets::Gems.ruby_folder}/gems/*{-darwin,-linux}")
153
- paths.map { |p| File.basename(p).sub(/-x\d+.*-(darwin|linux)/,'') }
160
+ paths.map { |p| File.basename(p).sub(GEM_REGEXP,'') }
154
161
  end
155
162
 
156
163
  def registered_compiled_gems
@@ -158,7 +165,7 @@ EOL
158
165
  registered_gems = registered.all # no version numbers in this list
159
166
 
160
167
  paths = Dir.glob("#{Jets.build_root}/stage/opt/ruby/gems/#{Jets::Gems.ruby_folder}/gems/*")
161
- project_gems = paths.map { |p| File.basename(p).sub(/-x\d+.*-(darwin|linux)/,'') }
168
+ project_gems = paths.map { |p| File.basename(p).sub(GEM_REGEXP,'') }
162
169
  project_gems.select do |name|
163
170
  name_only = name.sub(/-\d+\.\d+\.\d+.*/,'')
164
171
  registered_gems.include?(name_only)
@@ -2,29 +2,11 @@ module Jets::Gems
2
2
  class Exist
3
3
  include Jets::Gems::Api::Concern
4
4
 
5
- # We check all the availability before even downloading so we can provide a
6
- # full list of gems they might want to research all at once instead of incrementally
7
- #
8
- # Examples:
9
- #
10
- # check(single_gem)
11
- # check(list, of, gems)
12
- def check(*gem_names)
13
- gem_names = gem_names.flatten
14
- exists = gem_names.inject({}) do |hash, gem_name|
15
- exist = gem_exist?(gem_name)
16
- hash[gem_name] = exist
17
- hash.merge(hash)
18
- end
19
-
20
- exists.values.all? {|v| v } # all_exist
21
- end
22
-
23
- def gem_exist?(gem_name)
24
- data = api.check_exist(gem_name: gem_name)
25
- data["exist"]
5
+ # gem_name IE: nokogiri-1.1.1
6
+ def check(gem_name)
7
+ api.check_exist(gem_name: gem_name) # data = {"exist": ..., "available"}
26
8
  rescue SocketError, OpenURI::HTTPError, OpenSSL::SSL::SSLError
27
- false
9
+ {"exist" => false, gem_name: gem_name, available: [] }
28
10
  end
29
11
  end
30
- end
12
+ end
@@ -41,13 +41,12 @@ module Jets::Gems::Extract
41
41
  end
42
42
 
43
43
  say "Downloading..."
44
+ downloaded = URI.open(url, 'rb') { |read_file| read_file.read }
45
+
44
46
  FileUtils.mkdir_p(File.dirname(dest)) # ensure parent folder exists
45
47
 
46
- File.open(dest, 'wb') do |saved_file|
47
- URI.open(url, 'rb') do |read_file|
48
- saved_file.write(read_file.read)
49
- end
50
- end
48
+ File.open(dest, 'wb') { |saved_file| saved_file.write(downloaded) }
49
+
51
50
  dest
52
51
  end
53
52
 
@@ -1,5 +1,5 @@
1
1
  module Jets
2
2
  module Gems
3
- VERSION = "0.1.4"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverlessgems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-15 00:00:00.000000000 Z
11
+ date: 2022-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gems
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
- rubygems_version: 3.2.5
149
+ rubygems_version: 3.3.10
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Client Library works with Serverless Gems API for Jets Ruby Serverless Framework