mirror of
https://github.com/paralus/paralus.git
synced 2026-05-06 16:36:46 +00:00
Add two constructors for authContext
This includes: - SetupAuthContext: Setups authContext with new authContext fields. - NewAuthContext: Create AuthContext with using authContext fields from caller function.
This commit is contained in:
2
main.go
2
main.go
@@ -554,7 +554,7 @@ func runRPC(wg *sync.WaitGroup, ctx context.Context) {
|
||||
var opts []_grpc.ServerOption
|
||||
if !dev {
|
||||
_log.Infow("adding auth interceptor")
|
||||
ac := authv3.NewAuthContext()
|
||||
ac := authv3.NewAuthContext(kc, ks, as)
|
||||
o := authv3.Option{}
|
||||
opts = append(opts, _grpc.UnaryInterceptor(
|
||||
ac.NewAuthUnaryInterceptor(o),
|
||||
|
||||
@@ -37,8 +37,10 @@ type authContext struct {
|
||||
as service.AuthzService
|
||||
}
|
||||
|
||||
// NewAuthContext setup authentication and authorization dependencies.
|
||||
func NewAuthContext() authContext {
|
||||
// SetupAuthContext sets up new authContext along with its
|
||||
// dependencies. If the caller already has instances of authContext
|
||||
// fields created then use NewAuthContext instead.
|
||||
func SetupAuthContext() authContext {
|
||||
var (
|
||||
kc *kclient.APIClient
|
||||
kratosScheme string
|
||||
@@ -93,3 +95,19 @@ func getEnvWithDefault(env, def string) string {
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
// NewAuthContext instantiate authContext. NewAuthContext creates
|
||||
// authContext reusing dependency instances from calling function
|
||||
// instead of creating new instances. To create authContext along with
|
||||
// its dependencies, use SetupAuthContext.
|
||||
func NewAuthContext(
|
||||
kc *kclient.APIClient,
|
||||
apiKeySvc service.ApiKeyService,
|
||||
authzSvc service.AuthzService,
|
||||
) authContext {
|
||||
return authContext{
|
||||
kc: kc,
|
||||
ks: apiKeySvc,
|
||||
as: authzSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ type authMiddleware struct {
|
||||
|
||||
func NewAuthMiddleware(opt Option) negroni.Handler {
|
||||
return &authMiddleware{
|
||||
ac: NewAuthContext(),
|
||||
ac: SetupAuthContext(),
|
||||
opt: opt,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user