@@ -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.
11941234func (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.
31663206func 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 {
0 commit comments