cantemo-portal-agent 1.0.9

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54171a0f3c7ff03ad9ea8411d2f0df91ce7b352a
4
+ data.tar.gz: 7ca1ab0d8df364f79e19c29c31f315245b797217
5
+ SHA512:
6
+ metadata.gz: 953df856aa882c921ec522d1bea9664fb72f8545af8f488c62b10a9f0d47b11a0dab564c6b1b61399243887263c39cf28777599860f1d4449a625e5c2d7d0450
7
+ data.tar.gz: ae7adea3924f9f89d70d00c5a8c07be688eb0a04498557ad078c761d5e68a4b0d82d3f9c97c19fa00bbaaa70c049a83bc1134022976f0e00afb471ec3a2176ce
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ARGV.unshift 'vidispine'
4
+ should_retry = true
5
+
6
+ begin
7
+ require 'envoi/mam/agent/cli'
8
+
9
+ Envoi::Mam::Agent::Cli::CONFIG_FILE_PATHS.clear
10
+ Envoi::Mam::Agent::Cli::CONFIG_FILE_PATHS.concat [
11
+ "./cantemo-portal-agent-config.json",
12
+ "~/cantemo-portal-agent-config.json",
13
+ ]
14
+ require 'envoi/mam/agent/cli/commands/vidispine'
15
+ rescue LoadError => e
16
+ lib_path = __FILE__ == '(irb)' ? File.join(Dir.cwd, 'lib') : File.expand_path('../../lib', __FILE__)
17
+ $:.unshift(lib_path) unless $:.include?(lib_path) or !File.exist?(lib_path)
18
+ if should_retry
19
+ should_retry = false
20
+ retry
21
+ end
22
+ abort(e.message)
23
+ end
24
+
25
+
26
+
@@ -0,0 +1,9 @@
1
+ require 'cantemo/portal/agent/version'
2
+
3
+ module Cantemo
4
+ module Portal
5
+ class Agent
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Cantemo
2
+ module Portal
3
+ class Agent
4
+ VERSION = '1.0.9'.freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,119 @@
1
+ require 'logger'
2
+ require 'open3'
3
+
4
+ require 'envoi/mam/agent/version'
5
+ require 'envoi/mam/agent/config_service_client'
6
+
7
+ module Envoi
8
+ module Mam
9
+ class Agent
10
+
11
+ attr_accessor :logger, :initial_args, :config, :api_client
12
+
13
+ def initialize(args = { })
14
+ @initial_args = args.clone
15
+ @config = args[:config]
16
+ @notifiers = args[:notifiers] || [ ]
17
+
18
+ @dry_run = args.fetch(:dry_run, false)
19
+
20
+ initialize_logger(args)
21
+ initialize_api_client(args) # if self.respond_to?(:initialize_api_client)
22
+ after_initialize
23
+ end
24
+
25
+ def after_initialize
26
+
27
+ end
28
+
29
+ def initialize_logger(args = { })
30
+ @logger = args[:logger] || Logger.new(STDOUT)
31
+ end
32
+
33
+ def dry_run?; @dry_run end
34
+
35
+ def notify(message, args = { })
36
+ return if @notifiers.empty?
37
+ args[:level] ||= :info
38
+ args[:message] ||= message
39
+ @notifiers.each { |notifier| notifier.notify(args) }
40
+ end
41
+
42
+ # @param [Hash] args {}
43
+ # @option args [Object] :api_client
44
+ # Will usually be overridden by child class
45
+ def initialize_api_client(args = { })
46
+ @api_client = args[:api_client] || begin
47
+
48
+ end
49
+ end
50
+
51
+ def shell_execute(command, dry_run = @dry_run)
52
+ if dry_run
53
+ logger.debug { "Skipping Execution of Command: '#{command}' " }
54
+ return
55
+ end
56
+ logger.debug { "Executing Command: '#{command}'" }
57
+
58
+ Open3.popen3(command) do |stdin, stdout, stderr, thread|
59
+ # stdin.sync = true
60
+ # stdout.sync = true
61
+ # stderr.sync = true
62
+
63
+ output = ''
64
+ until thread.stop?
65
+ output << stdout.read #rescue nil
66
+ output << stderr.read # rescue nil
67
+ unless output.empty?
68
+ print output
69
+ output.clear
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def self.load_from_config_file(args)
76
+ config_file_path = args[:config_file_path]
77
+ config_file_path = config_file_path.find { |v| File.exists?(v) } if config_file_path.is_a?(Array)
78
+ abort("Missing Config File. '#{config_file_path}'") unless config_file_path && !config_file_path.empty? && File.exists?(config_file_path)
79
+
80
+ begin
81
+ config = JSON.parse(File.read(config_file_path))
82
+ rescue => e
83
+ abort("Config File Failed to Load. '#{$!}'")
84
+ end
85
+ args[:config] = config
86
+
87
+ self.new(args.merge({ :config => config }))
88
+ end
89
+
90
+ def self.load_from_config_service(args)
91
+ args_out = { }
92
+ args_out[:app_id] = args[:config_service_app_id]
93
+ args_out[:token] = args[:config_service_app_token]
94
+ args_out[:api_url] = args[:config_service_app_url]
95
+ config = Envoi::Mam::Agent::ConfigServiceClient.config_get(args_out)
96
+ args[:config] = config
97
+
98
+ self.new(args.merge({ :config => config }))
99
+ end
100
+
101
+ def self.load_config_and_init(args)
102
+ if args[:config_service_app_id] && args[:config_service_app_token]
103
+ load_from_config_service(args)
104
+ else args[:config_file_path]
105
+ load_from_config_file(args)
106
+ end
107
+ end
108
+
109
+
110
+ def run_operation
111
+ case initial_args[:operation]
112
+ when :upload; upload(initial_args) if self.respond_to?(:upload)
113
+ when :download; download(initial_args) if self.respond_to?(:download)
114
+ end
115
+ end
116
+
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,32 @@
1
+ module Envoi
2
+ module Mam
3
+ class Agent
4
+
5
+ class BaseDaemon
6
+
7
+ attr_accessor :logger, :initial_args
8
+
9
+ def initialize(*args)
10
+ @initial_args = args
11
+ end
12
+
13
+ # Processes a hash and creates instance variables for each key set to it's corresponding value
14
+ # If args is an array then it processes the first hash it comes to in that array (Good for passing *args from a previous method)
15
+ #
16
+ # @param args (Hash|Array|nil) The hash or array to process
17
+ def set_instance_variables(args = nil)
18
+ _args = args
19
+ _args = _args.find { |v| v.is_a? Hash } if _args.is_a? Array
20
+ _args.each { |key, val| instance_variable_set("@#{key}", val) } if _args.is_a? Hash
21
+ end
22
+
23
+ end
24
+
25
+ # Agent
26
+ end
27
+
28
+ # Mam
29
+ end
30
+
31
+ # Envoi
32
+ end
@@ -0,0 +1,37 @@
1
+ require 'optparse'
2
+
3
+ require 'envoi/mam/agent'
4
+
5
+ module Envoi
6
+ module Mam
7
+ class Agent
8
+
9
+ class Cli
10
+
11
+ CONFIG_FILE_PATHS = [
12
+ "./envoi-mam-agent-config.json",
13
+ "~/envoi-mam-agent-config.json",
14
+ ]
15
+ CONFIG_FILE_PATHS.map! { |v| File.expand_path(v) }
16
+
17
+ attr_accessor :logger, :initial_args
18
+
19
+ def initialize(*args)
20
+ @initial_args = args
21
+ end
22
+
23
+ def parse_arguments
24
+
25
+ end
26
+
27
+
28
+ end
29
+
30
+ # Agent
31
+ end
32
+
33
+ # Mam
34
+ end
35
+
36
+ # Envoi
37
+ end
@@ -0,0 +1,89 @@
1
+ #Command Loader
2
+ #
3
+
4
+ # module Envoi
5
+ # module Mam
6
+ # class Agent
7
+ # class CLI
8
+ # class Commands
9
+ #
10
+ #
11
+ # # Commands
12
+ # end
13
+ #
14
+ # # CLI
15
+ # end
16
+ #
17
+ # # Agent
18
+ # end
19
+ #
20
+ # # Mam
21
+ # end
22
+ #
23
+ # # Envoi
24
+ # end
25
+
26
+ def usage
27
+ command_list_str = ''
28
+ Dir.glob(File.join(@commands_dir, "*#{@command_ext}")).each do |fn|
29
+ command_list_str += "\n\t - #{File.basename(fn, @command_ext)}"
30
+ end
31
+
32
+ <<-EOT
33
+ Usage: #{File.basename($0)} COMMAND [ARGS]
34
+
35
+ Available Commands:
36
+ #{command_list_str}
37
+
38
+ All commands can be run with -h (or --help) for more information.
39
+ EOT
40
+ end
41
+
42
+ @commands_dir = File.join(File.dirname(__FILE__), 'commands')
43
+ @command_ext = '.rb'
44
+
45
+ command_aliases = {
46
+ }
47
+
48
+ if ARGV.empty?
49
+ should_show_usage = true
50
+ else
51
+ command_name = ARGV[0].clone
52
+ command_name = command_aliases[command_name] || command_name
53
+ should_show_usage = %w(-h --help).include?(command_name.downcase)
54
+ end
55
+ if should_show_usage
56
+ puts usage
57
+ exit(true)
58
+ end
59
+
60
+ command_file_path = File.join(@commands_dir, command_name)
61
+ abort(usage) unless File.exist?("#{command_file_path}#{@command_ext}")
62
+
63
+ require 'envoi/mam/agent/cli'
64
+
65
+ begin
66
+ require "#{command_file_path}#{@command_ext}"
67
+ rescue LoadError => e
68
+ abort(e.message)
69
+ end
70
+
71
+
72
+ # Execute the command if it is in object form, otherwise it's just a script and executed when we required it
73
+ if Envoi::Mam::Agent::Cli.const_defined?('Commands')
74
+ command_class_name = command_name.to_s.capitalize
75
+ if Envoi::Mam::Agent::Cli::Commands.const_defined?(command_class_name)
76
+ command_object = Envoi::Mam::Agent::Cli::Commands.const_get( command_class_name.capitalize ) rescue nil
77
+ end
78
+ command_object ||= begin
79
+ command_class_name = command_class_name.upcase
80
+ Envoi::Mam::Agent::Cli::Commands.const_defined?(command_class_name) ? Envoi::Mam::Agent::Cli::Commands.const_get( command_class_name ) : false
81
+ end
82
+ if command_object
83
+ command_instance = command_object.new if command_object.respond_to?(:new)
84
+ command_instance.execute if command_instance.respond_to?(:execute)
85
+ end
86
+ end
87
+
88
+
89
+
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+ lib_path = __FILE__ == '(irb)' ? File.join(Dir.cwd, 'lib') : File.expand_path('../../../lib', __FILE__)
3
+ $:.unshift(lib_path) unless $:.include?(lib_path) or !File.exists?(lib_path)
4
+ require 'rubygems'
5
+ require 'optparse'
6
+
7
+ require 'envoi/mam/agent/cli'
8
+ require 'envoi/mam/iconik/agent'
9
+
10
+ current_command = ARGV.shift
11
+ ARGV << '--help' if ARGV.empty?
12
+
13
+ default_config_file_paths = Envoi::Mam::Agent::Cli::CONFIG_FILE_PATHS
14
+
15
+ aspera_ascp_paths = Envoi::Mam::Agent::TransferClient::Aspera::ASCP_PATHS
16
+ default_aspera_ascp_path = aspera_ascp_paths.find { |v| File.exist? v } || aspera_ascp_paths.first
17
+
18
+ # test_args = %w(--download --send-to-envoi --destination-path /tmp)
19
+ # ARGV.concat test_args
20
+ args = {
21
+ :config_file_path => default_config_file_paths,
22
+ :default_ascp_path => default_aspera_ascp_path,
23
+ :dry_run => false,
24
+ :preserve_path => true,
25
+ :destination_path => File.expand_path('.'),
26
+ :should_download_presentation => false,
27
+ :should_add_presentation_assets_to_envoi => false
28
+ }
29
+
30
+ args[:config_service_app_id] = ENV['ENVOI_MAM_AGENT_APP_ID']
31
+ args[:config_service_app_token] = ENV['ENVOI_MAM_AGENT_APP_TOKEN']
32
+ args[:config_service_app_url] = ENV['ENVOI_MAM_AGENT_APP_URL']
33
+
34
+ op = OptionParser.new
35
+ op.on('-c', '--config-file-path FILEPATH', 'The path to the configuration file.') { |v| args[:config_file_path] = v }
36
+ op.on('--agent-app-id ID', '') { |v| args[:config_service_app_id] = v }
37
+ op.on('--agent-token TOKEN', '') { |v| args[:config_service_app_token] = v }
38
+ op.on('--agent-service-api URL', '') { |v| args[:config_service_api_url] = v }
39
+
40
+ op.on('--asset-id ASSETID', 'The Iconik item ID.') { |v| args[:asset_id] = v }
41
+ op.on('-f', '--format-name FORMATNAME', 'The Iconik format name used to find the file to download.') { |v| args[:format_name] = v }
42
+ op.on('--storage-id STORAGEID', 'The Iconik storage id to use for the transfer.') { |v| args[:storage_id] = v}
43
+ #
44
+
45
+ op.on('--file-path PATH', '') { |v| args[:file_path] = v }
46
+ op.on('-d', '--destination-path DIRPATH', 'The destination path to download or upload to.', "default: '#{args[:destination_path]}'") { |v| args[:destination_path] = v }
47
+ op.on('-p','--[no-]preserve-path', "default: #{args[:preserve_path]}") { |v| args[:preserve_path] = v }
48
+
49
+ op.on('-o', '--operation OP', [ :download, :upload ], 'Transfer Direction.', "default: #{args[:operation]}" ) { |v| args[:operation] = v }
50
+ op.on('--transfer-type TYPE', [ :aspera, :s3 ],'Force the type of transfer to use. Ex: aspera || s3') { |v| args[:transfer_type] = v }
51
+
52
+ # op.on('--dry-run', 'Run without executing the transfer.') { |v| args[:dry_run] = v }
53
+ op.on('--help', 'Show this message.') { puts op; exit }
54
+ op.load
55
+ op.parse!
56
+
57
+ args[:file_path] ||= ARGV.shift
58
+ args[:destination_path] ||= ARGV.shift unless ARGV.empty?
59
+
60
+ agent = Envoi::Mam::Iconik::Agent.load_config_and_init(args)
61
+ agent.run_operation
@@ -0,0 +1,296 @@
1
+ #!/usr/bin/env ruby
2
+ # lib_path = __FILE__ == '(irb)' ? File.join(Dir.cwd, 'lib') : File.expand_path('../../../lib', __FILE__)
3
+ # $:.unshift(lib_path) unless $:.include?(lib_path) or !File.exists?(lib_path)
4
+ # require 'rubygems'
5
+ require 'optparse'
6
+ require 'pp'
7
+
8
+ require 'envoi/mam/agent/cli'
9
+ require 'envoi/mam/mediasilo/agent'
10
+
11
+ current_command = ARGV.shift
12
+ ARGV << '--help' if ARGV.empty?
13
+
14
+ default_config_file_paths = Envoi::Mam::Agent::Cli::CONFIG_FILE_PATHS
15
+
16
+ aspera_ascp_paths = Envoi::Mam::Agent::TransferClient::Aspera::ASCP_PATHS
17
+ default_aspera_ascp_path = aspera_ascp_paths.find { |v| File.exist? v } || aspera_ascp_paths.first
18
+
19
+ args = {
20
+ :config_file_path => default_config_file_paths,
21
+ :default_aspera_ascp_path => default_aspera_ascp_path,
22
+ :dry_run => false,
23
+ :operation => :download,
24
+ :preserve_path => true,
25
+ :transfer_type => '',
26
+
27
+ :asset_derivative_type => 'source',
28
+ }
29
+
30
+ args[:config_service_app_id] = ENV['ENVOI_MAM_AGENT_APP_ID']
31
+ args[:config_service_app_token] = ENV['ENVOI_MAM_AGENT_APP_TOKEN']
32
+ args[:config_service_app_url] = ENV['ENVOI_MAM_AGENT_APP_URL']
33
+
34
+ op = OptionParser.new
35
+ op.on('--mediasilo-path PATH', 'The path on MediaSilo to download from or upload to.', "PROJECTNAME/[FOLDERNAME]/.../[ASSETTITLE]") { |v| args[:mediasilo_path] = v }
36
+ op.on('--mediasilo-project-name PROJECTNAME') { |v| args[:mediasilo_project_name] = v }
37
+ op.on('--mediasilo-asset-derivative-type DERIVATIVE', 'The derivative to use when downloading and asset.', "default: #{args[:asset_derivative_type]}") { |v| args[:asset_derivative_type] = v }
38
+ op.on('--mediasilo-asset-id ASSETID', '') { |v| args[:asset_id] = v }
39
+
40
+ op.on('-c', '--config-file-path FILEPATH', 'The path to the configuration file.') { |v| args[:config_file_path] = v }
41
+ op.on('--agent-app-id ID', '') { |v| args[:config_service_app_id] = v }
42
+ op.on('--agent-token TOKEN', '') { |v| args[:config_service_app_token] = v }
43
+ op.on('--agent-service-api URL', '') { |v| args[:config_service_api_url] = v }
44
+
45
+ op.on('--file-path PATH', '') { |v| args[:file_path] = v }
46
+ op.on('-d', '--destination-path DIRPATH', 'The destination path to download or upload to.', "default: '.'") { |v| args[:destination_path] = v }
47
+ op.on('-p','--[no-]preserve-path', "default: true") { |v| args[:preserve_path] = v }
48
+ op.on('-o', '--operation OP', [ :download, :upload ], 'Transfer Direction.', "default: #{args[:operation]}" ) { |v| args[:operation] = v }
49
+ op.on('--transfer-type TYPE', [ :aspera, :s3 ],'Force the type of transfer to use. Ex: aspera || s3') { |v| args[:transfer_type] = v }
50
+ op.on('--transfer-token TOKEN', '') { |v| args[:transfer_token] = v }
51
+ op.on('--dry-run', 'Run without executing the transfer.') { |v| args[:dry_run] = v }
52
+ op.on('--help', 'Show this message.') { puts op; exit }
53
+ op.load
54
+ op.parse!
55
+
56
+ args[:file_path] ||= ARGV.shift
57
+ args[:destination_path] ||= ARGV.shift unless ARGV.empty?
58
+
59
+ # module Envoi
60
+ #
61
+ # module Mam
62
+ #
63
+ # class MediaSilo
64
+ #
65
+ # attr_accessor :logger, :config, :api_client
66
+ #
67
+ # class Agent < Envoi::Mam::Agent
68
+ #
69
+ # DEFAULT_DOWNLOAD_DESTINATION_PATH = '.'
70
+ #
71
+ # class CaseSensitiveHeaderKey < String
72
+ # # def downcase; self end
73
+ # def capitalize; self end
74
+ # end
75
+ #
76
+ # class FileToSend < File
77
+ # def bytesize; size end
78
+ # end
79
+ #
80
+ # def initialize_api_client(args = { })
81
+ # @api_client = args[:api_client] || begin
82
+ # ms_config = config['mediasilo']
83
+ # mediasilo_hostname = ms_config['hostname']
84
+ # mediasilo_username = ms_config['username']
85
+ # mediasilo_password = ms_config['password']
86
+ # mediasilo_api_key = ms_config['api_key']
87
+ #
88
+ # client_args = { }
89
+ # client_args[:hostname] = mediasilo_hostname if mediasilo_hostname
90
+ # client_args[:username] = mediasilo_username if mediasilo_username
91
+ # client_args[:password] = mediasilo_password if mediasilo_password
92
+ # client_args[:api_key] = mediasilo_api_key if mediasilo_api_key
93
+ # Ubiquity::MediaSilo::API::V3::Utilities.new(client_args)
94
+ # end
95
+ #
96
+ # end
97
+ #
98
+ # def download(args = { })
99
+ # transfer_type = args[:transfer_type]
100
+ #
101
+ # file_path = args[:file_path]
102
+ # project_id = args[:project_id]
103
+ # folder_id = args[:folder_id]
104
+ # asset_id = args[:asset_id]
105
+ #
106
+ # mediasilo_path = args[:mediasilo_path]
107
+ # project_name = args[:project_name]
108
+ # folder_name = args[:folder_name]
109
+ #
110
+ # if mediasilo_path || project_name || folder_name
111
+ # check_path_result = api_client.check_path(mediasilo_path)
112
+ # found = check_path_result[:existing]
113
+ #
114
+ # project = found[:project] || { }
115
+ # project_id = project['id']
116
+ #
117
+ # folders = found[:folders]
118
+ # folder_id = (folders.last || { })['id']
119
+ #
120
+ # asset = found[:asset] || { }
121
+ # asset_id = asset['id']
122
+ # end
123
+ #
124
+ # asset ||= asset_id
125
+ #
126
+ # destination_file_path = args[:destination_path] || DEFAULT_DOWNLOAD_DESTINATION_PATH
127
+ #
128
+ # case transfer_type
129
+ # when :aspera; download_using_aspera(asset_id, destination_file_path, args)
130
+ # else
131
+ # do_upload_response = download_using_http(asset, destination_file_path, args)
132
+ # asset_url = do_upload_response[:asset_url]
133
+ # end
134
+ #
135
+ # end
136
+ #
137
+ # def download_using_aspera(asset_id, destination_file_path, args = { })
138
+ # derivative_type = args[:asset_derivative_type]
139
+ # derivative_type = derivative_type.downcase == 'source' ? 'source' : 'proxy'
140
+ # ticket = api.aspera_file_download_ticket_create(:asset_id => asset_id, :target => derivative_type)
141
+ #
142
+ # host = ticket['server']
143
+ # username = ticket['username']
144
+ # password = ticket['password']
145
+ # token = ticket['token']
146
+ #
147
+ # original_file_name = ticket['fileName']
148
+ #
149
+ # file_path = ticket['path']
150
+ # target_path = destination_file_path
151
+ #
152
+ # FileUtils.mkdir_p(target_path) if target_path.end_with?('/') && !File.directory?(target_path)
153
+ # if target_path.end_with?('/') || File.directory?(target_path)
154
+ # target_path = File.join(target_path, original_file_name)
155
+ # end
156
+ #
157
+ # aspera_config = { }
158
+ # aspera_config['host'] = host
159
+ # aspera_config['username'] = username
160
+ # aspera_config['password'] = password
161
+ # aspera_config['token'] = token
162
+ #
163
+ # client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self)
164
+ # client.download(aspera_config, file_path, target_path)
165
+ # end
166
+ #
167
+ # def download_using_http(asset, destination_file_path, args)
168
+ # overwrite = args.fetch(:overwrite, false)
169
+ # derivative_type = args[:asset_derivative_type]
170
+ # api_client.asset_download_derivative(derivative_type, asset, destination_file_path, overwrite)
171
+ # end
172
+ #
173
+ # def upload(args = { })
174
+ # transfer_type = args[:transfer_type]
175
+ #
176
+ # file_path = args[:file_path]
177
+ # project_id = args[:project_id]
178
+ # folder_id = args[:folder_id]
179
+ # asset_id = args[:asset_id]
180
+ #
181
+ # mediasilo_path = args[:mediasilo_path]
182
+ # project_name = args[:project_name]
183
+ # folder_name = args[:folder_name]
184
+ #
185
+ # if mediasilo_path || project_name || folder_name
186
+ # check_path_result = api_client.check_path(mediasilo_path, true)
187
+ # found = check_path_result[:existing]
188
+ #
189
+ # project = found[:project] || { }
190
+ # project_id = project['id']
191
+ #
192
+ # folders = found[:folders]
193
+ # folder_id = (folders.last || { })['id']
194
+ # end
195
+ #
196
+ # # # preserve_path = args.fetch(:preserve_path, vidispine_storage_true)
197
+ # # preserve_path = args.fetch(:preserve_path, true)
198
+ # #
199
+ # # destination_path = args[:destination_path] || DEFAULT_DESTINATION_PATH
200
+ # # relative_path = preserve_path ? File.dirname(file_path) : nil
201
+ # # relative_path = nil if relative_path == '.'
202
+ # #
203
+ # # target_path = relative_path ? File.join(destination_path, relative_path) : destination_path
204
+ # # target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/')
205
+ #
206
+ # # upload file
207
+ # case transfer_type
208
+ # when :aspera; upload_using_aspera(file_path, args)
209
+ # else
210
+ # do_upload_response = upload_using_http(file_path)
211
+ # asset_url = do_upload_response[:asset_url]
212
+ # end
213
+ #
214
+ # asset_create_args = {
215
+ # 'projectId' => project_id,
216
+ # 'folderId' => folder_id,
217
+ # :source_url => asset_url
218
+ # }
219
+ # response = api_client.asset_create(asset_create_args)
220
+ # end
221
+ #
222
+ # def upload_using_aspera(file_path, args = { })
223
+ # raise 'Upload using Aspera not yet Implemented.'
224
+ #
225
+ # file_name = File.basename(file_path)
226
+ #
227
+ # ticket = api.aspera_file_upload_ticket_create(:file_name => file_name)
228
+ #
229
+ # host = ticket['server']
230
+ # username = ticket['username']
231
+ # password = ticket['password']
232
+ # token = ticket['token']
233
+ # destination = ticket['destination']
234
+ #
235
+ # target_path = destination
236
+ #
237
+ # aspera_config = { }
238
+ # aspera_config['host'] = host
239
+ # aspera_config['username'] = username
240
+ # aspera_config['password'] = password
241
+ # aspera_config['token'] = token
242
+ #
243
+ # client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self)
244
+ # client.upload(aspera_config, file_path, target_path)
245
+ # end
246
+ #
247
+ # def upload_using_http(file_path)
248
+ # file_name = File.basename(file_path)
249
+ #
250
+ # res = api_client.asset_upload_ticket_create(:file_name => file_name)
251
+ # uri_str = res['assetUrl']
252
+ #
253
+ # uri = URI.parse(uri_str)
254
+ #
255
+ # amz_date = res['amzDate']
256
+ # amz_acl = res['amzAcl']
257
+ # content_type = res['contentType']
258
+ # authorization = res['authorization']
259
+ #
260
+ # file = File.open(file_path)
261
+ # # file = FileToSend.open(file_path)
262
+ #
263
+ # req = Net::HTTP::Put.new(uri.request_uri)
264
+ # req['x-amz-date'] = amz_date
265
+ # req['x-amz-acl'] = amz_acl
266
+ # req[CaseSensitiveHeaderKey.new('Content-Type')] = content_type
267
+ # res[CaseSensitiveHeaderKey.new('Authorization')] = authorization
268
+ # req[CaseSensitiveHeaderKey.new('Transfer-Encoding')] = 'chunked'
269
+ # req[CaseSensitiveHeaderKey.new('Content-Length')] = file.size
270
+ #
271
+ # req.body_stream = file
272
+ #
273
+ # # req.body = FileToSend.open(file_path)
274
+ #
275
+ # request = req
276
+ # http = Net::HTTP.new(uri.host, uri.port)
277
+ # http.use_ssl = true
278
+ # logger.debug { %(REQUEST: #{request.method} https://#{http.address}:#{http.port}#{request.path} HEADERS: #{request.to_hash.inspect} #{api_client.http_client.log_request_body and request.request_body_permitted? ? "BODY: #{api_client.http_client.format_body_for_log_output(request)}" : ''}) }
279
+ #
280
+ # res = http.request(req)
281
+ # { :asset_url => uri_str }
282
+ # end
283
+ #
284
+ #
285
+ # end
286
+ #
287
+ # end
288
+ #
289
+ # end
290
+ #
291
+ # end
292
+
293
+ agent = Envoi::Mam::MediaSilo::Agent.load_config_and_init(args)
294
+ agent.run_operation
295
+
296
+