Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Add support for connection strings #26

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN echo "<source>\n\
@type azure-storage-append-blob\n\
azure_storage_account \"#{ENV['STORAGE_ACCOUNT']}\"\n\
azure_storage_access_key \"#{ENV['STORAGE_ACCESS_KEY']}\"\n\
azure_storage_connection_string \"#{ENV['STORAGE_CONNECTION_STRING']}\"\n\
azure_storage_sas_token \"#{ENV['STORAGE_SAS_TOKEN']}\"\n\
azure_container fluentd\n\
auto_create_container true\n\
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ And then execute:

azure_storage_account <your azure storage account>
azure_storage_access_key <your azure storage access key> # leave empty to use MSI
azure_storage_connection_string <your azure storage connection string> # leave empty to use MSI
azure_storage_sas_token <your azure storage sas token> # leave empty to use MSI
azure_imds_api_version <Azure Instance Metadata Service API Version> # only used for MSI
azure_token_refresh_interval <refresh interval in min> # only used for MSI
Expand All @@ -50,12 +51,12 @@ And then execute:

Your Azure Storage Account Name. This can be retrieved from Azure Management portal.

### `azure_storage_access_key` or `azure_storage_sas_token` (Either required or both empty to use MSI)
### `azure_storage_access_key` or `azure_storage_sas_token` or `azure_storage_connection_string` (Any required or all empty to use MSI)

Your Azure Storage Access Key (Primary or Secondary) or shared access signature (SAS) token.
Your Azure Storage Access Key (Primary or Secondary) or shared access signature (SAS) token or full connection string.
This also can be retrieved from Azure Management portal.

If both are empty, the plugin will use the local Managed Identity endpoint to obtain a token for the target storage account.
If all are empty, the plugin will use the local Managed Identity endpoint to obtain a token for the target storage account.

### `azure_imds_api_version` (Optional, only for MSI)

Expand Down
26 changes: 12 additions & 14 deletions lib/fluent/plugin/out_azure-storage-append-blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AzureStorageAppendBlobOut < Fluent::Plugin::Output
config_param :azure_storage_account, :string, default: nil
config_param :azure_storage_access_key, :string, default: nil, secret: true
config_param :azure_storage_sas_token, :string, default: nil, secret: true
config_param :azure_storage_connection_string, :string, default: nil, secret: true
config_param :azure_container, :string, default: nil
config_param :azure_imds_api_version, :string, default: '2019-08-15'
config_param :azure_token_refresh_interval, :integer, default: 60
Expand Down Expand Up @@ -63,7 +64,9 @@ def configure(conf)

raise ConfigError, 'azure_container needs to be specified' if @azure_container.nil?

if (@azure_storage_access_key.nil? || @azure_storage_access_key.empty?) && (@azure_storage_sas_token.nil? || @azure_storage_sas_token.empty?)
if (@azure_storage_access_key.nil? || @azure_storage_access_key.empty?) &&
(@azure_storage_sas_token.nil? || @azure_storage_sas_token.empty?) &&
(@azure_storage_connection_string.nil? || @azure_storage_connection_string.empty?)
log.info 'Using MSI since neither azure_storage_access_key nor azure_storage_sas_token was provided.'
@use_msi = true
end
Expand Down Expand Up @@ -102,6 +105,8 @@ def start
end
sleep 0.1 while renew_token.status != 'sleep'
renew_token.run
elsif !@azure_storage_connection_string.nil? && !@azure_storage_connection_string.empty?
@bs = Azure::Storage::Blob::BlobService.create_from_connection_string(@azure_storage_connection_string)
else
@bs_params = { storage_account_name: @azure_storage_account }

Expand All @@ -112,6 +117,7 @@ def start
end

@bs = Azure::Storage::Blob::BlobService.create(@bs_params)

end

ensure_container
Expand Down Expand Up @@ -142,25 +148,21 @@ def write(chunk)
append_blob(content, metadata)
@last_azure_storage_path = @azure_storage_path
ensure
begin
tmp.close(true)
rescue StandardError
nil
end
tmp.close(true) rescue nil
end
end

def container_exists?(container)
begin
@bs.get_container_properties(container)
rescue Azure::Core::Http::HTTPError => ex
if ex.status_code == 404 # container does not exist
rescue Azure::Core::Http::HTTPError => e
if e.status_code == 404 # container does not exist
return false
else
raise
end
end
return true
true
end

private
Expand All @@ -175,14 +177,12 @@ def ensure_container
end
end

private

def generate_log_name(metadata, index)
time_slice = if metadata.timekey.nil?
''.freeze
else
Time.at(metadata.timekey).utc.strftime(@time_slice_format)
end
end

path = @path_slicer.call(@path)
values_for_object_key = {
Expand All @@ -194,8 +194,6 @@ def generate_log_name(metadata, index)
@azure_storage_path = extract_placeholders(storage_path, metadata)
end

private

def append_blob(content, metadata)
position = 0
log.debug "azure_storage_append_blob: append_blob.start: Content size: #{content.length}"
Expand Down