Skip to content

Commit

Permalink
Rename feature/dsql/token to feature/dsql/auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Madrigal committed Dec 10, 2024
1 parent 11fd9ee commit 6b18784
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package token
package auth

import (
"context"
Expand All @@ -17,12 +17,12 @@ import (
const (
vendorCode = "dsql"
emptyPayloadHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
userAction = "DbConnect"
adminUserAction = "DbConnectAdmin"
userAction = "DbConnect"
adminUserAction = "DbConnectAdmin"
)

// AuthTokenOptions is the optional set of configuration properties for AuthToken
type AuthTokenOptions struct {
// TokenOptions is the optional set of configuration properties for AuthToken
type TokenOptions struct {
ExpiresIn time.Duration
}

Expand All @@ -33,7 +33,7 @@ type AuthTokenOptions struct {
// * endpoint - Endpoint is the hostname to connect to the database
// * region - Region is where the database is located
// * creds - Credentials to use when signing the token
func GenerateDbConnectAuthToken(ctx context.Context, endpoint, region string, creds aws.CredentialsProvider, optFns ...func(options *AuthTokenOptions)) (string, error) {
func GenerateDbConnectAuthToken(ctx context.Context, endpoint, region string, creds aws.CredentialsProvider, optFns ...func(options *TokenOptions)) (string, error) {
values := url.Values{
"Action": []string{userAction},
}
Expand All @@ -47,7 +47,7 @@ func GenerateDbConnectAuthToken(ctx context.Context, endpoint, region string, cr
// * endpoint - Endpoint is the hostname to connect to the database
// * region - Region is where the database is located
// * creds - Credentials to use when signing the token
func GenerateDBConnectAdminAuthToken(ctx context.Context, endpoint, region string, creds aws.CredentialsProvider, optFns ...func(options *AuthTokenOptions)) (string, error) {
func GenerateDBConnectAdminAuthToken(ctx context.Context, endpoint, region string, creds aws.CredentialsProvider, optFns ...func(options *TokenOptions)) (string, error) {
values := url.Values{
"Action": []string{adminUserAction},
}
Expand All @@ -56,15 +56,15 @@ func GenerateDBConnectAdminAuthToken(ctx context.Context, endpoint, region strin

// All generate token functions are presigned URLs behind the scenes with the scheme stripped.
// This function abstracts generating this for all use cases
func generateAuthToken(ctx context.Context, endpoint, region string, values url.Values, signingID string, creds aws.CredentialsProvider, optFns ...func(options *AuthTokenOptions)) (string, error) {
func generateAuthToken(ctx context.Context, endpoint, region string, values url.Values, signingID string, creds aws.CredentialsProvider, optFns ...func(options *TokenOptions)) (string, error) {
if len(region) == 0 {
return "", fmt.Errorf("region is required")
}
if len(endpoint) == 0 {
return "", fmt.Errorf("endpoint is required")
}

o := AuthTokenOptions{}
o := TokenOptions{}

for _, fn := range optFns {
fn(&o)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package token
package auth

import (
"context"
Expand All @@ -21,7 +21,7 @@ type dbTokenTestCase struct {
expectedError string
}

type tokenGenFunc func(ctx context.Context, endpoint, region string, creds aws.CredentialsProvider, optFns ...func(options *AuthTokenOptions)) (string, error)
type tokenGenFunc func(ctx context.Context, endpoint, region string, creds aws.CredentialsProvider, optFns ...func(options *TokenOptions)) (string, error)

func TestGenerateDbConnectAuthToken(t *testing.T) {
cases := map[string]dbTokenTestCase{
Expand Down Expand Up @@ -81,9 +81,9 @@ func TestGenerateDbConnectAuthToken(t *testing.T) {
for _, c := range cases {
creds := &staticCredentials{AccessKey: "akid", SecretKey: "secret", expiresIn: c.credsExpireIn}
defer withTempGlobalTime(time.Date(2024, time.August, 27, 0, 0, 0, 0, time.UTC))()
optFns := func(options *AuthTokenOptions) {}
optFns := func(options *TokenOptions) {}
if c.expires != 0 {
optFns = func(options *AuthTokenOptions) {
optFns = func(options *TokenOptions) {
options.ExpiresIn = c.expires
}
}
Expand All @@ -103,7 +103,7 @@ func TestGenerateDbConnectAuthToken(t *testing.T) {
}
}

func verifyTestCase(f tokenGenFunc, c dbTokenTestCase, creds aws.CredentialsProvider, optFns func(options *AuthTokenOptions), t *testing.T) {
func verifyTestCase(f tokenGenFunc, c dbTokenTestCase, creds aws.CredentialsProvider, optFns func(options *TokenOptions), t *testing.T) {
token, err := f(context.Background(), c.endpoint, c.region, creds, optFns)
isErrorExpected := len(c.expectedError) > 0
if err != nil && !isErrorExpected {
Expand Down
4 changes: 2 additions & 2 deletions feature/dsql/token/doc.go → feature/dsql/auth/doc.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Package token is used to generate authentication tokens for Amazon Aurora DSQL.
// Package auth is used to generate authentication tokens for Amazon Aurora DSQL.
//
// These tokens use IAM policies to generate a token that will be used to connect
// to a database.
//
// You can see more details about it at the [official docs]
//
// [official docs]: https://docs.aws.amazon.com/aurora-dsql/latest/userguide/SECTION_authentication-token.html
package token
package auth
2 changes: 1 addition & 1 deletion feature/dsql/token/go.mod → feature/dsql/auth/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/aws/aws-sdk-go-v2/feature/dsql/token
module github.com/aws/aws-sdk-go-v2/feature/dsql/auth

go 1.21

Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b18784

Please sign in to comment.