Skip to content

Commit f37f36f

Browse files
authored
Merge pull request #80 from data-integrations/PLUGIN-692
[PLUGIN-692] Add Service Account auth to http
2 parents 09aee0b + 3882f35 commit f37f36f

17 files changed

Lines changed: 657 additions & 119 deletions

docs/HTTP-batchsource.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,30 @@ can be omitted as long as the field is present in schema.
203203

204204
**CSV Skip First Row:** Whether to skip the first row of the HTTP response. This is usually set if the first row is a header row.
205205

206-
### Basic Authentication
207-
208-
**Username:** Username for basic authentication.
209-
210-
**Password:** Password for basic authentication.
206+
### Authentication
207+
* **OAuth2**
208+
* **Auth URL:** Endpoint for the authorization server used to retrieve the authorization code.
209+
* **Token URL:** Endpoint for the resource server, which exchanges the authorization code for an access token.
210+
* **Client ID:** Client identifier obtained during the Application registration process.
211+
* **Client Secret:** Client secret obtained during the Application registration process.
212+
* **Scopes:** Scope of the access request, which might have multiple space-separated values.
213+
* **Refresh Token:** Token used to receive accessToken, which is end product of OAuth2.
214+
* **Service Account** - service account key used for authorization
215+
* **File Path**: Path on the local file system of the service account key used for
216+
authorization. Can be set to 'auto-detect' when running on a Dataproc cluster.
217+
When running on other clusters, the file must be present on every node in the cluster.
218+
* **JSON**: Contents of the service account JSON file.
219+
* **Scope**: The additional Google credential scopes required to access entered url, cloud-platform is included by
220+
default, visit https://developers.google.com/identity/protocols/oauth2/scopes for more information.
221+
* Scope example:
222+
223+
```
224+
https://www.googleapis.com/auth/bigquery
225+
https://www.googleapis.com/auth/cloud-platform
226+
```
227+
* **Basic Authentication**
228+
* **Username:** Username for basic authentication.
229+
* **Password:** Password for basic authentication.
211230

212231
### HTTP Proxy
213232

@@ -373,22 +392,6 @@ def get_next_page_url(url, page, headers):
373392
The above code iterates over first five pages of searchcode.com results. When 'None' is returned the iteration
374393
is stopped.
375394

376-
### OAuth2
377-
378-
**OAuth2 Enabled:** If true, plugin will perform OAuth2 authentication.
379-
380-
**Auth URL:** Endpoint for the authorization server used to retrieve the authorization code.
381-
382-
**Token URL:** Endpoint for the resource server, which exchanges the authorization code for an access token.
383-
384-
**Client ID:** Client identifier obtained during the Application registration process.
385-
386-
**Client Secret:** Client secret obtained during the Application registration process.
387-
388-
**Scopes:** Scope of the access request, which might have multiple space-separated values.
389-
390-
**Refresh Token:** Token used to receive accessToken, which is end product of OAuth2.
391-
392395
### SSL/TLS
393396

394397
**Verify HTTPS Trust Certificates:** If false, untrusted trust certificates (e.g. self signed), will not lead to an

docs/HTTP-streamingsource.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,30 @@ can be omitted as long as the field is present in schema.
207207

208208
**CSV Skip First Row:** Whether to skip the first row of the HTTP response. This is usually set if the first row is a header row.
209209

210-
### Basic Authentication
211-
212-
**Username:** Username for basic authentication.
213-
214-
**Password:** Password for basic authentication.
210+
### Authentication
211+
* **OAuth2**
212+
* **Auth URL:** Endpoint for the authorization server used to retrieve the authorization code.
213+
* **Token URL:** Endpoint for the resource server, which exchanges the authorization code for an access token.
214+
* **Client ID:** Client identifier obtained during the Application registration process.
215+
* **Client Secret:** Client secret obtained during the Application registration process.
216+
* **Scopes:** Scope of the access request, which might have multiple space-separated values.
217+
* **Refresh Token:** Token used to receive accessToken, which is end product of OAuth2.
218+
* **Service Account** - service account key used for authorization
219+
* **File Path**: Path on the local file system of the service account key used for
220+
authorization. Can be set to 'auto-detect' when running on a Dataproc cluster.
221+
When running on other clusters, the file must be present on every node in the cluster.
222+
* **JSON**: Contents of the service account JSON file.
223+
* **Scope**: The additional Google credential scopes required to access entered url, cloud-platform is included by
224+
default, visit https://developers.google.com/identity/protocols/oauth2/scopes for more information.
225+
* Scope example:
226+
227+
```
228+
https://www.googleapis.com/auth/bigquery
229+
https://www.googleapis.com/auth/cloud-platform
230+
```
231+
* **Basic Authentication**
232+
* **Username:** Username for basic authentication.
233+
* **Password:** Password for basic authentication.
215234

216235
### HTTP Proxy
217236

@@ -381,22 +400,6 @@ def get_next_page_url(url, page, headers):
381400
The above code iterates over first five pages of searchcode.com results. When 'None' is returned the iteration
382401
is stopped.
383402

