0

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

Bot
  • 11,868
  • 11
  • 75
  • 131
  • when i saw this error the last time, my ssl setup was broken. i used https://github.com/mislav/ssl-tools to track down whats wrong. – Sascha Kaestle Nov 28 '16 at 12:17
  • according to https://github.com/mislav/ssl-tools/issues/3 the tool won't help me. – Bot Nov 29 '16 at 00:03
  • I had a similar error when I needed to upgrade openssl versions on ruby 2.3.0 and Ubuntu 14.04 – BigRon Dec 01 '16 at 18:51
  • @BigRon what version of openssl were you on and which did you upgrade too? It would seem like it is something with the project maybe as it opens fine before i add it to the rails app and just run the script on its own. – Bot Dec 01 '16 at 19:01
  • Ubuntu's package manager's latest version is 1.0.1f, but it's backported to new versions of openssl. I'm not sure how this is handled on a windows system. I believe if you are just compiling openssl yourself, you should have openssl 1.1.0c, which [covers the latest security bug](https://www.openssl.org/news/vulnerabilities.html#y2016) – BigRon Dec 01 '16 at 19:13
  • and if you are sticking with 1.0.1 you should get up to 1.0.1u – BigRon Dec 01 '16 at 19:19
  • Did you have any luck with this? – BigRon Dec 05 '16 at 15:33
  • @BigRon I have not. – Bot Dec 05 '16 at 17:08

1 Answers1

-1

This might have to do with the version of Ruby you're using.

See this for more information: https://stackoverflow.com/a/33311685/777425

Community
  • 1
  • 1
samdunne
  • 306
  • 1
  • 2
  • 14