Skip to content

Commit

Permalink
chore: update env var
Browse files Browse the repository at this point in the history
Signed-off-by: Brad McCoy <bradmccoydev@gmail.com>
  • Loading branch information
bradmccoydev committed May 31, 2023
1 parent 1674d7f commit d8d44b4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions charts/cdevents-controller/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
version: 0.0.4
appVersion: 0.0.4
version: 0.0.5
appVersion: 0.0.5
name: cdevents-controller
engine: gotpl
description: CDEvents Github Contoller Helm Chart
Expand Down
2 changes: 1 addition & 1 deletion charts/cdevents-controller/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ spec:
- --h2c
{{- end }}
env:
- name: cdevents-controller_MONGODB_URL
- name: MONGODB_URL
valueFrom:
secretKeyRef:
name: mongodb
Expand Down
2 changes: 1 addition & 1 deletion cmd/cdevents-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {
viper.RegisterAlias("backendUrl", "backend-url")
hostname, _ := os.Hostname()
viper.SetDefault("jwt-secret", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9")
viper.SetDefault("mongodb-url", "mongodb://mongodb-headless:27017")
viper.SetDefault("mongodb-url", "mongodb://mongodb-headless:27017") //localhost
viper.SetDefault("ui-logo", "https://raw.githubusercontent.com/bradmccoydev/cdevents-controller/gh-pages/cuddle_clap.gif")
viper.Set("hostname", hostname)
viper.Set("version", version.VERSION)
Expand Down
23 changes: 14 additions & 9 deletions pkg/api/cdevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package api

import (
"context"
"fmt"
"io"
"log"
"net/http"
"os"
"time"

"github.com/gorilla/mux"
Expand All @@ -28,33 +28,38 @@ func (s *Server) cdEventHandler(w http.ResponseWriter, r *http.Request) {

key := mux.Vars(r)["key"]
body, err := io.ReadAll(r.Body)
fmt.Printf("key: %s, body: %s", key, body)
log.Printf("key: %s, body: %s", key, body)
if err != nil {
s.ErrorResponse(w, r, span, "reading the request body failed", http.StatusBadRequest)
return
}

var cdevent CDEvent
if err := yaml.Unmarshal(body, &cdevent); err != nil {
log.Fatal(err)
log.Printf("Error Unmarshalling CDEvent: %s", err)
}

client, err := mongo.NewClient(options.Client().ApplyURI(s.config.MongodbURL))
mongoURL := os.Getenv("MONGODB_URL")
log.Printf("Mongo URL is: %s", mongoURL)

//client, err := mongo.NewClient(options.Client().ApplyURI(s.config.MongodbURL))
client, err := mongo.NewClient(options.Client().ApplyURI(mongoURL))

if err != nil {
log.Fatal(err)
log.Printf("Error Getting MongoDB Client: %s", err)
}

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
log.Printf("Error Connecting to Mongo: %s\n", err)
}

defer func() {
if err = client.Disconnect(ctx); err != nil {
log.Fatal(err)
log.Printf("Error Disconnecting from Mongo: %s\n", err)
}
}()

Expand All @@ -63,10 +68,10 @@ func (s *Server) cdEventHandler(w http.ResponseWriter, r *http.Request) {

result, err := collection.InsertOne(ctx, cdevent)
if err != nil {
fmt.Printf("Error With Mongo: %s\n", err)
log.Printf("Error With Mongo: %s\n", err)
}

fmt.Printf("Inserted document with _id: %v\n", result.InsertedID)
log.Printf("Inserted document with _id: %v\n", result.InsertedID)

s.JSONResponse(w, r, body)
}
Expand Down

0 comments on commit d8d44b4

Please sign in to comment.