minio-ruby 0.0.1 → 0.0.2

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: 4e80b50c33f3bf729385175bc47e0387e8a0fce1
4
- data.tar.gz: 2bd287d3cb03a2dea5abc42a38da1110df146bd7
3
+ metadata.gz: 7e603301cb856efa874228a10ad52c7f22aa7416
4
+ data.tar.gz: 59ef420b4973b3acd325bfe51cb4e37a2a3d5e1b
5
5
  SHA512:
6
- metadata.gz: cd4692fae1e4a41505644c32d2c8338b2f00f89484765d40a8ba57c9aa30f822de9f3e045e8ddadfd082536f17d4fa10621ebdb9f4cca401f5159742d76532d7
7
- data.tar.gz: d9716ef1fc2216e79938b671716cc3d9bb6bb72d052d2156448acb6c90f0ffc5e8fa92c63361afdcf43f0964920816437316dac02b5548fe4630c273b55b8342
6
+ metadata.gz: 26be7cf57ce7887bef1634441deda87ddf4bd5b5f3c96a2840bac1d2281b01d92eaeadc2239c342ae69455a614441963daf0cf2ac6ce6538bd32e5863921bb32
7
+ data.tar.gz: f8dd20d78260bae576d093f0263268df42106767e258acbc8c5b51bd1251ea8fa24380eccc4e191fab182789cc35305585f1da368ea434e993414cf492167402
@@ -3,8 +3,8 @@ require "net/https"
3
3
  require "base64"
4
4
  require "openssl"
5
5
  require 'uri'
6
- require "minio/signer"
7
- require "minio/digest"
6
+ require "minio-ruby/signer"
7
+ require "minio-ruby/digest"
8
8
  require 'digest'
9
9
 
