Skip to content

Commit

Permalink
Fix rebase issues
Browse files Browse the repository at this point in the history
Signed-off-by: Zheng Xi Zhou <[email protected]>
  • Loading branch information
zzxwill committed Jun 23, 2021
1 parent 281a8c7 commit 592c395
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
11 changes: 6 additions & 5 deletions pkg/clients/rds/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func TestNewClient(t *testing.T) {
ctx context.Context
accessKeyID string
accessKeySecret string
securityToken string
region string
}
type want struct {
Expand All @@ -114,7 +115,7 @@ func TestNewClient(t *testing.T) {

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
_, err := NewClient(tc.args.ctx, tc.args.accessKeyID, tc.args.accessKeySecret, tc.args.region)
_, err := NewClient(tc.args.ctx, tc.args.accessKeyID, tc.args.accessKeySecret, tc.args.securityToken, tc.args.region)
if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {
t.Errorf("\nNewClient(...) -want error, +got error:\n%s\n", diff)
}
Expand All @@ -123,7 +124,7 @@ func TestNewClient(t *testing.T) {
}

func TestDescribeDBInstance(t *testing.T) {
c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "cn-beijing")
c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "", "cn-beijing")
type args struct {
id string
}
Expand Down Expand Up @@ -167,7 +168,7 @@ func TestDescribeDBInstance(t *testing.T) {
}

func TestCreateDBInstance(t *testing.T) {
c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "cn-beijing")
c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "", "cn-beijing")
type args struct {
req CreateDBInstanceRequest
}
Expand Down Expand Up @@ -218,7 +219,7 @@ func TestCreateDBInstance(t *testing.T) {
}

func TestDeleteDBInstance(t *testing.T) {
c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "cn-beijing")
c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "", "cn-beijing")
type args struct {
id string
}
Expand Down Expand Up @@ -256,7 +257,7 @@ func TestDeleteDBInstance(t *testing.T) {
}

func TestCreateAccount(t *testing.T) {
c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "cn-beijing")
c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "", "cn-beijing")
type args struct {
id string
username string
Expand Down
39 changes: 8 additions & 31 deletions pkg/controller/oss/oss_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -38,14 +36,8 @@ import (
)

const (
errCreateClient = "cannot create OSS client"
errTrackUsage = "cannot track provider config usage"
errNoConnectionSecret = "no connection secret specified"
errGetConnectionSecret = "cannot get connection secret"
errFmtUnsupportedCredSource = "credentials source %q is not currently supported"
)

const (
errCreateClient = "cannot create OSS client"
errTrackUsage = "cannot track provider config usage"
errFailedToCreateBucket = "failed to create OSS bucket"
errFailedToUpdateBucket = "failed to update OSS bucket"
errFailedToDeleteBucket = "failed to delete OSS bucket"
Expand Down Expand Up @@ -84,41 +76,26 @@ func (c *Connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
return nil, errors.New(errNotBucket)
}

var (
secretKeySelector *xpv1.SecretKeySelector
region string
)

if err := c.Usage.Track(ctx, mg); err != nil {
return nil, errors.Wrap(err, errTrackUsage)
}

providerConfig, err := util.GetProviderConfig(ctx, c.Client, cr.Spec.ProviderConfigReference.Name)
pcName := cr.Spec.ProviderConfigReference.Name
cred, err := util.GetCredentials(ctx, c.Client, pcName)
if err != nil {
return nil, err
}

if s := providerConfig.Spec.Credentials.Source; s != xpv1.CredentialsSourceSecret {
return nil, errors.Errorf(errFmtUnsupportedCredSource, s)
}
secretKeySelector = providerConfig.Spec.Credentials.SecretRef
region = providerConfig.Spec.Region

if secretKeySelector == nil {
return nil, errors.New(errNoConnectionSecret)
}
s := &corev1.Secret{}
nn := types.NamespacedName{Namespace: secretKeySelector.Namespace, Name: secretKeySelector.Name}
if err := c.Client.Get(ctx, nn, s); err != nil {
return nil, errors.Wrap(err, errGetConnectionSecret)
region, err := util.GetRegion(ctx, c.Client, pcName)
if err != nil {
return nil, err
}

endpoint, err := util.GetEndpoint(cr.DeepCopyObject(), region)
if err != nil {
return nil, err
}

ossClient, err := c.NewClientFn(ctx, endpoint, string(s.Data[util.AccessKeyID]), string(s.Data[util.AccessKeySecret]), string(s.Data[util.SecurityToken]))
ossClient, err := c.NewClientFn(ctx, endpoint, cred.AccessKeyID, cred.AccessKeySecret, cred.SecurityToken)
return &External{ExternalClient: ossClient}, errors.Wrap(err, errCreateClient)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/sls/project_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
if err != nil {
return nil, err
}

slsClient := c.NewClientFn(cred.AccessKeyID, cred.AccessKeySecret, cred.SecurityToken, region)
return &external{client: slsClient}, nil
}
Expand Down

0 comments on commit 592c395

Please sign in to comment.