Skip to content

Commit 0a6f297

Browse files
committed
Simplify credentials schema for BigQuery plugin
1 parent 97e8cae commit 0a6f297

2 files changed

Lines changed: 12 additions & 54 deletions

File tree

splitgraph/ingestion/bigquery/__init__.py

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,9 @@ class BigQueryDataSource(ForeignDataWrapperDataSource):
1515
"type": "object",
1616
"properties": {
1717
"credentials": {
18-
"type": "object",
19-
"title": "Google credentials",
20-
"oneOf": [
21-
{
22-
"type": "object",
23-
"required": ["secret_type", "path"],
24-
"properties": {
25-
"secret_type": {
26-
"type": "string",
27-
"const": "file",
28-
"title": "Secret type",
29-
},
30-
"path": {
31-
"type": "string",
32-
"title": "Location of the GCP credentials",
33-
"description": "The json credentials file path",
34-
},
35-
},
36-
},
37-
{
38-
"type": "object",
39-
"required": ["secret_type", "credentials_str"],
40-
"properties": {
41-
"secret_type": {
42-
"type": "string",
43-
"const": "raw",
44-
"title": "Secret type",
45-
},
46-
"credentials_str": {
47-
"type": "string",
48-
"title": "GCP credentials",
49-
"description": "GCP credentials in string format",
50-
},
51-
},
52-
},
53-
],
54-
"description": "The credentials need not be supplied when running inside a GCP VM",
18+
"type": "string",
19+
"title": "GCP credentials",
20+
"description": "GCP credentials in JSON format",
5521
},
5622
},
5723
}
@@ -85,10 +51,7 @@ class BigQueryDataSource(ForeignDataWrapperDataSource):
8551
```
8652
$ sgr mount bigquery bq -o@- <<EOF
8753
{
88-
"credentials": {
89-
"secret_type": "file",
90-
"path": "/path/to/my/creds.json"
91-
},
54+
"credentials": "/path/to/my/creds.json",
9255
"project": "my-project-name",
9356
"dataset_name": "my_dataset"
9457
}
@@ -116,23 +79,23 @@ def get_fdw_name(self):
11679

11780
@classmethod
11881
def get_name(cls) -> str:
119-
return "Google Big Query"
82+
return "Google BigQuery"
12083

12184
@classmethod
12285
def get_description(cls) -> str:
123-
return "Query data in GCP Big Query datasets"
86+
return "Query data in GCP BigQuery datasets"
12487

12588
@classmethod
12689
def from_commandline(cls, engine, commandline_kwargs) -> "BigQueryDataSource":
12790
params = deepcopy(commandline_kwargs)
12891
credentials = Credentials({})
12992

130-
if "credentials" in params and params["credentials"]["secret_type"] == "file":
131-
with open(params["credentials"].pop("path"), "r") as credentials_file:
93+
if "credentials" in params:
94+
with open(params["credentials"], "r") as credentials_file:
13295
credentials_str = credentials_file.read()
13396

13497
params.pop("credentials")
135-
credentials["credentials"] = {"secret_type": "raw", "credentials_str": credentials_str}
98+
credentials["credentials"] = credentials_str
13699

137100
return cls(engine, credentials, params)
138101

@@ -165,7 +128,7 @@ def _build_db_url(self) -> str:
165128

166129
if "credentials" in self.credentials:
167130
# base64 encode the credentials
168-
credentials_str = self.credentials["credentials"]["credentials_str"]
131+
credentials_str = self.credentials["credentials"]
169132
credentials_base64 = base64.urlsafe_b64encode(credentials_str.encode()).decode()
170133
db_url += f"?credentials_base64={credentials_base64}"
171134

test/splitgraph/ingestion/test_bigquery.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ def test_bigquery_data_source_options_creds_file(local_engine_empty):
1313
source = BigQueryDataSource.from_commandline(
1414
local_engine_empty,
1515
{
16-
"credentials": {
17-
"secret_type": "file",
18-
"path": "test/resources/ingestion/bigquery/dummy_credentials.json",
19-
},
16+
"credentials": "test/resources/ingestion/bigquery/dummy_credentials.json",
2017
"project": "bigquery-public-data",
2118
"dataset_name": "hacker_news",
2219
},
@@ -35,9 +32,7 @@ def test_bigquery_data_source_options_creds_file(local_engine_empty):
3532
def test_bigquery_data_source_options_creds_raw():
3633
source = BigQueryDataSource(
3734
Mock(),
38-
credentials=Credentials(
39-
{"credentials": {"secret_type": "raw", "credentials_str": "test-raw-creds"}}
40-
),
35+
credentials=Credentials({"credentials": "test-raw-creds"}),
4136
params=Params(
4237
{
4338
"project": "bigquery-public-data",

0 commit comments

Comments
 (0)