Skip to content

Commit 879ca49

Browse files
Skip entitlements (#568)
* feat: add skip entitlements * remove cli option to skip entitlements
1 parent 778fa78 commit 879ca49

File tree

8 files changed

+249
-13
lines changed

8 files changed

+249
-13
lines changed

pb/c1/connector/v2/annotation_resource_tree.pb.go

Lines changed: 48 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pb/c1/connector/v2/annotation_resource_tree.pb.validate.go

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pb/c1/connector/v2/annotation_resource_tree_protoopaque.pb.go

Lines changed: 48 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ func MakeMainCommand[T field.Configurable](
356356
}
357357

358358
opts = append(opts, connectorrunner.WithSkipEntitlementsAndGrants(v.GetBool("skip-entitlements-and-grants")))
359+
359360
if v.GetBool("skip-grants") {
360361
opts = append(opts, connectorrunner.WithSkipGrants(v.GetBool("skip-grants")))
361362
}

pkg/field/defaults.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ var (
109109
WithExportTarget(ExportTargetNone),
110110
WithHidden(true),
111111
)
112+
112113
syncResourceTypeIDs = StringSliceField("sync-resource-types",
113114
WithDescription("The resource type IDs to sync"),
114115
WithPersistent(true),

pkg/sync/state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ type serializedToken struct {
169169
ShouldFetchRelatedResources bool `json:"should_fetch_related_resources,omitempty"`
170170
ShouldSkipEntitlementsAndGrants bool `json:"should_skip_entitlements_and_grants,omitempty"`
171171
ShouldSkipGrants bool `json:"should_skip_grants,omitempty"`
172+
ShouldSkipEntitlements bool `json:"should_skip_entitlements,omitempty"`
172173
}
173174

174175
// push adds a new action to the stack. If there is no current state, the action is directly set to current, else

pkg/sync/syncer.go

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ type syncer struct {
215215
dontExpandGrants bool
216216
syncID string
217217
skipEGForResourceType map[string]bool
218+
skipEntitlementsForResourceType map[string]bool
218219
skipEntitlementsAndGrants bool
219220
skipGrants bool
220221
resourceTypeTraits map[string][]v2.ResourceType_Trait
@@ -549,7 +550,9 @@ func (s *syncer) Sync(ctx context.Context) error {
549550
if !s.state.ShouldSkipGrants() {
550551
s.state.PushAction(ctx, Action{Op: SyncGrantsOp})
551552
}
553+
552554
s.state.PushAction(ctx, Action{Op: SyncEntitlementsOp})
555+
553556
s.state.PushAction(ctx, Action{Op: SyncStaticEntitlementsOp})
554557
}
555558
s.state.PushAction(ctx, Action{Op: SyncResourcesOp})
@@ -949,7 +952,7 @@ func (s *syncer) SyncTargetedResource(ctx context.Context) error {
949952
})
950953
}
951954

952-
shouldSkipEnts, err := s.shouldSkipEntitlementsAndGrants(ctx, resource)
955+
shouldSkipEnts, err := s.shouldSkipEntitlements(ctx, resource)
953956
if err != nil {
954957
return err
955958
}
@@ -1189,6 +1192,43 @@ func (s *syncer) shouldSkipGrants(ctx context.Context, r *v2.Resource) (bool, er
11891192
return s.shouldSkipEntitlementsAndGrants(ctx, r)
11901193
}
11911194

1195+
func (s *syncer) shouldSkipEntitlements(ctx context.Context, r *v2.Resource) (bool, error) {
1196+
ctx, span := tracer.Start(ctx, "syncer.shouldSkipEntitlements")
1197+
defer span.End()
1198+
1199+
ok, err := s.shouldSkipEntitlementsAndGrants(ctx, r)
1200+
if err != nil {
1201+
return false, err
1202+
}
1203+
1204+
if ok {
1205+
return true, nil
1206+
}
1207+
1208+
rAnnos := annotations.Annotations(r.GetAnnotations())
1209+
if rAnnos.Contains(&v2.SkipEntitlements{}) || rAnnos.Contains(&v2.SkipEntitlementsAndGrants{}) {
1210+
return true, nil
1211+
}
1212+
1213+
if skip, ok := s.skipEntitlementsForResourceType[r.GetId().GetResourceType()]; ok {
1214+
return skip, nil
1215+
}
1216+
1217+
rt, err := s.store.GetResourceType(ctx, reader_v2.ResourceTypesReaderServiceGetResourceTypeRequest_builder{
1218+
ResourceTypeId: r.GetId().GetResourceType(),
1219+
}.Build())
1220+
if err != nil {
1221+
return false, err
1222+
}
1223+
1224+
rtAnnos := annotations.Annotations(rt.GetResourceType().GetAnnotations())
1225+
1226+
skipEntitlements := rtAnnos.Contains(&v2.SkipEntitlements{}) || rtAnnos.Contains(&v2.SkipEntitlementsAndGrants{})
1227+
s.skipEntitlementsForResourceType[r.GetId().GetResourceType()] = skipEntitlements
1228+
1229+
return skipEntitlements, nil
1230+
}
1231+
11921232
// SyncEntitlements fetches the entitlements from the connector. It first lists each resource from the datastore,
11931233
// and pushes an action to fetch the entitlements for each resource.
11941234
func (s *syncer) SyncEntitlements(ctx context.Context) error {
@@ -1219,7 +1259,7 @@ func (s *syncer) SyncEntitlements(ctx context.Context) error {
12191259
}
12201260

12211261
for _, r := range resp.GetList() {
1222-
shouldSkipEntitlements, err := s.shouldSkipEntitlementsAndGrants(ctx, r)
1262+
shouldSkipEntitlements, err := s.shouldSkipEntitlements(ctx, r)
12231263
if err != nil {
12241264
return err
12251265
}
@@ -3165,11 +3205,12 @@ func WithSkipGrants(skip bool) SyncOpt {
31653205
// NewSyncer returns a new syncer object.
31663206
func NewSyncer(ctx context.Context, c types.ConnectorClient, opts ...SyncOpt) (Syncer, error) {
31673207
s := &syncer{
3168-
connector: c,
3169-
skipEGForResourceType: make(map[string]bool),
3170-
resourceTypeTraits: make(map[string][]v2.ResourceType_Trait),
3171-
counts: NewProgressCounts(),
3172-
syncType: connectorstore.SyncTypeFull,
3208+
connector: c,
3209+
skipEGForResourceType: make(map[string]bool),
3210+
skipEntitlementsForResourceType: make(map[string]bool),
3211+
resourceTypeTraits: make(map[string][]v2.ResourceType_Trait),
3212+
counts: NewProgressCounts(),
3213+
syncType: connectorstore.SyncTypeFull,
31733214
}
31743215

31753216
for _, o := range opts {

proto/c1/connector/v2/annotation_resource_tree.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ message ChildResourceType {
1111
message SkipEntitlementsAndGrants {}
1212

1313
message SkipGrants {}
14+
15+
message SkipEntitlements {}

0 commit comments

Comments
 (0)