From 66d42fc2bcd05af20918e4c06e5133d32249ca0b Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Sat, 12 Feb 2022 19:34:22 +0530 Subject: [PATCH] Add support for public private key from admin apis --- Makefile | 2 + server/graph/generated/generated.go | 104 ++++++++++++++++++++++++++++ server/graph/model/models_gen.go | 4 ++ server/graph/schema.graphqls | 4 ++ server/resolvers/env.go | 4 ++ 5 files changed, 118 insertions(+) diff --git a/Makefile b/Makefile index 1fca360..021f761 100644 --- a/Makefile +++ b/Makefile @@ -11,3 +11,5 @@ clean: rm -rf build test: cd server && go clean --testcache && go test -v ./test +generate: + cd server && go get github.com/99designs/gqlgen/cmd@v0.14.0 && go run github.com/99designs/gqlgen generate \ No newline at end of file diff --git a/server/graph/generated/generated.go b/server/graph/generated/generated.go index f5979c4..a93dbe4 100644 --- a/server/graph/generated/generated.go +++ b/server/graph/generated/generated.go @@ -70,6 +70,8 @@ type ComplexityRoot struct { GithubClientSecret func(childComplexity int) int GoogleClientID func(childComplexity int) int GoogleClientSecret func(childComplexity int) int + JwtPrivateKey func(childComplexity int) int + JwtPublicKey func(childComplexity int) int JwtRoleClaim func(childComplexity int) int JwtSecret func(childComplexity int) int JwtType func(childComplexity int) int @@ -391,6 +393,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Env.GoogleClientSecret(childComplexity), true + case "Env.JWT_PRIVATE_KEY": + if e.complexity.Env.JwtPrivateKey == nil { + break + } + + return e.complexity.Env.JwtPrivateKey(childComplexity), true + + case "Env.JWT_PUBLIC_KEY": + if e.complexity.Env.JwtPublicKey == nil { + break + } + + return e.complexity.Env.JwtPublicKey(childComplexity), true + case "Env.JWT_ROLE_CLAIM": if e.complexity.Env.JwtRoleClaim == nil { break @@ -1206,6 +1222,8 @@ type Env { SENDER_EMAIL: String JWT_TYPE: String JWT_SECRET: String + JWT_PRIVATE_KEY: String + JWT_PUBLIC_KEY: String ALLOWED_ORIGINS: [String!] APP_URL: String REDIS_URL: String @@ -1240,6 +1258,8 @@ input UpdateEnvInput { SENDER_EMAIL: String JWT_TYPE: String JWT_SECRET: String + JWT_PRIVATE_KEY: String + JWT_PUBLIC_KEY: String ALLOWED_ORIGINS: [String!] APP_URL: String REDIS_URL: String @@ -2229,6 +2249,70 @@ func (ec *executionContext) _Env_JWT_SECRET(ctx context.Context, field graphql.C return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } +func (ec *executionContext) _Env_JWT_PRIVATE_KEY(ctx context.Context, field graphql.CollectedField, obj *model.Env) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Env", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.JwtPrivateKey, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _Env_JWT_PUBLIC_KEY(ctx context.Context, field graphql.CollectedField, obj *model.Env) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Env", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.JwtPublicKey, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + func (ec *executionContext) _Env_ALLOWED_ORIGINS(ctx context.Context, field graphql.CollectedField, obj *model.Env) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -7044,6 +7128,22 @@ func (ec *executionContext) unmarshalInputUpdateEnvInput(ctx context.Context, ob if err != nil { return it, err } + case "JWT_PRIVATE_KEY": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("JWT_PRIVATE_KEY")) + it.JwtPrivateKey, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "JWT_PUBLIC_KEY": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("JWT_PUBLIC_KEY")) + it.JwtPublicKey, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } case "ALLOWED_ORIGINS": var err error @@ -7539,6 +7639,10 @@ func (ec *executionContext) _Env(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = ec._Env_JWT_TYPE(ctx, field, obj) case "JWT_SECRET": out.Values[i] = ec._Env_JWT_SECRET(ctx, field, obj) + case "JWT_PRIVATE_KEY": + out.Values[i] = ec._Env_JWT_PRIVATE_KEY(ctx, field, obj) + case "JWT_PUBLIC_KEY": + out.Values[i] = ec._Env_JWT_PUBLIC_KEY(ctx, field, obj) case "ALLOWED_ORIGINS": out.Values[i] = ec._Env_ALLOWED_ORIGINS(ctx, field, obj) case "APP_URL": diff --git a/server/graph/model/models_gen.go b/server/graph/model/models_gen.go index 5533a70..0d5a4cc 100644 --- a/server/graph/model/models_gen.go +++ b/server/graph/model/models_gen.go @@ -34,6 +34,8 @@ type Env struct { SenderEmail *string `json:"SENDER_EMAIL"` JwtType *string `json:"JWT_TYPE"` JwtSecret *string `json:"JWT_SECRET"` + JwtPrivateKey *string `json:"JWT_PRIVATE_KEY"` + JwtPublicKey *string `json:"JWT_PUBLIC_KEY"` AllowedOrigins []string `json:"ALLOWED_ORIGINS"` AppURL *string `json:"APP_URL"` RedisURL *string `json:"REDIS_URL"` @@ -153,6 +155,8 @@ type UpdateEnvInput struct { SenderEmail *string `json:"SENDER_EMAIL"` JwtType *string `json:"JWT_TYPE"` JwtSecret *string `json:"JWT_SECRET"` + JwtPrivateKey *string `json:"JWT_PRIVATE_KEY"` + JwtPublicKey *string `json:"JWT_PUBLIC_KEY"` AllowedOrigins []string `json:"ALLOWED_ORIGINS"` AppURL *string `json:"APP_URL"` RedisURL *string `json:"REDIS_URL"` diff --git a/server/graph/schema.graphqls b/server/graph/schema.graphqls index 1bbd2f8..0b88775 100644 --- a/server/graph/schema.graphqls +++ b/server/graph/schema.graphqls @@ -97,6 +97,8 @@ type Env { SENDER_EMAIL: String JWT_TYPE: String JWT_SECRET: String + JWT_PRIVATE_KEY: String + JWT_PUBLIC_KEY: String ALLOWED_ORIGINS: [String!] APP_URL: String REDIS_URL: String @@ -131,6 +133,8 @@ input UpdateEnvInput { SENDER_EMAIL: String JWT_TYPE: String JWT_SECRET: String + JWT_PRIVATE_KEY: String + JWT_PUBLIC_KEY: String ALLOWED_ORIGINS: [String!] APP_URL: String REDIS_URL: String diff --git a/server/resolvers/env.go b/server/resolvers/env.go index d514ef3..ab4769f 100644 --- a/server/resolvers/env.go +++ b/server/resolvers/env.go @@ -40,6 +40,8 @@ func EnvResolver(ctx context.Context) (*model.Env, error) { jwtType := store.StringEnv[constants.EnvKeyJwtType] jwtSecret := store.StringEnv[constants.EnvKeyJwtSecret] jwtRoleClaim := store.StringEnv[constants.EnvKeyJwtRoleClaim] + jwtPublicKey := store.StringEnv[constants.EnvKeyJwtPublicKey] + jwtPrivateKey := store.StringEnv[constants.EnvKeyJwtPrivateKey] allowedOrigins := store.SliceEnv[constants.EnvKeyAllowedOrigins] appURL := store.StringEnv[constants.EnvKeyAppURL] redisURL := store.StringEnv[constants.EnvKeyRedisURL] @@ -74,6 +76,8 @@ func EnvResolver(ctx context.Context) (*model.Env, error) { SenderEmail: &senderEmail, JwtType: &jwtType, JwtSecret: &jwtSecret, + JwtPrivateKey: &jwtPrivateKey, + JwtPublicKey: &jwtPublicKey, JwtRoleClaim: &jwtRoleClaim, AllowedOrigins: allowedOrigins, AppURL: &appURL,