Skip to content

Commit

Permalink
Merge branch 'dev' into pj/move-migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl authored Dec 12, 2024
2 parents a3c4316 + ed59b2b commit 9c08718
Show file tree
Hide file tree
Showing 3 changed files with 559 additions and 30 deletions.
11 changes: 11 additions & 0 deletions .changeset/add_bus_routes_to_openapi_spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
default: major
---

# Add bus section to openapi spec

Added routes:
- accounts
- alerts
- autopilot
- buckets
42 changes: 32 additions & 10 deletions bus/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ func (b *Bus) accountsFundHandler(jc jape.Context) {
return
}

// contract metadata
// fetch contract
cm, err := b.store.Contract(jc.Request.Context(), req.ContractID)
if jc.Check("failed to fetch contract metadata", err) != nil {
if errors.Is(err, api.ErrContractNotFound) {
jc.Error(err, http.StatusNotFound)
return
} else if jc.Check("failed to fetch contract metadata", err) != nil {
return
}

// host
// fetch host
host, err := b.store.Host(jc.Request.Context(), cm.HostKey)
if jc.Check("failed to fetch host for contract", err) != nil {
return
Expand Down Expand Up @@ -276,21 +279,33 @@ func (b *Bus) bucketsHandlerPOST(jc jape.Context) {
} else if err := req.Validate(); err != nil {
jc.Error(err, http.StatusBadRequest)
return
} else if jc.Check("failed to create bucket", b.store.CreateBucket(jc.Request.Context(), req.Name, req.Policy)) != nil {
}

err := b.store.CreateBucket(jc.Request.Context(), req.Name, req.Policy)
if errors.Is(err, api.ErrBucketExists) {
jc.Error(err, http.StatusConflict)
return
}
jc.Check("failed to create bucket", err)
}

func (b *Bus) bucketsHandlerPolicyPUT(jc jape.Context) {
var req api.BucketUpdatePolicyRequest
if jc.Decode(&req) != nil {
return
} else if bucket := jc.PathParam("name"); bucket == "" {
}
bucket := jc.PathParam("name")
if bucket == "" {
jc.Error(errors.New("no bucket name provided"), http.StatusBadRequest)
return
} else if jc.Check("failed to create bucket", b.store.UpdateBucketPolicy(jc.Request.Context(), bucket, req.Policy)) != nil {
}

err := b.store.UpdateBucketPolicy(jc.Request.Context(), bucket, req.Policy)
if errors.Is(err, api.ErrBucketNotFound) {
jc.Error(err, http.StatusNotFound)
return
}
jc.Check("failed to create bucket", err)
}

func (b *Bus) bucketHandlerDELETE(jc jape.Context) {
Expand All @@ -300,9 +315,18 @@ func (b *Bus) bucketHandlerDELETE(jc jape.Context) {
} else if name == "" {
jc.Error(errors.New("no name provided"), http.StatusBadRequest)
return
} else if jc.Check("failed to delete bucket", b.store.DeleteBucket(jc.Request.Context(), name)) != nil {
}

err := b.store.DeleteBucket(jc.Request.Context(), name)
if errors.Is(err, api.ErrBucketNotFound) {
jc.Error(err, http.StatusNotFound)
return
} else if errors.Is(err, api.ErrBucketNotEmpty) {
jc.Error(err, http.StatusConflict)
return
}

jc.Check("failed to delete bucket", err)
}

func (b *Bus) bucketHandlerGET(jc jape.Context) {
Expand Down Expand Up @@ -1864,9 +1888,7 @@ func (b *Bus) accountsHandlerPOST(jc jape.Context) {
return
}
}
if b.store.SaveAccounts(jc.Request.Context(), req.Accounts) != nil {
return
}
jc.Check("failed to save accounts", b.store.SaveAccounts(jc.Request.Context(), req.Accounts))
}

func (b *Bus) hostsCheckHandlerPUT(jc jape.Context) {
Expand Down
Loading

0 comments on commit 9c08718

Please sign in to comment.