mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-08 05:50:47 +00:00
Conver to regular Go vendor + dep tool
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
Custom Endpoint Example
|
||||
===
|
||||
|
||||
This example provides examples on how you can provide custom endpoints, and logic to how endpoints are resolved by the SDK.
|
||||
|
||||
The example creates multiple clients with different endpoint configuraiton. From a custom endpoint resolver that wraps the defeault resolver so that any S3 service client created uses the custom endpoint, to how you can provide your own logic to a single service's endpoint resolving.
|
||||
Generated
Vendored
+77
@@ -0,0 +1,77 @@
|
||||
// +build example
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/endpoints"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/dynamodb"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/aws/aws-sdk-go/service/sqs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defaultResolver := endpoints.DefaultResolver()
|
||||
s3CustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
|
||||
if service == "s3" {
|
||||
return endpoints.ResolvedEndpoint{
|
||||
URL: "s3.custom.endpoint.com",
|
||||
SigningRegion: "custom-signing-region",
|
||||
}, nil
|
||||
}
|
||||
|
||||
return defaultResolver.EndpointFor(service, region, optFns...)
|
||||
}
|
||||
sess := session.Must(session.NewSessionWithOptions(session.Options{
|
||||
Config: aws.Config{
|
||||
Region: aws.String("us-west-2"),
|
||||
EndpointResolver: endpoints.ResolverFunc(s3CustResolverFn),
|
||||
},
|
||||
}))
|
||||
|
||||
// Create the S3 service client with the shared session. This will
|
||||
// automatically use the S3 custom endpoint configured in the custom
|
||||
// endpoint resolver wrapping the default endpoint resolver.
|
||||
s3Svc := s3.New(sess)
|
||||
// Operation calls will be made to the custom endpoint.
|
||||
s3Svc.GetObject(&s3.GetObjectInput{
|
||||
Bucket: aws.String("myBucket"),
|
||||
Key: aws.String("myObjectKey"),
|
||||
})
|
||||
|
||||
// Create the SQS service client with the shared session. This will
|
||||
// fallback to the default endpoint resolver because the customization
|
||||
// passes any non S3 service endpoint resolve to the default resolver.
|
||||
sqsSvc := sqs.New(sess)
|
||||
// Operation calls will be made to the default endpoint for SQS for the
|
||||
// region configured.
|
||||
sqsSvc.ReceiveMessage(&sqs.ReceiveMessageInput{
|
||||
QueueUrl: aws.String("my-queue-url"),
|
||||
})
|
||||
|
||||
// Create a DynamoDB service client that will use a custom endpoint
|
||||
// resolver that overrides the shared session's. This is useful when
|
||||
// custom endpoints are generated, or multiple endpoints are switched on
|
||||
// by a region value.
|
||||
ddbCustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
|
||||
return endpoints.ResolvedEndpoint{
|
||||
URL: "dynamodb.custom.endpoint",
|
||||
SigningRegion: "custom-signing-region",
|
||||
}, nil
|
||||
}
|
||||
ddbSvc := dynamodb.New(sess, &aws.Config{
|
||||
EndpointResolver: endpoints.ResolverFunc(ddbCustResolverFn),
|
||||
})
|
||||
// Operation calls will be made to the custom endpoint set in the
|
||||
// ddCustResolverFn.
|
||||
ddbSvc.ListTables(&dynamodb.ListTablesInput{})
|
||||
|
||||
// Setting Config's Endpoint will override the EndpointResolver. Forcing
|
||||
// the service clien to make all operation to the endpoint specified
|
||||
// the in the config.
|
||||
ddbSvcLocal := dynamodb.New(sess, &aws.Config{
|
||||
Endpoint: aws.String("http://localhost:8088"),
|
||||
})
|
||||
ddbSvcLocal.ListTables(&dynamodb.ListTablesInput{})
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
Enumerate Regions and Endpoints Example
|
||||
===
|
||||
|
||||
Demostrates how the SDK's endpoints can be enumerated over to discover regions, services, and endpoints defined by the SDK's Regions and Endpoints metadata.
|
||||
|
||||
Usage
|
||||
---
|
||||
|
||||
The following parameters can be used to enumerate the SDK's partition metadata.
|
||||
|
||||
Example:
|
||||
|
||||
go run enumEndpoints.go -p aws -services -r us-west-2
|
||||
|
||||
Output:
|
||||
|
||||
Services with endpoint us-west-2 in aws:
|
||||
ec2
|
||||
dynamodb
|
||||
s3
|
||||
...
|
||||
|
||||
CLI parameters
|
||||
---
|
||||
|
||||
```
|
||||
-p=id partition id, e.g: aws
|
||||
-r=id region id, e.g: us-west-2
|
||||
-s=id service id, e.g: s3
|
||||
|
||||
-partitions Lists all partitions.
|
||||
-regions Lists all regions in a partition. Requires partition ID.
|
||||
If service ID is also provided will show endpoints for a service.
|
||||
-services Lists all services in a partition. Requires partition ID.
|
||||
If region ID is also provided, will show services available in that region.
|
||||
```
|
||||
|
||||
Generated
Vendored
+126
@@ -0,0 +1,126 @@
|
||||
// +build example
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/endpoints"
|
||||
)
|
||||
|
||||
// Demostrates how the SDK's endpoints can be enumerated over to discover
|
||||
// regions, services, and endpoints defined by the SDK's Regions and Endpoints
|
||||
// metadata.
|
||||
//
|
||||
// Usage:
|
||||
// -p=id partition id, e.g: aws
|
||||
// -r=id region id, e.g: us-west-2
|
||||
// -s=id service id, e.g: s3
|
||||
//
|
||||
// -partitions Lists all partitions.
|
||||
// -regions Lists all regions in a partition. Requires partition ID.
|
||||
// If service ID is also provided will show endpoints for a service.
|
||||
// -services Lists all services in a partition. Requires partition ID.
|
||||
// If region ID is also provided, will show services available in that region.
|
||||
//
|
||||
// Example:
|
||||
// go run enumEndpoints.go -p aws -services -r us-west-2
|
||||
//
|
||||
// Output:
|
||||
// Services with endpoint us-west-2 in aws:
|
||||
// ...
|
||||
func main() {
|
||||
var partitionID, regionID, serviceID string
|
||||
flag.StringVar(&partitionID, "p", "", "Partition ID")
|
||||
flag.StringVar(®ionID, "r", "", "Region ID")
|
||||
flag.StringVar(&serviceID, "s", "", "Service ID")
|
||||
|
||||
var cmdPartitions, cmdRegions, cmdServices bool
|
||||
flag.BoolVar(&cmdPartitions, "partitions", false, "Lists partitions.")
|
||||
flag.BoolVar(&cmdRegions, "regions", false, "Lists regions of a partition. Requires partition ID to be provided. Will filter by a service if '-s' is set.")
|
||||
flag.BoolVar(&cmdServices, "services", false, "Lists services for a partition. Requires partition ID to be provided. Will filter by a region if '-r' is set.")
|
||||
flag.Parse()
|
||||
|
||||
partitions := endpoints.DefaultResolver().(endpoints.EnumPartitions).Partitions()
|
||||
|
||||
if cmdPartitions {
|
||||
printPartitions(partitions)
|
||||
}
|
||||
|
||||
if !(cmdRegions || cmdServices) {
|
||||
return
|
||||
}
|
||||
|
||||
p, ok := findPartition(partitions, partitionID)
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, "Partition %q not found", partitionID)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if cmdRegions {
|
||||
printRegions(p, serviceID)
|
||||
}
|
||||
|
||||
if cmdServices {
|
||||
printServices(p, regionID)
|
||||
}
|
||||
}
|
||||
|
||||
func printPartitions(ps []endpoints.Partition) {
|
||||
fmt.Println("Partitions:")
|
||||
for _, p := range ps {
|
||||
fmt.Println(p.ID())
|
||||
}
|
||||
}
|
||||
|
||||
func printRegions(p endpoints.Partition, serviceID string) {
|
||||
if len(serviceID) != 0 {
|
||||
s, ok := p.Services()[serviceID]
|
||||
if !ok {
|
||||
fmt.Fprintf(os.Stderr, "service %q does not exist in partition %q", serviceID, p.ID())
|
||||
os.Exit(1)
|
||||
}
|
||||
es := s.Endpoints()
|
||||
fmt.Printf("Endpoints for %s in %s:\n", serviceID, p.ID())
|
||||
for _, e := range es {
|
||||
r, _ := e.ResolveEndpoint()
|
||||
fmt.Printf("%s: %s\n", e.ID(), r.URL)
|
||||
}
|
||||
|
||||
} else {
|
||||
rs := p.Regions()
|
||||
fmt.Printf("Regions in %s:\n", p.ID())
|
||||
for _, r := range rs {
|
||||
fmt.Println(r.ID())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printServices(p endpoints.Partition, endpointID string) {
|
||||
ss := p.Services()
|
||||
|
||||
if len(endpointID) > 0 {
|
||||
fmt.Printf("Services with endpoint %s in %s:\n", endpointID, p.ID())
|
||||
} else {
|
||||
fmt.Printf("Services in %s:\n", p.ID())
|
||||
}
|
||||
|
||||
for id, s := range ss {
|
||||
if _, ok := s.Endpoints()[endpointID]; !ok && len(endpointID) > 0 {
|
||||
continue
|
||||
}
|
||||
fmt.Println(id)
|
||||
}
|
||||
}
|
||||
|
||||
func findPartition(ps []endpoints.Partition, partitionID string) (endpoints.Partition, bool) {
|
||||
for _, p := range ps {
|
||||
if p.ID() == partitionID {
|
||||
return p, true
|
||||
}
|
||||
}
|
||||
|
||||
return endpoints.Partition{}, false
|
||||
}
|
||||
Reference in New Issue
Block a user