lambda_convert 0.0.6 → 1.0.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
- SHA1:
3
- metadata.gz: 6c605d6308b66aa522b51fe09121ea05a1e962eb
4
- data.tar.gz: 375b23a2819be672e58bb8894fc7c0df5fc3c10a
2
+ SHA256:
3
+ metadata.gz: dae0a87a2bc2e45653d677a270f8ff84b605f4175a9250b5241d309673a52180
4
+ data.tar.gz: 7d809ea4f044bbd9eae311ea7909f3f129baf1d32bc47a31b6c073577dcfa79c
5
5
  SHA512:
6
- metadata.gz: a55edfd1babe87ff83d2a9cc763e9a47501b63af31d7c1028f04479f222bffe1a566ae614af7ff896668e8c1cb1838e8586e7e521f138da47851f5263464c197
7
- data.tar.gz: 5f557c99c83614749f0b189e56764fc1640359a343f1a649e2943546086e5691e978cce192597e3b723437b2781110f96d702e8e3ccf9c3eab3db5687aaf2049
6
+ metadata.gz: 799f4822b0010635000df3f6256908fccaef8faf966d9ed30088b1388e5f2e0d97b75d716c09f67a8040161f9f65a5c33535f00fb64b2ca824c05c42b45662fc
7
+ data.tar.gz: 6517f828ceddd7a726acb56c321ccd281ea1eafa9c3f9a52df67a1a1e77f348ad1632276e3776d886362c88f670bb1149eede818b72949bccbc7a6c4ad11afc1
data/README.md CHANGED
@@ -19,10 +19,10 @@ To eliminate the big image file uploading issue and the security risk, the idea
19
19
 
20
20
  ## Environment variables
21
21
 
22
- - **CONVERT_S3_REGION** - AWS region for S3, default value will be reading from `AWS_REGION` if this environment variable is not set. (required)
23
- - **CONVERT_LAMBDA_REGION** - AWS region for Lambda, default value will be reading from `AWS_REGION` if this environment variable is not set. (required)
24
- - **CONVERT_ACCESS_KEY** - AWS access key, default value will be reading from `AWS_ACCESS_KEY_ID` if this environment variable is not set. (required)
25
- - **CONVERT_SECRET_ACCESS_KEY** - AWS secret key, default value will be reading from `AWS_SECRET_ACCESS_KEY` if this environment variable is not set. (required)
22
+ - **CONVERT_S3_REGION** - AWS region for S3, default value will be read from `AWS_REGION` if this environment variable is not set.
23
+ - **CONVERT_LAMBDA_REGION** - AWS region for Lambda, default value will be read from `AWS_REGION` if this environment variable is not set.
24
+ - **CONVERT_ACCESS_KEY** - AWS access key, default value will follow standard `aws-sdk` credential lookup sequence
25
+ - **CONVERT_SECRET_ACCESS_KEY** - AWS secret key, default value will follow standard `aws-sdk` credential lookup sequence
26
26
  - **CONVERT_S3_BUCKET** - AWS S3 bucket. (required)
27
27
  - **CONVERT_S3_KEY_PREFIX** - AWS S3 temporary file uploading prefix, default value is `_convert_tmp/`
28
28
  - **CONVERT_LAMBDA_FUNCTION** - Name of the AWS Lambda function to invoke, default value is `image-convert-prod`
@@ -1,62 +1,44 @@
1
- require 'rubygems'
2
1
  require 'json'
3
2
  require 'securerandom'
4
3
  require 'English'
5
4
 
6
- require 'aws-sdk'
5
+ require 'aws-sdk-lambda'
6
+ require 'aws-sdk-s3'
7
+ require 'forwardable'
7
8
 
8
9
  module LambdaConvert
9
10
  # `convert` command line tool implementation
10
11
  module CLI
11
- class <<self
12
+ class << self
13
+ extend Forwardable
14
+ def_delegator :LambdaConvert, :config
12
15
  attr_accessor :logger
13
16
 
14
17
  def aws_credentials
15
- Aws::Credentials.new(
16
- ENV['CONVERT_ACCESS_KEY'] || ENV['AWS_ACCESS_KEY_ID'],
17
- ENV['CONVERT_SECRET_ACCESS_KEY'] || ENV['AWS_SECRET_ACCESS_KEY']
18
- )
19
- end
20
-
21
- def lambda_region
22
- ENV['CONVERT_LAMBDA_REGION'] || ENV['AWS_REGION']
23
- end
24
-
25
- def lambda_function
26
- ENV['CONVERT_LAMBDA_FUNCTION'] || 'image-convert-prod'
27
- end
28
-
29
- def s3_region
30
- ENV['CONVERT_S3_REGION'] || ENV['AWS_REGION']
31
- end
32
-
33
- def s3_bucket
34
- ENV['CONVERT_S3_BUCKET']
35
- end
36
-
37
- def s3_key_prefix
38
- ENV['CONVERT_S3_KEY_PREFIX'] || '_convert_tmp/'
18
+ if config.access_key && config.secret_key
19
+ Aws::Credentials.new(config.access_key, config.secret_key)
20
+ end
39
21
  end
40
22
 
41
23
  def s3_client
42
24
  @s3_client ||= Aws::S3::Client.new(
43
- region: s3_region,
25
+ region: config.s3_region,
44
26
  credentials: aws_credentials
45
27
  )
46
28
  end
47
29
 
48
30
  def lambda_client
49
31
  @aws_lambda ||= Aws::Lambda::Client.new(
50
- region: lambda_region,
32
+ region: config.lambda_region,
51
33
  credentials: aws_credentials
52
34
  )
53
35
  end
54
36
  end
55
37
 
56
38
  def self.upload_file(input_file, input_key)
