-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from electric-saw/rbac
adding schema registry rbac list support
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ccloud | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/electric-saw/ccloud-client-go/ccloud/common" | ||
) | ||
|
||
type Rbac struct { | ||
common.BaseModel | ||
Principal string `json:"principal"` | ||
RoleName string `json:"role_name"` | ||
CrnPattern string `json:"crn_pattern"` | ||
} | ||
|
||
type RbacList struct { | ||
common.BaseModel | ||
Data []Rbac `json:"data"` | ||
} | ||
|
||
type SchemaRegistryRbacListOptions struct { | ||
common.PaginationOptions | ||
RoleName string `url:"role_name,omitempty"` | ||
CrnPattern string `url:"crn_pattern,omitempty"` | ||
Principal string `url:"principal,omitempty"` | ||
} | ||
|
||
func (c *ConfluentClient) ListSchemaRegistryRBAC(opt *SchemaRegistryRbacListOptions) (*RbacList, error) { | ||
urlPath := "/iam/v2/role-bindings" | ||
|
||
req, err := c.doRequest(urlPath, http.MethodGet, nil, opt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if http.StatusOK != req.StatusCode { | ||
return nil, fmt.Errorf("failed to get schema registry rbac: %s", req.Status) | ||
} | ||
|
||
defer req.Body.Close() | ||
|
||
var rbacList RbacList | ||
err = json.NewDecoder(req.Body).Decode(&rbacList) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &rbacList, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ccloud_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/electric-saw/ccloud-client-go/ccloud" | ||
"github.com/electric-saw/ccloud-client-go/ccloud/common" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetSchemaRegistryRbac(t *testing.T) { | ||
c := makeClient() | ||
crn := makeRbacCrn() | ||
|
||
rbacList, err := c.ListSchemaRegistryRBAC( | ||
&ccloud.SchemaRegistryRbacListOptions{ | ||
PaginationOptions: common.PaginationOptions{ | ||
PageSize: 10, | ||
}, | ||
CrnPattern: crn, | ||
}) | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, rbacList) | ||
|
||
rbacList, err = c.ListSchemaRegistryRBAC( | ||
&ccloud.SchemaRegistryRbacListOptions{ | ||
CrnPattern: rbacList.Data[0].CrnPattern, | ||
Principal: rbacList.Data[0].Principal, | ||
}) | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, rbacList) | ||
|
||
|
||
} |