10
10
  module MinioRuby
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require "openssl"
3
+
4
+ module MinioRuby
5
+ class Digestor
6
+ # calculate sha256 hex digest.
7
+ def self.hexdigest(value)
8
+ Digest::SHA256.new.update(value).hexdigest
9
+ end
10
+
11
+ # calculate hmac digest.
12
+ def self.hmac(key, value)
13
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), key, value)
14
+ end
15
+
16
+ # calculate hmac hex digest.
17
+ def self.hexhmac(key, value)
18
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, value)
19
+ end
20
+
21
+ def self.base64(value)
22
+ Digest::MD5.base64digest(value)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ module MinioRuby
2
+ class InvalidEndpointError < StandardError
3
+ attr_reader :str
4
+
5
+ def initialize(msg = 'Invalid Endpoint Error', str)
6
+ @str = str
7
+ super
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module MinioRuby
2
+ def isValidEndPoint
3
+ end
4
+
5
+ def isValidBucketName
6
+ end
7
+
8
+ def isValidObjectName
9
+ end
10
+ end
@@ -0,0 +1,162 @@
1
+ require "openssl"
2
+ require "time"
3
+ require "uri"
4
+ require "pathname"
5
+ require "minio-ruby/digest"
6
+
7
+ module MinioRuby
8
+ class Signer
9
+ RFC8601BASIC = "%Y%m%dT%H%M%SZ"
10
+ SIGNV4ALGO = 'AWS4-HMAC-SHA256'
11
+ attr_reader :access_key, :secret_key, :region, :date, :service
12
+ attr_reader :method, :uri, :headers
13
+
14
+ # Initialize signer for calculating your signature.
15
+ # Params:
16
+ # +config+: configuration data with access keys and region.
17
+ def initialize(config)
18
+ @access_key = config[:access_key] || config["access_key"]
19
+ @secret_key = config[:secret_key] || config["secret_key"]
20
+ @region = config[:region] || config["region"]
21
+ @date = Time.now.utc.strftime(RFC8601BASIC)
22
+ @service = "s3"
23
+ end
24
+
25
+ # Signature v4 function returns back headers with Authorization header.
26
+ # Params:
27
+ # +method+: http method.
28
+ # +endpoint+: S3 endpoint URL.
29
+ def sign_v4(method, endpoint, headers, body = nil, debug = false)
30
+ @method = method.upcase
31
+ @endpoint = endpoint
32
+ @headers = headers
33
+ @uri = URI(endpoint)
34
+
35
+ puts "EP : "+@endpoint
36
+ puts "Headers : "+@headers.to_s
37
+
38
+ headers["X-Amz-Date"] = date
39
+ headers["X-Amz-Content-Sha256"] = Digestor.hexdigest(body || "")
40
+
41
+
42
+ headers["Host"] = get_host(@uri)
43
+ puts "--->" + get_host(@uri)
44
+
45
+
46
+ dump if debug
47
+ signed_headers = headers.dup
48
+
49
+ signed_headers['Authorization'] = get_authorization(headers)
50
+ signed_headers
51
+ end
52
+
53
+ private
54
+
55
+ # Get host header value from endpoint.
56
+ # Params:
57
+ # +endpoint+: endpoint URI object.
58
+ def get_host(endpoint)
59
+ puts "recieved : "+ endpoint.to_s
60
+ puts "port : "+ endpoint.port.to_s
61
+ if endpoint.port
62
+ if ((endpoint.port == 443) || (endpoint.port == 80))
63
+ return endpoint.host
64
+ else
65
+ return endpoint.host + ":" + endpoint.port.to_s
66
+ end
67
+ else
68
+ #return endpoint.host
69
+ return endpoint.host + ":" + endpoint.port.to_s
70
+ end
71
+ end
72
+
73
+
74
+ # Get authorization header value.
75
+ # Params:
76
+ # +headers+: list of headers supplied for the request.
77
+ def get_authorization(headers)
78
+ [
79
+ "AWS4-HMAC-SHA256 Credential=#{access_key}/#{credential_scope}",
80
+ "SignedHeaders=#{headers.keys.map(&:downcase).sort.join(";")}",
81
+ "Signature=#{signature}"
82
+ ].join(', ')
83
+ end
84
+
85
+ # Calculate HMAC based signature in following format.
86
+ # --- format ---
87
+ # kSecret = Your AWS Secret Access Key
88
+ # kDate = HMAC("AWS4" + kSecret, Date)
89
+ # kRegion = HMAC(kDate, Region)
90
+ # kService = HMAC(kRegion, Service)
91
+ # kSigning = HMAC(kService, "aws4_request")
92
+ # --------------
93
+ def signature
94
+ k_date = Digestor.hmac("AWS4" + secret_key, date[0, 8])
95
+ k_region = Digestor.hmac(k_date, region)
96
+ k_service = Digestor.hmac(k_region, service)
97
+ k_credentials = Digestor.hmac(k_service, "aws4_request")
98
+ Digestor.hexhmac(k_credentials, string_to_sign)
99
+ end
100
+
101
+ # Generate string to sign.
102
+ # --- format ---
103
+ # StringToSign =
104
+ # Algorithm + '\n' +
105
+ # RequestDate + '\n' +
106
+ # CredentialScope + '\n' +
107
+ # HashedCanonicalRequest
108
+ # --------------
109
+ def string_to_sign
110
+ [
111
+ SIGNV4ALGO,
112
+ date,
113
+ credential_scope,
114
+ Digestor.hexdigest(canonical_request)
115
+ ].join("\n")
116
+ end
117
+
118
+ # Generate credential scope.
119
+ # --- format ---
120
+ # <mmddyyyy>/<region>/<service>/aws4_request
121
+ # --------------
122
+ def credential_scope
123
+ [
124
+ date[0, 8],
125
+ region,
126
+ service,
127
+ "aws4_request"
128
+ ].join("/")
129
+ end
130
+
131
+ # Generate a canonical request of following style.
132
+ # --- format ---
133
+ # canonicalRequest =
134
+ # <HTTPMethod>\n
135
+ # <CanonicalURI>\n
136
+ # <CanonicalQueryString>\n
137
+ # <CanonicalHeaders>\n
138
+ # <SignedHeaders>\n
139
+ # <HashedPayload>
140
+ # --------------
141
+ def canonical_request
142
+ [
143
+ method,
144
+ Pathname.new(uri.path).cleanpath.to_s,
145
+ uri.query,
146
+ headers.sort.map { |k, v| [k.downcase, v.strip].join(':') }.join("\n") + "\n",
147
+ headers.sort.map { |k, v| k.downcase }.join(";"),
148
+ headers["X-Amz-Content-Sha256"]
149
+ ].join("\n")
150
+ end
151
+
152
+ def dump
153
+ puts "-----------------DUMP BEGIN ---------------------"
154
+ puts "string to sign"
155
+ puts string_to_sign
156
+ puts "canonical_request"
157
+ puts canonical_request
158
+ puts "authorization"
159
+ puts "-----------------DUMP END ----------------------"
160
+ end
161
+ end
162
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minio-ruby
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
  - Minio, Inc.
