Skip to content

Commit 93ca264

Browse files
committed
chore: update config
Signed-off-by: Brad McCoy <[email protected]>
1 parent e762c9c commit 93ca264

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

.github/workflows/release.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ jobs:
8282
cosign sign ghcr.io/bradmccoydev/cdevents-controller:latest --yes
8383
cosign sign ghcr.io/bradmccoydev/cdevents-controller:${{ steps.prep.outputs.VERSION }} --yes
8484
85-
8685
# - name: Generate SBOM
8786
# uses: anchore/sbom-action@4d571ad1038a9cc29d676154ef265ab8f9027042 # v0.14.2
8887
# with:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ EXTRA_RUN_ARGS?=
1313
run:
1414
go run -ldflags "-s -w -X github.com/bradmccoydev/cdevents-controller/pkg/version.REVISION=$(GIT_COMMIT)" cmd/cdevents-controller/* \
1515
--level=debug --grpc-port=9999 --backend-url=https://httpbin.org/status/401 --backend-url=https://httpbin.org/status/500 \
16-
--ui-logo=https://raw.githubusercontent.com/bradmccoydev/cdevents-controller/gh-pages/cuddle_clap.gif $(EXTRA_RUN_ARGS)
16+
$(EXTRA_RUN_ARGS)
1717

1818
.PHONY: test
1919
test:

cmd/cdevents-controller/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func main() {
7676
viper.RegisterAlias("backendUrl", "backend-url")
7777
hostname, _ := os.Hostname()
7878
viper.SetDefault("jwt-secret", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9")
79+
viper.SetDefault("mongodb-url", "mongodb://mongodb-headless:27017")
7980
viper.SetDefault("ui-logo", "https://raw.githubusercontent.com/bradmccoydev/cdevents-controller/gh-pages/cuddle_clap.gif")
8081
viper.Set("hostname", hostname)
8182
viper.Set("version", version.VERSION)

pkg/api/cdevent.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/gorilla/mux"
1212
"go.mongodb.org/mongo-driver/mongo"
1313
"go.mongodb.org/mongo-driver/mongo/options"
14+
"gopkg.in/yaml.v3"
1415
)
1516

1617
// Info godoc
@@ -33,7 +34,12 @@ func (s *Server) cdEventHandler(w http.ResponseWriter, r *http.Request) {
3334
return
3435
}
3536

36-
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://mongodb-headless:27017/cdevents?ssl=false"))
37+
var cdevent CDEvent
38+
if err := yaml.Unmarshal(body, &cdevent); err != nil {
39+
log.Fatal(err)
40+
}
41+
42+
client, err := mongo.NewClient(options.Client().ApplyURI(s.config.MongodbURL))
3743
if err != nil {
3844
log.Fatal(err)
3945
}
@@ -55,36 +61,29 @@ func (s *Server) cdEventHandler(w http.ResponseWriter, r *http.Request) {
5561
db := client.Database("cdevents")
5662
collection := db.Collection("items")
5763

58-
cdevent := CDEvent{
59-
SubjectID: "1",
60-
SubjectSource: "2",
61-
SubjectType: "3",
62-
SubjectContent: "4",
63-
ContextVersion: "5",
64-
ContextID: "6",
65-
ContextSource: "7",
66-
ContextType: "8",
67-
ContextTimestamp: "9",
68-
}
69-
70-
_, err = collection.InsertOne(ctx, cdevent)
64+
result, err := collection.InsertOne(ctx, cdevent)
7165
if err != nil {
7266
log.Fatal(err)
7367
}
7468

75-
fmt.Printf("Item inserted successfully! %s", key)
69+
fmt.Printf("Inserted document with _id: %v\n", result.InsertedID)
7670

7771
s.JSONResponse(w, r, body)
7872
}
7973

8074
type CDEvent struct {
81-
SubjectID string `json:"subjectId"`
82-
SubjectSource string `json:"subjectSource"`
83-
SubjectType string `json:"subjectType"`
84-
SubjectContent string `json:"subjectContent"`
85-
ContextVersion string `json:"contextVersion"`
86-
ContextID string `json:"contextId"`
87-
ContextSource string `json:"contextSource"`
88-
ContextType string `json:"contextType"`
89-
ContextTimestamp string `json:"contextTimestamp"`
75+
Context struct {
76+
Version string `json:"version"`
77+
ID string `json:"id"`
78+
Source string `json:"source"`
79+
Type string `json:"type"`
80+
Timestamp time.Time `json:"timestamp"`
81+
} `json:"context"`
82+
Subject struct {
83+
ID string `json:"id"`
84+
Source string `json:"source"`
85+
Type string `json:"type"`
86+
Content struct {
87+
} `json:"content"`
88+
} `json:"subject"`
9089
}

pkg/api/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type Config struct {
7272
Unready bool `mapstructure:"unready"`
7373
JWTSecret string `mapstructure:"jwt-secret"`
7474
CacheServer string `mapstructure:"cache-server"`
75+
MongodbURL string `mapstructure:"mongodb-url"`
7576
}
7677

7778
type Server struct {

0 commit comments

Comments
 (0)