Skip to content

Commit 0b8c86a

Browse files
committed
Introduce general abstraction for storage clis
1 parent 12c1b6d commit 0b8c86a

File tree

11 files changed

+626
-196
lines changed

11 files changed

+626
-196
lines changed

lib/cloud_controller/blobstore/cli/azure_blob.rb

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/cloud_controller/blobstore/cli/azure_cli_client.rb

Lines changed: 0 additions & 145 deletions
This file was deleted.

lib/cloud_controller/blobstore/client_provider.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'cloud_controller/blobstore/client'
22
require 'cloud_controller/blobstore/retryable_client'
33
require 'cloud_controller/blobstore/fog/fog_client'
4-
require 'cloud_controller/blobstore/fog/error_handling_client'
4+
require 'cloud_controller/blobstore/error_handling_client'
55
require 'cloud_controller/blobstore/webdav/dav_client'
66
require 'cloud_controller/blobstore/safe_delete_client'
7-
require 'cloud_controller/blobstore/cli/azure_cli_client'
7+
require 'cloud_controller/blobstore/storage_cli/storage_cli_client'
88
require 'google/apis/errors'
99

1010
module CloudController
@@ -13,8 +13,11 @@ class ClientProvider
1313
def self.provide(options:, directory_key:, root_dir: nil, resource_type: nil)
1414
if options[:blobstore_type].blank? || (options[:blobstore_type] == 'fog')
1515
provide_fog(options, directory_key, root_dir)
16-
elsif options[:blobstore_type] == 'cli'
17-
provide_azure_cli(options, directory_key, root_dir)
16+
elsif options[:blobstore_type] == 'storage-cli'
17+
provide_storage_cli(options, directory_key, root_dir)
18+
elsif options[:blobstore_type] == 'storage-cli-fork'
19+
# Just for testing not yet merged features in bosh-azure-cli
20+
provide_storage_cli(options, directory_key, root_dir, fork: true)
1821
else
1922
provide_webdav(options, directory_key, root_dir)
2023
end
@@ -69,18 +72,17 @@ def provide_webdav(options, directory_key, root_dir)
6972
Client.new(SafeDeleteClient.new(retryable_client, root_dir))
7073
end
7174

72-
def provide_azure_cli(options, directory_key, root_dir)
75+
def provide_storage_cli(options, directory_key, root_dir, fork: false)
76+
client = StorageCliClient.build(fog_connection: options.fetch(:fog_connection),
77+
directory_key: directory_key,
78+
root_dir: root_dir,
79+
min_size: options[:minimum_size],
80+
max_size: options[:maximum_size],
81+
fork: fork)
7382

74-
client = AzureCliClient.new(fog_connection: options.fetch(:fog_connection),
75-
directory_key: directory_key,
76-
root_dir: root_dir,
77-
min_size: options[:minimum_size],
78-
max_size: options[:maximum_size],
79-
)
80-
81-
logger = Steno.logger('cc.blobstore.azure_cli')
83+
logger = Steno.logger('cc.blobstore.storage_cli_client')
8284
errors = [StandardError]
83-
retryable_client = RetryableClient.new(client: client, errors: errors, logger: logger)
85+
retryable_client = RetryableClient.new(client:, errors:, logger:)
8486

8587
Client.new(SafeDeleteClient.new(retryable_client, root_dir))
8688
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module CloudController
2+
module Blobstore
3+
class AzureStorageCliClient < StorageCliClient
4+
StorageCliClient.register('AzureRM', CloudController::Blobstore::AzureStorageCliClient)
5+
6+
def cli_path
7+
ENV['AZURE_STORAGE_CLI_PATH'] || '/var/vcap/packages/azure-storage-cli/bin/azure-storage-cli'
8+
end
9+
10+
def build_config(fog_connection)
11+
{
12+
account_name: fog_connection[:azure_storage_account_name],
13+
account_key: fog_connection[:azure_storage_access_key],
14+
container_name: @directory_key,
15+
environment: fog_connection[:environment]
16+
}.compact
17+
end
18+
end
19+
end
20+
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module CloudController
2+
module Blobstore
3+
class StorageCliBlob < Blob
4+
attr_reader :key
5+
6+
def initialize(key, properties: nil, signed_url: nil)
7+
@key = key
8+
@signed_url = signed_url if signed_url
9+
# Set properties to an empty hash if nil to avoid nil errors
10+
@properties = properties || {}
11+
end
12+
13+
def internal_download_url
14+
signed_url
15+
end
16+
17+
def public_download_url
18+
signed_url
19+
end
20+
21+
def attributes(*keys)
22+
@attributes ||= {
23+
etag: @properties.fetch('etag', nil),
24+
last_modified: @properties.fetch('last_modified', nil),
25+
content_length: @properties.fetch('content_length', nil),
26+
created_at: @properties.fetch('created_at', nil)
27+
}
28+
29+
return @attributes if keys.empty?
30+
31+
@attributes.select { |key, _| keys.include? key }
32+
end
33+
34+
private
35+
36+
def signed_url
37+
raise BlobstoreError.new('StorageCliBlob not configured with a signed URL') unless @signed_url
38+
39+
@signed_url
40+
end
41+
end
42+
end
43+
end

0 commit comments

Comments
 (0)