Class: Embulk::Input::GoogleSpreadsheets::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/embulk/input/google_spreadsheets/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ Auth

Returns a new instance of Auth.



11
12
13
14
# File 'lib/embulk/input/google_spreadsheets/auth.rb', line 11

def initialize(task)
  @auth_method = task['auth_method']
  @json_key = task['json_keyfile']
end

Instance Attribute Details

#auth_methodObject (readonly)

Returns the value of attribute auth_method.



9
10
11
# File 'lib/embulk/input/google_spreadsheets/auth.rb', line 9

def auth_method
  @auth_method
end

Instance Method Details

#authenticateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/embulk/input/google_spreadsheets/auth.rb', line 16

def authenticate
  case auth_method
  when 'authorized_user'
    key = StringIO.new(credentials.to_json)
    return Google::Auth::UserRefreshCredentials.make_creds(json_key_io: key, scope: scope)
  when 'compute_engine'
    return Google::Auth::GCECredentials.new
  when 'service_account'
    key = StringIO.new(credentials.to_json)
    return Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: key, scope: scope)
  when 'application_default'
    return Google::Auth.get_application_default([scope])
  else
    raise ConfigError.new("Unknown auth method: #{auth_method}")
  end
end

#scopeObject



33
34
35
# File 'lib/embulk/input/google_spreadsheets/auth.rb', line 33

def scope
  Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY
end