Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add a timeout to the http client we use to call IT services #165

Merged
merged 2 commits into from
Feb 9, 2024
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
3 changes: 3 additions & 0 deletions config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type EntitlementsConfigKeysType struct {
SubsCacheMaxSize string
SubsCacheItemPrune string
AMSAcctMgmt11Msg string
ITServicesTimeoutSeconds string
}

// Keys is a struct that houses all the env variables key names
Expand Down Expand Up @@ -99,6 +100,7 @@ var Keys = EntitlementsConfigKeysType{
SubsCacheMaxSize: "SUBS_CACHE_MAX_SIZE",
SubsCacheItemPrune: "SUBS_CACHE_ITEM_PRUNE",
AMSAcctMgmt11Msg: "AMS_ACCT_MGMT_11_ERR_MSG",
ITServicesTimeoutSeconds: "IT_SERVICES_TIMEOUT_SECONDS",
}

func getRootCAs(localCertFile string) *x509.CertPool {
Expand Down Expand Up @@ -190,6 +192,7 @@ func initialize() {
options.SetDefault(Keys.SubsCacheMaxSize, 500)
options.SetDefault(Keys.SubsCacheItemPrune, 50)
options.SetDefault(Keys.AMSAcctMgmt11Msg, "Please have this user log into \"https://console.redhat.com/openshift\" to grant their account the required permissions, or try again later.")
options.SetDefault(Keys.ITServicesTimeoutSeconds, 10)

options.SetEnvPrefix("ENT")
options.AutomaticEnv()
Expand Down
10 changes: 8 additions & 2 deletions controllers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ package controllers

import (
"crypto/tls"
"github.com/RedHatInsights/entitlements-api-go/config"
"net/http"
"time"

"github.com/RedHatInsights/entitlements-api-go/config"
)

func getClient() *http.Client {
cfg := config.GetConfig()
timeout := cfg.Options.GetInt(config.Keys.ITServicesTimeoutSeconds)

// Create a HTTPS client that uses the supplied pub/priv mutual TLS certs
return &http.Client{
Timeout: time.Duration(timeout) * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: config.GetConfig().RootCAs,
RootCAs: cfg.RootCAs,
Certificates: []tls.Certificate{*config.GetConfig().Certs},
},
},
Expand Down
5 changes: 5 additions & 0 deletions deployment/clowdapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ objects:
value: ${SUBS_CACHE_ITEM_PRUNE}
- name: ENT_AMS_ACCT_MGMT_11_ERR_MSG
value: ${AMS_ACCT_MGMT_11_ERR_MSG}
- name: ENT_IT_SERVICES_TIMEOUT_SECONDS
value: ${IT_SERVICES_TIMEOUT_SECONDS}
- name: GLITCHTIP_DSN
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -234,3 +236,6 @@ parameters:
- description: Error message to display for the ACCT-MGMT-11 error message
name: AMS_ACCT_MGMT_11_ERR_MSG
required: false
- description: Timeout for outbound requests to IT services, in seconds
name: IT_SERVICES_TIMEOUT_SECONDS
required: false
Loading