Не мога да разбера какъв е проблемът тук. Имам приложение Rails / ActiveAdmin, за което настройвам задача. Задачата е обвита в задача за релси.
upload.rb
require 'google/apis/drive_v3'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'certified'
require 'fileutils'
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
APPLICATION_NAME = 'Google Sync'
CLIENT_SECRETS_PATH = 'client_secret.json'
CREDENTIALS_PATH = File.join(Dir.home, '.credentials', "app-sync.yaml")
SCOPE = Google::Apis::DriveV3::AUTH_DRIVE_FILE
##
## Ensure valid credentials, either by restoring from the saved credentials
## files or intitiating an OAuth2 authorization. If authorization is required,
## the user's default browser will be launched to approve the request.
##
## @return [Google::Auth::UserRefreshCredentials] OAuth2 credentials
def authorize
FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))
client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)
authorizer = Google::Auth::UserAuthorizer.new(
client_id, SCOPE, token_store)
user_id = 'default'
credentials = authorizer.get_credentials(user_id)
if credentials.nil?
url = authorizer.get_authorization_url(
base_url: OOB_URI)
puts "Open the following URL in the browser and enter the " +
"resulting code after authorization"
puts url
code = gets
credentials = authorizer.get_and_store_credentials_from_code(
user_id: user_id, code: code, base_url: OOB_URI)
end
credentials
end
# Initialize the API
Drive = Google::Apis::DriveV3 # Alias the module
drive = Drive::DriveService.new
drive.client_options.application_name = APPLICATION_NAME
drive.authorization = authorize
# Upload a file
# Instead of passing a name for a file on the file system, create a pseudo file from a string
file_contents = StringIO.new(<<FILE_CONTENTS)
Field1,Field2,Field3
Some,Useless,Data
More,Useless,Info
FILE_CONTENTS
parent_folder_id = 'abcde...'
new_file = Drive::File.new(name: 'Test Upload CSV', parents: [parent_folder_id])
new_file = drive.create_file(new_file, upload_source: file_contents, content_type: 'text/csv')
puts "File '#{new_file.name}' created with id '#{new_file.id}'. Folder Location: https://drive.google.com/drive/folders/#{parent_folder_id}"
горният код ще качи прост тестов файл съвсем добре, когато се изпълнява с ruby upload.rb
обаче, когато обвия това в рейк задача и стартирам rake google_test
, тя връща следните грешки
rake aborted!
Google::Apis::ServerError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A
C:/Users/Brian/Path/To/App/lib/tasks/member_status_tasks.rake:122:in `block (2 levels) in <top (required)>'
Faraday::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A
C:/Users/Path/To/App/lib/tasks/member_status_tasks.rake:122:in `block (2 levels) in <top (required)>'
OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A
C:/Users/Path/To/App/lib/tasks/member_status_tasks.rake:122:in `block (2 levels) in <top (required)>'
Tasks: TOP => reps_exports:member_status
(See full trace by running task with --trace)
редът, който също препраща, е new_file = drive.create_file(new_file, upload_source: file_contents, content_type: 'text/csv')
Някой знае ли защо това работи добре, когато се изпълнява като страничен скрипт, но веднъж добавен към проекта като рейк задача, той се проваля, казвайки, че сървърът не приема SSL версията? Дори се опитах да посоча TLSv1_2
и пак ще излезе грешка с returned=5
Текущата инсталирана версия на openssl е 1.0.1j с Ruby 2.3.1 и Rails 5.0.0.1, на платформа Windows