netstorageapi 0.0.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 +4 -4
- data/lib/akamai/netstorage.rb +133 -131
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a99cc7c30421fc23825086161e0e31f8503a6c28
|
4
|
+
data.tar.gz: aa3f2f79bbec4a6edd06f66626b36de0d544d8b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae957130bf15715e95c5e45bb9c7fb7bcc558400a6e786f394c4b5de3e9e0ed20c4447b3bc0c8cbb4e7821f934d2f9a99e0e2e9a8f7279f59f9dd84dc685dc88
|
7
|
+
data.tar.gz: ccb4b1288d200974adcce701a7c5e9a679de3a5a8fcc62c893e123b6aea08acfe0fbdd3c1fad205e8aa07bf43686ed1469c7b557eca5c878be616bf7ac6d8d11
|
data/lib/akamai/netstorage.rb
CHANGED
@@ -24,158 +24,160 @@ require "openssl"
|
|
24
24
|
require "uri"
|
25
25
|
|
26
26
|
|
27
|
-
|
27
|
+
module Akamai
|
28
|
+
class Netstorage
|
28
29
|
|
29
|
-
|
30
|
+
attr_accessor :hostname, :keyname, :key
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def initialize(hostname, keyname, key)
|
33
|
+
@hostname = hostname
|
34
|
+
@keyname = keyname
|
35
|
+
@key = key
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
private
|
39
|
+
|
40
|
+
def _response(request, uri, kwargs)
|
41
|
+
if kwargs[:action] == "download"
|
42
|
+
local_destination = kwargs[:destination]
|
43
|
+
if kwargs[:path]
|
44
|
+
ns_filename = kwargs[:path][-1] != '/' ? File.basename(kwargs[:path]) : nil
|
45
|
+
if local_destination == ''
|
46
|
+
local_destination = ns_filename
|
47
|
+
elsif File.directory?(local_destination)
|
48
|
+
local_destination = File.join(local_destination, ns_filename)
|
49
|
+
end
|
48
50
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
response = Net::HTTP.start(uri.hostname, uri.port) { |http|
|
52
|
+
http.request request do |res|
|
53
|
+
open(local_destination, "wb") do |io|
|
54
|
+
res.read_body do |chunk|
|
55
|
+
io.write chunk
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
return response
|
70
|
-
end
|
71
|
-
|
72
|
-
def _request(kwargs={})
|
73
|
-
path = URI::escape(kwargs[:path])
|
74
|
-
acs_action = "version=1&action=#{kwargs[:action]}"
|
75
|
-
acs_auth_data = "5, 0.0.0.0, 0.0.0.0, #{Time.now.to_i}, #{Random.rand(100000)}, #{@keyname}"
|
76
|
-
sign_string = "#{path}\nx-akamai-acs-action:#{acs_action}\n"
|
77
|
-
message = acs_auth_data + sign_string
|
78
|
-
|
79
|
-
hash_ = OpenSSL::HMAC.digest("sha256", @key, message)
|
80
|
-
acs_auth_sign = Base64.encode64(hash_).rstrip
|
81
|
-
|
82
|
-
uri = URI("http://#{@hostname}#{path}")
|
83
|
-
headers = {
|
84
|
-
'X-Akamai-ACS-Action' => acs_action,
|
85
|
-
'X-Akamai-ACS-Auth-Data' => acs_auth_data,
|
86
|
-
'X-Akamai-ACS-Auth-Sign' => acs_auth_sign,
|
87
|
-
'Accept-Encoding' => "identity"
|
88
|
-
}
|
89
|
-
|
90
|
-
if kwargs[:method] == "GET"
|
91
|
-
request = Net::HTTP::Get.new(uri, initheader=headers)
|
92
|
-
elsif kwargs[:method] == "POST"
|
93
|
-
request = Net::HTTP::Post.new(uri, initheader=headers)
|
94
|
-
elsif kwargs[:method] == "PUT" # Use only upload
|
95
|
-
request = Net::HTTP::Put.new(uri, initheader=headers)
|
59
|
+
}
|
60
|
+
elsif kwargs[:action] == "upload"
|
61
|
+
request.body = File.read(kwargs[:source])
|
62
|
+
response = Net::HTTP.start(uri.hostname, uri.port) { |http|
|
63
|
+
http.request(request)
|
64
|
+
}
|
65
|
+
else
|
66
|
+
response = Net::HTTP.start(uri.hostname, uri.port) { |http|
|
67
|
+
http.request(request)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
return response
|
96
71
|
end
|
97
|
-
|
98
|
-
response = _response(request, uri, kwargs)
|
99
72
|
|
100
|
-
|
101
|
-
|
73
|
+
def _request(kwargs={})
|
74
|
+
path = URI::escape(kwargs[:path])
|
75
|
+
acs_action = "version=1&action=#{kwargs[:action]}"
|
76
|
+
acs_auth_data = "5, 0.0.0.0, 0.0.0.0, #{Time.now.to_i}, #{Random.rand(100000)}, #{@keyname}"
|
77
|
+
sign_string = "#{path}\nx-akamai-acs-action:#{acs_action}\n"
|
78
|
+
message = acs_auth_data + sign_string
|
79
|
+
|
80
|
+
hash_ = OpenSSL::HMAC.digest("sha256", @key, message)
|
81
|
+
acs_auth_sign = Base64.encode64(hash_).rstrip
|
82
|
+
|
83
|
+
uri = URI("http://#{@hostname}#{path}")
|
84
|
+
headers = {
|
85
|
+
'X-Akamai-ACS-Action' => acs_action,
|
86
|
+
'X-Akamai-ACS-Auth-Data' => acs_auth_data,
|
87
|
+
'X-Akamai-ACS-Auth-Sign' => acs_auth_sign,
|
88
|
+
'Accept-Encoding' => "identity"
|
89
|
+
}
|
102
90
|
|
103
|
-
|
91
|
+
if kwargs[:method] == "GET"
|
92
|
+
request = Net::HTTP::Get.new(uri, initheader=headers)
|
93
|
+
elsif kwargs[:method] == "POST"
|
94
|
+
request = Net::HTTP::Post.new(uri, initheader=headers)
|
95
|
+
elsif kwargs[:method] == "PUT" # Use only upload
|
96
|
+
request = Net::HTTP::Put.new(uri, initheader=headers)
|
97
|
+
end
|
104
98
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
99
|
+
response = _response(request, uri, kwargs)
|
100
|
+
|
101
|
+
return response.code == "200", response
|
102
|
+
end
|
110
103
|
|
111
|
-
|
112
|
-
return _request(action: "download",
|
113
|
-
method: "GET",
|
114
|
-
path: ns_source,
|
115
|
-
destination: local_destination)
|
116
|
-
end
|
104
|
+
public
|
117
105
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
106
|
+
def dir(ns_path)
|
107
|
+
return _request(action: "dir&format=xml",
|
108
|
+
method: "GET",
|
109
|
+
path: ns_path)
|
110
|
+
end
|
123
111
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
112
|
+
def download(ns_source, local_destination='')
|
113
|
+
return _request(action: "download",
|
114
|
+
method: "GET",
|
115
|
+
path: ns_source,
|
116
|
+
destination: local_destination)
|
117
|
+
end
|
129
118
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
119
|
+
def du(ns_path)
|
120
|
+
return _request(action: "du&format=xml",
|
121
|
+
method: "GET",
|
122
|
+
path: ns_path)
|
123
|
+
end
|
135
124
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
125
|
+
def stat(ns_path)
|
126
|
+
return _request(action: "stat&format=xml",
|
127
|
+
method: "GET",
|
128
|
+
path: ns_path)
|
129
|
+
end
|
141
130
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
131
|
+
def mkdir(ns_path)
|
132
|
+
return _request(action: "mkdir",
|
133
|
+
method: "POST",
|
134
|
+
path: ns_path)
|
135
|
+
end
|
147
136
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
137
|
+
def rmdir(ns_path)
|
138
|
+
return _request(action: "rmdir",
|
139
|
+
method: "POST",
|
140
|
+
path: ns_path)
|
141
|
+
end
|
153
142
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
143
|
+
def mtime(ns_path, mtime)
|
144
|
+
return _request(action: "mtime&format=xml&mtime=#{mtime}",
|
145
|
+
method: "POST",
|
146
|
+
path: ns_path)
|
147
|
+
end
|
159
148
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
149
|
+
def delete(ns_path)
|
150
|
+
return _request(action: "delete",
|
151
|
+
method: "POST",
|
152
|
+
path: ns_path)
|
153
|
+
end
|
165
154
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
155
|
+
def quick_delete(ns_path)
|
156
|
+
return _request(action: "quick-delete&quick-delete=imreallyreallysure",
|
157
|
+
method: "POST",
|
158
|
+
path: ns_path)
|
159
|
+
end
|
171
160
|
|
172
|
-
|
173
|
-
|
174
|
-
|
161
|
+
def rename(ns_target, ns_destination)
|
162
|
+
return _request(action: "rename&destination=#{CGI::escape(ns_destination)}",
|
163
|
+
method: "POST",
|
164
|
+
path: ns_target)
|
165
|
+
end
|
166
|
+
|
167
|
+
def symlink(ns_target, ns_destination)
|
168
|
+
return _request(action: "symlink&target=#{CGI::escape(ns_target)}",
|
169
|
+
method: "POST",
|
170
|
+
path: ns_destination)
|
171
|
+
end
|
172
|
+
|
173
|
+
def upload(local_source, ns_destination)
|
174
|
+
if File.file?(local_source) && ns_destination[-1] == "/"
|
175
|
+
ns_destination = "#{ns_destination}#{File.basename(local_source)}"
|
176
|
+
end
|
177
|
+
return _request(action: "upload",
|
178
|
+
method: "PUT",
|
179
|
+
source: local_source,
|
180
|
+
path: ns_destination)
|
175
181
|
end
|
176
|
-
return _request(action: "upload",
|
177
|
-
method: "PUT",
|
178
|
-
source: local_source,
|
179
|
-
path: ns_destination)
|
180
182
|
end
|
181
183
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netstorageapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Astin Choi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: NetstorageAPI is Akamai Netstorage (File/Object Store) API for Ruby
|
13
|
+
description: NetstorageAPI is Akamai Netstorage (File/Object Store) API for Ruby 2.0+
|
14
14
|
email: achoi@akamai.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -29,7 +29,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: '2.0'
|
33
33
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
35
|
- - ">="
|