diff --git a/hive/gateway/ec2.go b/hive/gateway/ec2.go index 396685b7d..af9d06e7b 100644 --- a/hive/gateway/ec2.go +++ b/hive/gateway/ec2.go @@ -10,6 +10,7 @@ import ( gateway_ec2_image "github.com/mulgadc/hive/hive/gateway/ec2/image" gateway_ec2_instance "github.com/mulgadc/hive/hive/gateway/ec2/instance" gateway_ec2_key "github.com/mulgadc/hive/hive/gateway/ec2/key" + gateway_ec2_regions "github.com/mulgadc/hive/hive/gateway/ec2/regions" "github.com/mulgadc/hive/hive/utils" ) @@ -276,6 +277,27 @@ func (gw *GatewayConfig) EC2_Request(ctx *fiber.Ctx) error { payload := utils.GenerateXMLPayload("DescribeImagesResponse", output) xmlOutput, err = utils.MarshalToXML(payload) + if err != nil { + return errors.New("failed to marshal response to XML") + } + case "DescribeRegions": + var input = &ec2.DescribeRegionsInput{} + err = awsec2query.QueryParamsToStruct(queryArgs, input) + + if err != nil { + return err + } + + output, err := gateway_ec2_regions.DescribeRegions(input, gw.Region) + + if err != nil { + return err + } + + // Convert to XML + payload := utils.GenerateXMLPayload("DescribeRegionsResponse", output) + xmlOutput, err = utils.MarshalToXML(payload) + if err != nil { return errors.New("failed to marshal response to XML") } diff --git a/hive/gateway/ec2/regions/DescribeRegions.go b/hive/gateway/ec2/regions/DescribeRegions.go new file mode 100644 index 000000000..7c6f05d2b --- /dev/null +++ b/hive/gateway/ec2/regions/DescribeRegions.go @@ -0,0 +1,19 @@ +package gateway_ec2_regions + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ec2" +) + +// uses the loaded config file to get the region. +func DescribeRegions(input *ec2.DescribeRegionsInput, region string) (output *ec2.DescribeRegionsOutput, err error) { + + output = &ec2.DescribeRegionsOutput{ + Regions: []*ec2.Region{ + { + RegionName: aws.String(region), + }, + }} + + return output, nil +} diff --git a/hive/gateway/gateway.go b/hive/gateway/gateway.go index abddad90c..2788d81a8 100644 --- a/hive/gateway/gateway.go +++ b/hive/gateway/gateway.go @@ -23,6 +23,7 @@ type GatewayConfig struct { NATSConn *nats.Conn // Shared NATS connection for service communication Config string // Shared AWS Gateway config for S3 auth ExpectedNodes int // Number of expected hive nodes for multi-node operations + Region string // Region this gateway is running in } var supportedServices = map[string]bool{ diff --git a/hive/services/awsgw/awsgw.go b/hive/services/awsgw/awsgw.go index 222844784..957620663 100644 --- a/hive/services/awsgw/awsgw.go +++ b/hive/services/awsgw/awsgw.go @@ -91,6 +91,7 @@ func launchService(config *config.ClusterConfig) (err error) { DisableLogging: false, NATSConn: natsConn, Config: nodeConfig.AWSGW.Config, + Region: nodeConfig.Region, } app := gw.SetupRoutes()