Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/ccoctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/openshift/cloud-credential-operator/pkg/cmd/provisioning/alibabacloud"
"github.com/openshift/cloud-credential-operator/pkg/cmd/provisioning/aws"
"github.com/openshift/cloud-credential-operator/pkg/cmd/provisioning/gcp"
"github.com/openshift/cloud-credential-operator/pkg/cmd/provisioning/ibmcloud"
Expand All @@ -19,6 +20,7 @@ func main() {
rootCmd.AddCommand(aws.NewAWSCmd())
rootCmd.AddCommand(gcp.NewGCPCmd())
rootCmd.AddCommand(ibmcloud.NewIBMCloudCmd())
rootCmd.AddCommand(alibabacloud.NewAliababaCloudCmd())

if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
Expand Down
123 changes: 123 additions & 0 deletions docs/ccoctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,126 @@ This command will delete the service id from the IBM Cloud
```bash
ccoctl ibmcloud delete-service-id --credentials-requests-dir <path-to-directory-with-list-of-credentials-requests> --name <name>
```

## Alibaba Cloud

This is a guide for using manual mode on alibaba cloud, for more info about manual mode, please refer to [cco-mode-manual](https://github.com/openshift/cloud-credential-operator/blob/master/docs/mode-manual-creds.md).
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeana-redhat while this is fine for 'upstream docs' when we downstream these docs we need to remove / redirect this to docs we have that don't reside on github.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, would def be pointing to the product docs version of this content 👍


For alibaba cloud, the CCO utility (`ccoctl`) binary will create credentials Secret manifests for the OpenShift installer. It will also create a user along with a long-lived RAM AccessKey (AK) for each OpenShift in-cluster component. Every RAM user who owns the AK would be attached RAM policies with the permission defined in each component's CredentialsRequest. To do all this, ccoctl consumes AK of a root RAM user with permissions required for creating user/policy and also attaching the policy to the user.

### Prerequisite

1. Extract and prepare the ccoctl binary from the release image.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show a command for how to do this; don't assume you users know how to do this.

Copy link
Copy Markdown

@jeana-redhat jeana-redhat Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, we show this for the AWS version and I will be modelling the structure for new platform support on what we have for AWS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sferich888 thanks for the review! I could only found a Chinese doc for these on https://help.aliyun.com/document_detail/311677.html, and I will check if there is an English version with my colleague


2. Choose an existing RAM user who has the below permissions, and get this user's accesskey id/secret for creating the RAM users and policies for each in-cluster component.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to tell the user where/how to get the accesskey id/secret for the user account they will use?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally these are given to a user when they are assigned an account. Users can manage their keys with their RAM (resource access management console). This document explains a littl emore about getting AccessKeys https://www.alibabacloud.com/help/doc-detail/53045.htm

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent - that documentation is very helpful.


```bash
ram:CreatePolicy
ram:GetPolicy
ram:CreatePolicyVersion
ram:DeletePolicy
ram:DetachPolicyFromUser
ram:ListPoliciesForUser
ram:AttachPolicyToUser
ram:CreateUser
ram:GetUser
ram:DeleteUser
ram:CreateAccessKey
ram:ListAccessKeys
ram:DeleteAccessKey
```

3. Use the selected RAM user’s accesskey id/secret to configure the Alibaba Cloud SDK client's credential provider chain with [Envionment Creadentials](https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md#1-environment-credentials) mode or through [Credentials File](https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/docs/2-Client-EN.md#2-credentials-file) mode
Copy link
Copy Markdown

@jeana-redhat jeana-redhat Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these links official Alibaba Cloud documentation intended for end user consumption?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this sdk is our official supported, and these docs are also for end user consumption.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 👍

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DahuK is there something more official? When we downstream these docs; we don't want to link to github; if at all possible.


### Procedure

1. Extract the list of CredentialsRequest custom resources (CRs) from the OpenShift Container Platform release image:

```bash
$ oc adm release extract --credentials-requests --cloud=alibabacloud --to=<path_to_directory_with_list_of_credentials_requests>/credrequests quay.io/<path_to>/ocp-release:<version>

Comment on lines +253 to +255
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality is not implemented yet in oc cli. We need to first complete that before merging this PR. Check the PR for ibmcloud here.

```

> step 2&3 are only needed when preparing for upgrading clusters with manually maintained credentials. When doing a fresh installation please skip step 2&3**

2. For each CredentialsRequest CR in the release image, ensure that a namespace that matches the text in the spec.secretRef.namespace field exists in the cluster. This field is where the generated secrets that hold the credentials configuration are stored.

Sample Alibaba Cloud CredentialsRequest object

```yaml
apiVersion: cloudcredential.openshift.io/v1
kind: CredentialsRequest
metadata:
name: cloud-credential-operator-ram-ro
namespace: openshift-cloud-credential-operator
spec:
providerSpec:
apiVersion: cloudcredential.openshift.io/v1
kind: AlibabaCloudProviderSpec
statementEntries:
- action:
- ecs:CopySnapshot
- ecs:DeleteDisk
- ecs:DescribeInstanceAttribute
- ecs:DescribeInstances
effect: Allow
resource: '*'
secretRef:
namespace: cloud-credential-operator-ram-ro-creds
name: openshift-cloud-credential-operator
```

3. For any `CredentialsRequest` CR for which the cluster does not already have a namespace with the name specified in `spec.secretRef.namespace`, create the namespace:

```bash
$ oc create namespace <component_namespace>
```

4. Use the `ccoctl` tool to process all `CredentialsRequest` objects in the `credrequests` directory:

```bash
$ ccoctl alibabacloud create-ram-users --name <name> --region=<region> --credentials-requests-dir=<path_to_directory_with_list_of_credentials_requests>/credrequests --output-dir=xxxxxx
```

where:

- `name` is the name used to tag any cloud resources that are created for tracking.
- `region` is the Alibaba Cloud region in which cloud resources will be created.
- `credentials-requests-dir` is the directory containing files of component CredentialsRequests.
- `output-dir`/manifests is the directory containing files of component credentials secret.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does /manifests on this line mean?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This /manifests means that results from the ccoctl binary will be placed in a directory on the system located at /manifests.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm interpreting that to mean <output-dir>/manifests then - let me know if that's incorrect

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeana-redhat your interpretation is correct, the manifests will be placed inside <output-dir>/manifests. Let me share some examples:
If I run:

ccoctl alibabacloud create-ram-users \
  --region ${ALIBABA_REGION_ID} \
  --name <cluster_name> \
  --credentials-requests-dir ${PWD}/cco-credrequests \
  --output-dir ${PWD}/cco-manifests

I will get that structure:

$ tree cco-manifests/
cco-manifests/
└── manifests
    ├── openshift-cluster-csi-drivers-alibaba-disk-credentials-credentials.yaml
    ├── openshift-image-registry-installer-cloud-credentials-credentials.yaml
    ├── openshift-ingress-operator-cloud-credentials-credentials.yaml
    └── openshift-machine-api-alibabacloud-credentials-credentials.yaml


> Note: A ram user can have up to two accesskeys at the same time, so when the `ccoctl alibabacloud create-ram-users` command is run more than twice, the previous generated manifests secret will become stale and you should apply the new generated secrets again.**

5. Prepare to run the OpenShift Container Platform installer:

a. Create the install-config.yaml file:
```bash
$ openshift-install create install-config --dir ./path/to/installation/dir
```
b. Configure the cluster to install with the CCO in manual mode:

```bash
$ echo "credentialsMode: Manual" >> ./path/to/installation/dir/install-config.yaml
```

c. Create install manifests:

```bash
$ openshift-install create manifests --dir ./path/to/installation/dir
```

d. Copy the generated credential files to the target manifests directory:

```bash
$ cp <output_dir>/manifests/*credentials.yaml ./path/to/installation/dir/manifests/
```
6. To delete resources created by ccoctl, run
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the user always delete after installing? Or is this a cleanup step for uninstalling (I am asking based on other provider docs)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These keys will most likely live until the cluster is uninstalled. The keys are being used by the cluster's internal components that require API access. They MUST not be deleted after installation or the cluster will not continue to function properly.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so a cleanup after uninstall step similar to other platforms then. Thanks!


```bash
$ ccoctl alibabacloud delete-ram-users --name <name> --region=<region> --credentials-requests-dir=<path_to_directory_with_list_of_credentials_requests>/credrequests
```
where:
- `name` is the name used to tag any cloud resources that are created for tracking.
- `region` is the Alibaba Cloud region in which cloud resources will be created.
- `credentials-requests-dir` is the directory containing files of component CredentialsRequests.

4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ require (
github.com/Azure/go-autorest/autorest/to v0.3.0
github.com/IBM/go-sdk-core/v5 v5.6.3
github.com/IBM/platform-services-go-sdk v0.19.4
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1323
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/aws/aws-sdk-go v1.37.14
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-bindata/go-bindata v3.1.2+incompatible
Expand Down Expand Up @@ -61,7 +63,6 @@ require (
github.com/Azure/go-autorest/tracing v0.5.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.0+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
Expand Down Expand Up @@ -120,6 +121,7 @@ require (
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
k8s.io/apiextensions-apiserver v0.19.2 // indirect
k8s.io/component-base v0.19.2 // indirect
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1323 h1:QSfS1AsgI1wwGhDeCEXC2LqjEssBCchiaUW+fHX5bFA=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1323/go.mod h1:9CMdKNL3ynIGPpfTcdwTvIm8SGuAZYYC4jFVSSvE1YQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
Expand Down Expand Up @@ -317,6 +319,7 @@ github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -419,6 +422,7 @@ github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3i
github.com/googleapis/gnostic v0.5.1 h1:A8Yhf6EtqTv9RMsU6MQTyrtV1TjWlR6xU9BsZIwuTCM=
github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU=
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v0.0.0-20191024121256-f395758b854c/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
Expand Down Expand Up @@ -471,20 +475,23 @@ github.com/imdario/mergo v0.3.10 h1:6q5mVkdH/vYmqngx7kZQTjJ5HRsx+ImorDIEQ+beJgc=
github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
Expand Down Expand Up @@ -658,7 +665,9 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down Expand Up @@ -1218,6 +1227,8 @@ gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWd
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ldap.v2 v2.5.1/go.mod h1:oI0cpe/D7HRtBQl8aTg+ZmzFUAvu4lsv3eLXMLGFxWk=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
Expand Down
130 changes: 130 additions & 0 deletions pkg/alibabacloud/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
Copyright 2021 The OpenShift 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 alibabacloud

import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ram"
"log"
)

//go:generate mockgen -source=./client.go -destination=./mock/client_generated.go -package=mock

// Client is a wrapper object for actual Alibaba Cloud SDK clients to allow for easier testing.
type Client interface {
//RAM
CreatePolicy(*ram.CreatePolicyRequest) (*ram.CreatePolicyResponse, error)
GetPolicy(*ram.GetPolicyRequest) (*ram.GetPolicyResponse, error)
CreatePolicyVersion(*ram.CreatePolicyVersionRequest) (*ram.CreatePolicyVersionResponse, error)
AttachPolicyToUser(*ram.AttachPolicyToUserRequest) (*ram.AttachPolicyToUserResponse, error)
CreateUser(*ram.CreateUserRequest) (*ram.CreateUserResponse, error)
GetUser(*ram.GetUserRequest) (*ram.GetUserResponse, error)
DeleteUser(*ram.DeleteUserRequest) (*ram.DeleteUserResponse, error)
CreateAccessKey(*ram.CreateAccessKeyRequest) (*ram.CreateAccessKeyResponse, error)
ListAccessKeys(*ram.ListAccessKeysRequest) (*ram.ListAccessKeysResponse, error)
DeleteAccessKey(*ram.DeleteAccessKeyRequest) (*ram.DeleteAccessKeyResponse, error)
DeletePolicy(request *ram.DeletePolicyRequest) (response *ram.DeletePolicyResponse, err error)
DetachPolicyFromUser(request *ram.DetachPolicyFromUserRequest) (response *ram.DetachPolicyFromUserResponse, err error)
ListPoliciesForUser(request *ram.ListPoliciesForUserRequest) (response *ram.ListPoliciesForUserResponse, err error)
DeletePolicyVersion(request *ram.DeletePolicyVersionRequest) (response *ram.DeletePolicyVersionResponse, err error)
ListPolicyVersions(request *ram.ListPolicyVersionsRequest) (response *ram.ListPolicyVersionsResponse, err error)
}

type alibabaCloudClient struct {
ramClient *ram.Client
}

func (c *alibabaCloudClient) CreatePolicy(request *ram.CreatePolicyRequest) (response *ram.CreatePolicyResponse, err error) {
return c.ramClient.CreatePolicy(request)
}

func (c *alibabaCloudClient) GetPolicy(request *ram.GetPolicyRequest) (response *ram.GetPolicyResponse, err error) {
return c.ramClient.GetPolicy(request)
}

func (c *alibabaCloudClient) CreatePolicyVersion(request *ram.CreatePolicyVersionRequest) (response *ram.CreatePolicyVersionResponse, err error) {
return c.ramClient.CreatePolicyVersion(request)
}

func (c *alibabaCloudClient) AttachPolicyToUser(input *ram.AttachPolicyToUserRequest) (*ram.AttachPolicyToUserResponse, error) {
return c.ramClient.AttachPolicyToUser(input)
}

func (c *alibabaCloudClient) DeletePolicy(request *ram.DeletePolicyRequest) (response *ram.DeletePolicyResponse, err error) {
return c.ramClient.DeletePolicy(request)
}

func (c *alibabaCloudClient) DetachPolicyFromUser(request *ram.DetachPolicyFromUserRequest) (response *ram.DetachPolicyFromUserResponse, err error) {
return c.ramClient.DetachPolicyFromUser(request)
}

func (c *alibabaCloudClient) ListPoliciesForUser(request *ram.ListPoliciesForUserRequest) (response *ram.ListPoliciesForUserResponse, err error) {
return c.ramClient.ListPoliciesForUser(request)
}

func (c *alibabaCloudClient) CreateUser(input *ram.CreateUserRequest) (*ram.CreateUserResponse, error) {
return c.ramClient.CreateUser(input)
}

func (c *alibabaCloudClient) GetUser(input *ram.GetUserRequest) (*ram.GetUserResponse, error) {
return c.ramClient.GetUser(input)
}

func (c *alibabaCloudClient) DeleteUser(input *ram.DeleteUserRequest) (*ram.DeleteUserResponse, error) {
return c.ramClient.DeleteUser(input)
}

func (c *alibabaCloudClient) ListAccessKeys(input *ram.ListAccessKeysRequest) (*ram.ListAccessKeysResponse, error) {
return c.ramClient.ListAccessKeys(input)
}

func (c *alibabaCloudClient) CreateAccessKey(input *ram.CreateAccessKeyRequest) (*ram.CreateAccessKeyResponse, error) {
return c.ramClient.CreateAccessKey(input)
}

func (c *alibabaCloudClient) DeleteAccessKey(input *ram.DeleteAccessKeyRequest) (*ram.DeleteAccessKeyResponse, error) {
return c.ramClient.DeleteAccessKey(input)
}

func (c *alibabaCloudClient) DeletePolicyVersion(input *ram.DeletePolicyVersionRequest) (*ram.DeletePolicyVersionResponse, error) {
return c.ramClient.DeletePolicyVersion(input)
}

func (c *alibabaCloudClient) ListPolicyVersions(input *ram.ListPolicyVersionsRequest) (*ram.ListPolicyVersionsResponse, error) {
return c.ramClient.ListPolicyVersions(input)
}

// NewClient creates our client wrapper object for the actual Alibaba Cloud clients we use.
func NewClient(regionId string) (Client, error) {
envProvider := provider.NewEnvProvider()
profileProvider := provider.NewProfileProvider()
pc := provider.NewProviderChain([]provider.Provider{envProvider, profileProvider})
credential, err := pc.Resolve()
if err != nil {
log.Fatalf("Failed to resolve an authentication provider: %v", err)
}
config := sdk.NewConfig().WithScheme("https")

rc, err := ram.NewClientWithOptions(regionId, config, credential)
if err != nil {
return nil, err
}
return &alibabaCloudClient{
ramClient: rc,
}, nil
}
Loading