Skip to content

Commit 4435052

Browse files
committed
Drop deprecated p12 key support
1 parent cc5ebfa commit 4435052

File tree

7 files changed

+32
-114
lines changed

7 files changed

+32
-114
lines changed

README.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ OAuth flow for installed applications.
3030
| name | type | required? | default | description |
3131
|:-------------------------------------|:------------|:-----------|:-------------------------|:-----------------------|
3232
| mode | string | optional | "append" | See [Mode](#mode) |
33-
| auth_method | string | optional | "private_key" | `private_key` , `json_key` or `compute_engine`
34-
| service_account_email | string | required when auth_method is private_key | | Your Google service account email
35-
| p12_keyfile | string | required when auth_method is private_key | | Fullpath of private key in P12(PKCS12) format |
33+
| auth_method | string | optional | "json\_key" | `json_key`, `compute_engine`, or `application_default`
3634
| json_keyfile | string | required when auth_method is json_key | | Fullpath of json key |
3735
| project | string | required if json_keyfile is not given | | project_id |
3836
| dataset | string | required | | dataset |
@@ -108,9 +106,8 @@ Following options are same as [bq command-line tools](https://cloud.google.com/b
108106
out:
109107
type: bigquery
110108
mode: append
111-
auth_method: private_key # default
112-
service_account_email: ABCXYZ123ABCXYZ123.gserviceaccount.com
113-
p12_keyfile: /path/to/p12_keyfile.p12
109+
auth_method: json_key # default
110+
json_keyfile: /path/to/json_keyfile.json
114111
project: your-project-000
115112
dataset: your_dataset_name
116113
table: your_table_name
@@ -167,22 +164,9 @@ NOTE: BigQuery does not support replacing (actually, copying into) a non-partiti
167164

168165
There are three methods supported to fetch access token for the service account.
169166

170-
1. Public-Private key pair of GCP(Google Cloud Platform)'s service account
171-
2. JSON key of GCP(Google Cloud Platform)'s service account
172-
3. Pre-defined access token (Google Compute Engine only)
173-
174-
#### Public-Private key pair of GCP's service account
175-
176-
You first need to create a service account (client ID),
177-
download its private key and deploy the key with embulk.
178-
179-
```yaml
180-
out:
181-
type: bigquery
182-
auth_method: private_key # default
183-
service_account_email: ABCXYZ123ABCXYZ123.gserviceaccount.com
184-
p12_keyfile: /path/to/p12_keyfile.p12
185-
```
167+
1. JSON key of GCP(Google Cloud Platform)'s service account
168+
1. Pre-defined access token (Google Compute Engine only)
169+
1. [Application Default](https://cloud.google.com/docs/authentication/production)
186170

187171
#### JSON key of GCP's service account
188172

@@ -211,7 +195,7 @@ out:
211195
}
212196
```
213197

214-
#### Pre-defined access token(GCE only)
198+
#### Pre-defined access token (GCE only)
215199

216200
On the other hand, you don't need to explicitly create a service account for embulk when you
217201
run embulk in Google Compute Engine. In this third authentication method, you need to
@@ -224,6 +208,16 @@ out:
224208
auth_method: compute_engine
225209
```
226210

211+
#### Application Default
212+
213+
See https://cloud.google.com/docs/authentication/production
214+
215+
```yaml
216+
out:
217+
type: bigquery
218+
auth_method: application_default
219+
```
220+
227221
### Table id formatting
228222

229223
`table` and option accept [Time#strftime](http://ruby-doc.org/core-1.9.3/Time.html#method-i-strftime)

lib/embulk/output/bigquery.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def self.load(v)
3333
def self.configure(config, schema, task_count)
3434
task = {
3535
'mode' => config.param('mode', :string, :default => 'append'),
36-
'auth_method' => config.param('auth_method', :string, :default => 'private_key'),
37-
'service_account_email' => config.param('service_account_email', :string, :default => nil),
38-
'p12_keyfile' => config.param('p12_keyfile', :string, :default => nil),
36+
'auth_method' => config.param('auth_method', :string, :default => 'json_key'),
3937
'json_keyfile' => config.param('json_keyfile', LocalFile, :default => nil),
4038
'project' => config.param('project', :string, :default => nil),
4139
'dataset' => config.param('dataset', :string),
@@ -125,11 +123,8 @@ def self.configure(config, schema, task_count)
125123
end
126124

127125
task['auth_method'] = task['auth_method'].downcase
128-
unless %w[private_key json_key compute_engine application_default].include?(task['auth_method'])
129-
raise ConfigError.new "`auth_method` must be one of private_key, json_key, compute_engine, application_default"
130-
end
131-
if task['auth_method'] == 'private_key' and task['p12_keyfile'].nil?
132-
raise ConfigError.new "`p12_keyfile` is required for auth_method private_key"
126+
unless %w[json_key compute_engine application_default].include?(task['auth_method'])
127+
raise ConfigError.new "`auth_method` must be one of json_key, compute_engine, application_default"
133128
end
134129
if task['auth_method'] == 'json_key' and task['json_keyfile'].nil?
135130
raise ConfigError.new "`json_keyfile` is required for auth_method json_key"

lib/embulk/output/bigquery/google_client.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,8 @@ def client
3838
Embulk.logger.debug { "embulk-output-bigquery: request_options: #{client.request_options.to_h}" }
3939

4040
case @task['auth_method']
41-
when 'private_key'
42-
private_key_passphrase = 'notasecret'
43-
key = Google::APIClient::KeyUtils.load_from_pkcs12(@task['p12_keyfile'], private_key_passphrase)
44-
auth = Signet::OAuth2::Client.new(
45-
token_credential_uri: "https://accounts.google.com/o/oauth2/token",
46-
audience: "https://accounts.google.com/o/oauth2/token",
47-
scope: @scope,
48-
issuer: @task['service_account_email'],
49-
signing_key: key)
50-
5141
when 'compute_engine'
5242
auth = Google::Auth::GCECredentials.new
53-
5443
when 'json_key'
5544
json_key = @task['json_keyfile']
5645
if File.exist?(json_key)
@@ -61,10 +50,8 @@ def client
6150
key = StringIO.new(json_key)
6251
auth = Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: key, scope: @scope)
6352
end
64-
6553
when 'application_default'
6654
auth = Google::Auth.get_application_default([@scope])
67-
6855
else
6956
raise ConfigError, "Unknown auth method: #{@task['auth_method']}"
7057
end

test/test_bigquery_client.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ def record
6161
def test_json_keyfile
6262
assert_nothing_raised { BigqueryClient.new(least_task, schema).client }
6363
end
64-
65-
def test_p12_keyfile
66-
# pending
67-
end
6864
end
6965

7066
sub_test_case "create_dataset" do

test/test_configure.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def shutdown
1818

1919
def least_config
2020
DataSource.new({
21-
'project' => 'your_project_name',
22-
'dataset' => 'your_dataset_name',
23-
'table' => 'your_table_name',
24-
'p12_keyfile' => __FILE__, # fake
21+
'project' => 'your_project_name',
22+
'dataset' => 'your_dataset_name',
23+
'table' => 'your_table_name',
24+
'json_keyfile' => File.join(EXAMPLE_ROOT, 'json_key.json'), # dummy
2525
})
2626
end
2727

@@ -43,10 +43,8 @@ def processor_count
4343
def test_configure_default
4444
task = Bigquery.configure(least_config, schema, processor_count)
4545
assert_equal "append", task['mode']
46-
assert_equal "private_key", task['auth_method']
47-
assert_equal nil, task['service_account_email']
48-
assert_equal __FILE__, task['p12_keyfile']
49-
assert_equal nil, task['json_keyfile']
46+
assert_equal "json_key", task['auth_method']
47+
assert_equal File.read(File.join(EXAMPLE_ROOT, 'json_key.json')), task['json_keyfile']
5048
assert_equal "your_project_name", task['project']
5149
assert_equal "your_dataset_name", task['dataset']
5250
assert_equal nil, task['location']
@@ -132,11 +130,6 @@ def test_auth_method
132130
config = least_config.merge('auth_method' => 'foobar')
133131
assert_raise { Bigquery.configure(config, schema, processor_count) }
134132

135-
config = least_config.merge('auth_method' => 'private_key').tap {|h| h.delete('p12_keyfile') }
136-
assert_raise { Bigquery.configure(config, schema, processor_count) }
137-
config = least_config.merge('auth_method' => 'private_key', 'p12_keyfile' => 'dummy')
138-
assert_nothing_raised { Bigquery.configure(config, schema, processor_count) }
139-
140133
config = least_config.merge('auth_method' => 'json_key').tap {|h| h.delete('json_keyfile') }
141134
assert_raise { Bigquery.configure(config, schema, processor_count) }
142135
config = least_config.merge('auth_method' => 'json_key', 'json_keyfile' => "#{EXAMPLE_ROOT}/json_key.json")

test/test_example.rb

Lines changed: 0 additions & 47 deletions
This file was deleted.

test/test_transaction.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ class Output::Bigquery
88
class TestTransaction < Test::Unit::TestCase
99
def least_config
1010
DataSource.new({
11-
'project' => 'your_project_name',
12-
'dataset' => 'your_dataset_name',
13-
'table' => 'your_table_name',
14-
'p12_keyfile' => __FILE__, # fake
15-
'temp_table' => 'temp_table', # randomly created is not good for our test
16-
'path_prefix' => 'tmp/', # randomly created is not good for our test
11+
'project' => 'your_project_name',
12+
'dataset' => 'your_dataset_name',
13+
'table' => 'your_table_name',
14+
'temp_table' => 'temp_table', # randomly created is not good for our test
15+
'path_prefix' => 'tmp/', # randomly created is not good for our test
16+
'json_keyfile' => File.join(EXAMPLE_ROOT, 'json_key.json'), # dummy
1717
})
1818
end
1919

0 commit comments

Comments
 (0)