Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -S --ssl flag to use SSL (amqps) #1

Merged
merged 2 commits into from
Dec 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add -S --ssl flag to use SSL (amqps)
You still need to pass -P 5671 for SSL port. Unsure how to override the
default port depending on if ssl flag is given
marcinkoziej committed Dec 3, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 7adf7c457b31365915e7c4f7c24a4b05c626d653
3 changes: 1 addition & 2 deletions cmd/consume.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"reflect"
"strconv"
"strings"

"github.com/oleiade/reflections"
@@ -36,8 +35,8 @@ Use comma-separated values for binding the same queue with multiple routing keys
cmd.SilenceUsage = true
cmd.SilenceErrors = true

uri := getUri()
// Dial amqp server
uri := "amqp://" + username + ":" + password + "@" + host + ":" + strconv.Itoa(port) + vhost
conn, err := amqp.Dial(uri)
if err != nil {
return fmt.Errorf("connection.open: %v", err)
3 changes: 1 addition & 2 deletions cmd/produce.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (
"io/ioutil"
"os"
"reflect"
"strconv"
"time"

"github.com/spf13/cobra"
@@ -46,7 +45,7 @@ To pass headers and properites, use '--headers' & '--properties' any number of t
message = string(bytes)
}

uri := "amqp://" + username + ":" + password + "@" + host + ":" + strconv.Itoa(port) + vhost
uri := getUri()
conn, err := amqp.Dial(uri)
if err != nil {
return fmt.Errorf("connection.open: %v", err)
11 changes: 11 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strings"
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
@@ -18,6 +19,7 @@ var (
vhost string
username string
password string
ssl bool

// exchange options
exchange string
@@ -34,6 +36,14 @@ var (
durableQueue bool
)

func getUri() string {
var proto string = "amqp://"
if (ssl) {
proto = "amqps://"
}
return proto + username + ":" + password + "@" + host + ":" + strconv.Itoa(port) + vhost
}

var valid_properties = map[string]string{
"content-type": "ContentType",
"content-encoding": "ContentEncoding",
@@ -93,6 +103,7 @@ func commonFlagSet() *pflag.FlagSet {
fs.StringVarP(&vhost, "vhost", "v", "/", "specify vhost")
fs.StringVarP(&username, "username", "u", "guest", "specify username")
fs.StringVarP(&password, "password", "p", "guest", "specify password")
fs.BoolVarP(&ssl, "ssl", "S", false, "use amqps")

fs.StringVarP(&exchange, "exchange", "e", "", `exchange name (default "")`)
fs.StringVarP(&routingkey, "key", "k", "", `routing key (default "")`)