mirror of https://github.com/kubernetes/kops.git
implement Ram task for ALICloud
This commit is contained in:
parent
1f475d3b8d
commit
5c8f1df4df
|
|
@ -228,6 +228,7 @@
|
|||
"common",
|
||||
"ecs",
|
||||
"oss",
|
||||
"ram",
|
||||
"slb",
|
||||
"util"
|
||||
]
|
||||
|
|
@ -494,6 +495,7 @@
|
|||
"openstack/networking/v2/extensions/security/groups",
|
||||
"openstack/networking/v2/extensions/security/rules",
|
||||
"openstack/networking/v2/networks",
|
||||
"openstack/networking/v2/ports",
|
||||
"openstack/networking/v2/subnets",
|
||||
"openstack/objectstorage/v1/accounts",
|
||||
"openstack/objectstorage/v1/containers",
|
||||
|
|
@ -1710,6 +1712,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "f032b5357d53130f8adac38b7595b2920df27b34fd311be7845f3c15c263da4b"
|
||||
inputs-digest = "466d4f729f9b42c133774b443359841aa56e918db97a9adf33e609df9be4cee9"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ go_library(
|
|||
"loadbalancerlistener_fitask.go",
|
||||
"loadbalancerwhitelist.go",
|
||||
"loadbalancerwhitelist_fitask.go",
|
||||
"rampolicy.go",
|
||||
"rampolicy_fitask.go",
|
||||
"ramrole.go",
|
||||
"ramrole_fitask.go",
|
||||
"sshkey.go",
|
||||
"sshkey_fitask.go",
|
||||
"vpc.go",
|
||||
|
|
@ -26,6 +30,7 @@ go_library(
|
|||
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
||||
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
|
||||
"//vendor/github.com/denverdino/aliyungo/ecs:go_default_library",
|
||||
"//vendor/github.com/denverdino/aliyungo/ram:go_default_library",
|
||||
"//vendor/github.com/denverdino/aliyungo/slb:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package alitasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/denverdino/aliyungo/ram"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||
)
|
||||
|
||||
//go:generate fitask -type=RAMPolicy
|
||||
|
||||
type RAMPolicy struct {
|
||||
Lifecycle *fi.Lifecycle
|
||||
Name *string
|
||||
PolicyDocument *string
|
||||
RamRole *RAMRole
|
||||
PolicyType *string
|
||||
}
|
||||
|
||||
var _ fi.CompareWithID = &RAMPolicy{}
|
||||
|
||||
func (r *RAMPolicy) CompareWithID() *string {
|
||||
return r.Name
|
||||
}
|
||||
|
||||
func (r *RAMPolicy) Find(c *fi.Context) (*RAMPolicy, error) {
|
||||
cloud := c.Cloud.(aliup.ALICloud)
|
||||
|
||||
policyQueryRequest := ram.PolicyQueryRequest{
|
||||
PolicyType: ram.Type(fi.StringValue(r.PolicyType)),
|
||||
}
|
||||
policyList, err := cloud.RamClient().ListPolicies(policyQueryRequest)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error listing RamPolicy: %v", err)
|
||||
}
|
||||
|
||||
if len(policyList.Policies.Policy) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
for _, policy := range policyList.Policies.Policy {
|
||||
if policy.PolicyName == fi.StringValue(r.Name) {
|
||||
|
||||
glog.V(2).Infof("found matching RamPolicy with name: %q", *r.Name)
|
||||
actual := &RAMPolicy{}
|
||||
actual.Name = fi.String(policy.PolicyName)
|
||||
actual.PolicyType = fi.String(string(policy.PolicyType))
|
||||
|
||||
// Ignore "system" fields
|
||||
actual.Lifecycle = r.Lifecycle
|
||||
return actual, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *RAMPolicy) Run(c *fi.Context) error {
|
||||
return fi.DefaultDeltaRunMethod(r, c)
|
||||
}
|
||||
|
||||
func (_ *RAMPolicy) CheckChanges(a, e, changes *RAMPolicy) error {
|
||||
|
||||
if e.PolicyDocument == nil {
|
||||
return fi.RequiredField("PolicyDocument")
|
||||
}
|
||||
if e.Name == nil {
|
||||
return fi.RequiredField("Name")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_ *RAMPolicy) RenderALI(t *aliup.ALIAPITarget, a, e, changes *RAMPolicy) error {
|
||||
|
||||
policyRequest := ram.PolicyRequest{}
|
||||
|
||||
if a == nil {
|
||||
glog.V(2).Infof("Creating RAMPolicy with Name:%q", fi.StringValue(e.Name))
|
||||
|
||||
policyRequest = ram.PolicyRequest{
|
||||
PolicyName: fi.StringValue(e.Name),
|
||||
PolicyDocument: fi.StringValue(e.PolicyDocument),
|
||||
PolicyType: ram.Type(fi.StringValue(e.PolicyType)),
|
||||
}
|
||||
|
||||
_, err := t.Cloud.RamClient().CreatePolicy(policyRequest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating RAMPolicy: %v", err)
|
||||
}
|
||||
|
||||
attachPolicyRequest := ram.AttachPolicyToRoleRequest{
|
||||
PolicyRequest: policyRequest,
|
||||
RoleName: fi.StringValue(e.RamRole.Name),
|
||||
}
|
||||
|
||||
_, err = t.Cloud.RamClient().AttachPolicyToRole(attachPolicyRequest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error attaching RAMPolicy to RAMRole: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
type terraformRAMPolicy struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Document *string `json:"document,omitempty"`
|
||||
}
|
||||
|
||||
type terraformRAMPolicyAttach struct {
|
||||
PolicyName *terraform.Literal `json:"policy_name,omitempty"`
|
||||
PolicyType *string `json:"policy_type,omitempty"`
|
||||
RoleName *terraform.Literal `json:"role_name,omitempty"`
|
||||
}
|
||||
|
||||
func (_ *RAMPolicy) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *RAMPolicy) error {
|
||||
tf := &terraformRAMPolicy{
|
||||
Name: e.Name,
|
||||
Document: e.PolicyDocument,
|
||||
}
|
||||
err := t.RenderResource("alicloud_ram_policy", *e.Name, tf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
policyType := "Custom"
|
||||
tfAttach := &terraformRAMPolicyAttach{
|
||||
PolicyName: e.TerraformLink(),
|
||||
RoleName: e.RamRole.TerraformLink(),
|
||||
PolicyType: &policyType,
|
||||
}
|
||||
err = t.RenderResource("alicloud_ram_role_policy_attachment", *e.Name, tfAttach)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *RAMPolicy) TerraformLink() *terraform.Literal {
|
||||
return terraform.LiteralProperty("alicloud_ram_policy", *s.Name, "id")
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by ""fitask" -type=RAMPolicy"; DO NOT EDIT
|
||||
|
||||
package alitasks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
)
|
||||
|
||||
// RAMPolicy
|
||||
|
||||
// JSON marshalling boilerplate
|
||||
type realRAMPolicy RAMPolicy
|
||||
|
||||
// UnmarshalJSON implements conversion to JSON, supporitng an alternate specification of the object as a string
|
||||
func (o *RAMPolicy) UnmarshalJSON(data []byte) error {
|
||||
var jsonName string
|
||||
if err := json.Unmarshal(data, &jsonName); err == nil {
|
||||
o.Name = &jsonName
|
||||
return nil
|
||||
}
|
||||
|
||||
var r realRAMPolicy
|
||||
if err := json.Unmarshal(data, &r); err != nil {
|
||||
return err
|
||||
}
|
||||
*o = RAMPolicy(r)
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ fi.HasLifecycle = &RAMPolicy{}
|
||||
|
||||
// GetLifecycle returns the Lifecycle of the object, implementing fi.HasLifecycle
|
||||
func (o *RAMPolicy) GetLifecycle() *fi.Lifecycle {
|
||||
return o.Lifecycle
|
||||
}
|
||||
|
||||
// SetLifecycle sets the Lifecycle of the object, implementing fi.SetLifecycle
|
||||
func (o *RAMPolicy) SetLifecycle(lifecycle fi.Lifecycle) {
|
||||
o.Lifecycle = &lifecycle
|
||||
}
|
||||
|
||||
var _ fi.HasName = &RAMPolicy{}
|
||||
|
||||
// GetName returns the Name of the object, implementing fi.HasName
|
||||
func (o *RAMPolicy) GetName() *string {
|
||||
return o.Name
|
||||
}
|
||||
|
||||
// SetName sets the Name of the object, implementing fi.SetName
|
||||
func (o *RAMPolicy) SetName(name string) {
|
||||
o.Name = &name
|
||||
}
|
||||
|
||||
// String is the stringer function for the task, producing readable output using fi.TaskAsString
|
||||
func (o *RAMPolicy) String() string {
|
||||
return fi.TaskAsString(o)
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package alitasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/denverdino/aliyungo/ram"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||
)
|
||||
|
||||
//go:generate fitask -type=RAMRole
|
||||
|
||||
type RAMRole struct {
|
||||
Lifecycle *fi.Lifecycle
|
||||
Name *string
|
||||
AssumeRolePolicyDocument *string
|
||||
RAMRoleId *string
|
||||
}
|
||||
|
||||
var _ fi.CompareWithID = &RAMRole{}
|
||||
|
||||
func (r *RAMRole) CompareWithID() *string {
|
||||
return r.Name
|
||||
}
|
||||
|
||||
func (r *RAMRole) Find(c *fi.Context) (*RAMRole, error) {
|
||||
cloud := c.Cloud.(aliup.ALICloud)
|
||||
|
||||
roleList, err := cloud.RamClient().ListRoles()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error listing RamRoles: %v", err)
|
||||
}
|
||||
|
||||
// Don't exist RAMrole with specified User.
|
||||
if len(roleList.Roles.Role) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// The same user's RAM resource name can not be repeated
|
||||
for _, role := range roleList.Roles.Role {
|
||||
if role.RoleName == fi.StringValue(r.Name) {
|
||||
|
||||
glog.V(2).Infof("found matching RamRole with name: %q", *r.Name)
|
||||
actual := &RAMRole{}
|
||||
actual.Name = fi.String(role.RoleName)
|
||||
actual.RAMRoleId = fi.String(role.RoleId)
|
||||
actual.AssumeRolePolicyDocument = fi.String(role.AssumeRolePolicyDocument)
|
||||
|
||||
// Ignore "system" fields
|
||||
actual.Lifecycle = r.Lifecycle
|
||||
r.RAMRoleId = actual.RAMRoleId
|
||||
return actual, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *RAMRole) Run(c *fi.Context) error {
|
||||
return fi.DefaultDeltaRunMethod(r, c)
|
||||
}
|
||||
|
||||
func (_ *RAMRole) CheckChanges(a, e, changes *RAMRole) error {
|
||||
if a == nil {
|
||||
if e.AssumeRolePolicyDocument == nil {
|
||||
return fi.RequiredField("AssumeRolePolicyDocument")
|
||||
}
|
||||
if e.Name == nil {
|
||||
return fi.RequiredField("Name")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_ *RAMRole) RenderALI(t *aliup.ALIAPITarget, a, e, changes *RAMRole) error {
|
||||
if a == nil {
|
||||
glog.V(2).Infof("Creating RAMRole with Name:%q", fi.StringValue(e.Name))
|
||||
|
||||
roleRequest := ram.RoleRequest{
|
||||
RoleName: fi.StringValue(e.Name),
|
||||
AssumeRolePolicyDocument: fi.StringValue(e.AssumeRolePolicyDocument),
|
||||
}
|
||||
|
||||
roleResponse, err := t.Cloud.RamClient().CreateRole(roleRequest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating RAMRole: %v", err)
|
||||
}
|
||||
|
||||
e.RAMRoleId = fi.String(roleResponse.Role.RoleId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type terraformRAMRole struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Document *string `json:"document,omitempty"`
|
||||
}
|
||||
|
||||
func (_ *RAMRole) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *RAMRole) error {
|
||||
tf := &terraformRAMRole{
|
||||
Name: e.Name,
|
||||
Document: e.AssumeRolePolicyDocument,
|
||||
}
|
||||
return t.RenderResource("alicloud_ram_role", *e.Name, tf)
|
||||
}
|
||||
|
||||
func (s *RAMRole) TerraformLink() *terraform.Literal {
|
||||
return terraform.LiteralProperty("alicloud_ram_role", *s.Name, "name")
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by ""fitask" -type=RAMRole"; DO NOT EDIT
|
||||
|
||||
package alitasks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
)
|
||||
|
||||
// RAMRole
|
||||
|
||||
// JSON marshalling boilerplate
|
||||
type realRAMRole RAMRole
|
||||
|
||||
// UnmarshalJSON implements conversion to JSON, supporitng an alternate specification of the object as a string
|
||||
func (o *RAMRole) UnmarshalJSON(data []byte) error {
|
||||
var jsonName string
|
||||
if err := json.Unmarshal(data, &jsonName); err == nil {
|
||||
o.Name = &jsonName
|
||||
return nil
|
||||
}
|
||||
|
||||
var r realRAMRole
|
||||
if err := json.Unmarshal(data, &r); err != nil {
|
||||
return err
|
||||
}
|
||||
*o = RAMRole(r)
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ fi.HasLifecycle = &RAMRole{}
|
||||
|
||||
// GetLifecycle returns the Lifecycle of the object, implementing fi.HasLifecycle
|
||||
func (o *RAMRole) GetLifecycle() *fi.Lifecycle {
|
||||
return o.Lifecycle
|
||||
}
|
||||
|
||||
// SetLifecycle sets the Lifecycle of the object, implementing fi.SetLifecycle
|
||||
func (o *RAMRole) SetLifecycle(lifecycle fi.Lifecycle) {
|
||||
o.Lifecycle = &lifecycle
|
||||
}
|
||||
|
||||
var _ fi.HasName = &RAMRole{}
|
||||
|
||||
// GetName returns the Name of the object, implementing fi.HasName
|
||||
func (o *RAMRole) GetName() *string {
|
||||
return o.Name
|
||||
}
|
||||
|
||||
// SetName sets the Name of the object, implementing fi.SetName
|
||||
func (o *RAMRole) SetName(name string) {
|
||||
o.Name = &name
|
||||
}
|
||||
|
||||
// String is the stringer function for the task, producing readable output using fi.TaskAsString
|
||||
func (o *RAMRole) String() string {
|
||||
return fi.TaskAsString(o)
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ go_library(
|
|||
"//upup/pkg/fi:go_default_library",
|
||||
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
|
||||
"//vendor/github.com/denverdino/aliyungo/ecs:go_default_library",
|
||||
"//vendor/github.com/denverdino/aliyungo/ram:go_default_library",
|
||||
"//vendor/github.com/denverdino/aliyungo/slb:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"github.com/denverdino/aliyungo/common"
|
||||
"github.com/denverdino/aliyungo/ecs"
|
||||
"github.com/denverdino/aliyungo/ram"
|
||||
"github.com/denverdino/aliyungo/slb"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
|
|
@ -45,6 +46,8 @@ type ALICloud interface {
|
|||
|
||||
EcsClient() *ecs.Client
|
||||
SlbClient() *slb.Client
|
||||
RamClient() *ram.RamClient
|
||||
|
||||
Region() string
|
||||
AddClusterTags(tags map[string]string)
|
||||
GetTags(resourceId string, resourceType string) (map[string]string, error)
|
||||
|
|
@ -56,6 +59,7 @@ type ALICloud interface {
|
|||
type aliCloudImplementation struct {
|
||||
ecsClient *ecs.Client
|
||||
slbClient *slb.Client
|
||||
ramClient *ram.RamClient
|
||||
|
||||
region string
|
||||
tags map[string]string
|
||||
|
|
@ -80,6 +84,10 @@ func NewALICloud(region string, tags map[string]string) (ALICloud, error) {
|
|||
|
||||
c.ecsClient = ecs.NewClient(accessKeyId, accessKeySecret)
|
||||
c.ecsClient.SetUserAgent(KubernetesKopsIdentity)
|
||||
c.slbClient = slb.NewClient(accessKeyId, accessKeySecret)
|
||||
ramclient := ram.NewClient(accessKeyId, accessKeySecret)
|
||||
c.ramClient = ramclient.(*ram.RamClient)
|
||||
|
||||
c.tags = tags
|
||||
|
||||
return c, nil
|
||||
|
|
@ -93,6 +101,10 @@ func (c *aliCloudImplementation) SlbClient() *slb.Client {
|
|||
return c.slbClient
|
||||
}
|
||||
|
||||
func (c *aliCloudImplementation) RamClient() *ram.RamClient {
|
||||
return c.ramClient
|
||||
}
|
||||
|
||||
func (c *aliCloudImplementation) Region() string {
|
||||
return c.region
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"account.go",
|
||||
"ak.go",
|
||||
"api.go",
|
||||
"client.go",
|
||||
"error.go",
|
||||
"group.go",
|
||||
"mfa.go",
|
||||
"policy.go",
|
||||
"profile.go",
|
||||
"role.go",
|
||||
"security.go",
|
||||
"types.go",
|
||||
],
|
||||
importmap = "vendor/github.com/denverdino/aliyungo/ram",
|
||||
importpath = "github.com/denverdino/aliyungo/ram",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//vendor/github.com/denverdino/aliyungo/common:go_default_library"],
|
||||
)
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package ram
|
||||
|
||||
type UserRequest struct {
|
||||
User
|
||||
}
|
||||
|
||||
type UserResponse struct {
|
||||
RamCommonResponse
|
||||
User User
|
||||
}
|
||||
|
||||
type UpdateUserRequest struct {
|
||||
UserName string
|
||||
NewUserName string
|
||||
NewDisplayName string
|
||||
NewMobilePhone string
|
||||
NewEmail string
|
||||
NewComments string
|
||||
}
|
||||
|
||||
type ListUserRequest struct {
|
||||
Marker string
|
||||
MaxItems int8
|
||||
}
|
||||
|
||||
type ListUserResponse struct {
|
||||
RamCommonResponse
|
||||
IsTruncated bool
|
||||
Marker string
|
||||
Users struct {
|
||||
User []User
|
||||
}
|
||||
}
|
||||
|
||||
func (client *RamClient) CreateUser(user UserRequest) (UserResponse, error) {
|
||||
var userResponse UserResponse
|
||||
err := client.Invoke("CreateUser", user, &userResponse)
|
||||
if err != nil {
|
||||
return UserResponse{}, err
|
||||
}
|
||||
return userResponse, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetUser(userQuery UserQueryRequest) (UserResponse, error) {
|
||||
var userResponse UserResponse
|
||||
err := client.Invoke("GetUser", userQuery, &userResponse)
|
||||
if err != nil {
|
||||
return UserResponse{}, nil
|
||||
}
|
||||
return userResponse, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) UpdateUser(newUser UpdateUserRequest) (UserResponse, error) {
|
||||
var userResponse UserResponse
|
||||
err := client.Invoke("UpdateUser", newUser, &userResponse)
|
||||
if err != nil {
|
||||
return UserResponse{}, err
|
||||
}
|
||||
return userResponse, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DeleteUser(userQuery UserQueryRequest) (RamCommonResponse, error) {
|
||||
var commonResp RamCommonResponse
|
||||
err := client.Invoke("DeleteUser", userQuery, &commonResp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return commonResp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListUsers(listParams ListUserRequest) (ListUserResponse, error) {
|
||||
var userList ListUserResponse
|
||||
err := client.Invoke("ListUsers", listParams, &userList)
|
||||
if err != nil {
|
||||
return ListUserResponse{}, err
|
||||
}
|
||||
return userList, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package ram
|
||||
|
||||
/*
|
||||
CreateAccessKey()
|
||||
UpdateAccessKey()
|
||||
DeleteAccessKey()
|
||||
ListAccessKeys()
|
||||
*/
|
||||
type State string
|
||||
|
||||
type AccessKeyResponse struct {
|
||||
RamCommonResponse
|
||||
AccessKey AccessKey
|
||||
}
|
||||
|
||||
type UpdateAccessKeyRequest struct {
|
||||
UserAccessKeyId string
|
||||
Status State
|
||||
UserName string
|
||||
}
|
||||
|
||||
type AccessKeyListResponse struct {
|
||||
RamCommonResponse
|
||||
AccessKeys struct {
|
||||
AccessKey []AccessKey
|
||||
}
|
||||
}
|
||||
|
||||
func (client *RamClient) CreateAccessKey(userQuery UserQueryRequest) (AccessKeyResponse, error) {
|
||||
var accesskeyResp AccessKeyResponse
|
||||
err := client.Invoke("CreateAccessKey", userQuery, &accesskeyResp)
|
||||
if err != nil {
|
||||
return AccessKeyResponse{}, err
|
||||
}
|
||||
return accesskeyResp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) UpdateAccessKey(accessKeyRequest UpdateAccessKeyRequest) (RamCommonResponse, error) {
|
||||
var commonResp RamCommonResponse
|
||||
err := client.Invoke("UpdateAccessKey", accessKeyRequest, &commonResp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return commonResp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DeleteAccessKey(accessKeyRequest UpdateAccessKeyRequest) (RamCommonResponse, error) {
|
||||
var commonResp RamCommonResponse
|
||||
err := client.Invoke("DeleteAccessKey", accessKeyRequest, &commonResp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return commonResp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListAccessKeys(userQuery UserQueryRequest) (AccessKeyListResponse, error) {
|
||||
var accessKeyListResp AccessKeyListResponse
|
||||
err := client.Invoke("ListAccessKeys", userQuery, &accessKeyListResp)
|
||||
if err != nil {
|
||||
return AccessKeyListResponse{}, err
|
||||
}
|
||||
return accessKeyListResp, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package ram
|
||||
|
||||
/*
|
||||
ringtail 2016/1/19
|
||||
All RAM apis provided
|
||||
*/
|
||||
|
||||
type RamClientInterface interface {
|
||||
//ram user
|
||||
CreateUser(user UserRequest) (UserResponse, error)
|
||||
GetUser(userQuery UserQueryRequest) (UserResponse, error)
|
||||
UpdateUser(newUser UpdateUserRequest) (UserResponse, error)
|
||||
DeleteUser(userQuery UserQueryRequest) (RamCommonResponse, error)
|
||||
ListUsers(listParams ListUserRequest) (ListUserResponse, error)
|
||||
|
||||
//ram login profile
|
||||
CreateLoginProfile(req ProfileRequest) (ProfileResponse, error)
|
||||
GetLoginProfile(req UserQueryRequest) (ProfileResponse, error)
|
||||
DeleteLoginProfile(req UserQueryRequest) (RamCommonResponse, error)
|
||||
UpdateLoginProfile(req ProfileRequest) (ProfileResponse, error)
|
||||
|
||||
//ram ak
|
||||
CreateAccessKey(userQuery UserQueryRequest) (AccessKeyResponse, error)
|
||||
UpdateAccessKey(accessKeyRequest UpdateAccessKeyRequest) (RamCommonResponse, error)
|
||||
DeleteAccessKey(accessKeyRequest UpdateAccessKeyRequest) (RamCommonResponse, error)
|
||||
ListAccessKeys(userQuery UserQueryRequest) (AccessKeyListResponse, error)
|
||||
|
||||
//ram mfa
|
||||
CreateVirtualMFADevice(req MFARequest) (MFAResponse, error)
|
||||
ListVirtualMFADevices() (MFAListResponse, error)
|
||||
DeleteVirtualMFADevice(req MFADeleteRequest) (RamCommonResponse, error)
|
||||
BindMFADevice(req MFABindRequest) (RamCommonResponse, error)
|
||||
UnbindMFADevice(req UserQueryRequest) (MFAUserResponse, error)
|
||||
GetUserMFAInfo(req UserQueryRequest) (MFAUserResponse, error)
|
||||
|
||||
//ram group
|
||||
CreateGroup(req GroupRequest) (GroupResponse, error)
|
||||
GetGroup(req GroupQueryRequest) (GroupResponse, error)
|
||||
UpdateGroup(req GroupUpdateRequest) (GroupResponse, error)
|
||||
ListGroup(req GroupListRequest) (GroupListResponse, error)
|
||||
DeleteGroup(req GroupQueryRequest) (RamCommonResponse, error)
|
||||
AddUserToGroup(req UserRelateGroupRequest) (RamCommonResponse, error)
|
||||
RemoveUserFromGroup(req UserRelateGroupRequest) (RamCommonResponse, error)
|
||||
ListGroupsForUser(req UserQueryRequest) (GroupListResponse, error)
|
||||
ListUsersForGroup(req GroupQueryRequest) (ListUserResponse, error)
|
||||
|
||||
CreateRole(role RoleRequest) (RoleResponse, error)
|
||||
GetRole(roleQuery RoleQueryRequest) (RoleResponse, error)
|
||||
UpdateRole(newRole UpdateRoleRequest) (RoleResponse, error)
|
||||
ListRoles() (ListRoleResponse, error)
|
||||
DeleteRole(roleQuery RoleQueryRequest) (RamCommonResponse, error)
|
||||
|
||||
//DONE policy
|
||||
CreatePolicy(policyReq PolicyRequest) (PolicyResponse, error)
|
||||
GetPolicy(policyReq PolicyRequest) (PolicyResponse, error)
|
||||
DeletePolicy(policyReq PolicyRequest) (RamCommonResponse, error)
|
||||
ListPolicies(policyQuery PolicyQueryRequest) (PolicyQueryResponse, error)
|
||||
ListPoliciesForUser(userQuery UserQueryRequest) (PolicyListResponse, error)
|
||||
|
||||
//ram policy version
|
||||
CreatePolicyVersion(policyReq PolicyRequest) (PolicyVersionResponse, error)
|
||||
GetPolicyVersion(policyReq PolicyRequest) (PolicyVersionResponse, error)
|
||||
GetPolicyVersionNew(policyReq PolicyRequest) (PolicyVersionResponseNew, error)
|
||||
DeletePolicyVersion(policyReq PolicyRequest) (RamCommonResponse, error)
|
||||
ListPolicyVersions(policyReq PolicyRequest) (PolicyVersionResponse, error)
|
||||
ListPolicyVersionsNew(policyReq PolicyRequest) (PolicyVersionsResponse, error)
|
||||
AttachPolicyToUser(attachPolicyRequest AttachPolicyRequest) (RamCommonResponse, error)
|
||||
DetachPolicyFromUser(attachPolicyRequest AttachPolicyRequest) (RamCommonResponse, error)
|
||||
ListEntitiesForPolicy(policyReq PolicyRequest) (PolicyListEntitiesResponse, error)
|
||||
SetDefaultPolicyVersion(policyReq PolicyRequest) (RamCommonResponse, error)
|
||||
ListPoliciesForGroup(groupQuery GroupQueryRequest) (PolicyListResponse, error)
|
||||
AttachPolicyToGroup(attachPolicyRequest AttachPolicyToGroupRequest) (RamCommonResponse, error)
|
||||
DetachPolicyFromGroup(attachPolicyRequest AttachPolicyToGroupRequest) (RamCommonResponse, error)
|
||||
AttachPolicyToRole(attachPolicyRequest AttachPolicyToRoleRequest) (RamCommonResponse, error)
|
||||
DetachPolicyFromRole(attachPolicyRequest AttachPolicyToRoleRequest) (RamCommonResponse, error)
|
||||
ListPoliciesForRole(roleQuery RoleQueryRequest) (PolicyListResponse, error)
|
||||
|
||||
//ram security
|
||||
SetAccountAlias(accountAlias AccountAliasRequest) (RamCommonResponse, error)
|
||||
GetAccountAlias() (AccountAliasResponse, error)
|
||||
ClearAccountAlias() (RamCommonResponse, error)
|
||||
SetPasswordPolicy(passwordPolicy PasswordPolicyRequest) (PasswordPolicyResponse, error)
|
||||
GetPasswordPolicy() (PasswordPolicyResponse, error)
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package ram
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/denverdino/aliyungo/common"
|
||||
)
|
||||
|
||||
const (
|
||||
// RAMDefaultEndpoint is the default API endpoint of RAM services
|
||||
RAMDefaultEndpoint = "https://ram.aliyuncs.com"
|
||||
RAMAPIVersion = "2015-05-01"
|
||||
)
|
||||
|
||||
type RamClient struct {
|
||||
common.Client
|
||||
}
|
||||
|
||||
func NewClient(accessKeyId string, accessKeySecret string) RamClientInterface {
|
||||
return NewClientWithSecurityToken(accessKeyId, accessKeySecret, "")
|
||||
}
|
||||
|
||||
func NewClientWithSecurityToken(accessKeyId string, accessKeySecret string, securityToken string) RamClientInterface {
|
||||
endpoint := os.Getenv("RAM_ENDPOINT")
|
||||
if endpoint == "" {
|
||||
endpoint = RAMDefaultEndpoint
|
||||
}
|
||||
|
||||
return NewClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, securityToken)
|
||||
}
|
||||
|
||||
func NewClientWithEndpoint(endpoint string, accessKeyId string, accessKeySecret string) RamClientInterface {
|
||||
return NewClientWithEndpointAndSecurityToken(endpoint, accessKeyId, accessKeySecret, "")
|
||||
}
|
||||
|
||||
func NewClientWithEndpointAndSecurityToken(endpoint string, accessKeyId string, accessKeySecret string, securityToken string) RamClientInterface {
|
||||
client := &RamClient{}
|
||||
client.WithEndpoint(endpoint).
|
||||
WithVersion(RAMAPIVersion).
|
||||
WithAccessKeyId(accessKeyId).
|
||||
WithAccessKeySecret(accessKeySecret).
|
||||
WithSecurityToken(securityToken).
|
||||
InitClient()
|
||||
return client
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package ram
|
||||
|
||||
//common errors
|
||||
var ()
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
package ram
|
||||
|
||||
type GroupRequest struct {
|
||||
Group
|
||||
}
|
||||
|
||||
type GroupQueryRequest struct {
|
||||
GroupName string
|
||||
}
|
||||
|
||||
type GroupUpdateRequest struct {
|
||||
GroupName string
|
||||
NewGroupName string
|
||||
NewComments string
|
||||
}
|
||||
|
||||
type GroupListRequest struct {
|
||||
Marker string
|
||||
MaxItems int8
|
||||
}
|
||||
|
||||
type UserRelateGroupRequest struct {
|
||||
UserName string
|
||||
GroupName string
|
||||
}
|
||||
|
||||
type GroupResponse struct {
|
||||
RamCommonResponse
|
||||
Group Group
|
||||
}
|
||||
|
||||
type GroupListResponse struct {
|
||||
RamCommonResponse
|
||||
IsTruncated bool
|
||||
Marker string
|
||||
Groups struct {
|
||||
Group []Group
|
||||
}
|
||||
}
|
||||
|
||||
func (client *RamClient) CreateGroup(req GroupRequest) (GroupResponse, error) {
|
||||
var resp GroupResponse
|
||||
err := client.Invoke("CreateGroup", req, &resp)
|
||||
if err != nil {
|
||||
return GroupResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetGroup(req GroupQueryRequest) (GroupResponse, error) {
|
||||
var resp GroupResponse
|
||||
err := client.Invoke("GetGroup", req, &resp)
|
||||
if err != nil {
|
||||
return GroupResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) UpdateGroup(req GroupUpdateRequest) (GroupResponse, error) {
|
||||
var resp GroupResponse
|
||||
err := client.Invoke("UpdateGroup", req, &resp)
|
||||
if err != nil {
|
||||
return GroupResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListGroup(req GroupListRequest) (GroupListResponse, error) {
|
||||
var resp GroupListResponse
|
||||
err := client.Invoke("ListGroups", req, &resp)
|
||||
if err != nil {
|
||||
return GroupListResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DeleteGroup(req GroupQueryRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("DeleteGroup", req, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) AddUserToGroup(req UserRelateGroupRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("AddUserToGroup", req, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) RemoveUserFromGroup(req UserRelateGroupRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("RemoveUserFromGroup", req, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListGroupsForUser(req UserQueryRequest) (GroupListResponse, error) {
|
||||
var resp GroupListResponse
|
||||
err := client.Invoke("ListGroupsForUser", req, &resp)
|
||||
if err != nil {
|
||||
return GroupListResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListUsersForGroup(req GroupQueryRequest) (ListUserResponse, error) {
|
||||
var resp ListUserResponse
|
||||
err := client.Invoke("ListUsersForGroup", req, &resp)
|
||||
if err != nil {
|
||||
return ListUserResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package ram
|
||||
|
||||
type MFARequest struct {
|
||||
VirtualMFADeviceName string
|
||||
}
|
||||
|
||||
type MFADeleteRequest struct {
|
||||
MFADevice
|
||||
}
|
||||
|
||||
type MFABindRequest struct {
|
||||
SerialNumber string
|
||||
UserName string
|
||||
AuthenticationCode1 string
|
||||
AuthenticationCode2 string
|
||||
}
|
||||
|
||||
type MFAResponse struct {
|
||||
RamCommonResponse
|
||||
VirtualMFADevice VirtualMFADevice
|
||||
}
|
||||
|
||||
type MFAListResponse struct {
|
||||
RamCommonResponse
|
||||
VirtualMFADevices struct {
|
||||
VirtualMFADevice []VirtualMFADevice
|
||||
}
|
||||
}
|
||||
|
||||
type MFAUserResponse struct {
|
||||
RamCommonResponse
|
||||
MFADevice MFADevice
|
||||
}
|
||||
|
||||
func (client *RamClient) CreateVirtualMFADevice(req MFARequest) (MFAResponse, error) {
|
||||
var resp MFAResponse
|
||||
err := client.Invoke("CreateVirtualMFADevice", req, &resp)
|
||||
if err != nil {
|
||||
return MFAResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListVirtualMFADevices() (MFAListResponse, error) {
|
||||
var resp MFAListResponse
|
||||
err := client.Invoke("ListVirtualMFADevices", struct{}{}, &resp)
|
||||
if err != nil {
|
||||
return MFAListResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DeleteVirtualMFADevice(req MFADeleteRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("DeleteVirtualMFADevice", req, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) BindMFADevice(req MFABindRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("BindMFADevice", req, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) UnbindMFADevice(req UserQueryRequest) (MFAUserResponse, error) {
|
||||
var resp MFAUserResponse
|
||||
err := client.Invoke("UnbindMFADevice", req, &resp)
|
||||
if err != nil {
|
||||
return MFAUserResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetUserMFAInfo(req UserQueryRequest) (MFAUserResponse, error) {
|
||||
var resp MFAUserResponse
|
||||
err := client.Invoke("GetUserMFAInfo", req, &resp)
|
||||
if err != nil {
|
||||
return MFAUserResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,291 @@
|
|||
package ram
|
||||
|
||||
type Type string
|
||||
|
||||
const (
|
||||
Custom Type = "Custom"
|
||||
System Type = "System"
|
||||
)
|
||||
|
||||
type PolicyRequest struct {
|
||||
PolicyName string
|
||||
PolicyType Type
|
||||
Description string
|
||||
PolicyDocument string
|
||||
SetAsDefault string
|
||||
VersionId string
|
||||
}
|
||||
type PolicyListResponse struct {
|
||||
RamCommonResponse
|
||||
Policies struct {
|
||||
Policy []Policy
|
||||
}
|
||||
}
|
||||
|
||||
type PolicyResponse struct {
|
||||
RamCommonResponse
|
||||
Policy Policy
|
||||
}
|
||||
|
||||
type PolicyQueryRequest struct {
|
||||
PolicyType Type
|
||||
Marker string
|
||||
MaxItems int8
|
||||
}
|
||||
|
||||
type PolicyQueryResponse struct {
|
||||
RamCommonResponse
|
||||
IsTruncated bool
|
||||
Marker string
|
||||
Policies struct {
|
||||
Policy []Policy
|
||||
}
|
||||
}
|
||||
|
||||
type PolicyVersionResponse struct {
|
||||
RamCommonResponse
|
||||
IsDefaultVersion bool
|
||||
VersionId string
|
||||
CreateDate string
|
||||
PolicyDocument string
|
||||
}
|
||||
|
||||
type AttachPolicyRequest struct {
|
||||
PolicyRequest
|
||||
UserName string
|
||||
}
|
||||
|
||||
type AttachPolicyToRoleRequest struct {
|
||||
PolicyRequest
|
||||
RoleName string
|
||||
}
|
||||
|
||||
type PolicyVersionResponseNew struct {
|
||||
RamCommonResponse
|
||||
PolicyVersion struct {
|
||||
IsDefaultVersion bool
|
||||
VersionId string
|
||||
CreateDate string
|
||||
PolicyDocument string
|
||||
}
|
||||
}
|
||||
|
||||
type AttachPolicyToGroupRequest struct {
|
||||
PolicyRequest
|
||||
GroupName string
|
||||
}
|
||||
|
||||
type PolicyVersionsResponse struct {
|
||||
RamCommonResponse
|
||||
PolicyVersions struct {
|
||||
PolicyVersion []PolicyVersion
|
||||
}
|
||||
}
|
||||
|
||||
type PolicyListEntitiesResponse struct {
|
||||
RamCommonResponse
|
||||
Groups struct {
|
||||
Group []Group
|
||||
}
|
||||
Users struct {
|
||||
User []User
|
||||
}
|
||||
Roles struct {
|
||||
Role []Role
|
||||
}
|
||||
}
|
||||
|
||||
func (client *RamClient) CreatePolicy(policyReq PolicyRequest) (PolicyResponse, error) {
|
||||
var resp PolicyResponse
|
||||
err := client.Invoke("CreatePolicy", policyReq, &resp)
|
||||
if err != nil {
|
||||
return PolicyResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetPolicy(policyReq PolicyRequest) (PolicyResponse, error) {
|
||||
var resp PolicyResponse
|
||||
err := client.Invoke("GetPolicy", policyReq, &resp)
|
||||
if err != nil {
|
||||
return PolicyResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DeletePolicy(policyReq PolicyRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("DeletePolicy", policyReq, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListPolicies(policyQuery PolicyQueryRequest) (PolicyQueryResponse, error) {
|
||||
var resp PolicyQueryResponse
|
||||
err := client.Invoke("ListPolicies", policyQuery, &resp)
|
||||
if err != nil {
|
||||
return PolicyQueryResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) CreatePolicyVersion(policyReq PolicyRequest) (PolicyVersionResponse, error) {
|
||||
var resp PolicyVersionResponse
|
||||
err := client.Invoke("CreatePolicyVersion", policyReq, &resp)
|
||||
if err != nil {
|
||||
return PolicyVersionResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetPolicyVersion(policyReq PolicyRequest) (PolicyVersionResponse, error) {
|
||||
var resp PolicyVersionResponse
|
||||
err := client.Invoke("GetPolicyVersion", policyReq, &resp)
|
||||
if err != nil {
|
||||
return PolicyVersionResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetPolicyVersionNew(policyReq PolicyRequest) (PolicyVersionResponseNew, error) {
|
||||
var resp PolicyVersionResponseNew
|
||||
err := client.Invoke("GetPolicyVersion", policyReq, &resp)
|
||||
if err != nil {
|
||||
return PolicyVersionResponseNew{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DeletePolicyVersion(policyReq PolicyRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("DeletePolicyVersion", policyReq, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListPolicyVersions(policyReq PolicyRequest) (PolicyVersionResponse, error) {
|
||||
var resp PolicyVersionResponse
|
||||
err := client.Invoke("ListPolicyVersions", policyReq, &resp)
|
||||
if err != nil {
|
||||
return PolicyVersionResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListPolicyVersionsNew(policyReq PolicyRequest) (PolicyVersionsResponse, error) {
|
||||
var resp PolicyVersionsResponse
|
||||
err := client.Invoke("ListPolicyVersions", policyReq, &resp)
|
||||
if err != nil {
|
||||
return PolicyVersionsResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) SetDefaultPolicyVersion(policyReq PolicyRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("SetDefaultPolicyVersion", policyReq, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) AttachPolicyToUser(attachPolicyRequest AttachPolicyRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("AttachPolicyToUser", attachPolicyRequest, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DetachPolicyFromUser(attachPolicyRequest AttachPolicyRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("DetachPolicyFromUser", attachPolicyRequest, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListEntitiesForPolicy(policyReq PolicyRequest) (PolicyListEntitiesResponse, error) {
|
||||
var resp PolicyListEntitiesResponse
|
||||
err := client.Invoke("ListEntitiesForPolicy", policyReq, &resp)
|
||||
if err != nil {
|
||||
return PolicyListEntitiesResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListPoliciesForUser(userQuery UserQueryRequest) (PolicyListResponse, error) {
|
||||
var resp PolicyListResponse
|
||||
err := client.Invoke("ListPoliciesForUser", userQuery, &resp)
|
||||
if err != nil {
|
||||
return PolicyListResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
//
|
||||
//Role related
|
||||
//
|
||||
func (client *RamClient) AttachPolicyToRole(attachPolicyRequest AttachPolicyToRoleRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("AttachPolicyToRole", attachPolicyRequest, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DetachPolicyFromRole(attachPolicyRequest AttachPolicyToRoleRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("DetachPolicyFromRole", attachPolicyRequest, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListPoliciesForRole(roleQuery RoleQueryRequest) (PolicyListResponse, error) {
|
||||
var resp PolicyListResponse
|
||||
err := client.Invoke("ListPoliciesForRole", roleQuery, &resp)
|
||||
if err != nil {
|
||||
return PolicyListResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
//
|
||||
//Group related
|
||||
//
|
||||
func (client *RamClient) AttachPolicyToGroup(attachPolicyRequest AttachPolicyToGroupRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("AttachPolicyToGroup", attachPolicyRequest, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DetachPolicyFromGroup(attachPolicyRequest AttachPolicyToGroupRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("DetachPolicyFromGroup", attachPolicyRequest, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListPoliciesForGroup(groupQuery GroupQueryRequest) (PolicyListResponse, error) {
|
||||
var resp PolicyListResponse
|
||||
err := client.Invoke("ListPoliciesForGroup", groupQuery, &resp)
|
||||
if err != nil {
|
||||
return PolicyListResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package ram
|
||||
|
||||
/*
|
||||
CreateLoginProfile()
|
||||
GetLoginProfile()
|
||||
DeleteLoginProfile()
|
||||
UpdateLoginProfile()
|
||||
*/
|
||||
|
||||
type ProfileRequest struct {
|
||||
UserName string
|
||||
Password string
|
||||
PasswordResetRequired bool
|
||||
MFABindRequired bool
|
||||
}
|
||||
|
||||
type ProfileResponse struct {
|
||||
RamCommonResponse
|
||||
LoginProfile LoginProfile
|
||||
}
|
||||
|
||||
func (client *RamClient) CreateLoginProfile(req ProfileRequest) (ProfileResponse, error) {
|
||||
var resp ProfileResponse
|
||||
err := client.Invoke("CreateLoginProfile", req, &resp)
|
||||
if err != nil {
|
||||
return ProfileResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetLoginProfile(req UserQueryRequest) (ProfileResponse, error) {
|
||||
var resp ProfileResponse
|
||||
err := client.Invoke("GetLoginProfile", req, &resp)
|
||||
if err != nil {
|
||||
return ProfileResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DeleteLoginProfile(req UserQueryRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("DeleteLoginProfile", req, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) UpdateLoginProfile(req ProfileRequest) (ProfileResponse, error) {
|
||||
var resp ProfileResponse
|
||||
err := client.Invoke("UpdateLoginProfile", req, &resp)
|
||||
if err != nil {
|
||||
return ProfileResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package ram
|
||||
|
||||
type RoleRequest struct {
|
||||
RoleName string
|
||||
AssumeRolePolicyDocument string
|
||||
Description string
|
||||
}
|
||||
|
||||
type RoleResponse struct {
|
||||
RamCommonResponse
|
||||
Role Role
|
||||
}
|
||||
|
||||
type RoleQueryRequest struct {
|
||||
RoleName string
|
||||
}
|
||||
|
||||
type UpdateRoleRequest struct {
|
||||
RoleName string
|
||||
NewAssumeRolePolicyDocument string
|
||||
}
|
||||
|
||||
type ListRoleResponse struct {
|
||||
RamCommonResponse
|
||||
Roles struct {
|
||||
Role []Role
|
||||
}
|
||||
}
|
||||
|
||||
func (client *RamClient) CreateRole(role RoleRequest) (RoleResponse, error) {
|
||||
var roleResponse RoleResponse
|
||||
err := client.Invoke("CreateRole", role, &roleResponse)
|
||||
if err != nil {
|
||||
return RoleResponse{}, err
|
||||
}
|
||||
return roleResponse, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetRole(roleQuery RoleQueryRequest) (RoleResponse, error) {
|
||||
var roleResponse RoleResponse
|
||||
err := client.Invoke("GetRole", roleQuery, &roleResponse)
|
||||
if err != nil {
|
||||
return RoleResponse{}, nil
|
||||
}
|
||||
return roleResponse, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) UpdateRole(newRole UpdateRoleRequest) (RoleResponse, error) {
|
||||
var roleResponse RoleResponse
|
||||
err := client.Invoke("UpdateRole", newRole, &roleResponse)
|
||||
if err != nil {
|
||||
return RoleResponse{}, err
|
||||
}
|
||||
return roleResponse, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ListRoles() (ListRoleResponse, error) {
|
||||
var roleList ListRoleResponse
|
||||
err := client.Invoke("ListRoles", struct{}{}, &roleList)
|
||||
if err != nil {
|
||||
return ListRoleResponse{}, err
|
||||
}
|
||||
return roleList, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) DeleteRole(roleQuery RoleQueryRequest) (RamCommonResponse, error) {
|
||||
var commonResp RamCommonResponse
|
||||
err := client.Invoke("DeleteRole", roleQuery, &commonResp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return commonResp, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package ram
|
||||
|
||||
//TODO implement ram api about security
|
||||
/*
|
||||
SetAccountAlias()
|
||||
GetAccountAlias()
|
||||
ClearAccountAlias()
|
||||
SetPasswordPolicy()
|
||||
GetPasswordPolicy()
|
||||
*/
|
||||
type AccountAliasResponse struct {
|
||||
RamCommonResponse
|
||||
AccountAlias string
|
||||
}
|
||||
|
||||
type PasswordPolicyResponse struct {
|
||||
RamCommonResponse
|
||||
PasswordPolicy
|
||||
}
|
||||
|
||||
type PasswordPolicyRequest struct {
|
||||
PasswordPolicy
|
||||
}
|
||||
|
||||
type AccountAliasRequest struct {
|
||||
AccountAlias string
|
||||
}
|
||||
|
||||
func (client *RamClient) SetAccountAlias(accountalias AccountAliasRequest) (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("SetAccountAlias", accountalias, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetAccountAlias() (AccountAliasResponse, error) {
|
||||
var resp AccountAliasResponse
|
||||
err := client.Invoke("GetAccountAlias", struct{}{}, &resp)
|
||||
if err != nil {
|
||||
return AccountAliasResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) ClearAccountAlias() (RamCommonResponse, error) {
|
||||
var resp RamCommonResponse
|
||||
err := client.Invoke("ClearAccountAlias", struct{}{}, &resp)
|
||||
if err != nil {
|
||||
return RamCommonResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) SetPasswordPolicy(passwordPolicy PasswordPolicyRequest) (PasswordPolicyResponse, error) {
|
||||
var resp PasswordPolicyResponse
|
||||
err := client.Invoke("SetPasswordPolicy", passwordPolicy, &resp)
|
||||
if err != nil {
|
||||
return PasswordPolicyResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (client *RamClient) GetPasswordPolicy() (PasswordPolicyResponse, error) {
|
||||
var resp PasswordPolicyResponse
|
||||
err := client.Invoke("GetPasswordPolicy", struct{}{}, &resp)
|
||||
if err != nil {
|
||||
return PasswordPolicyResponse{}, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
package ram
|
||||
|
||||
import (
|
||||
"github.com/denverdino/aliyungo/common"
|
||||
)
|
||||
|
||||
/*
|
||||
All common struct
|
||||
*/
|
||||
|
||||
const (
|
||||
Active State = "Active"
|
||||
Inactive State = "Inactive"
|
||||
)
|
||||
|
||||
/*
|
||||
AccountAlias
|
||||
类型:String
|
||||
必须:是
|
||||
描述:指定云账号的别名, 长度限制为3-63个字符
|
||||
限制:^[a-z0-9](([a-z0-9]|-(?!-))*[a-z0-9])?$
|
||||
*/
|
||||
type AccountAlias string
|
||||
|
||||
type UserQueryRequest struct {
|
||||
UserName string
|
||||
}
|
||||
|
||||
type User struct {
|
||||
UserId string
|
||||
UserName string
|
||||
DisplayName string
|
||||
MobilePhone string
|
||||
Email string
|
||||
Comments string
|
||||
CreateDate string
|
||||
UpdateDate string
|
||||
LastLoginDate string
|
||||
}
|
||||
|
||||
type LoginProfile struct {
|
||||
UserName string
|
||||
PasswordResetRequired bool
|
||||
MFABindRequired bool
|
||||
}
|
||||
|
||||
type MFADevice struct {
|
||||
SerialNumber string
|
||||
}
|
||||
|
||||
type VirtualMFADevice struct {
|
||||
SerialNumber string
|
||||
Base32StringSeed string
|
||||
QRCodePNG string
|
||||
ActivateDate string
|
||||
User User
|
||||
}
|
||||
|
||||
type AccessKey struct {
|
||||
AccessKeyId string
|
||||
AccessKeySecret string
|
||||
Status State
|
||||
CreateDate string
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
GroupName string
|
||||
Comments string
|
||||
}
|
||||
|
||||
type Role struct {
|
||||
RoleId string
|
||||
RoleName string
|
||||
Arn string
|
||||
Description string
|
||||
AssumeRolePolicyDocument string
|
||||
CreateDate string
|
||||
UpdateDate string
|
||||
}
|
||||
|
||||
type Policy struct {
|
||||
PolicyName string
|
||||
PolicyType string
|
||||
Description string
|
||||
DefaultVersion string
|
||||
CreateDate string
|
||||
UpdateDate string
|
||||
AttachmentCount int64
|
||||
}
|
||||
|
||||
type PolicyVersion struct {
|
||||
VersionId string
|
||||
IsDefaultVersion bool
|
||||
CreateDate string
|
||||
PolicyDocument string
|
||||
}
|
||||
|
||||
type PolicyDocument struct {
|
||||
Statement []PolicyItem
|
||||
Version string
|
||||
}
|
||||
|
||||
type PolicyItem struct {
|
||||
Action string
|
||||
Effect string
|
||||
Resource string
|
||||
}
|
||||
|
||||
type AssumeRolePolicyDocument struct {
|
||||
Statement []AssumeRolePolicyItem
|
||||
Version string
|
||||
}
|
||||
|
||||
type AssumeRolePolicyItem struct {
|
||||
Action string
|
||||
Effect string
|
||||
Principal AssumeRolePolicyPrincpal
|
||||
}
|
||||
|
||||
type AssumeRolePolicyPrincpal struct {
|
||||
RAM []string
|
||||
}
|
||||
|
||||
/*
|
||||
"PasswordPolicy": {
|
||||
"MinimumPasswordLength": 12,
|
||||
"RequireLowercaseCharacters": true,
|
||||
"RequireUppercaseCharacters": true,
|
||||
"RequireNumbers": true,
|
||||
"RequireSymbols": true
|
||||
}
|
||||
*/
|
||||
|
||||
type PasswordPolicy struct {
|
||||
MinimumPasswordLength int8
|
||||
RequireLowercaseCharacters bool
|
||||
RequireUppercaseCharacters bool
|
||||
RequireNumbers bool
|
||||
RequireSymbols bool
|
||||
}
|
||||
|
||||
type RamCommonResponse struct {
|
||||
common.Response
|
||||
}
|
||||
Loading…
Reference in New Issue