Skip to content

Commit

Permalink
move aws region selector to shared and add types and endpoints (#31179)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudream authored Sep 18, 2023
1 parent 678274a commit eb25bf9
Show file tree
Hide file tree
Showing 17 changed files with 449 additions and 64 deletions.
14 changes: 7 additions & 7 deletions lib/integrations/awsoidc/list_ec2ice.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@ func (req *ListEC2ICERequest) CheckAndSetDefaults() error {
// EC2InstanceConnectEndpoint is the Teleport representation of an EC2 Instance Connect Endpoint
type EC2InstanceConnectEndpoint struct {
// Name is the endpoint name.
Name string
Name string `json:"name,omitempty"`

// State is the endpoint state.
// Known values:
// create-in-progress | create-complete | create-failed | delete-in-progress | delete-complete | delete-failed
State string
State string `json:"state,omitempty"`

// StateMessage contains a message describing the state of the EICE.
// Can be empty.
StateMessage string
StateMessage string `json:"stateMessage,omitempty"`

// DashboardLink is a URL to AWS Console where the user can see the EC2 Instance Connect Endpoint.
DashboardLink string
DashboardLink string `json:"dashboardLink,omitempty"`

// SubnetID is the subnet used by the endpoint.
// Please note that the Endpoint should be able to reach any subnet within the VPC.
SubnetID string
SubnetID string `json:"subnetId,omitempty"`
}

// ListEC2ICEResponse contains a page of AWS EC2 Instances as Teleport Servers.
type ListEC2ICEResponse struct {
// EC2ICEs contains the page of EC2 Instance Connect Endpoint.
EC2ICEs []EC2InstanceConnectEndpoint
EC2ICEs []EC2InstanceConnectEndpoint `json:"ec2InstanceConnectEndpoints,omitempty"`

// NextToken is used for pagination.
// If non-empty, it can be used to request the next page.
NextToken string
NextToken string `json:"nextToken,omitempty"`
}

// ListEC2ICEClient describes the required methods to List EC2 Instances using a 3rd Party API.
Expand Down
26 changes: 13 additions & 13 deletions lib/integrations/awsoidc/list_security_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ func (req *ListSecurityGroupsRequest) CheckAndSetDefaults() error {
type SecurityGroup struct {
// Name is the Security Group name.
// This is just a friendly name and should not be used for further API calls
Name string
Name string `json:"name"`

// ID is the security group ID.
// This is the value that should be used when doing further API calls.
ID string
ID string `json:"id"`

// Description is a small description of the Security Group.
// Might be empty.
Description string
Description string `json:"description"`

// InboundRules describe the Security Group Inbound Rules.
// The CIDR of each rule represents the source IP that the rule applies to.
InboundRules []SecurityGroupRule
InboundRules []SecurityGroupRule `json:"inboundRules"`

// OutboundRules describe the Security Group Outbound Rules.
// The CIDR of each rule represents the destination IP that the rule applies to.
OutboundRules []SecurityGroupRule
OutboundRules []SecurityGroupRule `json:"outboundRules"`
}

// SecurityGroupRule is a SecurityGroup role.
Expand All @@ -79,34 +79,34 @@ type SecurityGroupRule struct {
// If the rule applies to all protocols, the "all" value is used.
// The IP protocol name ( tcp , udp , icmp , icmpv6 ) or number (see Protocol
// Numbers (http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)).
IPProtocol string
IPProtocol string `json:"ipProtocol"`

// FromPort is the inclusive start of the Port range for the Rule.
FromPort int
FromPort int `json:"fromPort"`

// ToPort is the inclusive end of the Port range for the Rule.
ToPort int
ToPort int `json:"toPort"`

// CIDRs contains a list of IP ranges that this rule applies to and a description for the value.
CIDRs []CIDR
CIDRs []CIDR `json:"cidrs"`
}

// CIDR has a CIDR (IP Range) and a description for the value.
type CIDR struct {
// CIDR is the IP range using CIDR notation.
CIDR string
CIDR string `json:"cidr"`
// Description contains a small text describing the CIDR.
Description string
Description string `json:"description"`
}

// ListSecurityGroupsResponse contains a page of SecurityGroups.
type ListSecurityGroupsResponse struct {
// SecurityGroups contains the page of VPC Security Groups.
SecurityGroups []SecurityGroup
SecurityGroups []SecurityGroup `json:"securityGroups"`

// NextToken is used for pagination.
// If non-empty, it can be used to request the next page.
NextToken string
NextToken string `json:"nextToken"`
}

// ListSecurityGroupsClient describes the required methods to List Security Groups a 3rd Party API.
Expand Down
2 changes: 1 addition & 1 deletion lib/web/integrations_awsoidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (h *Handler) awsOIDCListEC2(w http.ResponseWriter, r *http.Request, p httpr
}, nil
}

// awsOIDCListSecurityGroups returns a list of VPC Security Groups the ListSecurityGroups action of the AWS OIDC Integration.
// awsOIDCListSecurityGroups returns a list of VPC Security Groups using the ListSecurityGroups action of the AWS OIDC Integration.
func (h *Handler) awsOIDCListSecurityGroups(w http.ResponseWriter, r *http.Request, p httprouter.Params, sctx *SessionContext, site reversetunnelclient.RemoteSite) (any, error) {
ctx := r.Context()

Expand Down
12 changes: 11 additions & 1 deletion lib/web/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,15 @@ func (h *Handler) handleNodeCreate(w http.ResponseWriter, r *http.Request, p htt
return nil, trace.Wrap(err)
}

return server, nil
accessChecker, err := sctx.GetUserAccessChecker()
if err != nil {
return nil, trace.Wrap(err)
}

uiServer, err := ui.MakeServer(site.GetName(), server, accessChecker)
if err != nil {
return nil, trace.Wrap(err)
}

return uiServer, nil
}
6 changes: 3 additions & 3 deletions lib/web/ui/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ type AWSOIDCDeployEC2ICERequest struct {
// Region is the AWS Region.
Region string `json:"region"`
// SubnetID is the subnet id for the EC2 Instance Connect Endpoint.
SubnetID string `json:"subnetID"`
SubnetID string `json:"subnetId"`
// SecurityGroupIDs is the list of SecurityGroups to apply to the Endpoint.
// If not specified, the Endpoint will receive the default SG for the Subnet's VPC.
SecurityGroupIDs []string `json:"securityGroupIds"`
}

// AWSOIDCDeployEC2ICEResponse contains a list of AWS Instance Connect Endpoints and a next token if more pages are available.
// AWSOIDCDeployEC2ICEResponse is the response after creating an AWS EC2 Instance Connect Endpoint.
type AWSOIDCDeployEC2ICEResponse struct {
// Name is the endpoint Name that was created.
// Name is the name of the endpoint that was created.
Name string `json:"name"`
}
24 changes: 23 additions & 1 deletion lib/web/ui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ type Server struct {
// SSHLogins is the list of logins this user can use on this server
SSHLogins []string `json:"sshLogins"`
// AWS contains metadata for instances hosted in AWS.
AWS *types.AWSInfo `json:"aws,omitempty"`
AWS *AWSMetadata `json:"aws,omitempty"`
}

// AWSMetadata describes the AWS metadata for instances hosted in AWS.
// This type is the same as types.AWSInfo but has json fields in camelCase form for the WebUI.
type AWSMetadata struct {
AccountID string `json:"accountId"`
InstanceID string `json:"instanceId"`
Region string `json:"region"`
VPCID string `json:"vpcId"`
Integration string `json:"integration"`
SubnetID string `json:"subnetId"`
}

// sortedLabels is a sort wrapper that sorts labels by name
Expand Down Expand Up @@ -98,6 +109,17 @@ func MakeServer(clusterName string, server types.Server, accessChecker services.
SSHLogins: serverLogins,
}

if server.GetSubKind() == types.SubKindOpenSSHEICENode {
awsMetadata := server.GetAWSInfo()
uiServer.AWS = &AWSMetadata{
AccountID: awsMetadata.AccountID,
InstanceID: awsMetadata.InstanceID,
Region: awsMetadata.Region,
Integration: awsMetadata.Integration,
SubnetID: awsMetadata.SubnetID,
}
}

return uiServer, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,13 @@

import React from 'react';

import { AwsRegionSelector } from './AwsRegionSelector';
import { DatabaseList } from './RdsDatabaseList';
import { CheckedAwsRdsDatabase } from './EnrollRdsDatabase';

export default {
title: 'Teleport/Discover/Database/EnrollRds',
};

export const AwsRegionsSelectorDisabled = () => (
<AwsRegionSelector
onFetch={() => null}
onRefresh={() => null}
disableSelector={true}
clear={() => null}
/>
);

export const AwsRegionsSelectorEnabled = () => (
<AwsRegionSelector
onFetch={() => null}
onRefresh={() => null}
disableSelector={false}
clear={() => null}
/>
);

export const AwsRegionsSelectorRefreshEnabled = () => (
<AwsRegionSelector
onFetch={() => null}
onRefresh={() => null}
disableSelector={false}
clear={() => null}
/>
);

export const RdsDatabaseList = () => (
<DatabaseList
items={fixtures}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import React, { useState } from 'react';
import { Box } from 'design';
import { Box, Text } from 'design';
import { FetchStatus } from 'design/DataTable/types';
import { Danger } from 'design/Alert';

Expand All @@ -30,14 +30,14 @@ import {
integrationService,
} from 'teleport/services/integrations';
import { DatabaseEngine } from 'teleport/Discover/SelectResource';
import { AwsRegionSelector } from 'teleport/Discover/Shared/AwsRegionSelector';
import { Database } from 'teleport/services/databases';

import { ActionButtons, Header } from '../../Shared';

import { useCreateDatabase } from '../CreateDatabase/useCreateDatabase';
import { CreateDatabaseDialog } from '../CreateDatabase/CreateDatabaseDialog';

import { AwsRegionSelector } from './AwsRegionSelector';
import { DatabaseList } from './RdsDatabaseList';

type TableData = {
Expand Down Expand Up @@ -205,6 +205,9 @@ export function EnrollRdsDatabase() {
{fetchDbAttempt.status === 'failed' && (
<Danger mt={3}>{fetchDbAttempt.statusText}</Danger>
)}
<Text mt={4}>
Select the AWS Region you would like to see databases for:
</Text>
<AwsRegionSelector
onFetch={fetchDatabasesWithNewRegion}
onRefresh={refreshDatabaseList}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2023 Gravitational, Inc.
*
* 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.
*/

import React from 'react';
import { Text } from 'design';

import { AwsRegionSelector } from './AwsRegionSelector';

export default {
title: 'Teleport/Discover/Shared/AwsRegionSelector',
};

export const Disabled = () => (
<>
<Text mt={4}>
Select the AWS Region you would like to see resources for:
</Text>
<AwsRegionSelector
onFetch={() => null}
onRefresh={() => null}
disableSelector={true}
clear={() => null}
/>
</>
);

export const Enabled = () => (
<>
<Text mt={4}>
Select the AWS Region you would like to see resources for:
</Text>
<AwsRegionSelector
onFetch={() => null}
onRefresh={() => null}
disableSelector={false}
clear={() => null}
/>
</>
);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import React, { useState } from 'react';
import { Box, Text, Flex, ButtonSecondary, LabelInput } from 'design';
import { Box, Flex, ButtonSecondary, LabelInput } from 'design';
import Select, { Option } from 'shared/components/Select';
import { Refresh as RefreshIcon } from 'design/Icon';

Expand All @@ -42,9 +42,6 @@ export function AwsRegionSelector({

return (
<Box>
<Text mt={4}>
Select the AWS Region you would like to see databases for:
</Text>
<Flex alignItems="center" gap={3} mt={2} mb={3}>
<Box width="320px" mb={4}>
<LabelInput htmlFor={'select'}>AWS Region</LabelInput>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright 2023 Gravitational, Inc.
*
* 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.
*/

export { AwsRegionSelector } from './AwsRegionSelector';
Loading

0 comments on commit eb25bf9

Please sign in to comment.