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

Use amqp.URI #14

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ go:
- 1.13

install:
- go get -u golang.org/x/lint/golint
- go get -u github.com/mattn/goveralls
- GO111MODULE=off go get -u golang.org/x/lint/golint
- GO111MODULE=off go get -u github.com/mattn/goveralls

script:
- make check
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ All components receive configuration via environment variables. The following va
| `CASTELLUM_MAX_ASSET_SIZES` | *(optional)* | A comma-separated list of `<asset-type>=<max-size>` pairs. If present, only resource configurations honoring these constraints will be allowed. |
| `CASTELLUM_OSLO_POLICY_PATH` | *(required)* | Path to the `policy.json` file for this service. See [*Oslo policy*](#oslo-policy) for details. |
| `CASTELLUM_RABBITMQ_QUEUE_NAME` | *(required for enabling audit trail)* | Name for the queue that will hold the audit events. The events are published to the default exchange. |
| `CASTELLUM_RABBITMQ_USERNAME` | *(optional)* | RabbitMQ Username. |
| `CASTELLUM_RABBITMQ_PASSWORD` | *(optional)* | Password for the specified user. |
| `CASTELLUM_RABBITMQ_USERNAME` | `guest` | RabbitMQ Username. |
| `CASTELLUM_RABBITMQ_PASSWORD` | `guest` | Password for the specified user. |
| `CASTELLUM_RABBITMQ_HOSTNAME` | `localhost` | Hostname of the RabbitMQ server. |
| `CASTELLUM_RABBITMQ_PORT` | `5672` | Port number to which the underlying connection is made. |
| `CASTELLUM_AUDIT_SILENT` | `false` | Disable audit event logging to standard output. |
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ require (
github.com/prometheus/client_golang v1.7.1
github.com/prometheus/common v0.14.0
github.com/rs/cors v1.7.0
github.com/sapcc/go-bits v0.0.0-20201126124612-fcd600685fdb
github.com/sapcc/go-bits v0.0.0-20201203204854-32575942fc71
github.com/sapcc/gophercloud-limes v0.0.0-20200819120227-33ee0896b7e8
github.com/sapcc/hermes v0.0.0-20200928164006-62559084bfce
github.com/sapcc/limes v0.0.0-20200928094800-7845b54d12e7
github.com/streadway/amqp v1.0.0 // indirect
github.com/streadway/amqp v1.0.1-0.20200716223359-e6b33f460591
gopkg.in/gorp.v2 v2.2.0
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ github.com/sapcc/go-bits v0.0.0-20190910095551-3863bd6b4943 h1:tOsa/z/MGmhxp5qlu
github.com/sapcc/go-bits v0.0.0-20190910095551-3863bd6b4943/go.mod h1:YpW83RbRSHPedMBfuvdfYJMQbejxSxzK1Kj/39szShw=
github.com/sapcc/go-bits v0.0.0-20200719195243-6f202ca5296a h1:qYxXWqfFKGnHo3wLSyyXewRCQygkoanKnu/syOiRzDE=
github.com/sapcc/go-bits v0.0.0-20200719195243-6f202ca5296a/go.mod h1:r6AY7ym3xd4WK0Crz/D0Rf7J+oMg7haFiADpqiY1e3A=
github.com/sapcc/go-bits v0.0.0-20201126124612-fcd600685fdb h1:bvD4yq3nxjUryiy921Eld0i33PE1oST4GLxW6Wlhzk4=
github.com/sapcc/go-bits v0.0.0-20201126124612-fcd600685fdb/go.mod h1:MvjxocNfMqx+sQ2xdfrLveBljrUmGPaJT/UHUwyZ8lM=
github.com/sapcc/go-bits v0.0.0-20201203204854-32575942fc71 h1:WycbLaNKy5cLX8rEgG2dDyU9lRBP7DUtJeY7KoNFDiU=
github.com/sapcc/go-bits v0.0.0-20201203204854-32575942fc71/go.mod h1:K/nymIfebyify6kJ9K62XSQHFw/M5QNo8BmYNmuUJbk=
github.com/sapcc/gophercloud-limes v0.0.0-20200819120227-33ee0896b7e8 h1:oeLSkpv6DhRiNmMnYPwlCm/HeGfogYslFQDdLSWhRTY=
github.com/sapcc/gophercloud-limes v0.0.0-20200819120227-33ee0896b7e8/go.mod h1:8/BIFprjDN70kq0r6GyFgBmZHEWF6/8+q6wmcvSmHmM=
github.com/sapcc/hermes v0.0.0-20190722215605-d772f40f9fc6 h1:iI+ew9JUORCqP+8pElkSayI/smvdiYoPRX6J4DmkVTI=
Expand Down Expand Up @@ -409,8 +409,8 @@ github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94 h1:0ngsPmuP6XIjiFRN
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271 h1:WhxRHzgeVGETMlmVfqhRn8RIeeNoPr2Czh33I4Zdccw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v1.0.1-0.20200716223359-e6b33f460591 h1:DY61wv7mWBLELSYAGfxjItovf7QQKxjLBSFldNbLS/Q=
github.com/streadway/amqp v1.0.1-0.20200716223359-e6b33f460591/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
5 changes: 3 additions & 2 deletions internal/api/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/sapcc/go-bits/gopherpolicy"
"github.com/sapcc/go-bits/logg"
"github.com/sapcc/hermes/pkg/cadf"
"github.com/streadway/amqp"
)

//eventSink is a channel that receives audit events.
Expand All @@ -37,7 +38,7 @@ var eventSink chan<- cadf.Event
var showAuditOnStdout bool

// StartAuditLogging starts audit logging for the API.
func StartAuditLogging(rabbitURI, rabbitQueueName string) {
func StartAuditLogging(rabbitQueueName string, rabbitURI amqp.URI) {
silenceAuditLogging, _ := strconv.ParseBool(os.Getenv("CASTELLUM_AUDIT_SILENT"))
showAuditOnStdout = !silenceAuditLogging

Expand All @@ -57,7 +58,7 @@ func StartAuditLogging(rabbitURI, rabbitQueueName string) {
EventSink: s,
OnSuccessfulPublish: onSuccessFunc,
OnFailedPublish: onFailFunc,
}.Commit(rabbitURI, rabbitQueueName)
}.Commit(rabbitQueueName, rabbitURI)
}

var observerUUID = audittools.GenerateUUID()
Expand Down
31 changes: 17 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"database/sql"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
Expand All @@ -46,6 +47,7 @@ import (
"github.com/sapcc/go-bits/gopherpolicy"
"github.com/sapcc/go-bits/httpee"
"github.com/sapcc/go-bits/logg"
"github.com/streadway/amqp"
"gopkg.in/gorp.v2"

//load asset managers
Expand Down Expand Up @@ -74,7 +76,7 @@ func main() {
dbURL := &url.URL{
Scheme: "postgres",
User: url.UserPassword(dbUsername, dbPass),
Host: dbHost + ":" + dbPort,
Host: net.JoinHostPort(dbHost, dbPort),
Path: dbName,
RawQuery: dbConnOpts,
}
Expand Down Expand Up @@ -221,21 +223,22 @@ func runAPI(cfg *core.Config, dbi *gorp.DbMap, team core.AssetManagerTeam, provi
//Start audit logging.
rabbitQueueName := os.Getenv("CASTELLUM_RABBITMQ_QUEUE_NAME")
if rabbitQueueName != "" {
var rabbitUserInfo string
if rabbitUsername := os.Getenv("CASTELLUM_RABBITMQ_USERNAME"); rabbitUsername != "" {
rabbitUserInfo += rabbitUsername
}
if rabbitPass := os.Getenv("CASTELLUM_RABBITMQ_PASSWORD"); rabbitPass != "" {
rabbitUserInfo += ":" + rabbitPass
username := envOrDefault("CASTELLUM_RABBITMQ_USERNAME", "guest")
pass := envOrDefault("CASTELLUM_RABBITMQ_PASSWORD", "guest")
hostname := envOrDefault("CASTELLUM_RABBITMQ_HOSTNAME", "localhost")
port, err := strconv.Atoi(envOrDefault("CASTELLUM_RABBITMQ_PORT", "5672"))
if err != nil {
logg.Fatal("invalid value for CASTELLUM_RABBITMQ_PORT: " + err.Error())
}
if rabbitUserInfo != "" {
rabbitUserInfo += "@"
rabbitURI := amqp.URI{
Scheme: "amqp",
Host: hostname,
Port: port,
Username: username,
Password: pass,
Vhost: "/",
}
rabbitHost := envOrDefault("CASTELLUM_RABBITMQ_HOSTNAME", "localhost")
rabbitPort := envOrDefault("CASTELLUM_RABBITMQ_PORT", "5672")

rabbitURI := fmt.Sprintf("amqp://%s%s:%s/", rabbitUserInfo, rabbitHost, rabbitPort)
api.StartAuditLogging(rabbitURI, rabbitQueueName)
api.StartAuditLogging(rabbitQueueName, rabbitURI)
}

//metrics and healthcheck are deliberately not covered by any of the
Expand Down
47 changes: 26 additions & 21 deletions vendor/github.com/sapcc/go-bits/audittools/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions vendor/github.com/sapcc/go-bits/audittools/rabbitmq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 32 additions & 24 deletions vendor/github.com/sapcc/go-bits/audittools/trail.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion vendor/github.com/streadway/amqp/connection.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading