Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add option to configure the Keycloak client timeout #155

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The following provider attributes are supported:
- `password` (Optional) - The password of the user used by the provider for authentication via the password grant. Defaults to environment variable `KEYCLOAK_PASSWORD`. This attribute is required when using the password grant, and cannot be set when using the client credentials grant.
- `realm` (Optional) - The realm used by the provider for authentication. Defaults to environment variable `KEYCLOAK_REALM`, or `master` if the environment variable is not specified.
- `initial_login` (Optional) - Optionally avoid Keycloak login during provider setup, for when Keycloak itself is being provisioned by terraform. Defaults to true, which is the original method.
- `client_timeout` (Optional) - Sets the timeout of the client when addressing Keycloak, in seconds. Defaults to 5.

#### Example (client credentials)

Expand Down
4 changes: 2 additions & 2 deletions keycloak/keycloak_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const (
tokenUrl = "%s/auth/realms/%s/protocol/openid-connect/token"
)

func NewKeycloakClient(baseUrl, clientId, clientSecret, realm, username, password string, initialLogin bool) (*KeycloakClient, error) {
func NewKeycloakClient(baseUrl, clientId, clientSecret, realm, username, password string, initialLogin bool, clientTimeout int) (*KeycloakClient, error) {
httpClient := &http.Client{
Timeout: time.Second * 5,
Timeout: time.Second * time.Duration(clientTimeout),
}
clientCredentials := &ClientCredentials{
ClientId: clientId,
Expand Down
2 changes: 1 addition & 1 deletion keycloak/keycloak_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestAccKeycloakApiClientRefresh(t *testing.T) {
defer log.SetOutput(os.Stdout)
}

keycloakClient, err := NewKeycloakClient(os.Getenv("KEYCLOAK_URL"), os.Getenv("KEYCLOAK_CLIENT_ID"), os.Getenv("KEYCLOAK_CLIENT_SECRET"), os.Getenv("KEYCLOAK_REALM"), os.Getenv("KEYCLOAK_USER"), os.Getenv("KEYCLOAK_PASSWORD"), true)
keycloakClient, err := NewKeycloakClient(os.Getenv("KEYCLOAK_URL"), os.Getenv("KEYCLOAK_CLIENT_ID"), os.Getenv("KEYCLOAK_CLIENT_SECRET"), os.Getenv("KEYCLOAK_REALM"), os.Getenv("KEYCLOAK_USER"), os.Getenv("KEYCLOAK_PASSWORD"), true, 5)
if err != nil {
t.Fatalf("%s", err)
}
Expand Down
9 changes: 8 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func KeycloakProvider() *schema.Provider {
Description: "Whether or not to login to Keycloak instance on provider initialization",
Default: true,
},
"client_timeout": {
Optional: true,
Type: schema.TypeInt,
Description: "Timeout (in seconds) of the Keycloak client",
Default: 5,
},
},
ConfigureFunc: configureKeycloakProvider,
}
Expand All @@ -106,6 +112,7 @@ func configureKeycloakProvider(data *schema.ResourceData) (interface{}, error) {
password := data.Get("password").(string)
realm := data.Get("realm").(string)
initialLogin := data.Get("initial_login").(bool)
clientTimeout := data.Get("client_timeout").(int)

return keycloak.NewKeycloakClient(url, clientId, clientSecret, realm, username, password, initialLogin)
return keycloak.NewKeycloakClient(url, clientId, clientSecret, realm, username, password, initialLogin, clientTimeout)
}