Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

38
pkg/utils/auth_helper.go Normal file
View File

@@ -0,0 +1,38 @@
package utils
import (
"context"
"net/http"
c "fiskerinc.com/modules/common/context"
)
// auth_helper gives tool to our authorization services so that future middleware components and actual endpoints will have access
// to user data needed for specific granular control
func AUTHWriteProviderToRequest(provider string, r *http.Request) *http.Request {
newCTX := AUTHWriteProviderToContext(provider, r.Context())
r = r.Clone(newCTX)
return r
}
func AUTHWriteProviderToContext(provider string, ctx context.Context) (newCTX context.Context) {
newCTX = context.WithValue(ctx, c.ProviderKey, provider)
return newCTX
}
// If provider is not in context, will return an empty string
func AUTHGetProviderFromRequest(r *http.Request) string {
return AUTHGetProviderFromContext(r.Context())
}
// If provider is not in context, will return an empty string
func AUTHGetProviderFromContext(ctx context.Context) string {
val, ok := ctx.Value(c.ProviderKey).(string)
if !ok {
return ""
}
return val
}