Skip to content

Commit 1c6215f

Browse files
committed
Throw ConfigException if both project and project_id in json_keyfile are null
1 parent 2cd7af0 commit 1c6215f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/org/embulk/output/bigquery_java/BigqueryClient.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.stream.Collectors;
4545
import java.util.stream.Stream;
4646
import java.util.stream.StreamSupport;
47+
import org.embulk.config.ConfigException;
4748
import org.embulk.output.bigquery_java.config.BigqueryColumnOption;
4849
import org.embulk.output.bigquery_java.config.BigqueryTimePartitioning;
4950
import org.embulk.output.bigquery_java.config.PluginTask;
@@ -83,7 +84,7 @@ public class BigqueryClient {
8384
public BigqueryClient(PluginTask task, Schema schema) {
8485
this.task = task;
8586
this.schema = schema;
86-
project = task.getProject().orElse(getProjectIdFromJsonKeyfile());
87+
project = task.getProject().orElseGet(this::getProjectIdFromJsonKeyfile);
8788
destinationProject = task.getDestinationProject().orElse(project);
8889
destinationDataset = task.getDataset();
8990
if (task.getLocation().isPresent()) {
@@ -102,9 +103,14 @@ public BigqueryClient(PluginTask task, Schema schema) {
102103
}
103104

104105
private String getProjectIdFromJsonKeyfile() {
105-
return new JSONObject(
106-
new JSONTokener(new ByteArrayInputStream(task.getJsonKeyfile().getContent())))
107-
.getString("project_id");
106+
String projectId =
107+
new JSONObject(
108+
new JSONTokener(new ByteArrayInputStream(task.getJsonKeyfile().getContent())))
109+
.getString("project_id");
110+
if (projectId == null) {
111+
throw new ConfigException("Either project or project_id in json_keyfile is required");
112+
}
113+
return projectId;
108114
}
109115

110116
private BigQuery getBigQueryService() throws IOException {

0 commit comments

Comments
 (0)