Skip to content

Commit 7bf4fc4

Browse files
authored
Merge pull request #20 from ConductorOne/jirwin/skip-entitlements-grants
Add support to skip entitlements and grants on a resource type
2 parents f3d5868 + 631887a commit 7bf4fc4

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

pkg/bsql/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ type DatabaseConfig struct {
1919
}
2020

2121
type ResourceType struct {
22-
Name string `yaml:"name" json:"name"`
23-
List *ListQuery `yaml:"list,omitempty" json:"list,omitempty"`
24-
Entitlements *EntitlementsQuery `yaml:"entitlements,omitempty" json:"entitlements,omitempty"`
25-
StaticEntitlements []*EntitlementMapping `yaml:"static_entitlements,omitempty" json:"static_entitlements,omitempty"`
26-
Grants []*GrantsQuery `yaml:"grants,omitempty" json:"grants,omitempty"`
27-
Description string `yaml:"description,omitempty" json:"description,omitempty"`
22+
Name string `yaml:"name" json:"name"`
23+
List *ListQuery `yaml:"list,omitempty" json:"list,omitempty"`
24+
Entitlements *EntitlementsQuery `yaml:"entitlements,omitempty" json:"entitlements,omitempty"`
25+
StaticEntitlements []*EntitlementMapping `yaml:"static_entitlements,omitempty" json:"static_entitlements,omitempty"`
26+
Grants []*GrantsQuery `yaml:"grants,omitempty" json:"grants,omitempty"`
27+
Description string `yaml:"description,omitempty" json:"description,omitempty"`
28+
SkipEntitlementsAndGrants bool `yaml:"skip_entitlements_and_grants,omitempty" json:"skip_entitlements_and_grants,omitempty"`
2829
}
2930

3031
type ListQuery struct {

pkg/bsql/resource_types.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
8+
"github.com/conductorone/baton-sdk/pkg/annotations"
89
)
910

1011
func (c Config) extractTraits(rtID string) ([]v2.ResourceType_Trait, error) {
@@ -54,12 +55,19 @@ func (c Config) GetResourceTypes(ctx context.Context) ([]*v2.ResourceType, error
5455
return nil, err
5556
}
5657

57-
resourceTypes = append(resourceTypes, &v2.ResourceType{
58+
resourceType := &v2.ResourceType{
5859
Id: rtID,
5960
DisplayName: rt.Name,
6061
Description: rt.Description,
6162
Traits: traits,
62-
})
63+
}
64+
65+
if rt.SkipEntitlementsAndGrants {
66+
annos := annotations.Annotations(resourceType.Annotations)
67+
annos.Update(&v2.SkipEntitlementsAndGrants{})
68+
resourceType.Annotations = annos
69+
}
70+
resourceTypes = append(resourceTypes, resourceType)
6371
}
6472
return resourceTypes, nil
6573
}
@@ -75,10 +83,18 @@ func (c Config) GetResourceType(ctx context.Context, rtID string) (*v2.ResourceT
7583
return nil, fmt.Errorf("resource type %s not found in config", rtID)
7684
}
7785

78-
return &v2.ResourceType{
86+
ret := &v2.ResourceType{
7987
Id: rtID,
8088
DisplayName: rt.Name,
8189
Description: rt.Description,
8290
Traits: traits,
83-
}, nil
91+
}
92+
93+
if rt.SkipEntitlementsAndGrants {
94+
annos := annotations.Annotations(ret.Annotations)
95+
annos.Update(&v2.SkipEntitlementsAndGrants{})
96+
ret.Annotations = annos
97+
}
98+
99+
return ret, nil
84100
}

0 commit comments

Comments
 (0)