@@ -11,13 +11,13 @@ import (
1111)
1212
1313// CreateRole creates the role in the instance.
14- func (c * client ) CreateRole (ctx context.Context , instanceID int , create * api.RoleUpsert ) (* api.Role , error ) {
14+ func (c * client ) CreateRole (ctx context.Context , environmentID , instanceID string , create * api.RoleUpsert ) (* api.Role , error ) {
1515 payload , err := json .Marshal (create )
1616 if err != nil {
1717 return nil , err
1818 }
1919
20- req , err := http .NewRequestWithContext (ctx , "POST" , fmt .Sprintf ("%s/instance/%d/role " , c .HostURL , instanceID ), strings .NewReader (string (payload )))
20+ req , err := http .NewRequestWithContext (ctx , "POST" , fmt .Sprintf ("%s/environments/%s/instances/%s/roles " , c .HostURL , environmentID , instanceID ), strings .NewReader (string (payload )))
2121 if err != nil {
2222 return nil , err
2323 }
@@ -37,8 +37,8 @@ func (c *client) CreateRole(ctx context.Context, instanceID int, create *api.Rol
3737}
3838
3939// GetRole gets the role by instance id and role name.
40- func (c * client ) GetRole (ctx context.Context , instanceID int , roleName string ) (* api.Role , error ) {
41- req , err := http .NewRequestWithContext (ctx , "GET" , fmt .Sprintf ("%s/instance/%d/role /%s" , c .HostURL , instanceID , roleName ), nil )
40+ func (c * client ) GetRole (ctx context.Context , environmentID , instanceID , roleName string ) (* api.Role , error ) {
41+ req , err := http .NewRequestWithContext (ctx , "GET" , fmt .Sprintf ("%s/environments/%s/instances /%s/roles/%s " , c .HostURL , environmentID , instanceID , roleName ), nil )
4242 if err != nil {
4343 return nil , err
4444 }
@@ -58,8 +58,8 @@ func (c *client) GetRole(ctx context.Context, instanceID int, roleName string) (
5858}
5959
6060// ListRole lists the role in instance.
61- func (c * client ) ListRole (ctx context.Context , instanceID int ) ([]* api.Role , error ) {
62- req , err := http .NewRequestWithContext (ctx , "GET" , fmt .Sprintf ("%s/instance/%d/role " , c .HostURL , instanceID ), nil )
61+ func (c * client ) ListRole (ctx context.Context , environmentID , instanceID string ) ([]* api.Role , error ) {
62+ req , err := http .NewRequestWithContext (ctx , "GET" , fmt .Sprintf ("%s/environments/%s/instances/%s/roles " , c .HostURL , environmentID , instanceID ), nil )
6363 if err != nil {
6464 return nil , err
6565 }
@@ -82,13 +82,30 @@ func (c *client) ListRole(ctx context.Context, instanceID int) ([]*api.Role, err
8282}
8383
8484// UpdateRole updates the role in instance.
85- func (c * client ) UpdateRole (ctx context.Context , instanceID int , roleName string , patch * api.RoleUpsert ) (* api.Role , error ) {
85+ func (c * client ) UpdateRole (ctx context.Context , environmentID , instanceID , roleName string , patch * api.RoleUpsert ) (* api.Role , error ) {
8686 payload , err := json .Marshal (patch )
8787 if err != nil {
8888 return nil , err
8989 }
9090
91- req , err := http .NewRequestWithContext (ctx , "PATCH" , fmt .Sprintf ("%s/instance/%d/role/%s" , c .HostURL , instanceID , roleName ), strings .NewReader (string (payload )))
91+ paths := []string {}
92+ if patch .Title != roleName {
93+ paths = append (paths , "role.title" )
94+ }
95+ if patch .Password != nil {
96+ paths = append (paths , "role.password" )
97+ }
98+ if patch .ConnectionLimit != nil {
99+ paths = append (paths , "role.connection_limit" )
100+ }
101+ if patch .ValidUntil != nil {
102+ paths = append (paths , "role.valid_until" )
103+ }
104+ if patch .Attribute != nil {
105+ paths = append (paths , "role.attribute" )
106+ }
107+
108+ req , err := http .NewRequestWithContext (ctx , "PATCH" , fmt .Sprintf ("%s/environments/%s/instances/%s/roles/%s?update_mask=%s" , c .HostURL , environmentID , instanceID , roleName , strings .Join (paths , "," )), strings .NewReader (string (payload )))
92109 if err != nil {
93110 return nil , err
94111 }
@@ -108,8 +125,8 @@ func (c *client) UpdateRole(ctx context.Context, instanceID int, roleName string
108125}
109126
110127// DeleteRole deletes the role in the instance.
111- func (c * client ) DeleteRole (ctx context.Context , instanceID int , roleName string ) error {
112- req , err := http .NewRequestWithContext (ctx , "DELETE" , fmt .Sprintf ("%s/instance/%d/role /%s" , c .HostURL , instanceID , roleName ), nil )
128+ func (c * client ) DeleteRole (ctx context.Context , environmentID , instanceID , roleName string ) error {
129+ req , err := http .NewRequestWithContext (ctx , "DELETE" , fmt .Sprintf ("%s/environments/%s/instances /%s/roles/%s " , c .HostURL , environmentID , instanceID , roleName ), nil )
113130 if err != nil {
114131 return err
115132 }
0 commit comments