@@ -58,91 +58,10 @@ func (r *RoleAssignment) GetTarget() string {
5858 return r .Target .RoleAssignmentTarget
5959}
6060
61- // RoleAssignmentInput is the input for creating a role assignment.
62- type RoleAssignmentInput struct {
63- Grants []RoleAssignmentGrant `json:"grant,omitempty"`
64- Revokes []RoleAssignmentRevoke `json:"revoke,omitempty"`
65- }
66-
67- // RoleAssignmentGrant represents a role to grant.
68- type RoleAssignmentGrant struct {
69- Role string `json:"roleName"`
70- Principal string `json:"principal"`
71- Target string `json:"target"`
72- }
73-
74- // RoleAssignmentRevoke represents a role to revoke.
75- type RoleAssignmentRevoke struct {
76- Role string `json:"roleName"`
77- Principal string `json:"principal"`
78- Target string `json:"target"`
79- }
80-
81- func (i RoleAssignmentInput ) GetGraphQLType () string {
82- return "UpdateRoleAssignmentInput"
83- }
84-
8561type roleAssignmentAPI struct {
8662 c * graphql.Client
8763}
8864
89- // Create creates a role assignment.
90- // principal and target are opaque string identifiers (e.g., "user:123", "account-group:uuid").
91- func (r roleAssignmentAPI ) Create (ctx context.Context , roleName string , principal string , target string ) (* RoleAssignment , error ) {
92- input := RoleAssignmentInput {
93- Grants : []RoleAssignmentGrant {
94- {
95- Role : roleName ,
96- Principal : principal ,
97- Target : target ,
98- },
99- },
100- }
101-
102- var mutation struct {
103- Payload struct {
104- Grant []struct {
105- RoleAssignment RoleAssignment
106- }
107- } `graphql:"updateRoleAssignment(input: $input)"`
108- }
109-
110- variables := map [string ]any {"input" : input }
111- if err := r .c .Mutate (ctx , & mutation , variables ); err != nil {
112- return nil , NewAPIError (err )
113- }
114-
115- // The mutation returns a list of granted assignments
116- if len (mutation .Payload .Grant ) == 0 {
117- return nil , APIError {Kind : "API Error" , Detail : "No role assignment granted in response" }
118- }
119-
120- return & mutation .Payload .Grant [0 ].RoleAssignment , nil
121- }
122-
123- // Read returns data for a specific role assignment by ID.
124- func (r roleAssignmentAPI ) Read (ctx context.Context , id string ) (* RoleAssignment , error ) {
125- var query struct {
126- RoleAssignments struct {
127- Edges []struct {
128- Node RoleAssignment
129- }
130- } `graphql:"roleAssignments(filterElement: $filterElement)"`
131- }
132- variables := map [string ]any {
133- "filterElement" : newExactMatchFilter ("id" , id ),
134- }
135- if err := r .c .Query (ctx , & query , variables ); err != nil {
136- return nil , NewAPIError (err )
137- }
138-
139- if len (query .RoleAssignments .Edges ) == 0 {
140- return nil , NotFound {"Role assignment not found" }
141- }
142-
143- return & query .RoleAssignments .Edges [0 ].Node , nil
144- }
145-
14665// List returns role assignments, optionally filtered by target or principal.
14766// target and principal are opaque string identifiers. Pass nil to skip filtering.
14867func (r roleAssignmentAPI ) List (ctx context.Context , target * string , principal * string ) ([]RoleAssignment , error ) {
@@ -209,32 +128,3 @@ func (r roleAssignmentAPI) ListByTargetString(ctx context.Context, targetStr str
209128
210129 return assignments , nil
211130}
212-
213- // Delete removes a role assignment.
214- // principal and target are opaque string identifiers (e.g., "user:123", "account-group:uuid").
215- func (r roleAssignmentAPI ) Delete (ctx context.Context , roleName string , principal string , target string ) error {
216- input := RoleAssignmentInput {
217- Revokes : []RoleAssignmentRevoke {
218- {
219- Role : roleName ,
220- Principal : principal ,
221- Target : target ,
222- },
223- },
224- }
225-
226- var mutation struct {
227- Payload struct {
228- Revoke []struct {
229- RoleAssignment RoleAssignment
230- }
231- } `graphql:"updateRoleAssignment(input: $input)"`
232- }
233-
234- variables := map [string ]any {"input" : input }
235- if err := r .c .Mutate (ctx , & mutation , variables ); err != nil {
236- return NewAPIError (err )
237- }
238-
239- return nil
240- }
0 commit comments