I cannot figure out what the issue is here. I have a Rails / ActiveAdmin app that I setup a task for. The task is this wrapped in a rails task.
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}"
the above code will upload a simple test file just fine when ran with ruby upload.rb
however, when I wrap this into a rake task and run rake google_test
it returns the following errors
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)
the line that it refers too is new_file = drive.create_file(new_file, upload_source: file_contents, content_type: 'text/csv')
Anyone know why this works fine when run as a side script but once added to the project as a rake task it fails saying that the server doesn't accept the SSL version? I have even tried specifying TLSv1_2
and it will still error out with returned=5
Current openssl version installed is 1.0.1j with Ruby 2.3.1 and Rails 5.0.0.1, on Windows platform