Skip to content

Commit 1f3033a

Browse files
authored
Rename EC2 to S3Credentials (#5)
1 parent 2392784 commit 1f3033a

File tree

12 files changed

+82
-81
lines changed

12 files changed

+82
-81
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You can use this library to work with the following objects of the Selectel IAM
2121

2222
* [users](https://pkg.go.dev/github.com/selectel/iam-go/service/users)
2323
* [serviceusers](https://pkg.go.dev/github.com/selectel/iam-go/service/serviceusers)
24-
* [ec2](https://pkg.go.dev/github.com/selectel/iam-go/service/ec2)
24+
* [s3credentials](https://pkg.go.dev/github.com/selectel/iam-go/service/s3credentials)
2525

2626
### Installation
2727

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This directory contains examples that cover various use cases and functionality for iam-go.
44

55
### Concepts
6-
- [**Create & Delete EC2 Credentials**](./ec2-create-delete): Create a new EC2 credential for an existing Service User (ID is needed).
6+
- [**Create & Delete S3 Credentials**](./s3credentials-create-delete): Create a new S3 Credentials for an existing Service User (ID is needed) and delete it.
77
- [**Create, Update & Delete Service User**](./serviceuser-create-update-delete): Create a new Service User, then update it's data and delete it.
88
- [**Transfer role from one User to another**](./transfer-role): Find a billing User from all and transfer it's role to another User (ID is needed).
99
- [**Create & Delete User**](./user-create-delete): Create a new User and delete it.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# Create & Delete EC2 credential
1+
# Create & Delete S3 Credentials
22

3-
This example program demonstrates how to manage creating and deleting EC2 credential for a Service User.
3+
This example program demonstrates how to manage creating and deleting S3 Credentials for a Service User.
44

5-
The part of deleting a just-created credential is commented.
5+
The part of deleting a just-created credentials is commented.
66

77
## Running this example
88

99
Running this file will execute the following operations:
1010

11-
1. **Create:** Create is used to create a new EC2 credential. It is implied, that the Service User ID is known.
12-
2. **(Delete):** _(commented by default)_ Delete deletes a just-created credential on a previous step.
11+
1. **Create:** Create is used to create a new S3 Credentials. It is implied, that the Service User ID is known.
12+
2. **(Delete):** _(commented by default)_ Delete deletes a just-created credentials on a previous step.
1313

1414
You should see an output like the following (with both operations enabled):
1515

1616
```
17-
Step 1: Created credential Secret Key: a1b2c3... AccessKey: 1a2b3c...
18-
Step 2: Deleted the credential
17+
Step 1: Created credentials Secret Key: a1b2c3... AccessKey: 1a2b3c...
18+
Step 2: Deleted the credentials
1919
```

examples/ec2-create-delete/main.go renamed to examples/s3credentials-create-delete/main.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ func main() {
1414
// Prefix to be added to User-Agent.
1515
prefix := "iam-go"
1616

17-
// ID of the User to create EC2 credential for.
17+
// ID of the User to create S3 Credentials for.
1818
userID := "a1b2c3..."
1919

20-
// Name of the EC2 credential to create.
21-
name := "my-ec2-credential"
20+
// Name of the S3 Credentials to create.
21+
name := "my-s3-credentials"
2222

23-
// Project ID to create the EC2 credential for.
23+
// Project ID to create the S3 Credentials for.
2424
projectID := "a1b2c3..."
2525

2626
// Create a new IAM client.
@@ -34,14 +34,14 @@ func main() {
3434
return
3535
}
3636

37-
// Get the EC2 Credentials APIinstance.
38-
ec2CredAPI := iamClient.EC2
37+
// Get the S3 Credentials API instance.
38+
s3CredAPI := iamClient.S3Credentials
3939

4040
// Prepare an empty context.
4141
ctx := context.Background()
4242

43-
// Create a new EC2 credential for the Service User.
44-
credential, err := ec2CredAPI.Create(
43+
// Create a new S3 Credentials for the Service User.
44+
credentials, err := s3CredAPI.Create(
4545
ctx,
4646
userID,
4747
name,
@@ -53,18 +53,19 @@ func main() {
5353
return
5454
}
5555

56-
fmt.Printf("Step 1: Created credential Secret Key: %s Access Key: %s\n", credential.SecretKey, credential.AccessKey)
56+
fmt.Printf("Step 1: Created credentials Secret Key: %s Access Key: %s\n", credentials.SecretKey,
57+
credentials.AccessKey)
5758

58-
// // Delete an existing EC2 credential.
59-
// err = ec2CredAPI.Delete(ctx, &ec2.DeleteInput{
59+
// // Delete an existing S3 Credentials.
60+
// err = s3CredAPI.Delete(ctx, &s3credentials.DeleteInput{
6061
// UserID: userID,
61-
// AccessKey: credential.AccessKey,
62+
// AccessKey: credentials.AccessKey,
6263
// })
6364

6465
// // Handle the error.
6566
// if err != nil {
6667
// fmt.Println(err)
6768
// }
6869

69-
// fmt.Printf("Step 2: Deleted credential")
70+
// fmt.Printf("Step 2: Deleted credentials")
7071
}

iam.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/selectel/iam-go/iamerrors"
99
baseclient "github.com/selectel/iam-go/internal/client"
10-
"github.com/selectel/iam-go/service/ec2"
10+
"github.com/selectel/iam-go/service/s3credentials"
1111
"github.com/selectel/iam-go/service/serviceusers"
1212
"github.com/selectel/iam-go/service/users"
1313
)
@@ -45,14 +45,14 @@ type Client struct {
4545
// baseClient contains the configuration of the Client.
4646
baseClient *baseclient.BaseClient
4747

48-
// Users instance is used to make requests against Selectel IAM API and manage panel users.
48+
// Users instance is used to make requests against Selectel IAM API and manage Panel Users.
4949
Users *users.Users
5050

51-
// ServiceUsers instance is used to make requests against Selectel IAM API and manage service users.
51+
// ServiceUsers instance is used to make requests against Selectel IAM API and manage Service Users.
5252
ServiceUsers *serviceusers.ServiceUsers
5353

54-
// EC2 instance is used to make requests against Selectel IAM API and manage EC2 credentials.
55-
EC2 *ec2.EC2
54+
// S3Credentials instance is used to make requests against Selectel IAM API and manage S3 Credentials.
55+
S3Credentials *s3credentials.S3Credentials
5656
}
5757

5858
type AuthOpts struct {
@@ -122,7 +122,7 @@ func New(opts ...Option) (*Client, error) {
122122

123123
c.Users = users.New(c.baseClient)
124124
c.ServiceUsers = serviceusers.New(c.baseClient)
125-
c.EC2 = ec2.New(c.baseClient)
125+
c.S3Credentials = s3credentials.New(c.baseClient)
126126

127127
return c, nil
128128
}

iam_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/selectel/iam-go/iamerrors"
1212
baseclient "github.com/selectel/iam-go/internal/client"
13-
"github.com/selectel/iam-go/service/ec2"
13+
"github.com/selectel/iam-go/service/s3credentials"
1414
"github.com/selectel/iam-go/service/serviceusers"
1515
"github.com/selectel/iam-go/service/users"
1616
)
@@ -56,10 +56,10 @@ func TestNew(t *testing.T) {
5656
authOpts: &AuthOpts{
5757
KeystoneToken: testToken,
5858
},
59-
baseClient: baseClient,
60-
Users: users.New(baseClient),
61-
ServiceUsers: serviceusers.New(baseClient),
62-
EC2: ec2.New(baseClient),
59+
baseClient: baseClient,
60+
Users: users.New(baseClient),
61+
ServiceUsers: serviceusers.New(baseClient),
62+
S3Credentials: s3credentials.New(baseClient),
6363
}
6464
},
6565
expectedError: nil,
@@ -97,10 +97,10 @@ func TestNew(t *testing.T) {
9797
authOpts: &AuthOpts{
9898
KeystoneToken: testToken,
9999
},
100-
baseClient: baseClient,
101-
Users: users.New(baseClient),
102-
ServiceUsers: serviceusers.New(baseClient),
103-
EC2: ec2.New(baseClient),
100+
baseClient: baseClient,
101+
Users: users.New(baseClient),
102+
ServiceUsers: serviceusers.New(baseClient),
103+
S3Credentials: s3credentials.New(baseClient),
104104
}
105105
},
106106
expectedError: nil,
@@ -131,10 +131,10 @@ func TestNew(t *testing.T) {
131131
authOpts: &AuthOpts{
132132
KeystoneToken: testToken,
133133
},
134-
baseClient: baseClient,
135-
Users: users.New(baseClient),
136-
ServiceUsers: serviceusers.New(baseClient),
137-
EC2: ec2.New(baseClient),
134+
baseClient: baseClient,
135+
Users: users.New(baseClient),
136+
ServiceUsers: serviceusers.New(baseClient),
137+
S3Credentials: s3credentials.New(baseClient),
138138
}
139139
},
140140
expectedError: nil,

service/ec2/doc.go

Lines changed: 0 additions & 2 deletions
This file was deleted.

service/s3credentials/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package s3credentials provides a set of functions for interacting with the Selectel S3 Credentials API.
2+
package s3credentials
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ec2
1+
package s3credentials
22

33
import (
44
"bytes"
@@ -13,20 +13,20 @@ import (
1313

1414
const apiVersion = "iam/v1"
1515

16-
// EC2 is used to communicate with the EC2 Credentials API.
17-
type EC2 struct {
16+
// S3Credentials is used to communicate with the S3 Credentials API.
17+
type S3Credentials struct {
1818
baseClient *client.BaseClient
1919
}
2020

21-
// Initialises EC2 instance with the given client.
22-
func New(baseClient *client.BaseClient) *EC2 {
23-
return &EC2{
21+
// Initialises S3Credentials instance with the given client.
22+
func New(baseClient *client.BaseClient) *S3Credentials {
23+
return &S3Credentials{
2424
baseClient: baseClient,
2525
}
2626
}
2727

28-
// List returns a list of EC2 credentials for the given user.
29-
func (ec2 *EC2) List(ctx context.Context, userID string) ([]Credential, error) {
28+
// List returns a list of S3 Credentials for the given user.
29+
func (s3 *S3Credentials) List(ctx context.Context, userID string) ([]Credentials, error) {
3030
if userID == "" {
3131
return nil, iamerrors.Error{Err: iamerrors.ErrUserIDRequired, Desc: "No userID was provided."}
3232
}
@@ -36,7 +36,7 @@ func (ec2 *EC2) List(ctx context.Context, userID string) ([]Credential, error) {
3636
return nil, iamerrors.Error{Err: iamerrors.ErrInternalAppError, Desc: err.Error()}
3737
}
3838

39-
response, err := ec2.baseClient.DoRequest(ctx, client.DoRequestInput{
39+
response, err := s3.baseClient.DoRequest(ctx, client.DoRequestInput{
4040
Body: nil,
4141
Method: http.MethodGet,
4242
Path: path,
@@ -54,13 +54,13 @@ func (ec2 *EC2) List(ctx context.Context, userID string) ([]Credential, error) {
5454
return credentials.Credentials, nil
5555
}
5656

57-
// Create creates a new EC2 credential for the given user.
58-
func (ec2 *EC2) Create(ctx context.Context, userID, name, projectID string) (*CreatedCredential, error) {
57+
// Create creates a new S3 Credentials for the given user.
58+
func (s3 *S3Credentials) Create(ctx context.Context, userID, name, projectID string) (*CreatedCredentials, error) {
5959
if userID == "" {
6060
return nil, iamerrors.Error{Err: iamerrors.ErrUserIDRequired, Desc: "No userID was provided."}
6161
}
6262
if name == "" {
63-
return nil, iamerrors.Error{Err: iamerrors.ErrCredentialNameRequired, Desc: "No credential name was provided."}
63+
return nil, iamerrors.Error{Err: iamerrors.ErrCredentialNameRequired, Desc: "No credentials name was provided."}
6464
}
6565
if projectID == "" {
6666
return nil, iamerrors.Error{Err: iamerrors.ErrProjectIDRequired, Desc: "No projectID was provided."}
@@ -76,7 +76,7 @@ func (ec2 *EC2) Create(ctx context.Context, userID, name, projectID string) (*Cr
7676
return nil, iamerrors.Error{Err: iamerrors.ErrInternalAppError, Desc: err.Error()}
7777
}
7878

79-
response, err := ec2.baseClient.DoRequest(ctx, client.DoRequestInput{
79+
response, err := s3.baseClient.DoRequest(ctx, client.DoRequestInput{
8080
Body: bytes.NewReader(body),
8181
Method: http.MethodPost,
8282
Path: path,
@@ -86,16 +86,16 @@ func (ec2 *EC2) Create(ctx context.Context, userID, name, projectID string) (*Cr
8686
return nil, err
8787
}
8888

89-
var createdCredential CreatedCredential
89+
var createdCredential CreatedCredentials
9090
err = client.UnmarshalJSON(response, &createdCredential)
9191
if err != nil {
9292
return nil, iamerrors.Error{Err: iamerrors.ErrInternalAppError, Desc: err.Error()}
9393
}
9494
return &createdCredential, nil
9595
}
9696

97-
// Delete deletes an EC2 credential for the given user.
98-
func (ec2 *EC2) Delete(ctx context.Context, userID, accessKey string) error {
97+
// Delete deletes an S3 Credentials for the given user.
98+
func (s3 *S3Credentials) Delete(ctx context.Context, userID, accessKey string) error {
9999
if userID == "" {
100100
return iamerrors.Error{Err: iamerrors.ErrUserIDRequired, Desc: "No userID was provided."}
101101
}
@@ -107,7 +107,7 @@ func (ec2 *EC2) Delete(ctx context.Context, userID, accessKey string) error {
107107
if err != nil {
108108
return iamerrors.Error{Err: iamerrors.ErrInternalAppError, Desc: err.Error()}
109109
}
110-
_, err = ec2.baseClient.DoRequest(ctx, client.DoRequestInput{
110+
_, err = s3.baseClient.DoRequest(ctx, client.DoRequestInput{
111111
Body: nil,
112112
Method: http.MethodDelete,
113113
Path: path,

0 commit comments

Comments
 (0)