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

[NOREF] Add env vars for cache time and to bypass cache #2576

Merged
merged 3 commits into from
May 10, 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
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export CEDAR_API_URL="webmethods-apigw.cedarimpl.cms.gov"
export CEDAR_API_KEY=""
export CEDAR_CORE_API_VERSION="2.0.0"
export CEDAR_EMAIL_ADDRESS="EnterpriseArchitecture@notCMS.gov"
export CEDAR_CACHE_EXPIRE_TIME="7d"
export CEDAR_CORE_SKIP_PROXY=false

# Frontend Dev
export ESLINT_NO_DEV_ERRORS=true
Expand Down
3 changes: 2 additions & 1 deletion cedarproxy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ http {
# include /etc/nginx/conf.d/*.conf;

proxy_cache_path /nginxcache keys_zone=cedarcorecache:10m;
proxy_cache_valid 200 302 24h;
proxy_cache_valid 200 302 ${CEDAR_CACHE_EXPIRE_TIME};
proxy_cache_use_stale error timeout updating http_500 http_504

server {
listen 8001;
Expand Down
1 change: 1 addition & 0 deletions deploy/base/cedarproxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
namespace: easi
data:
CEDAR_API_URL: webmethods-apigw.cedarimpl.cms.gov
CEDAR_CACHE_EXPIRE_TIME: "7d"

---

Expand Down
4 changes: 2 additions & 2 deletions deploy/base/easi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ metadata:
data:
CEDAR_CORE_MOCK: 'true'
CEDAR_INTAKE_ENABLED: 'false'
CEDAR_API_KEY: ''
CEDAR_API_KEY: ""
CEDAR_PROXY_URL: ""
CEDAR_CORE_SKIP_PROXY: "false"
CEDAR_API_URL: "webmethods-apigw.cedarimpl.cms.gov"
CEDAR_CORE_API_VERSION: "2.0.0"
CEDAR_CACHE_INTERVAL: "30m"
CEDAR_EMAIL_ADDRESS: "EnterpriseArchitecture@notCMS.gov"
APP_ENV: local
CLIENT_PROTOCOL: http
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ services:
- CEDAR_API_KEY
- CEDAR_API_URL
- CEDAR_PROXY_URL=cedarproxy:8001
- CEDAR_CORE_SKIP_PROXY
- CEDAR_CORE_API_VERSION
- CEDAR_CACHE_INTERVAL
- CEDAR_EMAIL_ADDRESS
- HTTP_PROXY
- HTTPS_PROXY
Expand Down Expand Up @@ -79,6 +79,7 @@ services:
image: cedarproxy:latest
environment:
- CEDAR_API_URL
- CEDAR_CACHE_EXPIRE_TIME
build:
dockerfile: Dockerfile.cedarproxy
context: ./cedarproxy/
Expand Down
3 changes: 3 additions & 0 deletions pkg/appconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ const CEDARAPIURL = "CEDAR_API_URL"
// CEDARAPIKey is the key for accessing CEDAR
const CEDARAPIKey = "CEDAR_API_KEY" // #nosec

// CEDARCoreSkipProxy is the key for whether to make calls directly to CEDAR Core
const CEDARCoreSkipProxy = "CEDAR_CORE_SKIP_PROXY"

// CEDAREmailAddress is the key for the env var that holds the email address that we use when notifying CEDAR of changes
const CEDAREmailAddress = "CEDAR_EMAIL_ADDRESS"

Expand Down
9 changes: 8 additions & 1 deletion pkg/cedar/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ var (
cedarPath string
client *Client
clientOnce sync.Once
skipPurge bool
)

// Purges Proxy Cache by URL using a given path
func PurgeCacheByPath(ctx context.Context, path string) error {
if skipPurge {
return nil
}
req, err := http.NewRequest("PURGE", cedarPath+path, nil)
logger := appcontext.ZLogger(ctx)
if err != nil {
Expand All @@ -77,7 +81,7 @@ func PurgeCacheByPath(ctx context.Context, path string) error {
}

// NewClient builds the type that holds a connection to the CEDAR Core API
func NewClient(ctx context.Context, cedarHost string, cedarAPIKey string, cedarAPIVersion string, mockEnabled bool) *Client {
func NewClient(ctx context.Context, cedarHost string, cedarAPIKey string, cedarAPIVersion string, skipProxy bool, mockEnabled bool) *Client {
clientOnce.Do(func() {
hc := http.Client{
Transport: &loggingTransport{
Expand All @@ -87,6 +91,9 @@ func NewClient(ctx context.Context, cedarHost string, cedarAPIKey string, cedarA

basePath := "/gateway/CEDAR Core API/" + cedarAPIVersion
cedarPath = "http://" + cedarHost + basePath
if skipProxy {
skipPurge = true
}
client = &Client{
mockEnabled: mockEnabled,
auth: httptransport.APIKeyAuth(
Expand Down
2 changes: 1 addition & 1 deletion pkg/cedar/core/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s *ClientTestSuite) TestClient() {
ctx := appcontext.WithLogger(context.Background(), s.logger)

s.Run("Instantiation successful", func() {
c := NewClient(ctx, "fake", "fake", "1.0.0", true)
c := NewClient(ctx, "fake", "fake", "1.0.0", false, true)
s.NotNil(c)
})
}
8 changes: 4 additions & 4 deletions pkg/cedar/core/system_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *SystemSummaryTestSuite) TestGetSystemSummary() {
ctx := appcontext.WithLogger(context.Background(), s.logger)

s.Run("LD defaults protects invocation of GetSystemSummary", func() {
c := NewClient(ctx, "fake", "fake", "1.0.0", true)
c := NewClient(ctx, "fake", "fake", "1.0.0", false, true)
resp, err := c.GetSystemSummary(ctx)
s.NoError(err)

Expand All @@ -40,7 +40,7 @@ func (s *SystemSummaryTestSuite) TestGetSystemSummary() {
})

s.Run("Retrieves filtered list when EUA filter is present", func() {
c := NewClient(ctx, "fake", "fake", "1.0.0", true)
c := NewClient(ctx, "fake", "fake", "1.0.0", false, true)
resp, err := c.GetSystemSummary(ctx, WithEuaIDFilter("USR1"))
s.NoError(err)

Expand All @@ -52,7 +52,7 @@ func (s *SystemSummaryTestSuite) TestGetSystemSummary() {
})

s.Run("Retrieves filtered list when Sub-System filter is present", func() {
c := NewClient(ctx, "fake", "fake", "1.0.0", true)
c := NewClient(ctx, "fake", "fake", "1.0.0", false, true)
resp, err := c.GetSystemSummary(ctx, WithSubSystems("1"))
s.NoError(err)

Expand All @@ -68,7 +68,7 @@ func (s *SystemSummaryTestSuite) TestGetSystem() {
ctx := appcontext.WithLogger(context.Background(), s.logger)

s.Run("LD defaults protects invocation of GetSystem", func() {
c := NewClient(ctx, "fake", "fake", "1.0.0", true)
c := NewClient(ctx, "fake", "fake", "1.0.0", false, true)
_, err := c.GetSystem(ctx, "fake")
s.NoError(err)

Expand Down
2 changes: 1 addition & 1 deletion pkg/graph/schema.resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestGraphQLTestSuite(t *testing.T) {
}

oktaAPIClient := local.NewOktaAPIClient()
cedarCoreClient := cedarcore.NewClient(appcontext.WithLogger(context.Background(), logger), "fake", "fake", "1.0.0", true)
cedarCoreClient := cedarcore.NewClient(appcontext.WithLogger(context.Background(), logger), "fake", "fake", "1.0.0", false, true)

directives := generated.DirectiveRoot{HasRole: func(ctx context.Context, obj interface{}, next graphql.Resolver, role model.Role) (res interface{}, err error) {
return next(ctx)
Expand Down
10 changes: 9 additions & 1 deletion pkg/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,20 @@ func (s *Server) routes(
}
}

var cedarCoreURL string
if s.Config.GetBool(appconfig.CEDARCoreSkipProxy) {
cedarCoreURL = s.Config.GetString(appconfig.CEDARAPIURL)
} else {
cedarCoreURL = s.Config.GetString(appconfig.CEDARPROXYURL)
}

// set up CEDAR core API client
coreClient := cedarcore.NewClient(
appcontext.WithLogger(context.Background(), s.logger),
s.Config.GetString(appconfig.CEDARPROXYURL),
cedarCoreURL,
s.Config.GetString(appconfig.CEDARAPIKey),
s.Config.GetString(appconfig.CEDARCoreAPIVersion),
s.Config.GetBool(appconfig.CEDARCoreSkipProxy),
s.Config.GetBool(appconfig.CEDARCoreMock),
)

Expand Down
Loading