-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
720 additions
and
9 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
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,97 @@ | ||
package rbac | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
v2 "github.com/baidubce/bce-sdk-go/services/cce/v2" | ||
"github.com/baidubce/bce-sdk-go/services/cce/v2/model" | ||
) | ||
|
||
// CreateRBACForAllCluster 为指定用户授权所有集群 | ||
func CreateRBACForAllCluster() { | ||
// 用户的Access Key ID和Secret Access Key | ||
AK, SK := "", "" | ||
|
||
// 用户指定的endpoint | ||
ENDPOINT := "" | ||
|
||
// 初始化一个CCEClient | ||
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
args := &model.RBACRequest{ | ||
ClusterID: model.AllCluster, // 仅对当前已存在的集群生效,后续新增集群不生效。 | ||
UserID: "待授权的用户 ID", | ||
Role: model.RoleReadonly, | ||
} | ||
|
||
resp, err := ccev2Client.CreateRBAC(args) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
s, _ := json.MarshalIndent(resp, "", "\t") | ||
fmt.Println("Response:" + string(s)) | ||
} | ||
|
||
// CreateRBACForAllNamespace 为指定用户授权指定集群的所有 namepsace | ||
func CreateRBACForAllNamespace() { | ||
// 用户的Access Key ID和Secret Access Key | ||
AK, SK := "", "" | ||
|
||
// 用户指定的endpoint | ||
ENDPOINT := "" | ||
|
||
// 初始化一个CCEClient | ||
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
args := &model.RBACRequest{ | ||
ClusterID: "待授权的集群 ID", | ||
UserID: "待授权的用户 ID", | ||
Namespace: model.AllNamespace, | ||
Role: model.RoleReadonly, | ||
} | ||
|
||
resp, err := ccev2Client.CreateRBAC(args) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
s, _ := json.MarshalIndent(resp, "", "\t") | ||
fmt.Println("Response:" + string(s)) | ||
} | ||
|
||
// CreateRBACForOneNamespace 为指定用户授权指定集群的指定 namepsace | ||
func CreateRBACForOneNamespace() { | ||
// 用户的Access Key ID和Secret Access Key | ||
AK, SK := "", "" | ||
|
||
// 用户指定的endpoint | ||
ENDPOINT := "" | ||
|
||
// 初始化一个CCEClient | ||
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
args := &model.RBACRequest{ | ||
ClusterID: "待授权的集群 ID", | ||
UserID: "待授权的用户 ID", | ||
Namespace: "待授权的 namespace", | ||
Role: model.RoleReadonly, | ||
} | ||
|
||
resp, err := ccev2Client.CreateRBAC(args) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
s, _ := json.MarshalIndent(resp, "", "\t") | ||
fmt.Println("Response:" + string(s)) | ||
} |
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,66 @@ | ||
package rbac | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
v2 "github.com/baidubce/bce-sdk-go/services/cce/v2" | ||
"github.com/baidubce/bce-sdk-go/services/cce/v2/model" | ||
) | ||
|
||
// DeleteRBACForNamespace 删除指定用户、指定集群 RBAC 权限,该授权为指定 namespace | ||
func DeleteRBACForNamespace() { | ||
// 用户的Access Key ID和Secret Access Key | ||
AK, SK := "", "" | ||
|
||
// 用户指定的endpoint | ||
ENDPOINT := "" | ||
|
||
// 初始化一个CCEClient | ||
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
args := &model.RBACRequest{ | ||
ClusterID: "集群 ID", // 必须指定具体的 clusterID | ||
UserID: "用户 ID", | ||
Namespace: "已授权的 namespace", // namespace 需跟授权时保持一致,如果授权时是 all,则删除时必须也是 all。 | ||
} | ||
|
||
resp, err := ccev2Client.DeleteRBAC(args) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
s, _ := json.MarshalIndent(resp, "", "\t") | ||
fmt.Println("Response:" + string(s)) | ||
} | ||
|
||
// DeleteRBACForAllNamespace 删除指定用户、指定集群 RBAC 权限,该授权为所有命名空间 | ||
func DeleteRBACForAllNamespace() { | ||
// 用户的Access Key ID和Secret Access Key | ||
AK, SK := "", "" | ||
|
||
// 用户指定的endpoint | ||
ENDPOINT := "" | ||
|
||
// 初始化一个CCEClient | ||
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
args := &model.RBACRequest{ | ||
ClusterID: "集群 ID", // 必须指定具体的 clusterID | ||
UserID: "用户 ID", | ||
Namespace: model.AllNamespace, // namespace 需跟授权时保持一致,如果授权时是 all,则删除时必须也是 all。 | ||
} | ||
|
||
resp, err := ccev2Client.DeleteRBAC(args) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
s, _ := json.MarshalIndent(resp, "", "\t") | ||
fmt.Println("Response:" + string(s)) | ||
} |
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,35 @@ | ||
package rbac | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
v2 "github.com/baidubce/bce-sdk-go/services/cce/v2" | ||
"github.com/baidubce/bce-sdk-go/services/cce/v2/model" | ||
) | ||
|
||
// ListRBAC 根据用户 ID 查询该用户已有的 RBAC 权限 | ||
func ListRBAC() { | ||
// 用户的Access Key ID和Secret Access Key | ||
AK, SK := "", "" | ||
|
||
// 用户指定的endpoint | ||
ENDPOINT := "" | ||
|
||
// 初始化一个CCEClient | ||
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
args := &model.RBACRequest{ | ||
UserID: "用户 ID", // 仅支持根据用户 ID 查询 RBAC 信息 | ||
} | ||
|
||
resp, err := ccev2Client.ListRBAC(args) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
s, _ := json.MarshalIndent(resp, "", "\t") | ||
fmt.Println("Response:" + string(s)) | ||
} |
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,66 @@ | ||
package rbac | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
v2 "github.com/baidubce/bce-sdk-go/services/cce/v2" | ||
"github.com/baidubce/bce-sdk-go/services/cce/v2/model" | ||
) | ||
|
||
func RenewRBACForNamespace() { | ||
// 用户的Access Key ID和Secret Access Key | ||
AK, SK := "", "" | ||
|
||
// 用户指定的endpoint | ||
ENDPOINT := "" | ||
|
||
// 初始化一个CCEClient | ||
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
args := &model.RBACRequest{ | ||
ClusterID: "集群 ID", // 必须指定具体的 clusterID | ||
UserID: "用户 ID", | ||
Namespace: "已授权的 namespace", // 该值需跟授权时保持一致,如果授权时是 all,则重置时必须也是 all。 | ||
Role: model.RoleReadonly, // 该值需跟授权时保持一致 | ||
} | ||
|
||
resp, err := ccev2Client.RenewRBAC(args) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
s, _ := json.MarshalIndent(resp, "", "\t") | ||
fmt.Println("Response:" + string(s)) | ||
} | ||
|
||
func RenewRBACForAllNamespace() { | ||
// 用户的Access Key ID和Secret Access Key | ||
AK, SK := "", "" | ||
|
||
// 用户指定的endpoint | ||
ENDPOINT := "" | ||
|
||
// 初始化一个CCEClient | ||
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
args := &model.RBACRequest{ | ||
ClusterID: "集群 ID", // 必须指定具体的 clusterID | ||
UserID: "用户 ID", | ||
Namespace: model.AllNamespace, // 该值需跟授权时保持一致,如果授权时是 all,则重置时必须也是 all。 | ||
Role: model.RoleReadonly, // 该值需跟授权时保持一致 | ||
} | ||
|
||
resp, err := ccev2Client.RenewRBAC(args) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
s, _ := json.MarshalIndent(resp, "", "\t") | ||
fmt.Println("Response:" + string(s)) | ||
} |
Oops, something went wrong.