57
- logger.info("Uploading file to s3://#{s3_bucket}/#{input_key}")
39
+ logger.info("Uploading file to s3://#{config.s3_bucket}/#{input_key}")
58
40
  File.open(input_file, 'rb') do |file|
59
- s3_client.put_object(bucket: s3_bucket, key: input_key, body: file)
41
+ s3_client.put_object(bucket: config.s3_bucket, key: input_key, body: file)
60
42
  end
61
43
  end
62
44
 
@@ -66,7 +48,7 @@ module LambdaConvert
66
48
  instruction = {
67
49
  schema: 'envoy-convert-instruction',
68
50
  original: input_key,
69
- bucket: s3_bucket,
51
+ bucket: config.s3_bucket,
70
52
  write_options: {},
71
53
  key: output_key,
72
54
  args: [source] + args + ['{dest}']
@@ -74,7 +56,7 @@ module LambdaConvert
74
56
  logger.info("Invoking lambda with instruction #{instruction}")
75
57
 
76
58
  resp = lambda_client.invoke(
77
- function_name: lambda_function,
59
+ function_name: config.lambda_function,
78
60
  invocation_type: 'RequestResponse',
79
61
  payload: JSON.dump(instruction)
80
62
  )
@@ -84,20 +66,20 @@ module LambdaConvert
84
66
 
85
67
  def self.download_file(output_key, output_file)
86
68
  logger.info(
87
- "Downloading file from s3://#{s3_bucket}/#{output_key} to " \
69
+ "Downloading file from s3://#{config.s3_bucket}/#{output_key} to " \
88
70
  "#{output_file}"
89
71
  )
90
72
  s3_client.get_object(
91
73
  response_target: output_file,
92
- bucket: s3_bucket,
74
+ bucket: config.s3_bucket,
93
75
  key: output_key
94
76
  )
95
77
  end
96
78
 
97
79
  def self.delete_files(keys)
98
- logger.info("Delete files #{keys} from #{s3_bucket}")
80
+ logger.info("Delete files #{keys} from #{config.s3_bucket}")
99
81
  s3_client.delete_objects(
100
- bucket: s3_bucket,
82
+ bucket: config.s3_bucket,
101
83
  delete: {
102
84
  objects: keys.map { |key| { key: key } },
103
85
  quiet: true
@@ -112,8 +94,8 @@ module LambdaConvert
112
94
  # Notice: there is also special output file syntax for convert command,
113
95
  # but we are not supporting them now, as we probably won't use it
114
96
  output_file = ARGV[-1]
115
- input_key = "#{s3_key_prefix}#{SecureRandom.uuid}"
116
- output_key = "#{s3_key_prefix}#{SecureRandom.uuid}"
97
+ input_key = File.join config.s3_key_prefix.to_s, SecureRandom.uuid
98
+ output_key = File.join config.s3_key_prefix.to_s, SecureRandom.uuid
117
99
 
118
100
  upload_file(input_file, input_key)
119
101
  invoke_lambda(input_key, input_selecting, ARGV[1..-2], output_key)
@@ -0,0 +1,22 @@
1
+ module LambdaConvert
2
+ class Config
3
+ attr_accessor :access_key,
4
+ :lambda_function,
5
+ :lambda_region,
6
+ :s3_bucket,
7
+ :s3_key_prefix,
8
+ :s3_region,
9
+ :secret_key
10
+
11
+ # Set some defaults
12
+ def initialize
13
+ @access_key = ??
14
+ @secret_key = ??
15
+ @lambda_function = "image-convert-dev"
16
+ @lambda_region = "us-east-1"
17
+ @s3_region = "us-east-1"
18
+ @s3_bucket = "envoy-development-staging-2"
19
+ @s3_key_prefix = "_convert_tmp"
20
+ end
21
+ end
22
+ end
@@ -1,2 +1,13 @@
1
1
  require 'lambda_convert/cli'
2
+ require 'lambda_convert/config'
2
3
  require 'lambda_convert/utils'
4
+
5
+ module LambdaConvert
6
+ def self.config
7
+ @config ||= Config.new
8
+ end
9
+
10
+ def self.configure(&_block)
11
+ yield config
12
+ end
13
+ end
metadata CHANGED
@@ -1,48 +1,62 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambda_convert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fang-Pen Lin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aws-sdk
14
+ name: aws-sdk-lambda
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.6'
19
+ version: '1.0'
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: '2.6'
27
- description:
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-s3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description:
28
42
  email: fang@envoy.com
29
43
  executables:
30
44
  - convert
31
45
  extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
34
- - "./lib/.DS_Store"
35
48
  - "./lib/lambda_convert.rb"
36
49
  - "./lib/lambda_convert/cli.rb"
50
+ - "./lib/lambda_convert/config.rb"
37
51
  - "./lib/lambda_convert/utils.rb"
38
52
  - LICENSE
39
53
  - README.md
40
54
  - bin/convert
41
- homepage:
55
+ homepage:
42
56
  licenses:
43
57
  - MIT
44
58
  metadata: {}
45
- post_install_message:
59
+ post_install_message:
46
60
  rdoc_options: []
47
61
  require_paths:
48
62
  - lib
@@ -57,11 +71,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
71
  - !ruby/object:Gem::Version
58
72
  version: '0'
59
73
  requirements: []
60
- rubyforge_project:
61
- rubygems_version: 2.4.5.1
62
- signing_key:
74
+ rubygems_version: 3.4.22
75
+ signing_key:
63
76
  specification_version: 4
64
77
  summary: AWS Lambda powered drop-in replacement for ImageMagick convert command line
65
78
  tool
66
79
  test_files: []
67
- has_rdoc:
data/lib/.DS_Store DELETED
Binary file