@@ -31,11 +31,11 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - lib/minio.rb
35
- - lib/minio/digest.rb
36
- - lib/minio/error.rb
37
- - lib/minio/helper.rb
38
- - lib/minio/signer.rb
34
+ - lib/minio-ruby.rb
35
+ - lib/minio-ruby/digest.rb
36
+ - lib/minio-ruby/error.rb
37
+ - lib/minio-ruby/helper.rb
38
+ - lib/minio-ruby/signer.rb
39
39
  homepage: https://github.com/watsy0007/minio-ruby
40
40
  licenses:
41
41
  - Apache-2.0
@@ -1,28 +0,0 @@
1
- # encoding: UTF-8
2
- require "openssl"
3
-
4
- module MinioRuby
5
-
6
- class Digestor
7
- # calculate sha256 hex digest.
8
- def self.hexdigest(value)
9
- Digest::SHA256.new.update(value).hexdigest
10
- end
11
-
12
- # calculate hmac digest.
13
- def self.hmac(key, value)
14
- OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), key, value)
15
- end
16
-
17
- # calculate hmac hex digest.
18
- def self.hexhmac(key, value)
19
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, value)
20
- end
21
-
22
- def self.base64(value)
23
- return Digest::MD5.base64digest(value)
24
- end
25
- end
26
-
27
-
28
- end
@@ -1,10 +0,0 @@
1
- module MinioRuby
2
- class InvalidEndpointError < StandardError
3
- attr_reader :str
4
- def initialize(msg = "Invalid Endpoint Error", str)
5
- @str = str
6
- super
7
- end
8
- end
9
-
10
- end
@@ -1,18 +0,0 @@
1
-
2
-
3
- module MinioRuby
4
- def isValidEndPoint
5
-
6
-
7
-
8
- end
9
-
10
- def isValidBucketName
11
- end
12
-
13
- def isValidObjectName
14
- end
15
-
16
-
17
-
18
- end
@@ -1,169 +0,0 @@
1
-
2
- require "openssl"
3
- require "time"
4
- require "uri"
5
- require "pathname"
6
- require "minio/digest"
7
-
8
- module MinioRuby
9
- class Signer
10
- RFC8601BASIC = "%Y%m%dT%H%M%SZ"
11
- SIGNV4ALGO = 'AWS4-HMAC-SHA256'
12
- attr_reader :access_key, :secret_key, :region, :date, :service
13
- attr_reader :method, :uri, :headers
14
-
15
- # Initialize signer for calculating your signature.
16
- # Params:
17
- # +config+: configuration data with access keys and region.
18
- def initialize(config)
19
- @access_key = config[:access_key] || config["access_key"]
20
- @secret_key = config[:secret_key] || config["secret_key"]
21
- @region = config[:region] || config["region"]
22
- @date = Time.now.utc.strftime(RFC8601BASIC)
23
- @service = "s3"
24
- end
25
-
26
- # Signature v4 function returns back headers with Authorization header.
27
- # Params:
28
- # +method+: http method.
29
- # +endpoint+: S3 endpoint URL.
30
- def sign_v4(method, endpoint, headers, body = nil, debug = false)
31
- @method = method.upcase
32
- @endpoint = endpoint
33
- @headers = headers
34
- @uri = URI(endpoint)
35
-
36
- puts "EP : "+@endpoint
37
- puts "Headers : "+@headers.to_s
38
-
39
- headers["X-Amz-Date"] = date
40
- headers["X-Amz-Content-Sha256"] = Digestor.hexdigest(body || "")
41
-
42
-
43
- headers["Host"] = get_host(@uri)
44
- puts "--->" + get_host(@uri)
45
-
46
-
47
- dump if debug
48
- signed_headers = headers.dup
49
-
50
- signed_headers['Authorization'] = get_authorization(headers)
51
- signed_headers
52
- end
53
-
54
- private
55
-
56
- # Get host header value from endpoint.
57
- # Params:
58
- # +endpoint+: endpoint URI object.
59
- def get_host(endpoint)
60
- puts "recieved : "+ endpoint.to_s
61
- puts "port : "+ endpoint.port.to_s
62
- if endpoint.port
63
- if ((endpoint.port == 443) || (endpoint.port == 80))
64
- return endpoint.host
65
- else
66
- return endpoint.host + ":" + endpoint.port.to_s
67
- end
68
- else
69
- #return endpoint.host
70
- return endpoint.host + ":" + endpoint.port.to_s
71
- end
72
- end
73
-
74
-
75
-
76
-
77
-
78
- # Get authorization header value.
79
- # Params:
80
- # +headers+: list of headers supplied for the request.
81
- def get_authorization(headers)
82
- [
83
- "AWS4-HMAC-SHA256 Credential=#{access_key}/#{credential_scope}",
84
- "SignedHeaders=#{headers.keys.map(&:downcase).sort.join(";")}",
85
- "Signature=#{signature}"
86
- ].join(', ')
87
- end
88
-
89
- # Calculate HMAC based signature in following format.
90
- # --- format ---
91
- # kSecret = Your AWS Secret Access Key
92
- # kDate = HMAC("AWS4" + kSecret, Date)
93
- # kRegion = HMAC(kDate, Region)
94
- # kService = HMAC(kRegion, Service)
95
- # kSigning = HMAC(kService, "aws4_request")
96
- # --------------
97
- def signature
98
- k_date = Digestor.hmac("AWS4" + secret_key, date[0,8])
99
- k_region = Digestor.hmac(k_date, region)
100
- k_service = Digestor.hmac(k_region, service)
101
- k_credentials = Digestor.hmac(k_service, "aws4_request")
102
- Digestor.hexhmac(k_credentials, string_to_sign)
103
- end
104
-
105
- # Generate string to sign.
106
- # --- format ---
107
- # StringToSign =
108
- # Algorithm + '\n' +
109
- # RequestDate + '\n' +
110
- # CredentialScope + '\n' +
111
- # HashedCanonicalRequest
112
- # --------------
113
- def string_to_sign
114
- [
115
- SIGNV4ALGO,
116
- date,
117
- credential_scope,
118
- Digestor.hexdigest(canonical_request)
119
- ].join("\n")
120
- end
121
-
122
- # Generate credential scope.
123
- # --- format ---
124
- # <mmddyyyy>/<region>/<service>/aws4_request
125
- # --------------
126
- def credential_scope
127
- [
128
- date[0,8],
129
- region,
130
- service,
131
- "aws4_request"
132
- ].join("/")
133
- end
134
-
135
- # Generate a canonical request of following style.
136
- # --- format ---
137
- # canonicalRequest =
138
- # <HTTPMethod>\n
139
- # <CanonicalURI>\n
140
- # <CanonicalQueryString>\n
141
- # <CanonicalHeaders>\n
142
- # <SignedHeaders>\n
143
- # <HashedPayload>
144
- # --------------
145
- def canonical_request
146
- [
147
- method,
148
- Pathname.new(uri.path).cleanpath.to_s,
149
- uri.query,
150
- headers.sort.map {|k, v| [k.downcase,v.strip].join(':')}.join("\n") + "\n",
151
- headers.sort.map {|k, v| k.downcase}.join(";"),
152
- headers["X-Amz-Content-Sha256"]
153
- ].join("\n")
154
- end
155
-
156
- def dump
157
- puts "-----------------DUMP BEGIN ---------------------"
158
- puts "string to sign"
159
- puts string_to_sign
160
- puts "canonical_request"
161
- puts canonical_request
162
- puts "authorization"
163
- puts "-----------------DUMP END ----------------------"
164
- end
165
- end
166
-
167
-
168
-
169
- end