Class: Embulk::Input::GoogleSpreadsheets::Auth
- Inherits:
-
Object
- Object
- Embulk::Input::GoogleSpreadsheets::Auth
- Defined in:
- lib/embulk/input/google_spreadsheets/auth.rb
Instance Attribute Summary collapse
-
#auth_method ⇒ Object
readonly
Returns the value of attribute auth_method.
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(task) ⇒ Auth
constructor
A new instance of Auth.
- #scope ⇒ Object
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_method ⇒ Object (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
#authenticate ⇒ Object
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 |
#scope ⇒ Object
33 34 35 |
# File 'lib/embulk/input/google_spreadsheets/auth.rb', line 33 def scope Google::Apis::SheetsV4::AUTH_SPREADSHEETS_READONLY end |