acmesmith-google-cloud-storage 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: f75b4b821a87ef27b6f518fd08dd893dfaeb37c6
4
- data.tar.gz: 0df9612218e5379c3818a643355d89e3e4eb2fb4
3
+ metadata.gz: 1d8b3ee45e88b95d60bdd915a101a5117b283f2d
4
+ data.tar.gz: 1895c236bc86563184792b343329ef4b0351720e
5
5
  SHA512:
6
- metadata.gz: 71a2f9904d29d58f0a61ae921b042139600700aeeae721a3b15b022f70ac48c31e6402d5820742c452576b30adb459dc4c7a4c283e34d4d73b83d60070bbd0e8
7
- data.tar.gz: 7968535f05faeafef1df9160dac5a7769ceb835823bc2d428e56421b6830a53655d743068875ced81b03915be400de2dbe7b32ecce5bbe08e2714862c47bcfa0
6
+ metadata.gz: 5a58f61d4b008abbac7308d685d4a9540e4a4e35601b30d3c9a97894872c0f32af0ceb2bd078d58b39c160fdea3db54f3abdd50c63719fa8e0a67d38c9f06b68
7
+ data.tar.gz: 61be0ee2f6b92cf7377c812be2a9ef048eff118e13d577cd9e436496989a7f93e04e256534a01e516dab0c65c8b69c320e0ebcdc3faf361cbae0ce3072744504
@@ -1,3 +1,3 @@
1
1
  module AcmesmithGoogleCloudStorage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -11,7 +11,7 @@ module Acmesmith
11
11
  class GoogleCloudStorage < Base
12
12
  attr_reader :bucket, :prefix, :compute_engine_service_account, :private_key_json_file
13
13
 
14
- def initialize(bucket:, prefix:, compute_engine_service_account:nil, private_key_json_file:nil)
14
+ def initialize(bucket:, prefix:nil, compute_engine_service_account:nil, private_key_json_file:nil)
15
15
  @bucket = bucket
16
16
  @prefix = prefix
17
17
  if @prefix && !@prefix.end_with?('/')
@@ -39,9 +39,8 @@ module Acmesmith
39
39
  end
40
40
 
41
41
  def get_account_key
42
- obj = @api.get_object(bucket, account_key_key)
43
- media = get_media(obj.media_link)
44
- AccountKey.new media
42
+ @api.get_object(bucket, account_key_key)
43
+ AccountKey.new @api.get_object(bucket, account_key_key, download_dest: StringIO.new).string
45
44
  rescue Google::Apis::ClientError => e
46
45
  if e.status_code == 404
47
46
  raise NotExist.new("Account key doesn't exist")
@@ -97,9 +96,13 @@ module Acmesmith
97
96
  def get_certificate(common_name, version: 'current')
98
97
  version = certificate_current(common_name) if version == 'current'
99
98
 
100
- certificate = get_media(@api.get_object(bucket, certificate_key(common_name, version)).media_link)
101
- chain = get_media(@api.get_object(bucket, chain_key(common_name, version)).media_link)
102
- private_key = get_media(@api.get_object(bucket, private_key_key(common_name, version)).media_link)
99
+ get = ->(key) do
100
+ @api.get_object(bucket, key, download_dest: StringIO.new).string
101
+ end
102
+
103
+ certificate = get.call(certificate_key(common_name, version))
104
+ chain = get.call(chain_key(common_name, version))
105
+ private_key = get.call(private_key_key(common_name, version))
103
106
  Certificate.new(certificate, chain, private_key)
104
107
  rescue Google::Apis::ClientError => e
105
108
  if e.status_code == 404
@@ -111,24 +114,34 @@ module Acmesmith
111
114
 
112
115
  def list_certificates
113
116
  certs_prefix = "#{prefix}certs/"
114
- objects = @api.fetch_all do |token, s|
115
- s.list_objects(bucket, prefix: certs_prefix, page_token: token)
117
+ certs_prefix_regexp = /\A#{Regexp.escape(certs_prefix)}/
118
+ list = []
119
+ page_token = nil
120
+ loop do
121
+ objects = @api.list_objects(bucket, prefix: certs_prefix, delimiter: '/', page_token: page_token)
122
+ if objects.prefixes
123
+ list.concat objects.prefixes.map{|_| _.sub(certs_prefix_regexp, '').sub(/\/.+\z/,'').sub(/\/\z/, '')}
124
+ end
125
+ break if objects.next_page_token.nil? || objects.next_page_token == page_token
126
+ page_token = objects.next_page_token
116
127
  end
117
- objects.map{ |obj|
118
- regexp = /\A#{Regexp.escape(certs_prefix)}/
119
- obj.name.sub(regexp, '').sub(/\/.+\z/, '').sub(/\/\z/, '')
120
- }.uniq
128
+ list.uniq
121
129
  end
122
130
 
123
131
  def list_certificate_versions(common_name)
124
132
  cert_ver_prefix = "#{prefix}certs/#{common_name}/"
125
- objects = @api.fetch_all do |token, s|
126
- s.list_objects(bucket, prefix: cert_ver_prefix, page_token: token)
133
+ cert_ver_prefix_regexp = /\A#{Regexp.escape(cert_ver_prefix)}/
134
+ list = []
135
+ page_token = nil
136
+ loop do
137
+ objects = @api.list_objects(bucket, prefix: cert_ver_prefix, delimiter: '/', page_token: page_token)
138
+ if objects.prefixes
139
+ list.concat objects.prefixes.map{|_| _.sub(cert_ver_prefix_regexp, '').sub(/\/.+\z/, '').sub(/\/\z/, '') }
140
+ end
141
+ break if objects.next_page_token.nil? || objects.next_page_token == page_token
142
+ page_token = objects.next_page_token
127
143
  end
128
- objects.map { |obj|
129
- regexp = /\A#{Regexp.escape(cert_ver_prefix)}/
130
- obj.name.sub(regexp, '').sub(/\/.+\z/, '').sub(/\/\z/, '')
131
- }.uniq.reject { |_| _ == 'current' }
144
+ list.uniq.reject{ |_| _ == 'current' }
132
145
  end
133
146
 
134
147
  def get_current_certificate_version(common_name)
@@ -150,8 +163,8 @@ module Acmesmith
150
163
  end
151
164
 
152
165
  def certificate_current(cn)
153
- obj = @api.get_object(bucket, certificate_current_key(cn))
154
- get_media(obj.media_link).chomp
166
+ @api.get_object(bucket, certificate_current_key(cn))
167
+ @api.get_object(bucket, certificate_current_key(cn), download_dest: StringIO.new).string.chomp
155
168
  rescue Google::Apis::ClientError => e
156
169
  if e.status_code == 404
157
170
  raise NotExist.new("Certificate for #{cn.inspect} of current version doesn't exist")
@@ -176,10 +189,6 @@ module Acmesmith
176
189
  "#{certificate_base_key(cn, ver)}/fullchain.pem"
177
190
  end
178
191
 
179
- def get_media(media_link)
180
- open(media_link, {'Authorization' => "Bearer #{@api.authorization.access_token}"}).read
181
- end
182
-
183
192
  def load_json_key(filepath)
184
193
  obj = JSON.parse(File.read(filepath))
185
194
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acmesmith-google-cloud-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YAMADA Tsuyoshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-26 00:00:00.000000000 Z
11
+ date: 2016-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acmesmith