diff --git a/src/mapper/pkg/graph/generated/generated.go b/src/mapper/pkg/graph/generated/generated.go index e0b3ecba..47aceb46 100644 --- a/src/mapper/pkg/graph/generated/generated.go +++ b/src/mapper/pkg/graph/generated/generated.go @@ -74,6 +74,7 @@ type ComplexityRoot struct { Mutation struct { ReportAWSOperation func(childComplexity int, operation []model.AWSOperation) int + ReportAWSOperation2 func(childComplexity int, operation []model.AWSOperationWithIdentity) int ReportAzureOperation func(childComplexity int, operation []model.AzureOperation) int ReportCaptureResults func(childComplexity int, results model.CaptureResults) int ReportIstioConnectionResults func(childComplexity int, results model.IstioConnectionResults) int @@ -116,6 +117,7 @@ type MutationResolver interface { ReportKafkaMapperResults(ctx context.Context, results model.KafkaMapperResults) (bool, error) ReportIstioConnectionResults(ctx context.Context, results model.IstioConnectionResults) (bool, error) ReportAWSOperation(ctx context.Context, operation []model.AWSOperation) (bool, error) + ReportAWSOperation2(ctx context.Context, operation []model.AWSOperationWithIdentity) (bool, error) ReportAzureOperation(ctx context.Context, operation []model.AzureOperation) (bool, error) } type QueryResolver interface { @@ -246,6 +248,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.ReportAWSOperation(childComplexity, args["operation"].([]model.AWSOperation)), true + case "Mutation.reportAWSOperation2": + if e.complexity.Mutation.ReportAWSOperation2 == nil { + break + } + + args, err := ec.field_Mutation_reportAWSOperation2_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.ReportAWSOperation2(childComplexity, args["operation"].([]model.AWSOperationWithIdentity)), true + case "Mutation.reportAzureOperation": if e.complexity.Mutation.ReportAzureOperation == nil { break @@ -428,6 +442,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec := executionContext{rc, e, 0, 0, make(chan graphql.DeferredResult)} inputUnmarshalMap := graphql.BuildUnmarshalerMap( ec.unmarshalInputAWSOperation, + ec.unmarshalInputAWSOperationWithIdentity, ec.unmarshalInputAzureOperation, ec.unmarshalInputCaptureResults, ec.unmarshalInputCaptureTCPResults, @@ -683,6 +698,13 @@ input AWSOperation { srcIp: String! } +input AWSOperationWithIdentity { + resource: String! + actions: [String!]! + clientName: String! + clientNamespace: String! +} + input ServerFilter { name: String! namespace: String! @@ -731,8 +753,12 @@ type Mutation { reportSocketScanResults(results: SocketScanResults!): Boolean! reportKafkaMapperResults(results: KafkaMapperResults!): Boolean! reportIstioConnectionResults(results: IstioConnectionResults!): Boolean! + reportAWSOperation(operation: [AWSOperation!]!): Boolean! + reportAWSOperation2(operation: [AWSOperationWithIdentity!]!): Boolean! + reportAzureOperation(operation: [AzureOperation!]!): Boolean! + }`, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) @@ -741,6 +767,21 @@ var parsedSchema = gqlparser.MustLoadSchema(sources...) // region ***************************** args.gotpl ***************************** +func (ec *executionContext) field_Mutation_reportAWSOperation2_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 []model.AWSOperationWithIdentity + if tmp, ok := rawArgs["operation"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("operation")) + arg0, err = ec.unmarshalNAWSOperationWithIdentity2ᚕgithubᚗcomᚋotterizeᚋnetworkᚑmapperᚋsrcᚋmapperᚋpkgᚋgraphᚋmodelᚐAWSOperationWithIdentityᚄ(ctx, tmp) + if err != nil { + return nil, err + } + } + args["operation"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_reportAWSOperation_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1944,6 +1985,61 @@ func (ec *executionContext) fieldContext_Mutation_reportAWSOperation(ctx context return fc, nil } +func (ec *executionContext) _Mutation_reportAWSOperation2(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_reportAWSOperation2(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) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().ReportAWSOperation2(rctx, fc.Args["operation"].([]model.AWSOperationWithIdentity)) + }) + 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_Mutation_reportAWSOperation2(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + 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_Mutation_reportAWSOperation2_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Mutation_reportAzureOperation(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Mutation_reportAzureOperation(ctx, field) if err != nil { @@ -4541,6 +4637,54 @@ func (ec *executionContext) unmarshalInputAWSOperation(ctx context.Context, obj return it, nil } +func (ec *executionContext) unmarshalInputAWSOperationWithIdentity(ctx context.Context, obj interface{}) (model.AWSOperationWithIdentity, error) { + var it model.AWSOperationWithIdentity + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"resource", "actions", "clientName", "clientNamespace"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "resource": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("resource")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Resource = data + case "actions": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("actions")) + data, err := ec.unmarshalNString2ᚕstringᚄ(ctx, v) + if err != nil { + return it, err + } + it.Actions = data + case "clientName": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clientName")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.ClientName = data + case "clientNamespace": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("clientNamespace")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.ClientNamespace = data + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputAzureOperation(ctx context.Context, obj interface{}) (model.AzureOperation, error) { var it model.AzureOperation asMap := map[string]interface{}{} @@ -5255,6 +5399,13 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "reportAWSOperation2": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_reportAWSOperation2(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "reportAzureOperation": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_reportAzureOperation(ctx, field) @@ -5887,6 +6038,28 @@ func (ec *executionContext) unmarshalNAWSOperation2ᚕgithubᚗcomᚋotterizeᚋ return res, nil } +func (ec *executionContext) unmarshalNAWSOperationWithIdentity2githubᚗcomᚋotterizeᚋnetworkᚑmapperᚋsrcᚋmapperᚋpkgᚋgraphᚋmodelᚐAWSOperationWithIdentity(ctx context.Context, v interface{}) (model.AWSOperationWithIdentity, error) { + res, err := ec.unmarshalInputAWSOperationWithIdentity(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalNAWSOperationWithIdentity2ᚕgithubᚗcomᚋotterizeᚋnetworkᚑmapperᚋsrcᚋmapperᚋpkgᚋgraphᚋmodelᚐAWSOperationWithIdentityᚄ(ctx context.Context, v interface{}) ([]model.AWSOperationWithIdentity, error) { + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]model.AWSOperationWithIdentity, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNAWSOperationWithIdentity2githubᚗcomᚋotterizeᚋnetworkᚑmapperᚋsrcᚋmapperᚋpkgᚋgraphᚋmodelᚐAWSOperationWithIdentity(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + func (ec *executionContext) unmarshalNAzureOperation2githubᚗcomᚋotterizeᚋnetworkᚑmapperᚋsrcᚋmapperᚋpkgᚋgraphᚋmodelᚐAzureOperation(ctx context.Context, v interface{}) (model.AzureOperation, error) { res, err := ec.unmarshalInputAzureOperation(ctx, v) return res, graphql.ErrorOnPath(ctx, err) diff --git a/src/mapper/pkg/graph/model/models_gen.go b/src/mapper/pkg/graph/model/models_gen.go index f23c0425..41c07c50 100644 --- a/src/mapper/pkg/graph/model/models_gen.go +++ b/src/mapper/pkg/graph/model/models_gen.go @@ -15,6 +15,13 @@ type AWSOperation struct { SrcIP string `json:"srcIp"` } +type AWSOperationWithIdentity struct { + Resource string `json:"resource"` + Actions []string `json:"actions"` + ClientName string `json:"clientName"` + ClientNamespace string `json:"clientNamespace"` +} + type AzureOperation struct { Scope string `json:"scope"` Actions []string `json:"actions"` diff --git a/src/mapper/pkg/resolvers/schema.resolvers.go b/src/mapper/pkg/resolvers/schema.resolvers.go index 21edb968..69d64629 100644 --- a/src/mapper/pkg/resolvers/schema.resolvers.go +++ b/src/mapper/pkg/resolvers/schema.resolvers.go @@ -6,6 +6,7 @@ package resolvers import ( "context" + "fmt" "github.com/otterize/intents-operator/src/shared/errors" "github.com/otterize/network-mapper/src/mapper/pkg/graph/generated" "github.com/otterize/network-mapper/src/mapper/pkg/graph/model" @@ -107,6 +108,11 @@ func (r *mutationResolver) ReportAWSOperation(ctx context.Context, operation []m } } +// ReportAWSOperation2 is the resolver for the reportAWSOperation2 field. +func (r *mutationResolver) ReportAWSOperation2(ctx context.Context, operation []model.AWSOperationWithIdentity) (bool, error) { + panic(fmt.Errorf("not implemented: ReportAWSOperation2 - reportAWSOperation2")) +} + // ReportAzureOperation is the resolver for the reportAzureOperation field. func (r *mutationResolver) ReportAzureOperation(ctx context.Context, operation []model.AzureOperation) (bool, error) { select { diff --git a/src/mapperclient/generated.go b/src/mapperclient/generated.go index f51bc045..d28c7881 100644 --- a/src/mapperclient/generated.go +++ b/src/mapperclient/generated.go @@ -25,6 +25,25 @@ func (v *AWSOperation) GetActions() []string { return v.Actions } // GetSrcIp returns AWSOperation.SrcIp, and is useful for accessing the field via an interface. func (v *AWSOperation) GetSrcIp() string { return v.SrcIp } +type AWSOperationWithIdentity struct { + Resource string `json:"resource"` + Actions []string `json:"actions"` + ClientName string `json:"clientName"` + ClientNamespace string `json:"clientNamespace"` +} + +// GetResource returns AWSOperationWithIdentity.Resource, and is useful for accessing the field via an interface. +func (v *AWSOperationWithIdentity) GetResource() string { return v.Resource } + +// GetActions returns AWSOperationWithIdentity.Actions, and is useful for accessing the field via an interface. +func (v *AWSOperationWithIdentity) GetActions() []string { return v.Actions } + +// GetClientName returns AWSOperationWithIdentity.ClientName, and is useful for accessing the field via an interface. +func (v *AWSOperationWithIdentity) GetClientName() string { return v.ClientName } + +// GetClientNamespace returns AWSOperationWithIdentity.ClientNamespace, and is useful for accessing the field via an interface. +func (v *AWSOperationWithIdentity) GetClientNamespace() string { return v.ClientNamespace } + type AzureOperation struct { Scope string `json:"scope"` Actions []string `json:"actions"` @@ -149,6 +168,14 @@ type SocketScanResults struct { // GetResults returns SocketScanResults.Results, and is useful for accessing the field via an interface. func (v *SocketScanResults) GetResults() []RecordedDestinationsForSrc { return v.Results } +// __reportAWSOperation2Input is used internally by genqlient +type __reportAWSOperation2Input struct { + Operation []AWSOperationWithIdentity `json:"operation"` +} + +// GetOperation returns __reportAWSOperation2Input.Operation, and is useful for accessing the field via an interface. +func (v *__reportAWSOperation2Input) GetOperation() []AWSOperationWithIdentity { return v.Operation } + // __reportAWSOperationInput is used internally by genqlient type __reportAWSOperationInput struct { Operation []AWSOperation `json:"operation"` @@ -197,6 +224,14 @@ type __reportTCPCaptureResultsInput struct { // GetResults returns __reportTCPCaptureResultsInput.Results, and is useful for accessing the field via an interface. func (v *__reportTCPCaptureResultsInput) GetResults() CaptureTCPResults { return v.Results } +// reportAWSOperation2Response is returned by reportAWSOperation2 on success. +type reportAWSOperation2Response struct { + ReportAWSOperation2 bool `json:"reportAWSOperation2"` +} + +// GetReportAWSOperation2 returns reportAWSOperation2Response.ReportAWSOperation2, and is useful for accessing the field via an interface. +func (v *reportAWSOperation2Response) GetReportAWSOperation2() bool { return v.ReportAWSOperation2 } + // reportAWSOperationResponse is returned by reportAWSOperation on success. type reportAWSOperationResponse struct { ReportAWSOperation bool `json:"reportAWSOperation"` @@ -313,6 +348,39 @@ func reportAWSOperation( return &data_, err_ } +// The query or mutation executed by reportAWSOperation2. +const reportAWSOperation2_Operation = ` +mutation reportAWSOperation2 ($operation: [AWSOperationWithIdentity!]!) { + reportAWSOperation2(operation: $operation) +} +` + +func reportAWSOperation2( + ctx_ context.Context, + client_ graphql.Client, + operation []AWSOperationWithIdentity, +) (*reportAWSOperation2Response, error) { + req_ := &graphql.Request{ + OpName: "reportAWSOperation2", + Query: reportAWSOperation2_Operation, + Variables: &__reportAWSOperation2Input{ + Operation: operation, + }, + } + var err_ error + + var data_ reportAWSOperation2Response + resp_ := &graphql.Response{Data: &data_} + + err_ = client_.MakeRequest( + ctx_, + req_, + resp_, + ) + + return &data_, err_ +} + // The query or mutation executed by reportAzureOperation. const reportAzureOperation_Operation = ` mutation reportAzureOperation ($operation: [AzureOperation!]!) { diff --git a/src/mapperclient/operations.graphql b/src/mapperclient/operations.graphql index b933c862..c8a8da50 100644 --- a/src/mapperclient/operations.graphql +++ b/src/mapperclient/operations.graphql @@ -18,6 +18,10 @@ mutation reportAWSOperation($operation: [AWSOperation!]!) { reportAWSOperation(operation: $operation) } +mutation reportAWSOperation2($operation: [AWSOperationWithIdentity!]!) { + reportAWSOperation2(operation: $operation) +} + mutation reportAzureOperation($operation: [AzureOperation!]!) { reportAzureOperation(operation: $operation) } diff --git a/src/mappergraphql/schema.graphql b/src/mappergraphql/schema.graphql index 148aec94..ea452ca0 100644 --- a/src/mappergraphql/schema.graphql +++ b/src/mappergraphql/schema.graphql @@ -145,6 +145,13 @@ input AWSOperation { srcIp: String! } +input AWSOperationWithIdentity { + resource: String! + actions: [String!]! + clientName: String! + clientNamespace: String! +} + input ServerFilter { name: String! namespace: String! @@ -193,6 +200,10 @@ type Mutation { reportSocketScanResults(results: SocketScanResults!): Boolean! reportKafkaMapperResults(results: KafkaMapperResults!): Boolean! reportIstioConnectionResults(results: IstioConnectionResults!): Boolean! + reportAWSOperation(operation: [AWSOperation!]!): Boolean! + reportAWSOperation2(operation: [AWSOperationWithIdentity!]!): Boolean! + reportAzureOperation(operation: [AzureOperation!]!): Boolean! + } \ No newline at end of file