Skip to content
Snippets Groups Projects
Commit 6ba48b2c authored by Siarhei Khaletski (EPAM)'s avatar Siarhei Khaletski (EPAM) 🚩
Browse files

Merge branch 'fix/recache-endpoint-header-check' into 'master'

Added support to run cache init endpoint with custom header `X-Cache-Init`.

See merge request go3-nrg/os-entitlements-cache-sync!1
parents 336860ec 0e01840d
No related branches found
No related tags found
1 merge request!1Initial code base
Pipeline #6708 failed
......@@ -3,11 +3,13 @@ package api
import (
"encoding/json"
"entitlements-cache-sync/boom"
"entitlements-cache-sync/common"
"entitlements-cache-sync/logging"
"entitlements-cache-sync/mapping"
"fmt"
"github.com/pkg/errors"
"net/http"
"github.com/pkg/errors"
)
// ServiceAPI group service api
......@@ -20,8 +22,11 @@ func (api *ServiceAPI) InitalizeRedisCache(w http.ResponseWriter, r *http.Reques
// Set TraceID in context
logging.SetTraceID(r)
if r.Header.Get("X-Appengine-Cron") != "true" {
msg := fmt.Sprintf("Unauthorized to call the cron job %s", r.Header.Get("X-Appengine-Cron"))
isSetCronHeader := r.Header.Get(common.AppengineCronRecacheHeader) == "true"
isSetPublicHeader := r.Header.Get(common.OnDemandRecacheHeader) == "true"
if !isSetCronHeader && !isSetPublicHeader {
msg := fmt.Sprint("Unauthorized to call the job")
writeResponse(w, r, nil, boom.FromHTTP(http.StatusUnauthorized, msg))
return
}
......
......@@ -4,7 +4,7 @@ import "time"
// Entitlement clients config
var (
EntitlementBucket string
EntitlementBucket string
EntitlementServiceAccountFile string
GoogleCloudIdentityAdminEmail string
)
......@@ -26,7 +26,7 @@ const (
PartialDirectGroupKey = "-direct"
// PartialDirectMemberKey is the partial hash name used for the keys
PartialDirectMemberKey = "-directMember"
PartialDirectMemberKey = "-directMember"
// PartialDirectGroupKey is the partial hash name used for the keys
PartialFlatGroupKey = "-flat"
......@@ -56,6 +56,9 @@ const (
AppLoggerName = "entitlements-cache-sync.app"
Trace = "X-Cloud-Trace-Context"
OnDemandRecacheHeader = "X-Cache-Init"
AppengineCronRecacheHeader = "X-Appengine-Cron"
)
var (
......@@ -74,4 +77,4 @@ var (
// DefaultDbindex id redis default db number
DefaultDbindex = 1
)
\ No newline at end of file
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment