Class: Embulk::Output::Bigquery::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/embulk/output/bigquery/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, scope) ⇒ Auth

Returns a new instance of Auth.



10
11
12
13
14
# File 'lib/embulk/output/bigquery/auth.rb', line 10

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

Instance Attribute Details

#auth_methodObject (readonly)

Returns the value of attribute auth_method.



8
9
10
# File 'lib/embulk/output/bigquery/auth.rb', line 8

def auth_method
  @auth_method
end

#json_keyObject (readonly)

Returns the value of attribute json_key.



8
9
10
# File 'lib/embulk/output/bigquery/auth.rb', line 8

def json_key
  @json_key
end

#scopeObject (readonly)

Returns the value of attribute scope.



8
9
10
# File 'lib/embulk/output/bigquery/auth.rb', line 8

def scope
  @scope
end

Instance Method Details

#authenticateObject



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

def authenticate
  case auth_method
  when 'authorized_user'
    key = StringIO.new(json_key)
    return Google::Auth::UserRefreshCredentials.make_creds(json_key_io: key, scope: scope)
  when 'compute_engine'
    return Google::Auth::GCECredentials.new
  when 'service_account', 'json_key' # json_key is for backward compatibility
    key = StringIO.new(json_key)
    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