384-
### OAuth2
385-
386-
**OAuth2 Enabled:** If true, plugin will perform OAuth2 authentication.
387-
388-
**Auth URL:** Endpoint for the authorization server used to retrieve the authorization code.
389-
390-
**Token URL:** Endpoint for the resource server, which exchanges the authorization code for an access token.
391-
392-
**Client ID:** Client identifier obtained during the Application registration process.
393-
394-
**Client Secret:** Client secret obtained during the Application registration process.
395-
396-
**Scopes:** Scope of the access request, which might have multiple space-separated values.
397-
398-
**Refresh Token:** Token used to receive accessToken, which is end product of OAuth2.
399-
400403
### SSL/TLS
401404

402405
**Verify HTTPS Trust Certificates:** If false, untrusted trust certificates (e.g. self signed), will not lead to an

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@
7676

7777
<properties>
7878
<awaitility.version>3.1.6</awaitility.version>
79-
<cdap.version>6.1.1</cdap.version>
79+
<cdap.version>6.8.0-SNAPSHOT</cdap.version>
8080
<commons.version>3.9</commons.version>
8181
<common.codec.version>1.12</common.codec.version>
8282
<gson.version>2.8.5</gson.version>
83+
<googleauth.version>0.1.0</googleauth.version>
8384
<hadoop.version>2.3.0</hadoop.version>
8485
<httpcomponents.version>4.5.9</httpcomponents.version>
85-
<hydrator.version>2.4.0-SNAPSHOT</hydrator.version>
86+
<hydrator.version>2.10.0-SNAPSHOT</hydrator.version>
8687
<jackson.version>2.9.9</jackson.version>
8788
<junit.version>4.11</junit.version>
8889
<jython.version>2.7.1</jython.version>
@@ -324,6 +325,11 @@
324325
<artifactId>httpclient</artifactId>
325326
<version>${httpcomponents.version}</version>
326327
</dependency>
328+
<dependency>
329+
<groupId>com.google.auth</groupId>
330+
<artifactId>google-auth-library-oauth2-http</artifactId>
331+
<version>${googleauth.version}</version>
332+
</dependency>
327333
<dependency>
328334
<groupId>com.google.code.gson</groupId>
329335
<artifactId>gson</artifactId>

src/main/java/io/cdap/plugin/http/source/batch/HttpBatchSource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.cdap.cdap.api.data.schema.Schema;
2626
import io.cdap.cdap.api.dataset.lib.KeyValue;
2727
import io.cdap.cdap.etl.api.Emitter;
28+
import io.cdap.cdap.etl.api.FailureCollector;
2829
import io.cdap.cdap.etl.api.InvalidEntry;
2930
import io.cdap.cdap.etl.api.PipelineConfigurer;
3031
import io.cdap.cdap.etl.api.batch.BatchRuntimeContext;
@@ -59,15 +60,17 @@ public HttpBatchSource(HttpBatchSourceConfig config) {
5960

6061
@Override
6162
public void configurePipeline(PipelineConfigurer pipelineConfigurer) {
62-
config.validate(); // validate when macros not yet substituted
63+
FailureCollector failureCollector = pipelineConfigurer.getStageConfigurer().getFailureCollector();
64+
config.validate(failureCollector); // validate when macros not yet substituted
6365
config.validateSchema();
6466

6567
pipelineConfigurer.getStageConfigurer().setOutputSchema(config.getSchema());
6668
}
6769

6870
@Override
6971
public void prepareRun(BatchSourceContext context) {
70-
config.validate(); // validate when macros are already substituted
72+
FailureCollector failureCollector = context.getFailureCollector();
73+
config.validate(failureCollector); // validate when macros are already substituted
7174
config.validateSchema();
7275

7376
schema = config.getSchema();

src/main/java/io/cdap/plugin/http/source/batch/HttpBatchSourceConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private HttpBatchSourceConfig(HttpBatchSourceConfigBuilder builder) {
3939
this.readTimeout = builder.readTimeout;
4040
this.paginationType = builder.paginationType;
4141
this.verifyHttps = builder.verifyHttps;
42+
this.authType = builder.authType;
4243
}
4344

4445
public static HttpBatchSourceConfigBuilder builder() {
@@ -63,6 +64,7 @@ public static class HttpBatchSourceConfigBuilder {
6364
private Integer readTimeout;
6465
private String paginationType;
6566
private String verifyHttps;
67+
private String authType;
6668

6769
public HttpBatchSourceConfigBuilder setReferenceName (String referenceName) {
6870
this.referenceName = referenceName;
@@ -93,7 +95,7 @@ public HttpBatchSourceConfigBuilder setOauth2Enabled(String oauth2Enabled) {
9395
this.oauth2Enabled = oauth2Enabled;
9496
return this;
9597
}
96-
98+
9799
public HttpBatchSourceConfigBuilder setErrorHandling(String errorHandling) {
98100
this.errorHandling = errorHandling;
99101
return this;
@@ -129,6 +131,11 @@ public HttpBatchSourceConfigBuilder setVerifyHttps(String verifyHttps) {
129131
return this;
130132
}
131133

134+
public HttpBatchSourceConfigBuilder setAuthType(String authType) {
135+
this.authType = authType;
136+
return this;
137+
}
138+
132139
public HttpBatchSourceConfig build() {
133140
return new HttpBatchSourceConfig(this);
134141
}

0 commit comments

Comments
 (0)