From 9ecb1c646b86843bcf47ec3bcb07a66b4d3cf8d0 Mon Sep 17 00:00:00 2001 From: mchavez Date: Wed, 30 Oct 2024 11:45:21 -0600 Subject: [PATCH] Fixing validations and updating resource names --- pkg/connector/connector.go | 16 ++++++++-------- pkg/connector/resource_sets.go | 11 ++++++----- pkg/connector/resource_sets_bindings.go | 8 ++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index ab71c201..fa100ed4 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -114,10 +114,10 @@ var ( Annotations: v1AnnotationsForResourceType("role", false), } resourceTypeCustomRole = &v2.ResourceType{ - Id: "custom_role", + Id: "custom-role", DisplayName: "Custom Role", Traits: []v2.ResourceType_Trait{v2.ResourceType_TRAIT_ROLE}, - Annotations: v1AnnotationsForResourceType("custom_role", false), + Annotations: v1AnnotationsForResourceType("custom-role", false), } resourceTypeUser = &v2.ResourceType{ Id: "user", @@ -143,14 +143,14 @@ var ( Annotations: v1AnnotationsForResourceType("account", false), } resourceTypeResourceSets = &v2.ResourceType{ - Id: "resourcesets", - DisplayName: "Resource Sets", - Annotations: v1AnnotationsForResourceType("resourcesets", false), + Id: "resource-set", + DisplayName: "Resource Set", + Annotations: v1AnnotationsForResourceType("resource-set", false), } resourceTypeResourceSetsBindings = &v2.ResourceType{ - Id: "resourcesets_bindings", - DisplayName: "Resource Sets Bindings", - Annotations: v1AnnotationsForResourceType("resourcesets_bindings", false), + Id: "resourceset-binding", + DisplayName: "Resource Set Binding", + Annotations: v1AnnotationsForResourceType("resourceset-binding", false), } defaultScopes = []string{ "okta.users.read", diff --git a/pkg/connector/resource_sets.go b/pkg/connector/resource_sets.go index 75bfb73a..98432607 100644 --- a/pkg/connector/resource_sets.go +++ b/pkg/connector/resource_sets.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "net/url" + "strings" v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2" "github.com/conductorone/baton-sdk/pkg/annotations" @@ -133,13 +134,13 @@ func (rs *resourceSetsResourceType) Entitlements(_ context.Context, resource *v2 return []*v2.Entitlement{ sdkEntitlement.NewAssignmentEntitlement( resource, - "member", + "bindings", sdkEntitlement.WithAnnotation(&v2.V1Identifier{ Id: V1MembershipEntitlementID(resource.Id.GetResource()), }), sdkEntitlement.WithGrantableTo(resourceTypeResourceSets), - sdkEntitlement.WithDisplayName(fmt.Sprintf("%s Resource Sets Member", resource.DisplayName)), - sdkEntitlement.WithDescription(fmt.Sprintf("Member of %s resource-sets in Okta", resource.DisplayName)), + sdkEntitlement.WithDisplayName(fmt.Sprintf("%s Resource Set Member", resource.DisplayName)), + sdkEntitlement.WithDescription(fmt.Sprintf("Member of %s resource-set in Okta", resource.DisplayName)), ), }, "", nil, nil } @@ -302,12 +303,12 @@ func (rs *resourceSetsResourceType) Grants(ctx context.Context, resource *v2.Res } for _, role := range roles { - if role.Status == roleStatusInactive || role.Type != roleTypeCustom || role.ResourceSet != resource.Id.Resource { + if role.Status == roleStatusInactive || role.Type != roleTypeCustom || !strings.Contains(resource.Id.Resource, role.ResourceSet) { continue } rl := &v2.Resource{Id: &v2.ResourceId{ResourceType: resourceTypeCustomRole.Id, Resource: role.Role}} - gr := sdkGrant.NewGrant(resource, "member", rl, + gr := sdkGrant.NewGrant(resource, "bindings", rl, sdkGrant.WithAnnotation(&v2.V1Identifier{ Id: fmtGrantIdV1(V1MembershipEntitlementID(resource.Id.Resource), resource.Id.Resource), }), diff --git a/pkg/connector/resource_sets_bindings.go b/pkg/connector/resource_sets_bindings.go index 2e8c2fff..11a0433a 100644 --- a/pkg/connector/resource_sets_bindings.go +++ b/pkg/connector/resource_sets_bindings.go @@ -102,13 +102,13 @@ func (rsb *resourceSetsBindingsResourceType) Entitlements(_ context.Context, res return []*v2.Entitlement{ sdkEntitlement.NewAssignmentEntitlement( resource, - "member", + "members", sdkEntitlement.WithAnnotation(&v2.V1Identifier{ Id: V1MembershipEntitlementID(resource.Id.GetResource()), }), sdkEntitlement.WithGrantableTo(resourceTypeResourceSets), - sdkEntitlement.WithDisplayName(fmt.Sprintf("%s Resource Sets Bindings Member", resource.DisplayName)), - sdkEntitlement.WithDescription(fmt.Sprintf("Member of %s resource-sets-bindings in Okta", resource.DisplayName)), + sdkEntitlement.WithDisplayName(fmt.Sprintf("%s Resource Set Binding Member", resource.DisplayName)), + sdkEntitlement.WithDescription(fmt.Sprintf("Member of %s resource-set-binding in Okta", resource.DisplayName)), ), }, "", nil, nil } @@ -276,7 +276,7 @@ func (rsb *resourceSetsBindingsResourceType) Grants(ctx context.Context, resourc } rl := &v2.Resource{Id: &v2.ResourceId{ResourceType: resourceTypeCustomRole.Id, Resource: role.Role}} - gr := sdkGrant.NewGrant(resource, "member", rl, + gr := sdkGrant.NewGrant(resource, "members", rl, sdkGrant.WithAnnotation(&v2.V1Identifier{ Id: fmtGrantIdV1(V1MembershipEntitlementID(resource.Id.Resource), resource.Id.Resource), }),