diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /examples/rgw/golang/topic-creation | |
parent | Initial commit. (diff) | |
download | ceph-upstream/18.2.2.tar.xz ceph-upstream/18.2.2.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | examples/rgw/golang/topic-creation/README.md | 11 | ||||
-rw-r--r-- | examples/rgw/golang/topic-creation/go.mod | 5 | ||||
-rw-r--r-- | examples/rgw/golang/topic-creation/go.sum | 24 | ||||
-rw-r--r-- | examples/rgw/golang/topic-creation/topic-creation.go | 81 |
4 files changed, 121 insertions, 0 deletions
diff --git a/examples/rgw/golang/topic-creation/README.md b/examples/rgw/golang/topic-creation/README.md new file mode 100644 index 000000000..3033a86c5 --- /dev/null +++ b/examples/rgw/golang/topic-creation/README.md @@ -0,0 +1,11 @@ +# Introduction +This directory contains Golang code example on how to create an SNS Topic on a Ceph RGW cluster. + +# Prerequisite +Linux machine running an RGW Ceph cluster. Preferrably started with the ``OSD=1 MON=1 MDS=0 MGR=0 RGW=1 ../src/vstart.sh --debug --new `` command. +Go installed on the Linux machine. + +## Workflow Procedure +1. Navigate through your file system to where the Golang example code exists on your terminal. +2. Run ``` go mod tidy ``` to install the required Golang packages on the system. +3. Run the Golang program as ``` go run topic-creation.go -t sample-topic-1 -a '{"push-endpoint": "http://127.0.0.1:10900"}' ``` on the terminal window to create SNS topic with custom attributes. diff --git a/examples/rgw/golang/topic-creation/go.mod b/examples/rgw/golang/topic-creation/go.mod new file mode 100644 index 000000000..4b4f7fabd --- /dev/null +++ b/examples/rgw/golang/topic-creation/go.mod @@ -0,0 +1,5 @@ +module examples/topic-creation + +go 1.13 + +require github.com/aws/aws-sdk-go v1.44.61 diff --git a/examples/rgw/golang/topic-creation/go.sum b/examples/rgw/golang/topic-creation/go.sum new file mode 100644 index 000000000..4c3ec3873 --- /dev/null +++ b/examples/rgw/golang/topic-creation/go.sum @@ -0,0 +1,24 @@ +github.com/aws/aws-sdk-go v1.44.61 h1:NcpLSS3Z0MiVQIYugx4I40vSIEEAXT0baO684ExNRco= +github.com/aws/aws-sdk-go v1.44.61/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= +golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/examples/rgw/golang/topic-creation/topic-creation.go b/examples/rgw/golang/topic-creation/topic-creation.go new file mode 100644 index 000000000..128358f40 --- /dev/null +++ b/examples/rgw/golang/topic-creation/topic-creation.go @@ -0,0 +1,81 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "os" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/endpoints" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/sns" +) + +func main() { + topic := flag.String("t", "", "The name of the topic") + attributes := flag.String("a", "", "Topic attributes needed") + flag.Parse() + + attributesmap := map[string]*string{} + err := json.Unmarshal([]byte(*attributes), &attributesmap) // convert JSON string to Go map + if err != nil { + exitErrorf("Check your JSON String for any errors: %s : %s", err, *attributes) + } + + if *topic == "" { + fmt.Println("You must supply the name of the topic") + fmt.Println("-t TOPIC") + return + } + + if *attributes == "" { + fmt.Println("You must supply topic attributes") + fmt.Println("-a ATTRIBUTES") + return + } + //Ceph RGW Cluster credentials + access_key := "0555b35654ad1656d804" + secret_key := "h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==" + token_id := "" + url := "http://127.0.0.1:8000" + + defaultResolver := endpoints.DefaultResolver() + snsCustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) { + if service == "sns" { + return endpoints.ResolvedEndpoint{ + URL: url, + }, nil + } + + return defaultResolver.EndpointFor(service, region, optFns...) + } + + sess := session.Must(session.NewSessionWithOptions(session.Options{ + Config: aws.Config{ + Region: aws.String("default"), + Credentials: credentials.NewStaticCredentials(access_key, secret_key, token_id), + S3ForcePathStyle: aws.Bool(true), + EndpointResolver: endpoints.ResolverFunc(snsCustResolverFn), + }, + })) + + client := sns.New(sess) + + results, err := client.CreateTopic(&sns.CreateTopicInput{ + Attributes: attributesmap, + Name: topic, + }) + + if err != nil { + exitErrorf("Unable to create topic %s, %s", *topic, err) + } + + fmt.Printf("Succesfully created %s \n", *results.TopicArn) +} + +func exitErrorf(msg string, args ...interface{}) { + fmt.Fprintf(os.Stderr, msg+"\n", args...) + os.Exit(1) +} |