Skip to content

Commit

Permalink
docs: add bucket routes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Dec 11, 2024
1 parent 56ce3ff commit a350551
Show file tree
Hide file tree
Showing 2 changed files with 204 additions and 4 deletions.
28 changes: 24 additions & 4 deletions bus/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,32 @@ func (b *Bus) bucketsHandlerPOST(jc jape.Context) {
} else if bucket.Name == "" {
jc.Error(errors.New("no name provided"), http.StatusBadRequest)
return
} else if jc.Check("failed to create bucket", b.store.CreateBucket(jc.Request.Context(), bucket.Name, bucket.Policy)) != nil {
}
err := b.store.CreateBucket(jc.Request.Context(), bucket.Name, bucket.Policy)
if errors.Is(err, api.ErrBucketExists) {
jc.Error(err, http.StatusBadRequest)
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 @@ -303,9 +314,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
180 changes: 180 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,186 @@ paths:
schema:
type: string

/bus/buckets:
get:
summary: Get all buckets
description: Returns all known buckets.
responses:
"200":
description: Successfully retrieved buckets
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Bucket"
"500":
description: Internal server error
content:
text/plain:
schema:
type: string
post:
summary: Create bucket
description: Create a new bucket.
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
pattern: (?!(^xn--|.+-s3alias$))^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$
description: The name of the bucket
policy:
type: object
properties:
publicReadAccess:
type: boolean
description: Whether the bucket is publicly readable
responses:
"200":
description: Successfully saved buckets
content:
text/plain:
schema:
type: string
"400":
description: Malformed request
content:
text/plain:
schema:
type: string
examples:
invalidBucketName:
summary: Invalid bucket name example
value: "bucket name must match pattern '^(?!(^xn--|.+-s3alias$))^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$'"
bucketAlreadyExists:
summary: Bucket already exists example
value: "bucket already exists"
"500":
description: Internal server error
content:
text/plain:
schema:
type: string
/bus/bucket/{name}/policy:
put:
summary: Update bucket policy
description: Updates the policy of the specified bucket.
parameters:
- name: name
in: path
required: true
schema:
type: string
description: The name of the bucket
requestBody:
content:
application/json:
schema:
type: object
properties:
policy:
type: object
properties:
publicReadAccess:
type: boolean
description: Whether the bucket is publicly readable
responses:
"200":
description: Successfully updated bucket policy
content:
text/plain:
schema:
type: string
"400":
description: Malformed request
content:
text/plain:
schema:
type: string
examples:
noBucketName:
summary: No bucket name provided
value: "bucket name is required"
"404":
description: Bucket not found
content:
text/plain:
schema:
type: string
/bus/bucket/{name}:
get:
summary: Get bucket
description: Returns the specified bucket.
parameters:
- name: name
in: path
required: true
schema:
type: string
description: The name of the bucket
responses:
"200":
description: Successfully retrieved bucket
content:
application/json:
schema:
$ref: "#/components/schemas/Bucket"
"404":
description: Bucket not found
content:
text/plain:
schema:
type: string
delete:
summary: Delete bucket
description: Deletes the specified bucket.
parameters:
- name: name
in: path
required: true
schema:
type: string
description: The name of the bucket
responses:
"200":
description: Successfully deleted bucket
content:
text/plain:
schema:
type: string
"400":
description: Malformed request
content:
text/plain:
schema:
type: string
examples:
noBucketName:
summary: No bucket name provided
value: "bucket name is required"
"404":
description: Bucket not found
content:
text/plain:
schema:
type: string
"409":
description: Bucket not empty
content:
text/plain:
schema:
type: string
"500":
description: Internal server error
content:
text/plain:
schema:
type: string

components:
schemas:
#############################
Expand Down

0 comments on commit a350551

Please sign in to comment.