Skip to content

Commit

Permalink
Address docs and change new test case into table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-gr committed Jun 9, 2020
1 parent 7108a73 commit 246f1d9
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 318 deletions.
35 changes: 10 additions & 25 deletions x-pack/filebeat/docs/inputs/input-httpjson.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ Example configurations with authentication:
url: http://localhost
----

["source","yaml",subs="attributes"]
----
{beatname_lc}.inputs:
- type: httpjson
api_key: 12345678901234567890abcdef
url: http://localhost
----

["source","yaml",subs="attributes"]
----
{beatname_lc}.inputs:
Expand Down Expand Up @@ -294,24 +286,19 @@ the `oauth2` section is missing.

The `provider` setting can be used to configure supported oauth2 providers.
Each supported provider will require specific settings. It is not set by default.

NOTE: Supported providers are: `azure`, `google`.
Supported providers are: `azure`, `google`.

[float]
==== `oauth2.client.id`

The `client.id` setting is used as part of the authentication flow. It is always required
except if using `google` as provider.

NOTE: Required for providers: `default`, `azure`.
except if using `google` as provider. Required for providers: `default`, `azure`.

[float]
==== `oauth2.client.secret`

The `client.secret` setting is used as part of the authentication flow. It is always required
except if using `google` as provider.

NOTE: Required for providers: `default`, `azure`.
except if using `google` as provider. Required for providers: `default`, `azure`.

[float]
==== `oauth2.scopes`
Expand All @@ -325,16 +312,14 @@ It is optional for all providers.
The `token_url` setting specifies the endpoint that will be used to generate the
tokens during the oauth2 flow. It is required if no provider is specified.

NOTE: For `azure` provider, a default `token_url` will be used if none provided,
but it can be set to override the default one.
NOTE: For `azure` provider either `token_url` or `azure.tenant_id` is required.

[float]
==== `oauth2.endpoint_params`

The `endpoint_params` setting specifies a set of values that will be sent on each
request to the `token_url`. Each param key can have multiple values.

NOTE: Can be set for all providers except `google`.
Can be set for all providers except `google`.

["source","yaml",subs="attributes"]
----
Expand All @@ -355,8 +340,8 @@ The `azure.tenant_id` is used for authentication when using `azure` provider.
Since it is used in the process to generate the `token_url`, it can't be used in
combination with it. It is not required.

NOTE: For information about where to find it, you can refer to
https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal
For information about where to find it, you can refer to
https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal.

[float]
==== `oauth2.azure.resource`
Expand All @@ -370,7 +355,7 @@ It is not required.
The `google.credentials_file` setting specifies the credentials file for Google.

NOTE: Only one of the credentials settings can be set at once. If none is provided, loading
default credentials from the environment will be attempted via ADC. For for information about
default credentials from the environment will be attempted via ADC. For more information about
how to provide Google credentials, please refer to https://cloud.google.com/docs/authentication.

[float]
Expand All @@ -379,7 +364,7 @@ how to provide Google credentials, please refer to https://cloud.google.com/docs
The `google.credentials_json` setting allows to write your credentials information as raw JSON.

NOTE: Only one of the credentials settings can be set at once. If none is provided, loading
default credentials from the environment will be attempted via ADC. For for information about
default credentials from the environment will be attempted via ADC. For more information about
how to provide Google credentials, please refer to https://cloud.google.com/docs/authentication.

[float]
Expand All @@ -388,7 +373,7 @@ how to provide Google credentials, please refer to https://cloud.google.com/docs
The `google.jwt_file` setting specifies the JWT Account Key file for Google.

NOTE: Only one of the credentials settings can be set at once. If none is provided, loading
default credentials from the environment will be attempted via ADC. For for information about
default credentials from the environment will be attempted via ADC. For more information about
how to provide Google credentials, please refer to https://cloud.google.com/docs/authentication.

[id="{beatname_lc}-input-{type}-common-options"]
Expand Down
21 changes: 11 additions & 10 deletions x-pack/filebeat/input/httpjson/config_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,24 @@ func (o *OAuth2) Client(ctx context.Context, client *http.Client) (*http.Client,
ctx = context.WithValue(ctx, oauth2.HTTPClient, client)

switch o.GetProvider() {
case OAuth2ProviderAzure, OAuth2ProviderDefault:
creds := clientcredentials.Config{
ClientID: o.ClientID,
ClientSecret: o.ClientSecret,
TokenURL: o.GetTokenURL(),
Scopes: o.Scopes,
EndpointParams: o.GetEndpointParams(),
}
return creds.Client(ctx), nil
case OAuth2ProviderGoogle:
creds, err := google.CredentialsFromJSON(ctx, o.GoogleCredentialsJSON, o.Scopes...)
if err != nil {
return nil, fmt.Errorf("oauth2 client: error loading credentials: %w", err)
}
return oauth2.NewClient(ctx, creds.TokenSource), nil
default:
return nil, errors.New("oauth2 client: unknown provider")
}

creds := clientcredentials.Config{
ClientID: o.ClientID,
ClientSecret: o.ClientSecret,
TokenURL: o.GetTokenURL(),
Scopes: o.Scopes,
EndpointParams: o.GetEndpointParams(),
}

return creds.Client(ctx), nil
}

// GetTokenURL returns the TokenURL.
Expand Down
Loading

0 comments on commit 246f1d9

Please sign in to comment.