]> git.proxmox.com Git - ceph.git/blob - ceph/examples/rgw/golang/topic-creation/topic-creation.go
update ceph source to reef 18.1.2
[ceph.git] / ceph / examples / rgw / golang / topic-creation / topic-creation.go
1 package main
2
3 import (
4 "encoding/json"
5 "flag"
6 "fmt"
7 "os"
8
9 "github.com/aws/aws-sdk-go/aws"
10 "github.com/aws/aws-sdk-go/aws/credentials"
11 "github.com/aws/aws-sdk-go/aws/endpoints"
12 "github.com/aws/aws-sdk-go/aws/session"
13 "github.com/aws/aws-sdk-go/service/sns"
14 )
15
16 func main() {
17 topic := flag.String("t", "", "The name of the topic")
18 attributes := flag.String("a", "", "Topic attributes needed")
19 flag.Parse()
20
21 attributesmap := map[string]*string{}
22 err := json.Unmarshal([]byte(*attributes), &attributesmap) // convert JSON string to Go map
23 if err != nil {
24 exitErrorf("Check your JSON String for any errors: %s : %s", err, *attributes)
25 }
26
27 if *topic == "" {
28 fmt.Println("You must supply the name of the topic")
29 fmt.Println("-t TOPIC")
30 return
31 }
32
33 if *attributes == "" {
34 fmt.Println("You must supply topic attributes")
35 fmt.Println("-a ATTRIBUTES")
36 return
37 }
38 //Ceph RGW Cluster credentials
39 access_key := "0555b35654ad1656d804"
40 secret_key := "h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=="
41 token_id := ""
42 url := "http://127.0.0.1:8000"
43
44 defaultResolver := endpoints.DefaultResolver()
45 snsCustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
46 if service == "sns" {
47 return endpoints.ResolvedEndpoint{
48 URL: url,
49 }, nil
50 }
51
52 return defaultResolver.EndpointFor(service, region, optFns...)
53 }
54
55 sess := session.Must(session.NewSessionWithOptions(session.Options{
56 Config: aws.Config{
57 Region: aws.String("default"),
58 Credentials: credentials.NewStaticCredentials(access_key, secret_key, token_id),
59 S3ForcePathStyle: aws.Bool(true),
60 EndpointResolver: endpoints.ResolverFunc(snsCustResolverFn),
61 },
62 }))
63
64 client := sns.New(sess)
65
66 results, err := client.CreateTopic(&sns.CreateTopicInput{
67 Attributes: attributesmap,
68 Name: topic,
69 })
70
71 if err != nil {
72 exitErrorf("Unable to create topic %s, %s", *topic, err)
73 }
74
75 fmt.Printf("Succesfully created %s \n", *results.TopicArn)
76 }
77
78 func exitErrorf(msg string, args ...interface{}) {
79 fmt.Fprintf(os.Stderr, msg+"\n", args...)
80 os.Exit(1)
81 }