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
4 changes: 2 additions & 2 deletions lib/cloud/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,10 @@ func (c *cloudClients) getAWSSessionForRegion(region string) (*awssession.Sessio

// getAWSSessionForRole returns AWS session for the specified region and role.
func (c *cloudClients) getAWSSessionForRole(ctx context.Context, region string, options awsAssumeRoleOpts) (*awssession.Session, error) {
assumeRoler := sts.New(options.baseSession)
cacheKey := fmt.Sprintf("Region[%s]:RoleARN[%s]:ExternalID[%s]", region, options.assumeRoleARN, options.assumeRoleExternalID)
return utils.FnCacheGet(ctx, c.awsSessionsCache, cacheKey, func(ctx context.Context) (*awssession.Session, error) {
return newSessionWithRole(ctx, assumeRoler, region, options.assumeRoleARN, options.assumeRoleExternalID)
stsClient := sts.New(options.baseSession)
return newSessionWithRole(ctx, stsClient, region, options.assumeRoleARN, options.assumeRoleExternalID)
})
}

Expand Down
49 changes: 28 additions & 21 deletions lib/integrations/awsoidc/listdatabases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/aws/aws-sdk-go-v2/service/rds"
rdsTypes "github.com/aws/aws-sdk-go-v2/service/rds/types"
"github.com/google/go-cmp/cmp"
"github.com/gravitational/trace"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -187,12 +188,14 @@ func TestListDatabases(t *testing.T) {
Name: "my-db",
Description: "RDS instance in ",
Labels: map[string]string{
"account-id": "123456789012",
"endpoint-type": "instance",
"engine": "postgres",
"engine-version": "",
"region": "",
"status": "available",
"account-id": "123456789012",
"endpoint-type": "instance",
"engine": "postgres",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
"teleport.dev/origin": "cloud",
},
},
types.DatabaseSpecV3{
Expand All @@ -208,7 +211,7 @@ func TestListDatabases(t *testing.T) {
},
)
require.NoError(t, err)
require.Equal(t, expectedDB, ldr.Databases[0])
require.Empty(t, cmp.Diff(expectedDB, ldr.Databases[0]))
},
errCheck: noErrorFunc,
},
Expand Down Expand Up @@ -250,12 +253,14 @@ func TestListDatabases(t *testing.T) {
Name: "my-db",
Description: "RDS instance in ",
Labels: map[string]string{
"account-id": "123456789012",
"endpoint-type": "instance",
"engine": "postgres",
"engine-version": "",
"region": "",
"status": "available",
"account-id": "123456789012",
"endpoint-type": "instance",
"engine": "postgres",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
"teleport.dev/origin": "cloud",
},
},
types.DatabaseSpecV3{
Expand All @@ -271,7 +276,7 @@ func TestListDatabases(t *testing.T) {
},
)
require.NoError(t, err)
require.Equal(t, expectedDB, ldr.Databases[0])
require.Empty(t, cmp.Diff(expectedDB, ldr.Databases[0]))
},
errCheck: noErrorFunc,
},
Expand Down Expand Up @@ -300,12 +305,14 @@ func TestListDatabases(t *testing.T) {
Name: "my-dbc",
Description: "Aurora cluster in ",
Labels: map[string]string{
"account-id": "123456789012",
"endpoint-type": "primary",
"engine": "aurora-postgresql",
"engine-version": "",
"region": "",
"status": "available",
"account-id": "123456789012",
"endpoint-type": "primary",
"engine": "aurora-postgresql",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
"teleport.dev/origin": "cloud",
},
},
types.DatabaseSpecV3{
Expand All @@ -322,7 +329,7 @@ func TestListDatabases(t *testing.T) {
},
)
require.NoError(t, err)
require.Equal(t, expectedDB, ldr.Databases[0])
require.Empty(t, cmp.Diff(expectedDB, ldr.Databases[0]))
},
errCheck: noErrorFunc,
},
Expand Down
4 changes: 2 additions & 2 deletions lib/services/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,8 @@ func newElastiCacheDatabase(cluster *elasticache.ReplicationGroup, endpoint *ela
})
}

// NewDatabaseFromOpenSearchDomain creates a database resource from an OpenSearch domain.
func NewDatabaseFromOpenSearchDomain(domain *opensearchservice.DomainStatus, tags []*opensearchservice.Tag) (types.Databases, error) {
// NewDatabasesFromOpenSearchDomain creates database resources from an OpenSearch domain.
func NewDatabasesFromOpenSearchDomain(domain *opensearchservice.DomainStatus, tags []*opensearchservice.Tag) (types.Databases, error) {
var databases types.Databases

if aws.StringValue(domain.Endpoint) != "" {
Expand Down
3 changes: 3 additions & 0 deletions lib/srv/db/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/gravitational/teleport/lib/cloud/mocks"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/services"
discovery "github.com/gravitational/teleport/lib/srv/discovery/common"
)

// TestWatcher verifies that database server properly detects and applies
Expand Down Expand Up @@ -263,6 +264,7 @@ func TestWatcherCloudFetchers(t *testing.T) {
redshiftServerlessDatabase.SetStatusAWS(redshiftServerlessDatabase.GetAWS())
setDiscoveryGroupLabel(redshiftServerlessDatabase, "")
redshiftServerlessDatabase.SetOrigin(types.OriginCloud)
discovery.ApplyAWSDatabaseNameSuffix(redshiftServerlessDatabase, services.AWSMatcherRedshiftServerless)
// Test an Azure fetcher.
azSQLServer, azSQLServerDatabase := makeAzureSQLServer(t, "discovery-azure", "group")
setDiscoveryGroupLabel(azSQLServerDatabase, "")
Expand Down Expand Up @@ -375,5 +377,6 @@ func makeAzureSQLServer(t *testing.T, name, group string) (*armsql.Server, types
}
database, err := services.NewDatabaseFromAzureSQLServer(server)
require.NoError(t, err)
discovery.ApplyAzureDatabaseNameSuffix(database, services.AzureMatcherSQLServer)
Comment thread
GavinFrazar marked this conversation as resolved.
return server, database
}
Loading