From cab79c48a8ef73cf546b22355cb796ffa34d983b Mon Sep 17 00:00:00 2001 From: Piyush Kumar Date: Wed, 10 Jul 2024 19:19:33 +0530 Subject: [PATCH 1/2] check mres name availability based on managedservice name --- .../internal/app/graph/generated/generated.go | 55 +++++++------------ .../internal/app/graph/schema.graphqls | 2 +- .../internal/app/graph/schema.resolvers.go | 4 +- apps/console/internal/domain/api.go | 2 +- apps/console/internal/domain/names.go | 12 +++- 5 files changed, 35 insertions(+), 40 deletions(-) diff --git a/apps/console/internal/app/graph/generated/generated.go b/apps/console/internal/app/graph/generated/generated.go index c18344743..04c1f06cc 100644 --- a/apps/console/internal/app/graph/generated/generated.go +++ b/apps/console/internal/app/graph/generated/generated.go @@ -796,7 +796,7 @@ type ComplexityRoot struct { } Query struct { - CoreCheckNameAvailability func(childComplexity int, envName *string, resType entities.ResourceType, name string) int + CoreCheckNameAvailability func(childComplexity int, envName *string, msvcName *string, resType entities.ResourceType, name string) int CoreGetApp func(childComplexity int, envName string, name string) int CoreGetConfig func(childComplexity int, envName string, name string) int CoreGetConfigValues func(childComplexity int, envName string, queries []*domain.ConfigKeyRef) int @@ -1050,7 +1050,7 @@ type MutationResolver interface { CoreDeleteVPNDevice(ctx context.Context, deviceName string) (bool, error) } type QueryResolver interface { - CoreCheckNameAvailability(ctx context.Context, envName *string, resType entities.ResourceType, name string) (*domain.CheckNameAvailabilityOutput, error) + CoreCheckNameAvailability(ctx context.Context, envName *string, msvcName *string, resType entities.ResourceType, name string) (*domain.CheckNameAvailabilityOutput, error) CoreListEnvironments(ctx context.Context, search *model.SearchEnvironments, pq *repos.CursorPagination) (*model.EnvironmentPaginatedRecords, error) CoreGetEnvironment(ctx context.Context, name string) (*entities.Environment, error) CoreResyncEnvironment(ctx context.Context, name string) (bool, error) @@ -4561,7 +4561,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.CoreCheckNameAvailability(childComplexity, args["envName"].(*string), args["resType"].(entities.ResourceType), args["name"].(string)), true + return e.complexity.Query.CoreCheckNameAvailability(childComplexity, args["envName"].(*string), args["msvcName"].(*string), args["resType"].(entities.ResourceType), args["name"].(string)), true case "Query.core_getApp": if e.complexity.Query.CoreGetApp == nil { @@ -5620,11 +5620,7 @@ input CoreSearchVPNDevices { } type Query { - core_checkNameAvailability(envName: String, resType: ConsoleResType!, name: String!): ConsoleCheckNameAvailabilityOutput! @isLoggedIn @hasAccount - - # core_listProjects(search: SearchProjects, pq: CursorPaginationIn): ProjectPaginatedRecords @isLoggedInAndVerified @hasAccount - # core_getProject(name: String!): Project @isLoggedInAndVerified @hasAccount - # core_resyncProject(name: String!): Boolean! @isLoggedInAndVerified @hasAccount + core_checkNameAvailability(envName: String, msvcName: String ,resType: ConsoleResType!, name: String!): ConsoleCheckNameAvailabilityOutput! @isLoggedIn @hasAccount core_listEnvironments(search: SearchEnvironments, pq: CursorPaginationIn): EnvironmentPaginatedRecords @isLoggedInAndVerified @hasAccount core_getEnvironment(name: String!): Environment @isLoggedInAndVerified @hasAccount @@ -5660,29 +5656,18 @@ type Query { core_getManagedResouceOutputKeys(msvcName: String, envName:String , name: String!): [String!]! @isLoggedInAndVerified @hasAccount core_getManagedResouceOutputKeyValues(msvcName: String, envName:String, keyrefs: [ManagedResourceKeyRefIn]): [ManagedResourceKeyValueRef!]! @isLoggedInAndVerified @hasAccount + core_listManagedResources(search: SearchManagedResources, pq: CursorPaginationIn): ManagedResourcePaginatedRecords @isLoggedInAndVerified @hasAccount core_getManagedResource(msvcName: String, envName: String, name: String!): ManagedResource @isLoggedInAndVerified @hasAccount core_resyncManagedResource(msvcName: String!, name: String!): Boolean! @isLoggedInAndVerified @hasAccount - # core_listImportedManagedResources(envName: String! ,search: SearchManagedResources, pq: CursorPaginationIn): ManagedResourcePaginatedRecords @isLoggedInAndVerified @hasAccount - # core_getImportedManagedResource(envName: String!, name: String!): ManagedResource @isLoggedInAndVerified @hasAccount - core_listImportedManagedResources(envName: String!, search: SearchImportedManagedResources, pq: CursorPaginationIn): ImportedManagedResourcePaginatedRecords @isLoggedInAndVerified @hasAccount - # core_listProjectManagedServices(search: SearchProjectManagedService, pq: CursorPaginationIn): ProjectManagedServicePaginatedRecords @isLoggedInAndVerified @hasAccount - # core_getProjectManagedService( name: String!): ProjectManagedService @isLoggedInAndVerified @hasAccount - # core_resyncProjectManagedService(name: String!): Boolean! @isLoggedInAndVerified @hasAccount - # core_restartProjectManagedService(name: String!): Boolean! @isLoggedInAndVerified @hasAccount - core_listVPNDevices(search: CoreSearchVPNDevices, pq: CursorPaginationIn): ConsoleVPNDevicePaginatedRecords @isLoggedInAndVerified @hasAccount core_listVPNDevicesForUser: [ConsoleVPNDevice!] @isLoggedInAndVerified @hasAccount core_getVPNDevice(name: String!): ConsoleVPNDevice @isLoggedInAndVerified @hasAccount } type Mutation { - # core_createProject(project: ProjectIn!): Project @isLoggedInAndVerified @hasAccount - # core_updateProject(project: ProjectIn!): Project @isLoggedInAndVerified @hasAccount - # core_deleteProject(name: String!): Boolean! @isLoggedInAndVerified @hasAccount - core_createEnvironment(env: EnvironmentIn!): Environment @isLoggedInAndVerified @hasAccount core_updateEnvironment(env: EnvironmentIn!): Environment @isLoggedInAndVerified @hasAccount core_deleteEnvironment(envName: String!): Boolean! @isLoggedInAndVerified @hasAccount @@ -5719,16 +5704,9 @@ type Mutation { core_updateManagedResource(msvcName: String!, mres: ManagedResourceIn!): ManagedResource @isLoggedInAndVerified @hasAccount core_deleteManagedResource(msvcName: String!, mresName: String!): Boolean! @isLoggedInAndVerified @hasAccount - # core_importManagedResource(envName: String!, msvcName: String!, mresName: String!, importName: String!): ManagedResource @isLoggedInAndVerified @hasAccount - # core_deleteImportedManagedResource(envName: String!, importName: String!): Boolean! @isLoggedInAndVerified @hasAccount - core_importManagedResource(envName: String!, msvcName: String!, mresName: String!, importName: String!): ImportedManagedResource @isLoggedInAndVerified @hasAccount core_deleteImportedManagedResource(envName: String!, importName: String!): Boolean! @isLoggedInAndVerified @hasAccount - # core_createProjectManagedService(pmsvc: ProjectManagedServiceIn!): ProjectManagedService @isLoggedInAndVerified @hasAccount - # core_updateProjectManagedService(pmsvc: ProjectManagedServiceIn!): ProjectManagedService @isLoggedInAndVerified @hasAccount - # core_deleteProjectManagedService(pmsvcName: String!): Boolean! @isLoggedInAndVerified @hasAccount - core_createVPNDevice(vpnDevice: ConsoleVPNDeviceIn!): ConsoleVPNDevice @isLoggedInAndVerified @hasAccount core_updateVPNDevice(vpnDevice: ConsoleVPNDeviceIn!): ConsoleVPNDevice @isLoggedInAndVerified @hasAccount @@ -8097,24 +8075,33 @@ func (ec *executionContext) field_Query_core_checkNameAvailability_args(ctx cont } } args["envName"] = arg0 - var arg1 entities.ResourceType + var arg1 *string + if tmp, ok := rawArgs["msvcName"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("msvcName")) + arg1, err = ec.unmarshalOString2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["msvcName"] = arg1 + var arg2 entities.ResourceType if tmp, ok := rawArgs["resType"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("resType")) - arg1, err = ec.unmarshalNConsoleResType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋconsoleᚋinternalᚋentitiesᚐResourceType(ctx, tmp) + arg2, err = ec.unmarshalNConsoleResType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋconsoleᚋinternalᚋentitiesᚐResourceType(ctx, tmp) if err != nil { return nil, err } } - args["resType"] = arg1 - var arg2 string + args["resType"] = arg2 + var arg3 string if tmp, ok := rawArgs["name"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) - arg2, err = ec.unmarshalNString2string(ctx, tmp) + arg3, err = ec.unmarshalNString2string(ctx, tmp) if err != nil { return nil, err } } - args["name"] = arg2 + args["name"] = arg3 return args, nil } @@ -31847,7 +31834,7 @@ func (ec *executionContext) _Query_core_checkNameAvailability(ctx context.Contex resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { directive0 := func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().CoreCheckNameAvailability(rctx, fc.Args["envName"].(*string), fc.Args["resType"].(entities.ResourceType), fc.Args["name"].(string)) + return ec.resolvers.Query().CoreCheckNameAvailability(rctx, fc.Args["envName"].(*string), fc.Args["msvcName"].(*string), fc.Args["resType"].(entities.ResourceType), fc.Args["name"].(string)) } directive1 := func(ctx context.Context) (interface{}, error) { if ec.directives.IsLoggedIn == nil { diff --git a/apps/console/internal/app/graph/schema.graphqls b/apps/console/internal/app/graph/schema.graphqls index e90567021..370aa649f 100644 --- a/apps/console/internal/app/graph/schema.graphqls +++ b/apps/console/internal/app/graph/schema.graphqls @@ -94,7 +94,7 @@ input CoreSearchVPNDevices { } type Query { - core_checkNameAvailability(envName: String, resType: ConsoleResType!, name: String!): ConsoleCheckNameAvailabilityOutput! @isLoggedIn @hasAccount + core_checkNameAvailability(envName: String, msvcName: String ,resType: ConsoleResType!, name: String!): ConsoleCheckNameAvailabilityOutput! @isLoggedIn @hasAccount core_listEnvironments(search: SearchEnvironments, pq: CursorPaginationIn): EnvironmentPaginatedRecords @isLoggedInAndVerified @hasAccount core_getEnvironment(name: String!): Environment @isLoggedInAndVerified @hasAccount diff --git a/apps/console/internal/app/graph/schema.resolvers.go b/apps/console/internal/app/graph/schema.resolvers.go index 3ff30bfde..dd5ee389c 100644 --- a/apps/console/internal/app/graph/schema.resolvers.go +++ b/apps/console/internal/app/graph/schema.resolvers.go @@ -446,12 +446,12 @@ func (r *mutationResolver) CoreDeleteVPNDevice(ctx context.Context, deviceName s } // CoreCheckNameAvailability is the resolver for the core_checkNameAvailability field. -func (r *queryResolver) CoreCheckNameAvailability(ctx context.Context, envName *string, resType entities.ResourceType, name string) (*domain.CheckNameAvailabilityOutput, error) { +func (r *queryResolver) CoreCheckNameAvailability(ctx context.Context, envName *string, msvcName *string, resType entities.ResourceType, name string) (*domain.CheckNameAvailabilityOutput, error) { cc, err := toConsoleContext(ctx) if err != nil { return nil, err } - return r.Domain.CheckNameAvailability(ctx, cc.AccountName, envName, resType, name) + return r.Domain.CheckNameAvailability(ctx, cc.AccountName, envName, msvcName, resType, name) } // CoreListEnvironments is the resolver for the core_listEnvironments field. diff --git a/apps/console/internal/domain/api.go b/apps/console/internal/domain/api.go index cc23a84d9..5158e560f 100644 --- a/apps/console/internal/domain/api.go +++ b/apps/console/internal/domain/api.go @@ -134,7 +134,7 @@ type UpdateAndDeleteOpts struct { } type Domain interface { - CheckNameAvailability(ctx context.Context, accountName string, environmentName *string, resType entities.ResourceType, name string) (*CheckNameAvailabilityOutput, error) + CheckNameAvailability(ctx context.Context, accountName string, environmentName *string, msvcName *string, resType entities.ResourceType, name string) (*CheckNameAvailabilityOutput, error) // INFO: project have been disabled // ListProjects(ctx context.Context, userId repos.ID, accountName string, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Project], error) diff --git a/apps/console/internal/domain/names.go b/apps/console/internal/domain/names.go index ff84c2539..92d296e24 100644 --- a/apps/console/internal/domain/names.go +++ b/apps/console/internal/domain/names.go @@ -2,6 +2,7 @@ package domain import ( "context" + fc "github.com/kloudlite/api/apps/console/internal/entities/field-constants" "github.com/kloudlite/api/common/fields" @@ -27,11 +28,15 @@ func checkResourceName[T repos.Entity](ctx context.Context, filters repos.Filter }, nil } -func (d *domain) CheckNameAvailability(ctx context.Context, accountName string, environmentName *string, resType entities.ResourceType, name string) (*CheckNameAvailabilityOutput, error) { +func (d *domain) CheckNameAvailability(ctx context.Context, accountName string, environmentName *string, msvcName *string, resType entities.ResourceType, name string) (*CheckNameAvailabilityOutput, error) { errEnvironmentRequired := func() error { return errors.Newf("param environmentName is required for resource type %q", resType) } + errMsvcNameRequired := func() error { + return errors.Newf("param msvcName is required for resource type %q", resType) + } + if !fn.IsValidK8sResourceName(name) { return &CheckNameAvailabilityOutput{ Result: false, @@ -51,7 +56,10 @@ func (d *domain) CheckNameAvailability(ctx context.Context, accountName string, case entities.ResourceTypeManagedResource: { - return checkResourceName(ctx, repos.Filter{fields.AccountName: accountName, fields.MetadataName: name}, d.mresRepo) + if msvcName == nil { + return nil, errMsvcNameRequired() + } + return checkResourceName(ctx, repos.Filter{fields.AccountName: accountName, fields.MetadataName: name, fc.ManagedResourceManagedServiceName: msvcName}, d.mresRepo) } default: From beb9b896c9d38a05d8a886c3f35fe207062dcb66 Mon Sep 17 00:00:00 2001 From: Piyush Kumar Date: Thu, 11 Jul 2024 11:15:40 +0530 Subject: [PATCH 2/2] remove device intercepts while switching environment in cli --- .../internal/app/graph/generated/generated.go | 142 ++++++++++++++++++ .../internal/app/graph/schema.graphqls | 1 + .../internal/app/graph/schema.resolvers.go | 12 ++ apps/console/internal/domain/api.go | 1 + apps/console/internal/domain/app.go | 27 ++++ apps/console/internal/domain/domain.go | 14 +- 6 files changed, 190 insertions(+), 7 deletions(-) diff --git a/apps/console/internal/app/graph/generated/generated.go b/apps/console/internal/app/graph/generated/generated.go index 04c1f06cc..7af3bec07 100644 --- a/apps/console/internal/app/graph/generated/generated.go +++ b/apps/console/internal/app/graph/generated/generated.go @@ -821,6 +821,7 @@ type ComplexityRoot struct { CoreListSecrets func(childComplexity int, envName string, search *model.SearchSecrets, pq *repos.CursorPagination) int CoreListVPNDevices func(childComplexity int, search *model.CoreSearchVPNDevices, pq *repos.CursorPagination) int CoreListVPNDevicesForUser func(childComplexity int) int + CoreRemoveDeviceIntercepts func(childComplexity int, envName string, deviceName string) int CoreRestartApp func(childComplexity int, envName string, appName string) int CoreResyncApp func(childComplexity int, envName string, name string) int CoreResyncConfig func(childComplexity int, envName string, name string) int @@ -1061,6 +1062,7 @@ type QueryResolver interface { CoreGetApp(ctx context.Context, envName string, name string) (*entities.App, error) CoreResyncApp(ctx context.Context, envName string, name string) (bool, error) CoreRestartApp(ctx context.Context, envName string, appName string) (bool, error) + CoreRemoveDeviceIntercepts(ctx context.Context, envName string, deviceName string) (bool, error) CoreListExternalApps(ctx context.Context, envName string, search *model.SearchExternalApps, pq *repos.CursorPagination) (*model.ExternalAppPaginatedRecords, error) CoreGetExternalApp(ctx context.Context, envName string, name string) (*entities.ExternalApp, error) CoreResyncExternalApp(ctx context.Context, envName string, name string) (bool, error) @@ -4846,6 +4848,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.CoreListVPNDevicesForUser(childComplexity), true + case "Query.core_removeDeviceIntercepts": + if e.complexity.Query.CoreRemoveDeviceIntercepts == nil { + break + } + + args, err := ec.field_Query_core_removeDeviceIntercepts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.CoreRemoveDeviceIntercepts(childComplexity, args["envName"].(string), args["deviceName"].(string)), true + case "Query.core_restartApp": if e.complexity.Query.CoreRestartApp == nil { break @@ -5635,6 +5649,7 @@ type Query { core_getApp(envName: String!, name: String!): App @isLoggedInAndVerified @hasAccount core_resyncApp(envName: String!, name: String!): Boolean! @isLoggedInAndVerified @hasAccount core_restartApp(envName: String!, appName: String!): Boolean! @isLoggedInAndVerified @hasAccount + core_removeDeviceIntercepts(envName: String!, deviceName: String!): Boolean! @isLoggedInAndVerified @hasAccount core_listExternalApps(envName: String!, search: SearchExternalApps, pq: CursorPaginationIn): ExternalAppPaginatedRecords @isLoggedInAndVerified @hasAccount core_getExternalApp(envName: String!, name: String!): ExternalApp @isLoggedInAndVerified @hasAccount @@ -8711,6 +8726,30 @@ func (ec *executionContext) field_Query_core_listVPNDevices_args(ctx context.Con return args, nil } +func (ec *executionContext) field_Query_core_removeDeviceIntercepts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["envName"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("envName")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["envName"] = arg0 + var arg1 string + if tmp, ok := rawArgs["deviceName"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("deviceName")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["deviceName"] = arg1 + return args, nil +} + func (ec *executionContext) field_Query_core_restartApp_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -32834,6 +32873,87 @@ func (ec *executionContext) fieldContext_Query_core_restartApp(ctx context.Conte return fc, nil } +func (ec *executionContext) _Query_core_removeDeviceIntercepts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_core_removeDeviceIntercepts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().CoreRemoveDeviceIntercepts(rctx, fc.Args["envName"].(string), fc.Args["deviceName"].(string)) + } + directive1 := func(ctx context.Context) (interface{}, error) { + if ec.directives.IsLoggedInAndVerified == nil { + return nil, errors.New("directive isLoggedInAndVerified is not implemented") + } + return ec.directives.IsLoggedInAndVerified(ctx, nil, directive0) + } + directive2 := func(ctx context.Context) (interface{}, error) { + if ec.directives.HasAccount == nil { + return nil, errors.New("directive hasAccount is not implemented") + } + return ec.directives.HasAccount(ctx, nil, directive1) + } + + tmp, err := directive2(rctx) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(bool); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be bool`, tmp) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_core_removeDeviceIntercepts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_core_removeDeviceIntercepts_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Query_core_listExternalApps(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Query_core_listExternalApps(ctx, field) if err != nil { @@ -49514,6 +49634,28 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "core_removeDeviceIntercepts": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_core_removeDeviceIntercepts(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) case "core_listExternalApps": field := field diff --git a/apps/console/internal/app/graph/schema.graphqls b/apps/console/internal/app/graph/schema.graphqls index 370aa649f..ff221ef31 100644 --- a/apps/console/internal/app/graph/schema.graphqls +++ b/apps/console/internal/app/graph/schema.graphqls @@ -109,6 +109,7 @@ type Query { core_getApp(envName: String!, name: String!): App @isLoggedInAndVerified @hasAccount core_resyncApp(envName: String!, name: String!): Boolean! @isLoggedInAndVerified @hasAccount core_restartApp(envName: String!, appName: String!): Boolean! @isLoggedInAndVerified @hasAccount + core_removeDeviceIntercepts(envName: String!, deviceName: String!): Boolean! @isLoggedInAndVerified @hasAccount core_listExternalApps(envName: String!, search: SearchExternalApps, pq: CursorPaginationIn): ExternalAppPaginatedRecords @isLoggedInAndVerified @hasAccount core_getExternalApp(envName: String!, name: String!): ExternalApp @isLoggedInAndVerified @hasAccount diff --git a/apps/console/internal/app/graph/schema.resolvers.go b/apps/console/internal/app/graph/schema.resolvers.go index dd5ee389c..16fa2f249 100644 --- a/apps/console/internal/app/graph/schema.resolvers.go +++ b/apps/console/internal/app/graph/schema.resolvers.go @@ -612,6 +612,18 @@ func (r *queryResolver) CoreRestartApp(ctx context.Context, envName string, appN return true, nil } +// CoreRemoveDeviceIntercepts is the resolver for the core_removeDeviceIntercepts field. +func (r *queryResolver) CoreRemoveDeviceIntercepts(ctx context.Context, envName string, deviceName string) (bool, error) { + cc, err := toConsoleContext(ctx) + if err != nil { + return false, errors.NewE(err) + } + if err := r.Domain.RemoveDeviceIntercepts(newResourceContext(cc, envName), deviceName); err != nil { + return false, err + } + return true, nil +} + // CoreListExternalApps is the resolver for the core_listExternalApps field. func (r *queryResolver) CoreListExternalApps(ctx context.Context, envName string, search *model.SearchExternalApps, pq *repos.CursorPagination) (*model.ExternalAppPaginatedRecords, error) { cc, err := toConsoleContext(ctx) diff --git a/apps/console/internal/domain/api.go b/apps/console/internal/domain/api.go index 5158e560f..411a363fc 100644 --- a/apps/console/internal/domain/api.go +++ b/apps/console/internal/domain/api.go @@ -174,6 +174,7 @@ type Domain interface { InterceptApp(ctx ResourceContext, appName string, deviceName string, intercept bool, portMappings []crdsv1.AppInterceptPortMappings) (bool, error) RestartApp(ctx ResourceContext, appName string) error + RemoveDeviceIntercepts(ctx ResourceContext, deviceName string) error OnAppApplyError(ctx ResourceContext, errMsg string, name string, opts UpdateAndDeleteOpts) error OnAppDeleteMessage(ctx ResourceContext, app entities.App) error diff --git a/apps/console/internal/domain/app.go b/apps/console/internal/domain/app.go index fb1712162..0cf084f38 100644 --- a/apps/console/internal/domain/app.go +++ b/apps/console/internal/domain/app.go @@ -250,6 +250,33 @@ func (d *domain) RestartApp(ctx ResourceContext, appName string) error { return nil } +func (d *domain) RemoveDeviceIntercepts(ctx ResourceContext, deviceName string) error { + apps, err := d.appRepo.Find(ctx, repos.Query{ + Filter: repos.Filter{ + fields.AccountName: ctx.AccountName, + fields.EnvironmentName: ctx.EnvironmentName, + fc.AppSpecInterceptToDevice: deviceName, + }, + Sort: nil, + }) + if err != nil { + return errors.NewE(err) + } + + for i := range apps { + patchForUpdate := repos.Document{ + fc.AppSpecIntercept: nil, + } + + _, err := d.appRepo.PatchById(ctx, apps[i].Id, patchForUpdate) + if err != nil { + return errors.NewE(err) + } + } + + return nil +} + func (d *domain) OnAppUpdateMessage(ctx ResourceContext, app entities.App, status types.ResourceStatus, opts UpdateAndDeleteOpts) error { xApp, err := d.findApp(ctx, app.Name) if err != nil { diff --git a/apps/console/internal/domain/domain.go b/apps/console/internal/domain/domain.go index 77af9171f..f2f2d135e 100644 --- a/apps/console/internal/domain/domain.go +++ b/apps/console/internal/domain/domain.go @@ -49,14 +49,14 @@ type domain struct { environmentRepo repos.DbRepo[*entities.Environment] vpnDeviceRepo repos.DbRepo[*entities.ConsoleVPNDevice] - appRepo repos.DbRepo[*entities.App] - externalAppRepo repos.DbRepo[*entities.ExternalApp] - configRepo repos.DbRepo[*entities.Config] - secretRepo repos.DbRepo[*entities.Secret] - routerRepo repos.DbRepo[*entities.Router] - mresRepo repos.DbRepo[*entities.ManagedResource] + appRepo repos.DbRepo[*entities.App] + externalAppRepo repos.DbRepo[*entities.ExternalApp] + configRepo repos.DbRepo[*entities.Config] + secretRepo repos.DbRepo[*entities.Secret] + routerRepo repos.DbRepo[*entities.Router] + mresRepo repos.DbRepo[*entities.ManagedResource] importedMresRepo repos.DbRepo[*entities.ImportedManagedResource] - pullSecretsRepo repos.DbRepo[*entities.ImagePullSecret] + pullSecretsRepo repos.DbRepo[*entities.ImagePullSecret] envVars *env.Env