diff --git a/go.mod b/go.mod index a6b24b2b..bd34a0ba 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.25.2 require ( github.com/SAP/go-hdb v1.14.5 - github.com/conductorone/baton-sdk v0.5.16 + github.com/conductorone/baton-sdk v0.5.25 github.com/elliotchance/phpserialize v1.4.0 github.com/ennyjfrick/ruleguard-logfatal v0.0.2 github.com/go-sql-driver/mysql v1.9.2 diff --git a/go.sum b/go.sum index 423ddb9c..114256f4 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,8 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/conductorone/baton-sdk v0.5.16 h1:GCgzgaL39bP6q1+398TFEGJgGvC9QK83b/vE4DfdEdg= -github.com/conductorone/baton-sdk v0.5.16/go.mod h1:TQuaFYyonGW1Xblxjm+qQE3XsJGAZvTMPGaO4c4Yv6E= +github.com/conductorone/baton-sdk v0.5.25 h1:G0+MVkqwB4lGF0FbHDFh1Zt1fPsqn7gGGQWJx88w58Q= +github.com/conductorone/baton-sdk v0.5.25/go.mod h1:TQuaFYyonGW1Xblxjm+qQE3XsJGAZvTMPGaO4c4Yv6E= github.com/conductorone/dpop v0.2.4 h1:PaiDOX1gAIXtOJPxXf08GsGkpCuT/iECEjSJzLpi0zU= github.com/conductorone/dpop v0.2.4/go.mod h1:gyo8TtzB9SCFCsjsICH4IaLZ7y64CcrDXMOPBwfq/3s= github.com/conductorone/dpop/integrations/dpop_grpc v0.2.4 h1:lYxYi9/WTSL9sE96CO0QF2BY3kehs8dTTApI134TGCA= diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config.pb.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config.pb.go index 10482b57..14ec079e 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config.pb.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config.pb.go @@ -439,6 +439,7 @@ type FieldGroup struct { DisplayName string `protobuf:"bytes,2,opt,name=display_name,json=displayName,proto3" json:"display_name,omitempty"` HelpText string `protobuf:"bytes,3,opt,name=help_text,json=helpText,proto3" json:"help_text,omitempty"` Fields []string `protobuf:"bytes,4,rep,name=fields,proto3" json:"fields,omitempty"` + Default bool `protobuf:"varint,5,opt,name=default,proto3" json:"default,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -496,6 +497,13 @@ func (x *FieldGroup) GetFields() []string { return nil } +func (x *FieldGroup) GetDefault() bool { + if x != nil { + return x.Default + } + return false +} + func (x *FieldGroup) SetName(v string) { x.Name = v } @@ -512,6 +520,10 @@ func (x *FieldGroup) SetFields(v []string) { x.Fields = v } +func (x *FieldGroup) SetDefault(v bool) { + x.Default = v +} + type FieldGroup_builder struct { _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. @@ -519,6 +531,7 @@ type FieldGroup_builder struct { DisplayName string HelpText string Fields []string + Default bool } func (b0 FieldGroup_builder) Build() *FieldGroup { @@ -529,6 +542,7 @@ func (b0 FieldGroup_builder) Build() *FieldGroup { x.DisplayName = b.DisplayName x.HelpText = b.HelpText x.Fields = b.Fields + x.Default = b.Default return m0 } @@ -1514,13 +1528,14 @@ const file_c1_config_v1_config_proto_rawDesc = "" + "\x15secondary_field_names\x18\x03 \x03(\tR\x13secondaryFieldNames\x12\x12\n" + "\x04name\x18\x04 \x01(\tR\x04name\x12\x1b\n" + "\thelp_text\x18\x05 \x01(\tR\bhelpText\x12$\n" + - "\x0eis_field_group\x18\x06 \x01(\bR\fisFieldGroup\"x\n" + + "\x0eis_field_group\x18\x06 \x01(\bR\fisFieldGroup\"\x92\x01\n" + "\n" + "FieldGroup\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12!\n" + "\fdisplay_name\x18\x02 \x01(\tR\vdisplayName\x12\x1b\n" + "\thelp_text\x18\x03 \x01(\tR\bhelpText\x12\x16\n" + - "\x06fields\x18\x04 \x03(\tR\x06fields\"\xab\x04\n" + + "\x06fields\x18\x04 \x03(\tR\x06fields\x12\x18\n" + + "\adefault\x18\x05 \x01(\bR\adefault\"\xab\x04\n" + "\x05Field\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12!\n" + "\fdisplay_name\x18\x02 \x01(\tR\vdisplayName\x12 \n" + diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config.pb.validate.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config.pb.validate.go index 523c7c7b..ff0ca67d 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config.pb.validate.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config.pb.validate.go @@ -386,6 +386,8 @@ func (m *FieldGroup) validate(all bool) error { // no validation rules for HelpText + // no validation rules for Default + if len(errors) > 0 { return FieldGroupMultiError(errors) } diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config_protoopaque.pb.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config_protoopaque.pb.go index 763ebc8b..5dd83dbf 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config_protoopaque.pb.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/config/v1/config_protoopaque.pb.go @@ -445,6 +445,7 @@ type FieldGroup struct { xxx_hidden_DisplayName string `protobuf:"bytes,2,opt,name=display_name,json=displayName,proto3"` xxx_hidden_HelpText string `protobuf:"bytes,3,opt,name=help_text,json=helpText,proto3"` xxx_hidden_Fields []string `protobuf:"bytes,4,rep,name=fields,proto3"` + xxx_hidden_Default bool `protobuf:"varint,5,opt,name=default,proto3"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -502,6 +503,13 @@ func (x *FieldGroup) GetFields() []string { return nil } +func (x *FieldGroup) GetDefault() bool { + if x != nil { + return x.xxx_hidden_Default + } + return false +} + func (x *FieldGroup) SetName(v string) { x.xxx_hidden_Name = v } @@ -518,6 +526,10 @@ func (x *FieldGroup) SetFields(v []string) { x.xxx_hidden_Fields = v } +func (x *FieldGroup) SetDefault(v bool) { + x.xxx_hidden_Default = v +} + type FieldGroup_builder struct { _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. @@ -525,6 +537,7 @@ type FieldGroup_builder struct { DisplayName string HelpText string Fields []string + Default bool } func (b0 FieldGroup_builder) Build() *FieldGroup { @@ -535,6 +548,7 @@ func (b0 FieldGroup_builder) Build() *FieldGroup { x.xxx_hidden_DisplayName = b.DisplayName x.xxx_hidden_HelpText = b.HelpText x.xxx_hidden_Fields = b.Fields + x.xxx_hidden_Default = b.Default return m0 } @@ -1506,13 +1520,14 @@ const file_c1_config_v1_config_proto_rawDesc = "" + "\x15secondary_field_names\x18\x03 \x03(\tR\x13secondaryFieldNames\x12\x12\n" + "\x04name\x18\x04 \x01(\tR\x04name\x12\x1b\n" + "\thelp_text\x18\x05 \x01(\tR\bhelpText\x12$\n" + - "\x0eis_field_group\x18\x06 \x01(\bR\fisFieldGroup\"x\n" + + "\x0eis_field_group\x18\x06 \x01(\bR\fisFieldGroup\"\x92\x01\n" + "\n" + "FieldGroup\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12!\n" + "\fdisplay_name\x18\x02 \x01(\tR\vdisplayName\x12\x1b\n" + "\thelp_text\x18\x03 \x01(\tR\bhelpText\x12\x16\n" + - "\x06fields\x18\x04 \x03(\tR\x06fields\"\xab\x04\n" + + "\x06fields\x18\x04 \x03(\tR\x06fields\x12\x18\n" + + "\adefault\x18\x05 \x01(\bR\adefault\"\xab\x04\n" + "\x05Field\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12!\n" + "\fdisplay_name\x18\x02 \x01(\tR\vdisplayName\x12 \n" + diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant.pb.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant.pb.go index d993d3e8..65fa98c4 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant.pb.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant.pb.go @@ -347,6 +347,50 @@ func (b0 GrantAlreadyRevoked_builder) Build() *GrantAlreadyRevoked { return m0 } +// If a resource for a grant doesn't exist, insert it. +type InsertResourceGrants struct { + state protoimpl.MessageState `protogen:"hybrid.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *InsertResourceGrants) Reset() { + *x = InsertResourceGrants{} + mi := &file_c1_connector_v2_annotation_grant_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *InsertResourceGrants) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InsertResourceGrants) ProtoMessage() {} + +func (x *InsertResourceGrants) ProtoReflect() protoreflect.Message { + mi := &file_c1_connector_v2_annotation_grant_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +type InsertResourceGrants_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + +} + +func (b0 InsertResourceGrants_builder) Build() *InsertResourceGrants { + m0 := &InsertResourceGrants{} + b, x := &b0, m0 + _, _ = b, x + return m0 +} + var File_c1_connector_v2_annotation_grant_proto protoreflect.FileDescriptor const file_c1_connector_v2_annotation_grant_proto_rawDesc = "" + @@ -362,20 +406,22 @@ const file_c1_connector_v2_annotation_grant_proto_rawDesc = "" + "\tsource_id\x18\x01 \x01(\tR\bsourceId\x123\n" + "\bmetadata\x18\x02 \x01(\v2\x17.google.protobuf.StructR\bmetadata\"\x14\n" + "\x12GrantAlreadyExists\"\x15\n" + - "\x13GrantAlreadyRevokedB6Z4github.com/conductorone/baton-sdk/pb/c1/connector/v2b\x06proto3" + "\x13GrantAlreadyRevoked\"\x16\n" + + "\x14InsertResourceGrantsB6Z4github.com/conductorone/baton-sdk/pb/c1/connector/v2b\x06proto3" -var file_c1_connector_v2_annotation_grant_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_c1_connector_v2_annotation_grant_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_c1_connector_v2_annotation_grant_proto_goTypes = []any{ - (*GrantMetadata)(nil), // 0: c1.connector.v2.GrantMetadata - (*GrantExpandable)(nil), // 1: c1.connector.v2.GrantExpandable - (*GrantImmutable)(nil), // 2: c1.connector.v2.GrantImmutable - (*GrantAlreadyExists)(nil), // 3: c1.connector.v2.GrantAlreadyExists - (*GrantAlreadyRevoked)(nil), // 4: c1.connector.v2.GrantAlreadyRevoked - (*structpb.Struct)(nil), // 5: google.protobuf.Struct + (*GrantMetadata)(nil), // 0: c1.connector.v2.GrantMetadata + (*GrantExpandable)(nil), // 1: c1.connector.v2.GrantExpandable + (*GrantImmutable)(nil), // 2: c1.connector.v2.GrantImmutable + (*GrantAlreadyExists)(nil), // 3: c1.connector.v2.GrantAlreadyExists + (*GrantAlreadyRevoked)(nil), // 4: c1.connector.v2.GrantAlreadyRevoked + (*InsertResourceGrants)(nil), // 5: c1.connector.v2.InsertResourceGrants + (*structpb.Struct)(nil), // 6: google.protobuf.Struct } var file_c1_connector_v2_annotation_grant_proto_depIdxs = []int32{ - 5, // 0: c1.connector.v2.GrantMetadata.metadata:type_name -> google.protobuf.Struct - 5, // 1: c1.connector.v2.GrantImmutable.metadata:type_name -> google.protobuf.Struct + 6, // 0: c1.connector.v2.GrantMetadata.metadata:type_name -> google.protobuf.Struct + 6, // 1: c1.connector.v2.GrantImmutable.metadata:type_name -> google.protobuf.Struct 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name @@ -394,7 +440,7 @@ func file_c1_connector_v2_annotation_grant_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_c1_connector_v2_annotation_grant_proto_rawDesc), len(file_c1_connector_v2_annotation_grant_proto_rawDesc)), NumEnums: 0, - NumMessages: 5, + NumMessages: 6, NumExtensions: 0, NumServices: 0, }, diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant.pb.validate.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant.pb.validate.go index 33017b39..399f62ae 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant.pb.validate.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant.pb.validate.go @@ -600,3 +600,105 @@ var _ interface { Cause() error ErrorName() string } = GrantAlreadyRevokedValidationError{} + +// Validate checks the field values on InsertResourceGrants with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *InsertResourceGrants) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on InsertResourceGrants with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// InsertResourceGrantsMultiError, or nil if none found. +func (m *InsertResourceGrants) ValidateAll() error { + return m.validate(true) +} + +func (m *InsertResourceGrants) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if len(errors) > 0 { + return InsertResourceGrantsMultiError(errors) + } + + return nil +} + +// InsertResourceGrantsMultiError is an error wrapping multiple validation +// errors returned by InsertResourceGrants.ValidateAll() if the designated +// constraints aren't met. +type InsertResourceGrantsMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m InsertResourceGrantsMultiError) Error() string { + msgs := make([]string, 0, len(m)) + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m InsertResourceGrantsMultiError) AllErrors() []error { return m } + +// InsertResourceGrantsValidationError is the validation error returned by +// InsertResourceGrants.Validate if the designated constraints aren't met. +type InsertResourceGrantsValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e InsertResourceGrantsValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e InsertResourceGrantsValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e InsertResourceGrantsValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e InsertResourceGrantsValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e InsertResourceGrantsValidationError) ErrorName() string { + return "InsertResourceGrantsValidationError" +} + +// Error satisfies the builtin error interface +func (e InsertResourceGrantsValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sInsertResourceGrants.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = InsertResourceGrantsValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = InsertResourceGrantsValidationError{} diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant_protoopaque.pb.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant_protoopaque.pb.go index 41ce365b..71bd67e3 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant_protoopaque.pb.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_grant_protoopaque.pb.go @@ -347,6 +347,50 @@ func (b0 GrantAlreadyRevoked_builder) Build() *GrantAlreadyRevoked { return m0 } +// If a resource for a grant doesn't exist, insert it. +type InsertResourceGrants struct { + state protoimpl.MessageState `protogen:"opaque.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *InsertResourceGrants) Reset() { + *x = InsertResourceGrants{} + mi := &file_c1_connector_v2_annotation_grant_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *InsertResourceGrants) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InsertResourceGrants) ProtoMessage() {} + +func (x *InsertResourceGrants) ProtoReflect() protoreflect.Message { + mi := &file_c1_connector_v2_annotation_grant_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +type InsertResourceGrants_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + +} + +func (b0 InsertResourceGrants_builder) Build() *InsertResourceGrants { + m0 := &InsertResourceGrants{} + b, x := &b0, m0 + _, _ = b, x + return m0 +} + var File_c1_connector_v2_annotation_grant_proto protoreflect.FileDescriptor const file_c1_connector_v2_annotation_grant_proto_rawDesc = "" + @@ -362,20 +406,22 @@ const file_c1_connector_v2_annotation_grant_proto_rawDesc = "" + "\tsource_id\x18\x01 \x01(\tR\bsourceId\x123\n" + "\bmetadata\x18\x02 \x01(\v2\x17.google.protobuf.StructR\bmetadata\"\x14\n" + "\x12GrantAlreadyExists\"\x15\n" + - "\x13GrantAlreadyRevokedB6Z4github.com/conductorone/baton-sdk/pb/c1/connector/v2b\x06proto3" + "\x13GrantAlreadyRevoked\"\x16\n" + + "\x14InsertResourceGrantsB6Z4github.com/conductorone/baton-sdk/pb/c1/connector/v2b\x06proto3" -var file_c1_connector_v2_annotation_grant_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_c1_connector_v2_annotation_grant_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_c1_connector_v2_annotation_grant_proto_goTypes = []any{ - (*GrantMetadata)(nil), // 0: c1.connector.v2.GrantMetadata - (*GrantExpandable)(nil), // 1: c1.connector.v2.GrantExpandable - (*GrantImmutable)(nil), // 2: c1.connector.v2.GrantImmutable - (*GrantAlreadyExists)(nil), // 3: c1.connector.v2.GrantAlreadyExists - (*GrantAlreadyRevoked)(nil), // 4: c1.connector.v2.GrantAlreadyRevoked - (*structpb.Struct)(nil), // 5: google.protobuf.Struct + (*GrantMetadata)(nil), // 0: c1.connector.v2.GrantMetadata + (*GrantExpandable)(nil), // 1: c1.connector.v2.GrantExpandable + (*GrantImmutable)(nil), // 2: c1.connector.v2.GrantImmutable + (*GrantAlreadyExists)(nil), // 3: c1.connector.v2.GrantAlreadyExists + (*GrantAlreadyRevoked)(nil), // 4: c1.connector.v2.GrantAlreadyRevoked + (*InsertResourceGrants)(nil), // 5: c1.connector.v2.InsertResourceGrants + (*structpb.Struct)(nil), // 6: google.protobuf.Struct } var file_c1_connector_v2_annotation_grant_proto_depIdxs = []int32{ - 5, // 0: c1.connector.v2.GrantMetadata.metadata:type_name -> google.protobuf.Struct - 5, // 1: c1.connector.v2.GrantImmutable.metadata:type_name -> google.protobuf.Struct + 6, // 0: c1.connector.v2.GrantMetadata.metadata:type_name -> google.protobuf.Struct + 6, // 1: c1.connector.v2.GrantImmutable.metadata:type_name -> google.protobuf.Struct 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name @@ -394,7 +440,7 @@ func file_c1_connector_v2_annotation_grant_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_c1_connector_v2_annotation_grant_proto_rawDesc), len(file_c1_connector_v2_annotation_grant_proto_rawDesc)), NumEnums: 0, - NumMessages: 5, + NumMessages: 6, NumExtensions: 0, NumServices: 0, }, diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement.pb.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement.pb.go index c996ec09..fca3e908 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement.pb.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement.pb.go @@ -443,6 +443,204 @@ func (b0 EntitlementsServiceListEntitlementsResponse_builder) Build() *Entitleme return m0 } +type EntitlementsServiceListStaticEntitlementsRequest struct { + state protoimpl.MessageState `protogen:"hybrid.v1"` + ResourceTypeId string `protobuf:"bytes,1,opt,name=resource_type_id,json=resourceTypeId,proto3" json:"resource_type_id,omitempty"` + PageSize uint32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` + PageToken string `protobuf:"bytes,3,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"` + Annotations []*anypb.Any `protobuf:"bytes,4,rep,name=annotations,proto3" json:"annotations,omitempty"` + ActiveSyncId string `protobuf:"bytes,5,opt,name=active_sync_id,json=activeSyncId,proto3" json:"active_sync_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) Reset() { + *x = EntitlementsServiceListStaticEntitlementsRequest{} + mi := &file_c1_connector_v2_entitlement_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EntitlementsServiceListStaticEntitlementsRequest) ProtoMessage() {} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) ProtoReflect() protoreflect.Message { + mi := &file_c1_connector_v2_entitlement_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetResourceTypeId() string { + if x != nil { + return x.ResourceTypeId + } + return "" +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetPageSize() uint32 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetPageToken() string { + if x != nil { + return x.PageToken + } + return "" +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetAnnotations() []*anypb.Any { + if x != nil { + return x.Annotations + } + return nil +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetActiveSyncId() string { + if x != nil { + return x.ActiveSyncId + } + return "" +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetResourceTypeId(v string) { + x.ResourceTypeId = v +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetPageSize(v uint32) { + x.PageSize = v +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetPageToken(v string) { + x.PageToken = v +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetAnnotations(v []*anypb.Any) { + x.Annotations = v +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetActiveSyncId(v string) { + x.ActiveSyncId = v +} + +type EntitlementsServiceListStaticEntitlementsRequest_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + ResourceTypeId string + PageSize uint32 + PageToken string + Annotations []*anypb.Any + ActiveSyncId string +} + +func (b0 EntitlementsServiceListStaticEntitlementsRequest_builder) Build() *EntitlementsServiceListStaticEntitlementsRequest { + m0 := &EntitlementsServiceListStaticEntitlementsRequest{} + b, x := &b0, m0 + _, _ = b, x + x.ResourceTypeId = b.ResourceTypeId + x.PageSize = b.PageSize + x.PageToken = b.PageToken + x.Annotations = b.Annotations + x.ActiveSyncId = b.ActiveSyncId + return m0 +} + +type EntitlementsServiceListStaticEntitlementsResponse struct { + state protoimpl.MessageState `protogen:"hybrid.v1"` + List []*Entitlement `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` + NextPageToken string `protobuf:"bytes,2,opt,name=next_page_token,json=nextPageToken,proto3" json:"next_page_token,omitempty"` + Annotations []*anypb.Any `protobuf:"bytes,3,rep,name=annotations,proto3" json:"annotations,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) Reset() { + *x = EntitlementsServiceListStaticEntitlementsResponse{} + mi := &file_c1_connector_v2_entitlement_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EntitlementsServiceListStaticEntitlementsResponse) ProtoMessage() {} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) ProtoReflect() protoreflect.Message { + mi := &file_c1_connector_v2_entitlement_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) GetList() []*Entitlement { + if x != nil { + return x.List + } + return nil +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) GetNextPageToken() string { + if x != nil { + return x.NextPageToken + } + return "" +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) GetAnnotations() []*anypb.Any { + if x != nil { + return x.Annotations + } + return nil +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) SetList(v []*Entitlement) { + x.List = v +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) SetNextPageToken(v string) { + x.NextPageToken = v +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) SetAnnotations(v []*anypb.Any) { + x.Annotations = v +} + +type EntitlementsServiceListStaticEntitlementsResponse_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + List []*Entitlement + NextPageToken string + Annotations []*anypb.Any +} + +func (b0 EntitlementsServiceListStaticEntitlementsResponse_builder) Build() *EntitlementsServiceListStaticEntitlementsResponse { + m0 := &EntitlementsServiceListStaticEntitlementsResponse{} + b, x := &b0, m0 + _, _ = b, x + x.List = b.List + x.NextPageToken = b.NextPageToken + x.Annotations = b.Annotations + return m0 +} + var File_c1_connector_v2_entitlement_proto protoreflect.FileDescriptor const file_c1_connector_v2_entitlement_proto_rawDesc = "" + @@ -476,37 +674,59 @@ const file_c1_connector_v2_entitlement_proto_rawDesc = "" + "+EntitlementsServiceListEntitlementsResponse\x120\n" + "\x04list\x18\x01 \x03(\v2\x1c.c1.connector.v2.EntitlementR\x04list\x126\n" + "\x0fnext_page_token\x18\x02 \x01(\tB\x0e\xfaB\vr\t \x01(\x80\x80@\xd0\x01\x01R\rnextPageToken\x126\n" + - "\vannotations\x18\x03 \x03(\v2\x14.google.protobuf.AnyR\vannotations2\xa5\x01\n" + + "\vannotations\x18\x03 \x03(\v2\x14.google.protobuf.AnyR\vannotations\"\xad\x02\n" + + "0EntitlementsServiceListStaticEntitlementsRequest\x124\n" + + "\x10resource_type_id\x18\x01 \x01(\tB\n" + + "\xfaB\ar\x05 \x01(\x80\bR\x0eresourceTypeId\x12'\n" + + "\tpage_size\x18\x02 \x01(\rB\n" + + "\xfaB\a*\x05\x18\xfa\x01@\x01R\bpageSize\x12-\n" + + "\n" + + "page_token\x18\x03 \x01(\tB\x0e\xfaB\vr\t \x01(\x80\x80@\xd0\x01\x01R\tpageToken\x126\n" + + "\vannotations\x18\x04 \x03(\v2\x14.google.protobuf.AnyR\vannotations\x123\n" + + "\x0eactive_sync_id\x18\x05 \x01(\tB\r\xfaB\n" + + "r\b \x01(\x80\b\xd0\x01\x01R\factiveSyncId\"\xd5\x01\n" + + "1EntitlementsServiceListStaticEntitlementsResponse\x120\n" + + "\x04list\x18\x01 \x03(\v2\x1c.c1.connector.v2.EntitlementR\x04list\x126\n" + + "\x0fnext_page_token\x18\x02 \x01(\tB\x0e\xfaB\vr\t \x01(\x80\x80@\xd0\x01\x01R\rnextPageToken\x126\n" + + "\vannotations\x18\x03 \x03(\v2\x14.google.protobuf.AnyR\vannotations2\xc7\x02\n" + "\x13EntitlementsService\x12\x8d\x01\n" + - "\x10ListEntitlements\x12;.c1.connector.v2.EntitlementsServiceListEntitlementsRequest\x1a<.c1.connector.v2.EntitlementsServiceListEntitlementsResponseB6Z4github.com/conductorone/baton-sdk/pb/c1/connector/v2b\x06proto3" + "\x10ListEntitlements\x12;.c1.connector.v2.EntitlementsServiceListEntitlementsRequest\x1a<.c1.connector.v2.EntitlementsServiceListEntitlementsResponse\x12\x9f\x01\n" + + "\x16ListStaticEntitlements\x12A.c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest\x1aB.c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponseB6Z4github.com/conductorone/baton-sdk/pb/c1/connector/v2b\x06proto3" var file_c1_connector_v2_entitlement_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_c1_connector_v2_entitlement_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_c1_connector_v2_entitlement_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_c1_connector_v2_entitlement_proto_goTypes = []any{ - (Entitlement_PurposeValue)(0), // 0: c1.connector.v2.Entitlement.PurposeValue - (*Entitlement)(nil), // 1: c1.connector.v2.Entitlement - (*EntitlementsServiceListEntitlementsRequest)(nil), // 2: c1.connector.v2.EntitlementsServiceListEntitlementsRequest - (*EntitlementsServiceListEntitlementsResponse)(nil), // 3: c1.connector.v2.EntitlementsServiceListEntitlementsResponse - (*Resource)(nil), // 4: c1.connector.v2.Resource - (*ResourceType)(nil), // 5: c1.connector.v2.ResourceType - (*anypb.Any)(nil), // 6: google.protobuf.Any + (Entitlement_PurposeValue)(0), // 0: c1.connector.v2.Entitlement.PurposeValue + (*Entitlement)(nil), // 1: c1.connector.v2.Entitlement + (*EntitlementsServiceListEntitlementsRequest)(nil), // 2: c1.connector.v2.EntitlementsServiceListEntitlementsRequest + (*EntitlementsServiceListEntitlementsResponse)(nil), // 3: c1.connector.v2.EntitlementsServiceListEntitlementsResponse + (*EntitlementsServiceListStaticEntitlementsRequest)(nil), // 4: c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest + (*EntitlementsServiceListStaticEntitlementsResponse)(nil), // 5: c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponse + (*Resource)(nil), // 6: c1.connector.v2.Resource + (*ResourceType)(nil), // 7: c1.connector.v2.ResourceType + (*anypb.Any)(nil), // 8: google.protobuf.Any } var file_c1_connector_v2_entitlement_proto_depIdxs = []int32{ - 4, // 0: c1.connector.v2.Entitlement.resource:type_name -> c1.connector.v2.Resource - 5, // 1: c1.connector.v2.Entitlement.grantable_to:type_name -> c1.connector.v2.ResourceType - 6, // 2: c1.connector.v2.Entitlement.annotations:type_name -> google.protobuf.Any - 0, // 3: c1.connector.v2.Entitlement.purpose:type_name -> c1.connector.v2.Entitlement.PurposeValue - 4, // 4: c1.connector.v2.EntitlementsServiceListEntitlementsRequest.resource:type_name -> c1.connector.v2.Resource - 6, // 5: c1.connector.v2.EntitlementsServiceListEntitlementsRequest.annotations:type_name -> google.protobuf.Any - 1, // 6: c1.connector.v2.EntitlementsServiceListEntitlementsResponse.list:type_name -> c1.connector.v2.Entitlement - 6, // 7: c1.connector.v2.EntitlementsServiceListEntitlementsResponse.annotations:type_name -> google.protobuf.Any - 2, // 8: c1.connector.v2.EntitlementsService.ListEntitlements:input_type -> c1.connector.v2.EntitlementsServiceListEntitlementsRequest - 3, // 9: c1.connector.v2.EntitlementsService.ListEntitlements:output_type -> c1.connector.v2.EntitlementsServiceListEntitlementsResponse - 9, // [9:10] is the sub-list for method output_type - 8, // [8:9] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 6, // 0: c1.connector.v2.Entitlement.resource:type_name -> c1.connector.v2.Resource + 7, // 1: c1.connector.v2.Entitlement.grantable_to:type_name -> c1.connector.v2.ResourceType + 8, // 2: c1.connector.v2.Entitlement.annotations:type_name -> google.protobuf.Any + 0, // 3: c1.connector.v2.Entitlement.purpose:type_name -> c1.connector.v2.Entitlement.PurposeValue + 6, // 4: c1.connector.v2.EntitlementsServiceListEntitlementsRequest.resource:type_name -> c1.connector.v2.Resource + 8, // 5: c1.connector.v2.EntitlementsServiceListEntitlementsRequest.annotations:type_name -> google.protobuf.Any + 1, // 6: c1.connector.v2.EntitlementsServiceListEntitlementsResponse.list:type_name -> c1.connector.v2.Entitlement + 8, // 7: c1.connector.v2.EntitlementsServiceListEntitlementsResponse.annotations:type_name -> google.protobuf.Any + 8, // 8: c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest.annotations:type_name -> google.protobuf.Any + 1, // 9: c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponse.list:type_name -> c1.connector.v2.Entitlement + 8, // 10: c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponse.annotations:type_name -> google.protobuf.Any + 2, // 11: c1.connector.v2.EntitlementsService.ListEntitlements:input_type -> c1.connector.v2.EntitlementsServiceListEntitlementsRequest + 4, // 12: c1.connector.v2.EntitlementsService.ListStaticEntitlements:input_type -> c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest + 3, // 13: c1.connector.v2.EntitlementsService.ListEntitlements:output_type -> c1.connector.v2.EntitlementsServiceListEntitlementsResponse + 5, // 14: c1.connector.v2.EntitlementsService.ListStaticEntitlements:output_type -> c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponse + 13, // [13:15] is the sub-list for method output_type + 11, // [11:13] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name } func init() { file_c1_connector_v2_entitlement_proto_init() } @@ -521,7 +741,7 @@ func file_c1_connector_v2_entitlement_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_c1_connector_v2_entitlement_proto_rawDesc), len(file_c1_connector_v2_entitlement_proto_rawDesc)), NumEnums: 1, - NumMessages: 3, + NumMessages: 5, NumExtensions: 0, NumServices: 1, }, diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement.pb.validate.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement.pb.validate.go index 013ab1bc..cf8fb4e8 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement.pb.validate.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement.pb.validate.go @@ -698,3 +698,402 @@ var _ interface { Cause() error ErrorName() string } = EntitlementsServiceListEntitlementsResponseValidationError{} + +// Validate checks the field values on +// EntitlementsServiceListStaticEntitlementsRequest with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *EntitlementsServiceListStaticEntitlementsRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on +// EntitlementsServiceListStaticEntitlementsRequest with the rules defined in +// the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in +// EntitlementsServiceListStaticEntitlementsRequestMultiError, or nil if none found. +func (m *EntitlementsServiceListStaticEntitlementsRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *EntitlementsServiceListStaticEntitlementsRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if l := len(m.GetResourceTypeId()); l < 1 || l > 1024 { + err := EntitlementsServiceListStaticEntitlementsRequestValidationError{ + field: "ResourceTypeId", + reason: "value length must be between 1 and 1024 bytes, inclusive", + } + if !all { + return err + } + errors = append(errors, err) + } + + if m.GetPageSize() != 0 { + + if m.GetPageSize() > 250 { + err := EntitlementsServiceListStaticEntitlementsRequestValidationError{ + field: "PageSize", + reason: "value must be less than or equal to 250", + } + if !all { + return err + } + errors = append(errors, err) + } + + } + + if m.GetPageToken() != "" { + + if l := len(m.GetPageToken()); l < 1 || l > 1048576 { + err := EntitlementsServiceListStaticEntitlementsRequestValidationError{ + field: "PageToken", + reason: "value length must be between 1 and 1048576 bytes, inclusive", + } + if !all { + return err + } + errors = append(errors, err) + } + + } + + for idx, item := range m.GetAnnotations() { + _, _ = idx, item + + if all { + switch v := interface{}(item).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, EntitlementsServiceListStaticEntitlementsRequestValidationError{ + field: fmt.Sprintf("Annotations[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, EntitlementsServiceListStaticEntitlementsRequestValidationError{ + field: fmt.Sprintf("Annotations[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return EntitlementsServiceListStaticEntitlementsRequestValidationError{ + field: fmt.Sprintf("Annotations[%v]", idx), + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if m.GetActiveSyncId() != "" { + + if l := len(m.GetActiveSyncId()); l < 1 || l > 1024 { + err := EntitlementsServiceListStaticEntitlementsRequestValidationError{ + field: "ActiveSyncId", + reason: "value length must be between 1 and 1024 bytes, inclusive", + } + if !all { + return err + } + errors = append(errors, err) + } + + } + + if len(errors) > 0 { + return EntitlementsServiceListStaticEntitlementsRequestMultiError(errors) + } + + return nil +} + +// EntitlementsServiceListStaticEntitlementsRequestMultiError is an error +// wrapping multiple validation errors returned by +// EntitlementsServiceListStaticEntitlementsRequest.ValidateAll() if the +// designated constraints aren't met. +type EntitlementsServiceListStaticEntitlementsRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m EntitlementsServiceListStaticEntitlementsRequestMultiError) Error() string { + msgs := make([]string, 0, len(m)) + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m EntitlementsServiceListStaticEntitlementsRequestMultiError) AllErrors() []error { return m } + +// EntitlementsServiceListStaticEntitlementsRequestValidationError is the +// validation error returned by +// EntitlementsServiceListStaticEntitlementsRequest.Validate if the designated +// constraints aren't met. +type EntitlementsServiceListStaticEntitlementsRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e EntitlementsServiceListStaticEntitlementsRequestValidationError) Field() string { + return e.field +} + +// Reason function returns reason value. +func (e EntitlementsServiceListStaticEntitlementsRequestValidationError) Reason() string { + return e.reason +} + +// Cause function returns cause value. +func (e EntitlementsServiceListStaticEntitlementsRequestValidationError) Cause() error { + return e.cause +} + +// Key function returns key value. +func (e EntitlementsServiceListStaticEntitlementsRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e EntitlementsServiceListStaticEntitlementsRequestValidationError) ErrorName() string { + return "EntitlementsServiceListStaticEntitlementsRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e EntitlementsServiceListStaticEntitlementsRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sEntitlementsServiceListStaticEntitlementsRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = EntitlementsServiceListStaticEntitlementsRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = EntitlementsServiceListStaticEntitlementsRequestValidationError{} + +// Validate checks the field values on +// EntitlementsServiceListStaticEntitlementsResponse with the rules defined in +// the proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *EntitlementsServiceListStaticEntitlementsResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on +// EntitlementsServiceListStaticEntitlementsResponse with the rules defined in +// the proto definition for this message. If any rules are violated, the +// result is a list of violation errors wrapped in +// EntitlementsServiceListStaticEntitlementsResponseMultiError, or nil if none found. +func (m *EntitlementsServiceListStaticEntitlementsResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *EntitlementsServiceListStaticEntitlementsResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + for idx, item := range m.GetList() { + _, _ = idx, item + + if all { + switch v := interface{}(item).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, EntitlementsServiceListStaticEntitlementsResponseValidationError{ + field: fmt.Sprintf("List[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, EntitlementsServiceListStaticEntitlementsResponseValidationError{ + field: fmt.Sprintf("List[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return EntitlementsServiceListStaticEntitlementsResponseValidationError{ + field: fmt.Sprintf("List[%v]", idx), + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if m.GetNextPageToken() != "" { + + if l := len(m.GetNextPageToken()); l < 1 || l > 1048576 { + err := EntitlementsServiceListStaticEntitlementsResponseValidationError{ + field: "NextPageToken", + reason: "value length must be between 1 and 1048576 bytes, inclusive", + } + if !all { + return err + } + errors = append(errors, err) + } + + } + + for idx, item := range m.GetAnnotations() { + _, _ = idx, item + + if all { + switch v := interface{}(item).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, EntitlementsServiceListStaticEntitlementsResponseValidationError{ + field: fmt.Sprintf("Annotations[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, EntitlementsServiceListStaticEntitlementsResponseValidationError{ + field: fmt.Sprintf("Annotations[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return EntitlementsServiceListStaticEntitlementsResponseValidationError{ + field: fmt.Sprintf("Annotations[%v]", idx), + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return EntitlementsServiceListStaticEntitlementsResponseMultiError(errors) + } + + return nil +} + +// EntitlementsServiceListStaticEntitlementsResponseMultiError is an error +// wrapping multiple validation errors returned by +// EntitlementsServiceListStaticEntitlementsResponse.ValidateAll() if the +// designated constraints aren't met. +type EntitlementsServiceListStaticEntitlementsResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m EntitlementsServiceListStaticEntitlementsResponseMultiError) Error() string { + msgs := make([]string, 0, len(m)) + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m EntitlementsServiceListStaticEntitlementsResponseMultiError) AllErrors() []error { return m } + +// EntitlementsServiceListStaticEntitlementsResponseValidationError is the +// validation error returned by +// EntitlementsServiceListStaticEntitlementsResponse.Validate if the +// designated constraints aren't met. +type EntitlementsServiceListStaticEntitlementsResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e EntitlementsServiceListStaticEntitlementsResponseValidationError) Field() string { + return e.field +} + +// Reason function returns reason value. +func (e EntitlementsServiceListStaticEntitlementsResponseValidationError) Reason() string { + return e.reason +} + +// Cause function returns cause value. +func (e EntitlementsServiceListStaticEntitlementsResponseValidationError) Cause() error { + return e.cause +} + +// Key function returns key value. +func (e EntitlementsServiceListStaticEntitlementsResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e EntitlementsServiceListStaticEntitlementsResponseValidationError) ErrorName() string { + return "EntitlementsServiceListStaticEntitlementsResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e EntitlementsServiceListStaticEntitlementsResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sEntitlementsServiceListStaticEntitlementsResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = EntitlementsServiceListStaticEntitlementsResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = EntitlementsServiceListStaticEntitlementsResponseValidationError{} diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement_grpc.pb.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement_grpc.pb.go index 821161d3..6286b134 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement_grpc.pb.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement_grpc.pb.go @@ -19,7 +19,8 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - EntitlementsService_ListEntitlements_FullMethodName = "/c1.connector.v2.EntitlementsService/ListEntitlements" + EntitlementsService_ListEntitlements_FullMethodName = "/c1.connector.v2.EntitlementsService/ListEntitlements" + EntitlementsService_ListStaticEntitlements_FullMethodName = "/c1.connector.v2.EntitlementsService/ListStaticEntitlements" ) // EntitlementsServiceClient is the client API for EntitlementsService service. @@ -27,6 +28,7 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type EntitlementsServiceClient interface { ListEntitlements(ctx context.Context, in *EntitlementsServiceListEntitlementsRequest, opts ...grpc.CallOption) (*EntitlementsServiceListEntitlementsResponse, error) + ListStaticEntitlements(ctx context.Context, in *EntitlementsServiceListStaticEntitlementsRequest, opts ...grpc.CallOption) (*EntitlementsServiceListStaticEntitlementsResponse, error) } type entitlementsServiceClient struct { @@ -47,11 +49,22 @@ func (c *entitlementsServiceClient) ListEntitlements(ctx context.Context, in *En return out, nil } +func (c *entitlementsServiceClient) ListStaticEntitlements(ctx context.Context, in *EntitlementsServiceListStaticEntitlementsRequest, opts ...grpc.CallOption) (*EntitlementsServiceListStaticEntitlementsResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(EntitlementsServiceListStaticEntitlementsResponse) + err := c.cc.Invoke(ctx, EntitlementsService_ListStaticEntitlements_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // EntitlementsServiceServer is the server API for EntitlementsService service. // All implementations should embed UnimplementedEntitlementsServiceServer // for forward compatibility. type EntitlementsServiceServer interface { ListEntitlements(context.Context, *EntitlementsServiceListEntitlementsRequest) (*EntitlementsServiceListEntitlementsResponse, error) + ListStaticEntitlements(context.Context, *EntitlementsServiceListStaticEntitlementsRequest) (*EntitlementsServiceListStaticEntitlementsResponse, error) } // UnimplementedEntitlementsServiceServer should be embedded to have @@ -64,6 +77,9 @@ type UnimplementedEntitlementsServiceServer struct{} func (UnimplementedEntitlementsServiceServer) ListEntitlements(context.Context, *EntitlementsServiceListEntitlementsRequest) (*EntitlementsServiceListEntitlementsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListEntitlements not implemented") } +func (UnimplementedEntitlementsServiceServer) ListStaticEntitlements(context.Context, *EntitlementsServiceListStaticEntitlementsRequest) (*EntitlementsServiceListStaticEntitlementsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListStaticEntitlements not implemented") +} func (UnimplementedEntitlementsServiceServer) testEmbeddedByValue() {} // UnsafeEntitlementsServiceServer may be embedded to opt out of forward compatibility for this service. @@ -102,6 +118,24 @@ func _EntitlementsService_ListEntitlements_Handler(srv interface{}, ctx context. return interceptor(ctx, in, info, handler) } +func _EntitlementsService_ListStaticEntitlements_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EntitlementsServiceListStaticEntitlementsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EntitlementsServiceServer).ListStaticEntitlements(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: EntitlementsService_ListStaticEntitlements_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EntitlementsServiceServer).ListStaticEntitlements(ctx, req.(*EntitlementsServiceListStaticEntitlementsRequest)) + } + return interceptor(ctx, in, info, handler) +} + // EntitlementsService_ServiceDesc is the grpc.ServiceDesc for EntitlementsService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -113,6 +147,10 @@ var EntitlementsService_ServiceDesc = grpc.ServiceDesc{ MethodName: "ListEntitlements", Handler: _EntitlementsService_ListEntitlements_Handler, }, + { + MethodName: "ListStaticEntitlements", + Handler: _EntitlementsService_ListStaticEntitlements_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "c1/connector/v2/entitlement.proto", diff --git a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement_protoopaque.pb.go b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement_protoopaque.pb.go index d9f09c90..88a1142b 100644 --- a/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement_protoopaque.pb.go +++ b/vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/entitlement_protoopaque.pb.go @@ -453,6 +453,210 @@ func (b0 EntitlementsServiceListEntitlementsResponse_builder) Build() *Entitleme return m0 } +type EntitlementsServiceListStaticEntitlementsRequest struct { + state protoimpl.MessageState `protogen:"opaque.v1"` + xxx_hidden_ResourceTypeId string `protobuf:"bytes,1,opt,name=resource_type_id,json=resourceTypeId,proto3"` + xxx_hidden_PageSize uint32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3"` + xxx_hidden_PageToken string `protobuf:"bytes,3,opt,name=page_token,json=pageToken,proto3"` + xxx_hidden_Annotations *[]*anypb.Any `protobuf:"bytes,4,rep,name=annotations,proto3"` + xxx_hidden_ActiveSyncId string `protobuf:"bytes,5,opt,name=active_sync_id,json=activeSyncId,proto3"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) Reset() { + *x = EntitlementsServiceListStaticEntitlementsRequest{} + mi := &file_c1_connector_v2_entitlement_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EntitlementsServiceListStaticEntitlementsRequest) ProtoMessage() {} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) ProtoReflect() protoreflect.Message { + mi := &file_c1_connector_v2_entitlement_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetResourceTypeId() string { + if x != nil { + return x.xxx_hidden_ResourceTypeId + } + return "" +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetPageSize() uint32 { + if x != nil { + return x.xxx_hidden_PageSize + } + return 0 +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetPageToken() string { + if x != nil { + return x.xxx_hidden_PageToken + } + return "" +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetAnnotations() []*anypb.Any { + if x != nil { + if x.xxx_hidden_Annotations != nil { + return *x.xxx_hidden_Annotations + } + } + return nil +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) GetActiveSyncId() string { + if x != nil { + return x.xxx_hidden_ActiveSyncId + } + return "" +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetResourceTypeId(v string) { + x.xxx_hidden_ResourceTypeId = v +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetPageSize(v uint32) { + x.xxx_hidden_PageSize = v +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetPageToken(v string) { + x.xxx_hidden_PageToken = v +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetAnnotations(v []*anypb.Any) { + x.xxx_hidden_Annotations = &v +} + +func (x *EntitlementsServiceListStaticEntitlementsRequest) SetActiveSyncId(v string) { + x.xxx_hidden_ActiveSyncId = v +} + +type EntitlementsServiceListStaticEntitlementsRequest_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + ResourceTypeId string + PageSize uint32 + PageToken string + Annotations []*anypb.Any + ActiveSyncId string +} + +func (b0 EntitlementsServiceListStaticEntitlementsRequest_builder) Build() *EntitlementsServiceListStaticEntitlementsRequest { + m0 := &EntitlementsServiceListStaticEntitlementsRequest{} + b, x := &b0, m0 + _, _ = b, x + x.xxx_hidden_ResourceTypeId = b.ResourceTypeId + x.xxx_hidden_PageSize = b.PageSize + x.xxx_hidden_PageToken = b.PageToken + x.xxx_hidden_Annotations = &b.Annotations + x.xxx_hidden_ActiveSyncId = b.ActiveSyncId + return m0 +} + +type EntitlementsServiceListStaticEntitlementsResponse struct { + state protoimpl.MessageState `protogen:"opaque.v1"` + xxx_hidden_List *[]*Entitlement `protobuf:"bytes,1,rep,name=list,proto3"` + xxx_hidden_NextPageToken string `protobuf:"bytes,2,opt,name=next_page_token,json=nextPageToken,proto3"` + xxx_hidden_Annotations *[]*anypb.Any `protobuf:"bytes,3,rep,name=annotations,proto3"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) Reset() { + *x = EntitlementsServiceListStaticEntitlementsResponse{} + mi := &file_c1_connector_v2_entitlement_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EntitlementsServiceListStaticEntitlementsResponse) ProtoMessage() {} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) ProtoReflect() protoreflect.Message { + mi := &file_c1_connector_v2_entitlement_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) GetList() []*Entitlement { + if x != nil { + if x.xxx_hidden_List != nil { + return *x.xxx_hidden_List + } + } + return nil +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) GetNextPageToken() string { + if x != nil { + return x.xxx_hidden_NextPageToken + } + return "" +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) GetAnnotations() []*anypb.Any { + if x != nil { + if x.xxx_hidden_Annotations != nil { + return *x.xxx_hidden_Annotations + } + } + return nil +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) SetList(v []*Entitlement) { + x.xxx_hidden_List = &v +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) SetNextPageToken(v string) { + x.xxx_hidden_NextPageToken = v +} + +func (x *EntitlementsServiceListStaticEntitlementsResponse) SetAnnotations(v []*anypb.Any) { + x.xxx_hidden_Annotations = &v +} + +type EntitlementsServiceListStaticEntitlementsResponse_builder struct { + _ [0]func() // Prevents comparability and use of unkeyed literals for the builder. + + List []*Entitlement + NextPageToken string + Annotations []*anypb.Any +} + +func (b0 EntitlementsServiceListStaticEntitlementsResponse_builder) Build() *EntitlementsServiceListStaticEntitlementsResponse { + m0 := &EntitlementsServiceListStaticEntitlementsResponse{} + b, x := &b0, m0 + _, _ = b, x + x.xxx_hidden_List = &b.List + x.xxx_hidden_NextPageToken = b.NextPageToken + x.xxx_hidden_Annotations = &b.Annotations + return m0 +} + var File_c1_connector_v2_entitlement_proto protoreflect.FileDescriptor const file_c1_connector_v2_entitlement_proto_rawDesc = "" + @@ -486,37 +690,59 @@ const file_c1_connector_v2_entitlement_proto_rawDesc = "" + "+EntitlementsServiceListEntitlementsResponse\x120\n" + "\x04list\x18\x01 \x03(\v2\x1c.c1.connector.v2.EntitlementR\x04list\x126\n" + "\x0fnext_page_token\x18\x02 \x01(\tB\x0e\xfaB\vr\t \x01(\x80\x80@\xd0\x01\x01R\rnextPageToken\x126\n" + - "\vannotations\x18\x03 \x03(\v2\x14.google.protobuf.AnyR\vannotations2\xa5\x01\n" + + "\vannotations\x18\x03 \x03(\v2\x14.google.protobuf.AnyR\vannotations\"\xad\x02\n" + + "0EntitlementsServiceListStaticEntitlementsRequest\x124\n" + + "\x10resource_type_id\x18\x01 \x01(\tB\n" + + "\xfaB\ar\x05 \x01(\x80\bR\x0eresourceTypeId\x12'\n" + + "\tpage_size\x18\x02 \x01(\rB\n" + + "\xfaB\a*\x05\x18\xfa\x01@\x01R\bpageSize\x12-\n" + + "\n" + + "page_token\x18\x03 \x01(\tB\x0e\xfaB\vr\t \x01(\x80\x80@\xd0\x01\x01R\tpageToken\x126\n" + + "\vannotations\x18\x04 \x03(\v2\x14.google.protobuf.AnyR\vannotations\x123\n" + + "\x0eactive_sync_id\x18\x05 \x01(\tB\r\xfaB\n" + + "r\b \x01(\x80\b\xd0\x01\x01R\factiveSyncId\"\xd5\x01\n" + + "1EntitlementsServiceListStaticEntitlementsResponse\x120\n" + + "\x04list\x18\x01 \x03(\v2\x1c.c1.connector.v2.EntitlementR\x04list\x126\n" + + "\x0fnext_page_token\x18\x02 \x01(\tB\x0e\xfaB\vr\t \x01(\x80\x80@\xd0\x01\x01R\rnextPageToken\x126\n" + + "\vannotations\x18\x03 \x03(\v2\x14.google.protobuf.AnyR\vannotations2\xc7\x02\n" + "\x13EntitlementsService\x12\x8d\x01\n" + - "\x10ListEntitlements\x12;.c1.connector.v2.EntitlementsServiceListEntitlementsRequest\x1a<.c1.connector.v2.EntitlementsServiceListEntitlementsResponseB6Z4github.com/conductorone/baton-sdk/pb/c1/connector/v2b\x06proto3" + "\x10ListEntitlements\x12;.c1.connector.v2.EntitlementsServiceListEntitlementsRequest\x1a<.c1.connector.v2.EntitlementsServiceListEntitlementsResponse\x12\x9f\x01\n" + + "\x16ListStaticEntitlements\x12A.c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest\x1aB.c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponseB6Z4github.com/conductorone/baton-sdk/pb/c1/connector/v2b\x06proto3" var file_c1_connector_v2_entitlement_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_c1_connector_v2_entitlement_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_c1_connector_v2_entitlement_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_c1_connector_v2_entitlement_proto_goTypes = []any{ - (Entitlement_PurposeValue)(0), // 0: c1.connector.v2.Entitlement.PurposeValue - (*Entitlement)(nil), // 1: c1.connector.v2.Entitlement - (*EntitlementsServiceListEntitlementsRequest)(nil), // 2: c1.connector.v2.EntitlementsServiceListEntitlementsRequest - (*EntitlementsServiceListEntitlementsResponse)(nil), // 3: c1.connector.v2.EntitlementsServiceListEntitlementsResponse - (*Resource)(nil), // 4: c1.connector.v2.Resource - (*ResourceType)(nil), // 5: c1.connector.v2.ResourceType - (*anypb.Any)(nil), // 6: google.protobuf.Any + (Entitlement_PurposeValue)(0), // 0: c1.connector.v2.Entitlement.PurposeValue + (*Entitlement)(nil), // 1: c1.connector.v2.Entitlement + (*EntitlementsServiceListEntitlementsRequest)(nil), // 2: c1.connector.v2.EntitlementsServiceListEntitlementsRequest + (*EntitlementsServiceListEntitlementsResponse)(nil), // 3: c1.connector.v2.EntitlementsServiceListEntitlementsResponse + (*EntitlementsServiceListStaticEntitlementsRequest)(nil), // 4: c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest + (*EntitlementsServiceListStaticEntitlementsResponse)(nil), // 5: c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponse + (*Resource)(nil), // 6: c1.connector.v2.Resource + (*ResourceType)(nil), // 7: c1.connector.v2.ResourceType + (*anypb.Any)(nil), // 8: google.protobuf.Any } var file_c1_connector_v2_entitlement_proto_depIdxs = []int32{ - 4, // 0: c1.connector.v2.Entitlement.resource:type_name -> c1.connector.v2.Resource - 5, // 1: c1.connector.v2.Entitlement.grantable_to:type_name -> c1.connector.v2.ResourceType - 6, // 2: c1.connector.v2.Entitlement.annotations:type_name -> google.protobuf.Any - 0, // 3: c1.connector.v2.Entitlement.purpose:type_name -> c1.connector.v2.Entitlement.PurposeValue - 4, // 4: c1.connector.v2.EntitlementsServiceListEntitlementsRequest.resource:type_name -> c1.connector.v2.Resource - 6, // 5: c1.connector.v2.EntitlementsServiceListEntitlementsRequest.annotations:type_name -> google.protobuf.Any - 1, // 6: c1.connector.v2.EntitlementsServiceListEntitlementsResponse.list:type_name -> c1.connector.v2.Entitlement - 6, // 7: c1.connector.v2.EntitlementsServiceListEntitlementsResponse.annotations:type_name -> google.protobuf.Any - 2, // 8: c1.connector.v2.EntitlementsService.ListEntitlements:input_type -> c1.connector.v2.EntitlementsServiceListEntitlementsRequest - 3, // 9: c1.connector.v2.EntitlementsService.ListEntitlements:output_type -> c1.connector.v2.EntitlementsServiceListEntitlementsResponse - 9, // [9:10] is the sub-list for method output_type - 8, // [8:9] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 6, // 0: c1.connector.v2.Entitlement.resource:type_name -> c1.connector.v2.Resource + 7, // 1: c1.connector.v2.Entitlement.grantable_to:type_name -> c1.connector.v2.ResourceType + 8, // 2: c1.connector.v2.Entitlement.annotations:type_name -> google.protobuf.Any + 0, // 3: c1.connector.v2.Entitlement.purpose:type_name -> c1.connector.v2.Entitlement.PurposeValue + 6, // 4: c1.connector.v2.EntitlementsServiceListEntitlementsRequest.resource:type_name -> c1.connector.v2.Resource + 8, // 5: c1.connector.v2.EntitlementsServiceListEntitlementsRequest.annotations:type_name -> google.protobuf.Any + 1, // 6: c1.connector.v2.EntitlementsServiceListEntitlementsResponse.list:type_name -> c1.connector.v2.Entitlement + 8, // 7: c1.connector.v2.EntitlementsServiceListEntitlementsResponse.annotations:type_name -> google.protobuf.Any + 8, // 8: c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest.annotations:type_name -> google.protobuf.Any + 1, // 9: c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponse.list:type_name -> c1.connector.v2.Entitlement + 8, // 10: c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponse.annotations:type_name -> google.protobuf.Any + 2, // 11: c1.connector.v2.EntitlementsService.ListEntitlements:input_type -> c1.connector.v2.EntitlementsServiceListEntitlementsRequest + 4, // 12: c1.connector.v2.EntitlementsService.ListStaticEntitlements:input_type -> c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest + 3, // 13: c1.connector.v2.EntitlementsService.ListEntitlements:output_type -> c1.connector.v2.EntitlementsServiceListEntitlementsResponse + 5, // 14: c1.connector.v2.EntitlementsService.ListStaticEntitlements:output_type -> c1.connector.v2.EntitlementsServiceListStaticEntitlementsResponse + 13, // [13:15] is the sub-list for method output_type + 11, // [11:13] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name } func init() { file_c1_connector_v2_entitlement_proto_init() } @@ -531,7 +757,7 @@ func file_c1_connector_v2_entitlement_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_c1_connector_v2_entitlement_proto_rawDesc), len(file_c1_connector_v2_entitlement_proto_rawDesc)), NumEnums: 1, - NumMessages: 3, + NumMessages: 5, NumExtensions: 0, NumServices: 1, }, diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/config/generate.go b/vendor/github.com/conductorone/baton-sdk/pkg/config/generate.go index 6ce7100d..8d9b0709 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/config/generate.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/config/generate.go @@ -27,6 +27,18 @@ func Generate(name string, schema field.Configuration) { if len(schema.Fields) == 0 { panic("schema must contain at least one field") } + + defaultGroupCount := 0 + for _, group := range schema.FieldGroups { + if group.Default { + defaultGroupCount++ + } + } + + if defaultGroupCount > 1 { + panic("schema must not contain more than one default field group") + } + confschema := schema confschema.Fields = append(confschema.Fields, field.DefaultFields...) // Ensure unique fields diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/connectorbuilder/resource_syncer.go b/vendor/github.com/conductorone/baton-sdk/pkg/connectorbuilder/resource_syncer.go index 036a13a3..bd95f56f 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/connectorbuilder/resource_syncer.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/connectorbuilder/resource_syncer.go @@ -44,6 +44,10 @@ type ResourceSyncerLimited interface { Grants(ctx context.Context, resource *v2.Resource, pToken *pagination.Token) ([]*v2.Grant, string, annotations.Annotations, error) } +type StaticEntitlementSyncer interface { + StaticEntitlements(ctx context.Context, pToken *pagination.Token) ([]*v2.Entitlement, string, annotations.Annotations, error) +} + type ResourceSyncerV2 interface { ResourceType ResourceSyncerV2Limited @@ -55,6 +59,10 @@ type ResourceSyncerV2Limited interface { Grants(ctx context.Context, resource *v2.Resource, opts resource.SyncOpAttrs) ([]*v2.Grant, *resource.SyncOpResults, error) } +type StaticEntitlementSyncerV2 interface { + StaticEntitlements(ctx context.Context, opts resource.SyncOpAttrs) ([]*v2.Entitlement, *resource.SyncOpResults, error) +} + // ResourceTargetedSyncer extends ResourceSyncer to add capabilities for directly syncing an individual resource // // Implementing this interface indicates the connector supports calling "get" on a resource @@ -170,6 +178,57 @@ func (b *builder) GetResource(ctx context.Context, request *v2.ResourceGetterSer }.Build(), nil } +// ListStaticEntitlements returns all the static entitlements for a given resource type. +// Static entitlements are used to create entitlements for all resources of a given resource type. +func (b *builder) ListStaticEntitlements(ctx context.Context, request *v2.EntitlementsServiceListStaticEntitlementsRequest) (*v2.EntitlementsServiceListStaticEntitlementsResponse, error) { + ctx, span := tracer.Start(ctx, "builder.ListStaticEntitlements") + defer span.End() + + start := b.nowFunc() + tt := tasks.ListStaticEntitlementsType + rb, ok := b.resourceSyncers[request.GetResourceTypeId()] + if !ok { + b.m.RecordTaskFailure(ctx, tt, b.nowFunc().Sub(start)) + return nil, fmt.Errorf("error: list static entitlements with unknown resource type %s", request.GetResourceTypeId()) + } + rbse, ok := rb.(StaticEntitlementSyncerV2) + if !ok { + // Resource syncer doesn't support static entitlements. Return empty response. + return v2.EntitlementsServiceListStaticEntitlementsResponse_builder{ + List: []*v2.Entitlement{}, + NextPageToken: "", + Annotations: nil, + }.Build(), nil + } + + token := pagination.Token{ + Size: int(request.GetPageSize()), + Token: request.GetPageToken(), + } + opts := resource.SyncOpAttrs{SyncID: request.GetActiveSyncId(), PageToken: token, Session: WithSyncId(b.sessionStore, request.GetActiveSyncId())} + out, retOptions, err := rbse.StaticEntitlements(ctx, opts) + if retOptions == nil { + retOptions = &resource.SyncOpResults{} + } + + resp := v2.EntitlementsServiceListStaticEntitlementsResponse_builder{ + List: out, + NextPageToken: retOptions.NextPageToken, + Annotations: retOptions.Annotations, + }.Build() + if err != nil { + b.m.RecordTaskFailure(ctx, tt, b.nowFunc().Sub(start)) + return nil, fmt.Errorf("error: listing static entitlements failed: %w", err) + } + if request.GetPageToken() != "" && request.GetPageToken() == retOptions.NextPageToken { + b.m.RecordTaskFailure(ctx, tt, b.nowFunc().Sub(start)) + return resp, fmt.Errorf("error: listing static entitlements failed: next page token is the same as the current page token. this is most likely a connector bug") + } + + b.m.RecordTaskSuccess(ctx, tt, b.nowFunc().Sub(start)) + return resp, nil +} + // ListEntitlements returns all the entitlements for a given resource. func (b *builder) ListEntitlements(ctx context.Context, request *v2.EntitlementsServiceListEntitlementsRequest) (*v2.EntitlementsServiceListEntitlementsResponse, error) { ctx, span := tracer.Start(ctx, "builder.ListEntitlements") @@ -263,6 +322,9 @@ type resourceSyncerV1toV2 struct { rb ResourceSyncer } +var _ ResourceSyncerV2 = &resourceSyncerV1toV2{} +var _ StaticEntitlementSyncerV2 = &resourceSyncerV1toV2{} + func (rw *resourceSyncerV1toV2) ResourceType(ctx context.Context) *v2.ResourceType { return rw.rb.ResourceType(ctx) } @@ -279,13 +341,24 @@ func (rw *resourceSyncerV1toV2) Entitlements(ctx context.Context, r *v2.Resource return ents, ret, err } +func (rw *resourceSyncerV1toV2) StaticEntitlements(ctx context.Context, opts resource.SyncOpAttrs) ([]*v2.Entitlement, *resource.SyncOpResults, error) { + rb, ok := rw.rb.(StaticEntitlementSyncer) + if !ok { + return nil, &resource.SyncOpResults{NextPageToken: "", Annotations: annotations.Annotations{}}, nil + } + + ents, pageToken, annos, err := rb.StaticEntitlements(ctx, &opts.PageToken) + ret := &resource.SyncOpResults{NextPageToken: pageToken, Annotations: annos} + return ents, ret, err +} + func (rw *resourceSyncerV1toV2) Grants(ctx context.Context, r *v2.Resource, opts resource.SyncOpAttrs) ([]*v2.Grant, *resource.SyncOpResults, error) { grants, pageToken, annos, err := rw.rb.Grants(ctx, r, &opts.PageToken) ret := &resource.SyncOpResults{NextPageToken: pageToken, Annotations: annos} return grants, ret, err } -func (b *builder) addTargetedSyncer(_ context.Context, typeId string, in interface{}) error { +func (b *builder) addTargetedSyncer(_ context.Context, typeId string, in any) error { if targetedSyncer, ok := in.(ResourceTargetedSyncerLimited); ok { if _, ok := b.resourceTargetedSyncers[typeId]; ok { return fmt.Errorf("error: duplicate resource type found for resource targeted syncer %s", typeId) @@ -295,7 +368,7 @@ func (b *builder) addTargetedSyncer(_ context.Context, typeId string, in interfa return nil } -func (b *builder) addResourceSyncers(_ context.Context, typeId string, in interface{}) error { +func (b *builder) addResourceSyncers(_ context.Context, typeId string, in any) error { // no duplicates if _, ok := b.resourceSyncers[typeId]; ok { return fmt.Errorf("error: duplicate resource type found for resource builder %s", typeId) diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/dotc1z/entitlements.go b/vendor/github.com/conductorone/baton-sdk/pkg/dotc1z/entitlements.go index 7e0940e0..af966794 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/dotc1z/entitlements.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/dotc1z/entitlements.go @@ -97,6 +97,16 @@ func (c *C1File) GetEntitlement(ctx context.Context, request *reader_v2.Entitlem }.Build(), nil } +func (c *C1File) ListStaticEntitlements(ctx context.Context, request *v2.EntitlementsServiceListStaticEntitlementsRequest) (*v2.EntitlementsServiceListStaticEntitlementsResponse, error) { + _, span := tracer.Start(ctx, "C1File.ListStaticEntitlements") + defer span.End() + + return v2.EntitlementsServiceListStaticEntitlementsResponse_builder{ + List: []*v2.Entitlement{}, + NextPageToken: "", + }.Build(), nil +} + func (c *C1File) PutEntitlements(ctx context.Context, entitlementObjs ...*v2.Entitlement) error { ctx, span := tracer.Start(ctx, "C1File.PutEntitlements") defer span.End() diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/field/field_group.go b/vendor/github.com/conductorone/baton-sdk/pkg/field/field_group.go index 30e48e02..884c23e1 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/field/field_group.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/field/field_group.go @@ -5,6 +5,7 @@ type SchemaFieldGroup struct { DisplayName string HelpText string Fields []SchemaField + Default bool } func WithFieldGroups(fieldGroups []SchemaFieldGroup) configOption { diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/field/marshal.go b/vendor/github.com/conductorone/baton-sdk/pkg/field/marshal.go index 2e68a63d..029e97f8 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/field/marshal.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/field/marshal.go @@ -68,6 +68,7 @@ func fieldGroupToV1(fg SchemaFieldGroup) *v1_conf.FieldGroup { Name: fg.Name, DisplayName: fg.DisplayName, HelpText: fg.HelpText, + Default: fg.Default, }.Build() fieldGroupV1.SetFields(make([]string, 0, len(fg.Fields))) diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/field/struct.go b/vendor/github.com/conductorone/baton-sdk/pkg/field/struct.go index 62e50db3..26c69581 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/field/struct.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/field/struct.go @@ -94,10 +94,6 @@ func NewConfiguration(fields []SchemaField, opts ...configOption) Configuration func (c *Configuration) FieldGroupFields(group string) map[string]SchemaField { var fieldGroupMap map[string]SchemaField - if group == "" { - return fieldGroupMap - } - for _, fg := range c.FieldGroups { if fg.Name == group { fieldGroupMap = fg.FieldMap() @@ -105,5 +101,18 @@ func (c *Configuration) FieldGroupFields(group string) map[string]SchemaField { } } + if fieldGroupMap == nil { + for _, fg := range c.FieldGroups { + if fg.Default { + fieldGroupMap = fg.FieldMap() + break + } + } + } + + if fieldGroupMap == nil && len(c.FieldGroups) >= 1 { + fieldGroupMap = c.FieldGroups[0].FieldMap() + } + return fieldGroupMap } diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/sdk/empty_connector.go b/vendor/github.com/conductorone/baton-sdk/pkg/sdk/empty_connector.go index f7862da7..4126ad1b 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/sdk/empty_connector.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/sdk/empty_connector.go @@ -53,6 +53,16 @@ func (n *emptyConnector) ListEntitlements( }.Build(), nil } +func (n *emptyConnector) ListStaticEntitlements( + ctx context.Context, + request *v2.EntitlementsServiceListStaticEntitlementsRequest, + opts ...grpc.CallOption, +) (*v2.EntitlementsServiceListStaticEntitlementsResponse, error) { + return v2.EntitlementsServiceListStaticEntitlementsResponse_builder{ + List: []*v2.Entitlement{}, + }.Build(), nil +} + // ListGrants returns a list of grants. func (n *emptyConnector) ListGrants(ctx context.Context, request *v2.GrantsServiceListGrantsRequest, opts ...grpc.CallOption) (*v2.GrantsServiceListGrantsResponse, error) { return v2.GrantsServiceListGrantsResponse_builder{ diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go b/vendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go index ffad66dc..84105768 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go @@ -1,3 +1,3 @@ package sdk -const Version = "v0.5.15" +const Version = "v0.5.24" diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/session/noop_session.go b/vendor/github.com/conductorone/baton-sdk/pkg/session/noop_session.go index 2273834a..11300026 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/session/noop_session.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/session/noop_session.go @@ -43,7 +43,8 @@ func (n *NoOpSessionStore) Delete(ctx context.Context, key string, opt ...sessio } func (n *NoOpSessionStore) Clear(ctx context.Context, opt ...sessions.SessionStoreOption) error { - return n.logAndError(ctx, "Clear") + // NOTE: we call this unconditionally for cleanup, so don't throw. + return nil } func (n *NoOpSessionStore) GetAll(ctx context.Context, pageToken string, opt ...sessions.SessionStoreOption) (map[string][]byte, string, error) { diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/session/session.go b/vendor/github.com/conductorone/baton-sdk/pkg/session/session.go index 6fb6b156..97b05678 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/session/session.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/session/session.go @@ -28,6 +28,10 @@ type GetManyable[T any] interface { func UnrollGetMany[T any](ctx context.Context, ss GetManyable[T], keys []string, opt ...sessions.SessionStoreOption) (map[string]T, error) { all := make(map[string]T) + if len(keys) == 0 { + return all, nil + } + // TODO(Kans): parallelize this? for keys := range Chunk(keys, MaxKeysPerRequest) { some, err := ss.GetMany(ctx, keys, opt...) @@ -44,6 +48,9 @@ type SetManyable[T any] interface { } func UnrollSetMany[T any](ctx context.Context, ss SetManyable[T], items map[string]T, opt ...sessions.SessionStoreOption) error { + if len(items) == 0 { + return nil + } if len(items) <= MaxKeysPerRequest { return ss.SetMany(ctx, items, opt...) } diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/sync/state.go b/vendor/github.com/conductorone/baton-sdk/pkg/sync/state.go index 9cbb9c8b..71e14911 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/sync/state.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/sync/state.go @@ -52,6 +52,8 @@ func (s ActionOp) String() string { return "list-resources" case SyncEntitlementsOp: return "list-entitlements" + case ListResourcesForEntitlementsOp: + return "list-resources-for-entitlements" case SyncGrantsOp: return "list-grants" case SyncExternalResourcesOp: @@ -62,6 +64,8 @@ func (s ActionOp) String() string { return "grant-expansion" case SyncTargetedResourceOp: return "targeted-resource-sync" + case SyncStaticEntitlementsOp: + return "list-static-entitlements" default: return "unknown" } @@ -105,11 +109,17 @@ func newActionOp(str string) ActionOp { return SyncExternalResourcesOp case SyncTargetedResourceOp.String(): return SyncTargetedResourceOp + case SyncStaticEntitlementsOp.String(): + return SyncStaticEntitlementsOp + case ListResourcesForEntitlementsOp.String(): + return ListResourcesForEntitlementsOp default: return UnknownOp } } +// Do not change the order of these constants, and only append new ones at the end. +// Otherwise resuming a sync started by an older version of baton-sdk will cause very strange behavior. const ( UnknownOp ActionOp = iota InitOp @@ -122,6 +132,7 @@ const ( SyncAssetsOp SyncGrantExpansionOp SyncTargetedResourceOp + SyncStaticEntitlementsOp ) // Action stores the current operation, page token, and optional fields for which resource is being worked with. diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/sync/syncer.go b/vendor/github.com/conductorone/baton-sdk/pkg/sync/syncer.go index 576c4eff..48fb33b7 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/sync/syncer.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/sync/syncer.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "iter" "os" "slices" "strconv" @@ -431,15 +432,21 @@ func (s *syncer) Sync(ctx context.Context) error { currentAction := s.state.Current() currentActionOp := "" currentActionPageToken := "" + currentActionResourceID := "" + currentActionResourceTypeID := "" if currentAction != nil { currentActionOp = currentAction.Op.String() currentActionPageToken = currentAction.PageToken + currentActionResourceID = currentAction.ResourceID + currentActionResourceTypeID = currentAction.ResourceTypeID } entitlementGraph := s.state.EntitlementGraph(ctx) l.Info("resumed previous sync", zap.String("sync_id", syncID), zap.String("sync_type", string(s.syncType)), zap.String("current_action_op", currentActionOp), + zap.String("current_action_resource_id", currentActionResourceID), + zap.String("current_action_resource_type_id", currentActionResourceTypeID), zap.String("current_action_page_token", currentActionPageToken), zap.Bool("needs_expansion", s.state.NeedsExpansion()), zap.Bool("has_external_resources_grants", s.state.HasExternalResourcesGrants()), @@ -544,6 +551,7 @@ func (s *syncer) Sync(ctx context.Context) error { s.state.PushAction(ctx, Action{Op: SyncGrantsOp}) } s.state.PushAction(ctx, Action{Op: SyncEntitlementsOp}) + s.state.PushAction(ctx, Action{Op: SyncStaticEntitlementsOp}) } s.state.PushAction(ctx, Action{Op: SyncResourcesOp}) s.state.PushAction(ctx, Action{Op: SyncResourceTypesOp}) @@ -581,6 +589,18 @@ func (s *syncer) Sync(ctx context.Context) error { } continue + case SyncStaticEntitlementsOp: + err = s.SyncStaticEntitlements(ctx) + if isWarning(ctx, err) { + l.Warn("skipping sync static entitlements action", zap.Any("stateAction", stateAction), zap.Error(err)) + warnings = append(warnings, err) + s.state.FinishAction(ctx) + continue + } + if !retryer.ShouldWaitAndRetry(ctx, err) { + return err + } + continue case SyncEntitlementsOp: err = s.SyncEntitlements(ctx) if isWarning(ctx, err) { @@ -713,6 +733,29 @@ func (s *syncer) SkipSync(ctx context.Context) error { return nil } +func (s *syncer) listAllResourceTypes(ctx context.Context) iter.Seq2[[]*v2.ResourceType, error] { + return func(yield func([]*v2.ResourceType, error) bool) { + pageToken := "" + for { + resp, err := s.connector.ListResourceTypes(ctx, v2.ResourceTypesServiceListResourceTypesRequest_builder{PageToken: pageToken}.Build()) + if err != nil { + _ = yield(nil, err) + return + } + resourceTypes := resp.GetList() + if len(resourceTypes) > 0 { + if !yield(resourceTypes, err) { + return + } + } + pageToken = resp.GetNextPageToken() + if pageToken == "" { + return + } + } + } +} + // SyncResourceTypes calls the ListResourceType() connector endpoint and persists the results in to the datasource. func (s *syncer) SyncResourceTypes(ctx context.Context) error { ctx, span := tracer.Start(ctx, "syncer.SyncResourceTypes") @@ -1247,6 +1290,109 @@ func (s *syncer) syncEntitlementsForResource(ctx context.Context, resourceID *v2 return nil } +func (s *syncer) SyncStaticEntitlements(ctx context.Context) error { + ctx, span := tracer.Start(ctx, "syncer.SyncStaticEntitlements") + defer span.End() + + if s.state.ResourceTypeID(ctx) != "" { + return s.syncStaticEntitlementsForResourceType(ctx, s.state.ResourceTypeID(ctx)) + } + + ctxzap.Extract(ctx).Info("Syncing static entitlements...") + s.handleInitialActionForStep(ctx, *s.state.Current()) + + s.state.FinishAction(ctx) + for rts, err := range s.listAllResourceTypes(ctx) { + if err != nil { + return err + } + for _, rt := range rts { + // Queue up actions to sync static entitlements for each resource type + s.state.PushAction(ctx, Action{Op: SyncStaticEntitlementsOp, ResourceTypeID: rt.GetId()}) + } + } + + return nil +} + +func (s *syncer) syncStaticEntitlementsForResourceType(ctx context.Context, resourceTypeID string) error { + ctx, span := tracer.Start(ctx, "syncer.syncStaticEntitlementsForResource") + defer span.End() + + resp, err := s.connector.ListStaticEntitlements(ctx, v2.EntitlementsServiceListStaticEntitlementsRequest_builder{ + ResourceTypeId: resourceTypeID, + PageToken: s.state.PageToken(ctx), + ActiveSyncId: s.getActiveSyncID(), + }.Build()) + if err != nil { + // Ignore prefixError if we're calling a lambda with an old version of baton-sdk. + if strings.Contains(err.Error(), `unable to resolve \"type.googleapis.com/c1.connector.v2.EntitlementsServiceListStaticEntitlementsRequest\": \"not found\"","errorType":"prefixError"`) { + l := ctxzap.Extract(ctx) + l.Info("ignoring prefixError when calling ListStaticEntitlements", zap.Error(err)) + s.state.FinishAction(ctx) + return nil + } + + return err + } + + for _, ent := range resp.GetList() { + resourcePageToken := "" + for { + // Get all resources of resource type and create entitlements for each one. + resourcesResp, err := s.store.ListResources(ctx, v2.ResourcesServiceListResourcesRequest_builder{ + ResourceTypeId: resourceTypeID, + PageToken: resourcePageToken, + ActiveSyncId: s.getActiveSyncID(), + }.Build()) + if err != nil { + return err + } + entitlements := []*v2.Entitlement{} + for _, resource := range resourcesResp.GetList() { + displayName := ent.GetDisplayName() + if displayName == "" { + displayName = resource.GetDisplayName() + } + description := ent.GetDescription() + if description == "" { + description = resource.GetDescription() + } + + entitlements = append(entitlements, &v2.Entitlement{ + Resource: resource, + Id: entitlement.NewEntitlementID(resource, ent.GetSlug()), + DisplayName: displayName, + Description: description, + GrantableTo: ent.GetGrantableTo(), + Annotations: ent.GetAnnotations(), + }) + } + err = s.store.PutEntitlements(ctx, entitlements...) + if err != nil { + return err + } + resourcePageToken = resourcesResp.GetNextPageToken() + if resourcePageToken == "" { + break + } + } + } + + s.handleProgress(ctx, s.state.Current(), len(resp.GetList())) + + if resp.GetNextPageToken() != "" { + err = s.state.NextPage(ctx, resp.GetNextPageToken()) + if err != nil { + return err + } + } else { + s.state.FinishAction(ctx) + } + + return nil +} + // syncAssetsForResource looks up a resource given the input ID. From there it looks to see if there are any traits that // include references to an asset. For each AssetRef, we then call GetAsset on the connector and stream the asset from the connector. // Once we have the entire asset, we put it in the database. @@ -1767,6 +1913,10 @@ func (s *syncer) syncGrantsForResource(ctx context.Context, resourceID *v2.Resou grants = append(grants, resp.GetList()...) l := ctxzap.Extract(ctx) + resourcesToInsertMap := make(map[string]*v2.Resource, 0) + respAnnos := annotations.Annotations(resp.GetAnnotations()) + insertResourceGrants := respAnnos.Contains(&v2.InsertResourceGrants{}) + for _, grant := range grants { grantAnnos := annotations.Annotations(grant.GetAnnotations()) if !s.dontExpandGrants && grantAnnos.Contains(&v2.GrantExpandable{}) { @@ -1776,6 +1926,15 @@ func (s *syncer) syncGrantsForResource(ctx context.Context, resourceID *v2.Resou s.state.SetHasExternalResourcesGrants() } + if insertResourceGrants { + resource := grant.GetEntitlement().GetResource() + bid, err := bid.MakeBid(resource) + if err != nil { + return err + } + resourcesToInsertMap[bid] = resource + } + if !s.state.ShouldFetchRelatedResources() { continue } @@ -1804,6 +1963,18 @@ func (s *syncer) syncGrantsForResource(ctx context.Context, resourceID *v2.Resou } } } + + if len(resourcesToInsertMap) > 0 { + resourcesToInsert := make([]*v2.Resource, 0) + for _, resource := range resourcesToInsertMap { + resourcesToInsert = append(resourcesToInsert, resource) + } + err = s.store.PutResources(ctx, resourcesToInsert...) + if err != nil { + return err + } + } + err = s.store.PutGrants(ctx, grants...) if err != nil { return err @@ -1883,24 +2054,20 @@ func (s *syncer) SyncExternalResourcesWithGrantToEntitlement(ctx context.Context return err } - grants, err := s.listExternalGrantsForEntitlement(ctx, filterEntitlement.GetEntitlement()) - if err != nil { - return err - } - - ents := make([]*v2.Entitlement, 0) - principals := make([]*v2.Resource, 0) - resourceTypes := make([]*v2.ResourceType, 0) resourceTypeIDs := mapset.NewSet[string]() resourceIDs := make(map[string]*v2.ResourceId) - grantsForEnts := make([]*v2.Grant, 0) - - for _, g := range grants { - resourceTypeIDs.Add(g.GetPrincipal().GetId().GetResourceType()) - resourceIDs[g.GetPrincipal().GetId().GetResource()] = g.GetPrincipal().GetId() + for grants, err := range s.listExternalGrantsForEntitlement(ctx, filterEntitlement.GetEntitlement()) { + if err != nil { + return err + } + for _, g := range grants { + resourceTypeIDs.Add(g.GetPrincipal().GetId().GetResourceType()) + resourceIDs[g.GetPrincipal().GetId().GetResource()] = g.GetPrincipal().GetId() + } } + resourceTypes := make([]*v2.ResourceType, 0) for _, resourceTypeId := range resourceTypeIDs.ToSlice() { resourceTypeResp, err := s.externalResourceReader.GetResourceType(ctx, reader_v2.ResourceTypesReaderServiceGetResourceTypeRequest_builder{ResourceTypeId: resourceTypeId}.Build()) if err != nil { @@ -1919,6 +2086,12 @@ func (s *syncer) SyncExternalResourcesWithGrantToEntitlement(ctx context.Context skipEGForResourceType[resourceTypeResp.GetResourceType().GetId()] = skipEntitlements } + err = s.store.PutResourceTypes(ctx, resourceTypes...) + if err != nil { + return err + } + + principals := make([]*v2.Resource, 0) for _, resourceId := range resourceIDs { resourceResp, err := s.externalResourceReader.GetResource(ctx, reader_v2.ResourcesReaderServiceGetResourceRequest_builder{ResourceId: resourceId}.Build()) if err != nil { @@ -1940,6 +2113,13 @@ func (s *syncer) SyncExternalResourcesWithGrantToEntitlement(ctx context.Context principals = append(principals, resourceVal) } + err = s.store.PutResources(ctx, principals...) + if err != nil { + return err + } + + entsCount := 0 + ents := make([]*v2.Entitlement, 0) for _, principal := range principals { rAnnos := annotations.Annotations(principal.GetAnnotations()) skipEnts := skipEGForResourceType[principal.GetId().GetResourceType()] || rAnnos.Contains(&v2.SkipEntitlementsAndGrants{}) @@ -1952,45 +2132,37 @@ func (s *syncer) SyncExternalResourcesWithGrantToEntitlement(ctx context.Context return err } ents = append(ents, resourceEnts...) + entsCount += len(resourceEnts) + } + + err = s.store.PutEntitlements(ctx, ents...) + if err != nil { + return err } + grantsForEntsCount := 0 for _, ent := range ents { rAnnos := annotations.Annotations(ent.GetResource().GetAnnotations()) if rAnnos.Contains(&v2.SkipGrants{}) { continue } - grantsForEnt, err := s.listExternalGrantsForEntitlement(ctx, ent) - if err != nil { - return err + for grants, err := range s.listExternalGrantsForEntitlement(ctx, ent) { + if err != nil { + return err + } + grantsForEntsCount += len(grants) + err = s.store.PutGrants(ctx, grants...) + if err != nil { + return err + } } - grantsForEnts = append(grantsForEnts, grantsForEnt...) - } - - err = s.store.PutResourceTypes(ctx, resourceTypes...) - if err != nil { - return err - } - - err = s.store.PutResources(ctx, principals...) - if err != nil { - return err - } - - err = s.store.PutEntitlements(ctx, ents...) - if err != nil { - return err - } - - err = s.store.PutGrants(ctx, grantsForEnts...) - if err != nil { - return err } l.Info("Synced external resources for entitlement", zap.Int("resource_type_count", len(resourceTypes)), zap.Int("resource_count", len(principals)), - zap.Int("entitlement_count", len(ents)), - zap.Int("grant_count", len(grantsForEnts)), + zap.Int("entitlement_count", entsCount), + zap.Int("grant_count", grantsForEntsCount), ) err = s.processGrantsWithExternalPrincipals(ctx, principals) @@ -2020,7 +2192,6 @@ func (s *syncer) SyncExternalResourcesUsersAndGroups(ctx context.Context) error userAndGroupResourceTypes := make([]*v2.ResourceType, 0) ents := make([]*v2.Entitlement, 0) principals := make([]*v2.Resource, 0) - grantsForEnts := make([]*v2.Grant, 0) for _, rt := range resourceTypes { for _, t := range rt.GetTraits() { if t == v2.ResourceType_TRAIT_USER || t == v2.ResourceType_TRAIT_GROUP { @@ -2030,6 +2201,11 @@ func (s *syncer) SyncExternalResourcesUsersAndGroups(ctx context.Context) error } } + err = s.store.PutResourceTypes(ctx, userAndGroupResourceTypes...) + if err != nil { + return err + } + for _, rt := range userAndGroupResourceTypes { rtAnnos := annotations.Annotations(rt.GetAnnotations()) skipEntitlements := rtAnnos.Contains(&v2.SkipEntitlementsAndGrants{}) @@ -2049,6 +2225,13 @@ func (s *syncer) SyncExternalResourcesUsersAndGroups(ctx context.Context) error } } + err = s.store.PutResources(ctx, principals...) + if err != nil { + return err + } + + entsCount := 0 + principalsCount := len(principals) for _, principal := range principals { skipEnts := skipEGForResourceType[principal.GetId().GetResourceType()] if skipEnts { @@ -2064,45 +2247,36 @@ func (s *syncer) SyncExternalResourcesUsersAndGroups(ctx context.Context) error return err } ents = append(ents, resourceEnts...) + entsCount += len(resourceEnts) + err = s.store.PutEntitlements(ctx, resourceEnts...) + if err != nil { + return err + } } + grantsForEntsCount := 0 for _, ent := range ents { rAnnos := annotations.Annotations(ent.GetResource().GetAnnotations()) if rAnnos.Contains(&v2.SkipGrants{}) { continue } - grantsForEnt, err := s.listExternalGrantsForEntitlement(ctx, ent) - if err != nil { - return err + for grants, err := range s.listExternalGrantsForEntitlement(ctx, ent) { + if err != nil { + return err + } + grantsForEntsCount += len(grants) + err = s.store.PutGrants(ctx, grants...) + if err != nil { + return err + } } - grantsForEnts = append(grantsForEnts, grantsForEnt...) - } - - err = s.store.PutResourceTypes(ctx, userAndGroupResourceTypes...) - if err != nil { - return err - } - - err = s.store.PutResources(ctx, principals...) - if err != nil { - return err - } - - err = s.store.PutEntitlements(ctx, ents...) - if err != nil { - return err - } - - err = s.store.PutGrants(ctx, grantsForEnts...) - if err != nil { - return err } l.Info("Synced external resources", zap.Int("resource_type_count", len(userAndGroupResourceTypes)), - zap.Int("resource_count", len(principals)), - zap.Int("entitlement_count", len(ents)), - zap.Int("grant_count", len(grantsForEnts)), + zap.Int("resource_count", principalsCount), + zap.Int("entitlement_count", entsCount), + zap.Int("grant_count", grantsForEntsCount), ) err = s.processGrantsWithExternalPrincipals(ctx, principals) @@ -2156,24 +2330,30 @@ func (s *syncer) listExternalEntitlementsForResource(ctx context.Context, resour return ents, nil } -func (s *syncer) listExternalGrantsForEntitlement(ctx context.Context, ent *v2.Entitlement) ([]*v2.Grant, error) { - grantsForEnts := make([]*v2.Grant, 0) - entitlementGrantPageToken := "" - for { - grantsForEntitlementResp, err := s.externalResourceReader.ListGrantsForEntitlement(ctx, reader_v2.GrantsReaderServiceListGrantsForEntitlementRequest_builder{ - Entitlement: ent, - PageToken: entitlementGrantPageToken, - }.Build()) - if err != nil { - return nil, err - } - grantsForEnts = append(grantsForEnts, grantsForEntitlementResp.GetList()...) - entitlementGrantPageToken = grantsForEntitlementResp.GetNextPageToken() - if entitlementGrantPageToken == "" { - break +func (s *syncer) listExternalGrantsForEntitlement(ctx context.Context, ent *v2.Entitlement) iter.Seq2[[]*v2.Grant, error] { + return func(yield func([]*v2.Grant, error) bool) { + pageToken := "" + for { + grantsForEntitlementResp, err := s.externalResourceReader.ListGrantsForEntitlement(ctx, reader_v2.GrantsReaderServiceListGrantsForEntitlementRequest_builder{ + Entitlement: ent, + PageToken: pageToken, + }.Build()) + if err != nil { + _ = yield(nil, err) + return + } + grants := grantsForEntitlementResp.GetList() + if len(grants) > 0 { + if !yield(grants, err) { + return + } + } + pageToken = grantsForEntitlementResp.GetNextPageToken() + if pageToken == "" { + return + } } } - return grantsForEnts, nil } func (s *syncer) listExternalResourceTypes(ctx context.Context) ([]*v2.ResourceType, error) { @@ -2195,24 +2375,29 @@ func (s *syncer) listExternalResourceTypes(ctx context.Context) ([]*v2.ResourceT return resourceTypes, nil } -func (s *syncer) listAllGrants(ctx context.Context) ([]*v2.Grant, error) { - grants := make([]*v2.Grant, 0) - pageToken := "" - for { - grantsResp, err := s.store.ListGrants(ctx, v2.GrantsServiceListGrantsRequest_builder{ - PageToken: pageToken, - }.Build()) - if err != nil { - return nil, err - } +func (s *syncer) listAllGrants(ctx context.Context) iter.Seq2[[]*v2.Grant, error] { + return func(yield func([]*v2.Grant, error) bool) { + pageToken := "" + for { + grantsResp, err := s.store.ListGrants(ctx, v2.GrantsServiceListGrantsRequest_builder{ + PageToken: pageToken, + }.Build()) + if err != nil { + _ = yield(nil, err) + return + } - grants = append(grants, grantsResp.GetList()...) - pageToken = grantsResp.GetNextPageToken() - if pageToken == "" { - break + if len(grantsResp.GetList()) > 0 { + if !yield(grantsResp.GetList(), err) { + return + } + } + pageToken = grantsResp.GetNextPageToken() + if pageToken == "" { + return + } } } - return grants, nil } func (s *syncer) processGrantsWithExternalPrincipals(ctx context.Context, principals []*v2.Resource) error { @@ -2252,196 +2437,197 @@ func (s *syncer) processGrantsWithExternalPrincipals(ctx context.Context, princi grantsToDelete := make([]string, 0) expandedGrants := make([]*v2.Grant, 0) - grants, err := s.listAllGrants(ctx) - if err != nil { - return err - } - - for _, grant := range grants { - annos := annotations.Annotations(grant.GetAnnotations()) - if !annos.ContainsAny(&v2.ExternalResourceMatchAll{}, &v2.ExternalResourceMatch{}, &v2.ExternalResourceMatchID{}) { - continue - } - - // Match all - matchResourceMatchAllAnno, err := GetExternalResourceMatchAllAnnotation(annos) + for grants, err := range s.listAllGrants(ctx) { if err != nil { return err } - if matchResourceMatchAllAnno != nil { - var processPrincipals []*v2.Resource - switch matchResourceMatchAllAnno.GetResourceType() { - case v2.ResourceType_TRAIT_USER: - processPrincipals = userPrincipals - case v2.ResourceType_TRAIT_GROUP: - processPrincipals = groupPrincipals - default: - l.Error("unexpected external resource type trait", zap.Any("trait", matchResourceMatchAllAnno.GetResourceType())) - } - for _, principal := range processPrincipals { - newGrant := newGrantForExternalPrincipal(grant, principal) - expandedGrants = append(expandedGrants, newGrant) + + for _, grant := range grants { + annos := annotations.Annotations(grant.GetAnnotations()) + if !annos.ContainsAny(&v2.ExternalResourceMatchAll{}, &v2.ExternalResourceMatch{}, &v2.ExternalResourceMatchID{}) { + continue } - grantsToDelete = append(grantsToDelete, grant.GetId()) - continue - } - expandableAnno, err := GetExpandableAnnotation(annos) - if err != nil { - return err - } - expandableEntitlementsResourceMap := make(map[string][]*v2.Entitlement) - if expandableAnno != nil { - for _, entId := range expandableAnno.GetEntitlementIds() { - parsedEnt, err := bid.ParseEntitlementBid(entId) - if err != nil { - l.Error("error parsing expandable entitlement bid", zap.Any("entitlementId", entId)) - continue - } - resourceBID, err := bid.MakeBid(parsedEnt.GetResource()) - if err != nil { - l.Error("error making resource bid", zap.Any("parsedEnt.Resource", parsedEnt.GetResource())) - continue + // Match all + matchResourceMatchAllAnno, err := GetExternalResourceMatchAllAnnotation(annos) + if err != nil { + return err + } + if matchResourceMatchAllAnno != nil { + var processPrincipals []*v2.Resource + switch matchResourceMatchAllAnno.GetResourceType() { + case v2.ResourceType_TRAIT_USER: + processPrincipals = userPrincipals + case v2.ResourceType_TRAIT_GROUP: + processPrincipals = groupPrincipals + default: + l.Error("unexpected external resource type trait", zap.Any("trait", matchResourceMatchAllAnno.GetResourceType())) } - entitlementMap, ok := expandableEntitlementsResourceMap[resourceBID] - if !ok { - entitlementMap = make([]*v2.Entitlement, 0) + for _, principal := range processPrincipals { + newGrant := newGrantForExternalPrincipal(grant, principal) + expandedGrants = append(expandedGrants, newGrant) } - entitlementMap = append(entitlementMap, parsedEnt) - expandableEntitlementsResourceMap[resourceBID] = entitlementMap + grantsToDelete = append(grantsToDelete, grant.GetId()) + continue } - } - // Match by ID - matchResourceMatchIDAnno, err := GetExternalResourceMatchIDAnnotation(annos) - if err != nil { - return err - } - if matchResourceMatchIDAnno != nil { - if principal, ok := principalMap[matchResourceMatchIDAnno.GetId()]; ok { - newGrant := newGrantForExternalPrincipal(grant, principal) - expandedGrants = append(expandedGrants, newGrant) - - newGrantAnnos := annotations.Annotations(newGrant.GetAnnotations()) - - newExpandableEntitlementIDs := make([]string, 0) - if expandableAnno != nil { - groupPrincipalBID, err := bid.MakeBid(grant.GetPrincipal()) + expandableAnno, err := GetExpandableAnnotation(annos) + if err != nil { + return err + } + expandableEntitlementsResourceMap := make(map[string][]*v2.Entitlement) + if expandableAnno != nil { + for _, entId := range expandableAnno.GetEntitlementIds() { + parsedEnt, err := bid.ParseEntitlementBid(entId) if err != nil { - l.Error("error making group principal bid", zap.Error(err), zap.Any("grant.Principal", grant.GetPrincipal())) + l.Error("error parsing expandable entitlement bid", zap.Any("entitlementId", entId)) continue } - - principalEntitlements := expandableEntitlementsResourceMap[groupPrincipalBID] - for _, expandableGrant := range principalEntitlements { - newExpandableEntId := entitlement.NewEntitlementID(principal, expandableGrant.GetSlug()) - _, err := s.store.GetEntitlement(ctx, reader_v2.EntitlementsReaderServiceGetEntitlementRequest_builder{EntitlementId: newExpandableEntId}.Build()) - if err != nil { - if errors.Is(err, sql.ErrNoRows) { - l.Error("found no entitlement with entitlement id generated from external source sync", zap.Any("entitlementId", newExpandableEntId)) - continue - } - return err - } - newExpandableEntitlementIDs = append(newExpandableEntitlementIDs, newExpandableEntId) + resourceBID, err := bid.MakeBid(parsedEnt.GetResource()) + if err != nil { + l.Error("error making resource bid", zap.Any("parsedEnt.Resource", parsedEnt.GetResource())) + continue } - - newExpandableAnno := v2.GrantExpandable_builder{ - EntitlementIds: newExpandableEntitlementIDs, - Shallow: expandableAnno.GetShallow(), - ResourceTypeIds: expandableAnno.GetResourceTypeIds(), - }.Build() - newGrantAnnos.Update(newExpandableAnno) - newGrant.SetAnnotations(newGrantAnnos) - expandedGrants = append(expandedGrants, newGrant) + entitlementMap, ok := expandableEntitlementsResourceMap[resourceBID] + if !ok { + entitlementMap = make([]*v2.Entitlement, 0) + } + entitlementMap = append(entitlementMap, parsedEnt) + expandableEntitlementsResourceMap[resourceBID] = entitlementMap } } - // We still want to delete the grant even if there are no matches - // Since it does not correspond to any known user - grantsToDelete = append(grantsToDelete, grant.GetId()) - } + // Match by ID + matchResourceMatchIDAnno, err := GetExternalResourceMatchIDAnnotation(annos) + if err != nil { + return err + } + if matchResourceMatchIDAnno != nil { + if principal, ok := principalMap[matchResourceMatchIDAnno.GetId()]; ok { + newGrant := newGrantForExternalPrincipal(grant, principal) + expandedGrants = append(expandedGrants, newGrant) - // Match by key/val - matchExternalResource, err := GetExternalResourceMatchAnnotation(annos) - if err != nil { - return err - } + newGrantAnnos := annotations.Annotations(newGrant.GetAnnotations()) - if matchExternalResource != nil { - switch matchExternalResource.GetResourceType() { - case v2.ResourceType_TRAIT_USER: - for _, userPrincipal := range userPrincipals { - userTrait, err := resource.GetUserTrait(userPrincipal) - if err != nil { - l.Error("error getting user trait", zap.Any("userPrincipal", userPrincipal)) - continue - } - if matchExternalResource.GetKey() == "email" { - if userTraitContainsEmail(userTrait.GetEmails(), matchExternalResource.GetValue()) { - newGrant := newGrantForExternalPrincipal(grant, userPrincipal) - expandedGrants = append(expandedGrants, newGrant) - // continue to next principal since we found an email match + newExpandableEntitlementIDs := make([]string, 0) + if expandableAnno != nil { + groupPrincipalBID, err := bid.MakeBid(grant.GetPrincipal()) + if err != nil { + l.Error("error making group principal bid", zap.Error(err), zap.Any("grant.Principal", grant.GetPrincipal())) continue } - } - profileVal, ok := resource.GetProfileStringValue(userTrait.GetProfile(), matchExternalResource.GetKey()) - if ok && strings.EqualFold(profileVal, matchExternalResource.GetValue()) { - newGrant := newGrantForExternalPrincipal(grant, userPrincipal) + + principalEntitlements := expandableEntitlementsResourceMap[groupPrincipalBID] + for _, expandableGrant := range principalEntitlements { + newExpandableEntId := entitlement.NewEntitlementID(principal, expandableGrant.GetSlug()) + _, err := s.store.GetEntitlement(ctx, reader_v2.EntitlementsReaderServiceGetEntitlementRequest_builder{EntitlementId: newExpandableEntId}.Build()) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + l.Error("found no entitlement with entitlement id generated from external source sync", zap.Any("entitlementId", newExpandableEntId)) + continue + } + return err + } + newExpandableEntitlementIDs = append(newExpandableEntitlementIDs, newExpandableEntId) + } + + newExpandableAnno := v2.GrantExpandable_builder{ + EntitlementIds: newExpandableEntitlementIDs, + Shallow: expandableAnno.GetShallow(), + ResourceTypeIds: expandableAnno.GetResourceTypeIds(), + }.Build() + newGrantAnnos.Update(newExpandableAnno) + newGrant.SetAnnotations(newGrantAnnos) expandedGrants = append(expandedGrants, newGrant) } } - case v2.ResourceType_TRAIT_GROUP: - for _, groupPrincipal := range groupPrincipals { - groupTrait, err := resource.GetGroupTrait(groupPrincipal) - if err != nil { - l.Error("error getting group trait", zap.Any("groupPrincipal", groupPrincipal)) - continue - } - profileVal, ok := resource.GetProfileStringValue(groupTrait.GetProfile(), matchExternalResource.GetKey()) - if ok && strings.EqualFold(profileVal, matchExternalResource.GetValue()) { - newGrant := newGrantForExternalPrincipal(grant, groupPrincipal) - newGrantAnnos := annotations.Annotations(newGrant.GetAnnotations()) - - newExpandableEntitlementIDs := make([]string, 0) - if expandableAnno != nil { - groupPrincipalBID, err := bid.MakeBid(grant.GetPrincipal()) - if err != nil { - l.Error("error making group principal bid", zap.Error(err), zap.Any("grant.Principal", grant.GetPrincipal())) + + // We still want to delete the grant even if there are no matches + // Since it does not correspond to any known user + grantsToDelete = append(grantsToDelete, grant.GetId()) + } + + // Match by key/val + matchExternalResource, err := GetExternalResourceMatchAnnotation(annos) + if err != nil { + return err + } + + if matchExternalResource != nil { + switch matchExternalResource.GetResourceType() { + case v2.ResourceType_TRAIT_USER: + for _, userPrincipal := range userPrincipals { + userTrait, err := resource.GetUserTrait(userPrincipal) + if err != nil { + l.Error("error getting user trait", zap.Any("userPrincipal", userPrincipal)) + continue + } + if matchExternalResource.GetKey() == "email" { + if userTraitContainsEmail(userTrait.GetEmails(), matchExternalResource.GetValue()) { + newGrant := newGrantForExternalPrincipal(grant, userPrincipal) + expandedGrants = append(expandedGrants, newGrant) + // continue to next principal since we found an email match continue } - - principalEntitlements := expandableEntitlementsResourceMap[groupPrincipalBID] - for _, expandableGrant := range principalEntitlements { - newExpandableEntId := entitlement.NewEntitlementID(groupPrincipal, expandableGrant.GetSlug()) - _, err := s.store.GetEntitlement(ctx, reader_v2.EntitlementsReaderServiceGetEntitlementRequest_builder{EntitlementId: newExpandableEntId}.Build()) + } + profileVal, ok := resource.GetProfileStringValue(userTrait.GetProfile(), matchExternalResource.GetKey()) + if ok && strings.EqualFold(profileVal, matchExternalResource.GetValue()) { + newGrant := newGrantForExternalPrincipal(grant, userPrincipal) + expandedGrants = append(expandedGrants, newGrant) + } + } + case v2.ResourceType_TRAIT_GROUP: + for _, groupPrincipal := range groupPrincipals { + groupTrait, err := resource.GetGroupTrait(groupPrincipal) + if err != nil { + l.Error("error getting group trait", zap.Any("groupPrincipal", groupPrincipal)) + continue + } + profileVal, ok := resource.GetProfileStringValue(groupTrait.GetProfile(), matchExternalResource.GetKey()) + if ok && strings.EqualFold(profileVal, matchExternalResource.GetValue()) { + newGrant := newGrantForExternalPrincipal(grant, groupPrincipal) + newGrantAnnos := annotations.Annotations(newGrant.GetAnnotations()) + + newExpandableEntitlementIDs := make([]string, 0) + if expandableAnno != nil { + groupPrincipalBID, err := bid.MakeBid(grant.GetPrincipal()) if err != nil { - if errors.Is(err, sql.ErrNoRows) { - l.Error("found no entitlement with entitlement id generated from external source sync", zap.Any("entitlementId", newExpandableEntId)) - continue + l.Error("error making group principal bid", zap.Error(err), zap.Any("grant.Principal", grant.GetPrincipal())) + continue + } + + principalEntitlements := expandableEntitlementsResourceMap[groupPrincipalBID] + for _, expandableGrant := range principalEntitlements { + newExpandableEntId := entitlement.NewEntitlementID(groupPrincipal, expandableGrant.GetSlug()) + _, err := s.store.GetEntitlement(ctx, reader_v2.EntitlementsReaderServiceGetEntitlementRequest_builder{EntitlementId: newExpandableEntId}.Build()) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + l.Error("found no entitlement with entitlement id generated from external source sync", zap.Any("entitlementId", newExpandableEntId)) + continue + } + return err } - return err + newExpandableEntitlementIDs = append(newExpandableEntitlementIDs, newExpandableEntId) } - newExpandableEntitlementIDs = append(newExpandableEntitlementIDs, newExpandableEntId) - } - newExpandableAnno := v2.GrantExpandable_builder{ - EntitlementIds: newExpandableEntitlementIDs, - Shallow: expandableAnno.GetShallow(), - ResourceTypeIds: expandableAnno.GetResourceTypeIds(), - }.Build() - newGrantAnnos.Update(newExpandableAnno) - newGrant.SetAnnotations(newGrantAnnos) - expandedGrants = append(expandedGrants, newGrant) + newExpandableAnno := v2.GrantExpandable_builder{ + EntitlementIds: newExpandableEntitlementIDs, + Shallow: expandableAnno.GetShallow(), + ResourceTypeIds: expandableAnno.GetResourceTypeIds(), + }.Build() + newGrantAnnos.Update(newExpandableAnno) + newGrant.SetAnnotations(newGrantAnnos) + expandedGrants = append(expandedGrants, newGrant) + } } } + default: + l.Error("unexpected external resource type trait", zap.Any("trait", matchExternalResource.GetResourceType())) } - default: - l.Error("unexpected external resource type trait", zap.Any("trait", matchExternalResource.GetResourceType())) - } - // We still want to delete the grant even if there are no matches - grantsToDelete = append(grantsToDelete, grant.GetId()) + // We still want to delete the grant even if there are no matches + grantsToDelete = append(grantsToDelete, grant.GetId()) + } } } @@ -2450,7 +2636,7 @@ func (s *syncer) processGrantsWithExternalPrincipals(ctx context.Context, princi newGrantIDs.Add(ng.GetId()) } - err = s.store.PutGrants(ctx, expandedGrants...) + err := s.store.PutGrants(ctx, expandedGrants...) if err != nil { return err } diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/types/tasks/tasks.go b/vendor/github.com/conductorone/baton-sdk/pkg/types/tasks/tasks.go index 73071aa4..07e38a89 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/types/tasks/tasks.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/types/tasks/tasks.go @@ -40,12 +40,16 @@ func (tt TaskType) String() string { return "get_resource" case ListEntitlementsType: return "list_entitlements" + case ListStaticEntitlementsType: + return "list_static_entitlements" case ListGrantsType: return "list_grants" case GetMetadataType: return "get_metadata" case ListEventsType: return "list_events" + case ListEventFeedsType: + return "list_event_feeds" case StartDebugging: return "set_log_file_event" case BulkCreateTicketsType: @@ -60,6 +64,8 @@ func (tt TaskType) String() string { return "invoke_action" case ActionStatusType: return "action_status" + case CreateSyncDiff: + return "create_sync_diff" default: return "unknown" } @@ -97,4 +103,5 @@ const ( ActionInvokeType ActionStatusType CreateSyncDiff + ListStaticEntitlementsType ) diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go b/vendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go index 6feb0864..6befc8bb 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go @@ -433,7 +433,7 @@ func (c *BaseHttpClient) Do(req *http.Request, options ...DoOption) (*http.Respo // Log response headers directly for certain errors if resp.StatusCode >= 400 { - redactedHeaders := redactHeaders(resp.Header) + redactedHeaders := RedactSensitiveHeaders(resp.Header) l.Error("base-http-client: HTTP error status", zap.Int("status_code", resp.StatusCode), zap.String("status", resp.Status), @@ -476,13 +476,26 @@ func (c *BaseHttpClient) Do(req *http.Request, options ...DoOption) (*http.Respo return resp, errors.Join(optErrs...) } -func redactHeaders(h http.Header) http.Header { +func RedactSensitiveHeaders(h http.Header) http.Header { + if h == nil { + return nil + } safe := make(http.Header, len(h)) for k, v := range h { - switch strings.ToLower(k) { - case "authorization", "set-cookie", "cookie": + sensitive := false + headerKey := strings.ToLower(k) + if strings.HasPrefix(headerKey, "auth") { + sensitive = true + } else { + switch headerKey { + case "set-cookie", "cookie", "x-auth-token", "x-api-key", "x-auth-user", "proxy-authorization": + sensitive = true + } + } + + if sensitive { safe[k] = []string{"REDACTED"} - default: + } else { safe[k] = v } } diff --git a/vendor/modules.txt b/vendor/modules.txt index ed3934f0..1877051d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -178,7 +178,7 @@ github.com/benbjohnson/clock # github.com/cenkalti/backoff/v4 v4.3.0 ## explicit; go 1.18 github.com/cenkalti/backoff/v4 -# github.com/conductorone/baton-sdk v0.5.16 +# github.com/conductorone/baton-sdk v0.5.25 ## explicit; go 1.25.2 github.com/conductorone/baton-sdk/internal/connector github.com/conductorone/baton-sdk/pb/c1/c1z/v1