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

Feat test report #1244

Draft
wants to merge 42 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a2042f3
ground work
Dec 12, 2024
8fb48dc
feat: add sender rule for pipelines (#1206)
ecrupper Oct 25, 2024
a3b1bff
chore(lint): add struct tag align rule (#1216)
ecrupper Oct 25, 2024
2245376
chore(lint): address existing linter issues (#1218)
ecrupper Nov 4, 2024
5a1f403
enhance(build)!: add fork field for OIDC (#1221)
ecrupper Nov 20, 2024
9a5bf00
enhance(compiler): cache templates per compilation (#1224)
ecrupper Dec 3, 2024
58718a1
ground work
Dec 12, 2024
8e9cd8e
working admin endpoints for bucket management
Dec 17, 2024
3239b53
working admin endpoints for object operations
Dec 18, 2024
8a95775
all endpoints for storage
Jan 2, 2025
a4f29d0
some working test
Jan 7, 2025
41df509
working tests
Jan 8, 2025
86d822d
keys for test report step
Jan 17, 2025
83afd15
feat: deployment config for expected params and targets (#1214)
ecrupper Dec 18, 2024
8b5b79f
resolve conflicts with buildkite
Jan 17, 2025
9328ecd
feat: opt-in gh app integration (#1217)
plyr4 Dec 19, 2024
b16622f
chore(yaml): add go-yaml types package (#1225)
ecrupper Dec 23, 2024
3156794
resolve conflicts
Jan 17, 2025
57f8f9a
rebase
Jan 17, 2025
09da5df
enhance(yaml): allow for users to set version legacy for buildkite (#…
ecrupper Dec 26, 2024
114ae7b
refactor(db/build): drop source index, add event index (#1228)
wass3rw3rk Dec 27, 2024
fd16b7b
feat(repo)!: add pending approval timeout (#1227)
ecrupper Dec 30, 2024
68547d6
enhance(yaml): silent fix anchor merges in YAML maps (#1231)
ecrupper Dec 30, 2024
c7c1d0a
fix(webhook): use correct repo variable for enqueue (#1234)
ecrupper Dec 31, 2024
f43e2d1
feat(pipeline)!: add warnings to pipelines that use legacy YAML lib o…
ecrupper Jan 6, 2025
f1a98ac
feat: status endpoints (#1235)
plyr4 Jan 7, 2025
bf2313d
enhance(deploy): validate on CreateDeployment (#1236)
ecrupper Jan 8, 2025
9a532cf
enhance(metrics): include route specific queue length (#1237)
ecrupper Jan 9, 2025
9f13f97
chore(deps): update codecov/codecov-action action to v5 (#1222)
renovate[bot] Jan 10, 2025
3920eab
fix(deps): update module github.com/google/go-github/v65 to v68 (#1229)
renovate[bot] Jan 10, 2025
084fea3
chore: bump go (#1238)
wass3rw3rk Jan 10, 2025
52df828
fix(deployment): use Config instead of ConfigBackoff when fetching de…
ecrupper Jan 10, 2025
4eee25d
fix(build): use item build host (#1241)
ecrupper Jan 13, 2025
df21b7a
fix(build): ensure count/pagination links account for filter/query pa…
wass3rw3rk Jan 14, 2025
d24fd37
fix(yaml): improved messaging (#1243)
wass3rw3rk Jan 15, 2025
a051afa
keys for test report step
Jan 17, 2025
5254aad
resolve conflicts with buildkite
Jan 17, 2025
a138127
Merge branch 'main' into feat_test_report
timhuynh94 Jan 17, 2025
14660f5
mod tidy
Jan 17, 2025
05a09bb
fields for buildkite and ymal
Jan 20, 2025
657fe54
updates to storage client
Feb 12, 2025
d190aaf
upload with content type and size
Feb 19, 2025
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
392 changes: 392 additions & 0 deletions api/admin/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,392 @@
// SPDX-License-Identifier: Apache-2.0

package admin

import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-vela/server/api/types"
"github.com/go-vela/server/storage"
"github.com/go-vela/server/util"
"github.com/sirupsen/logrus"
"net/http"
)

// swagger:operation POST /api/v1/admin/storage/bucket admin CreateBucket

//
// Create a new bucket
//
// ---
// produces:
// - application/json
// parameters:
// - in: body
// name: body
// description: The bucket name to be created
// required: true
// schema:
// type: object
// properties:
// bucketName:
// type: string
// security:
// - ApiKeyAuth: []
// responses:
// '201':
// description: Successfully created the bucket
// '400':
// description: Invalid request payload
// schema:
// "$ref": "#/definitions/Error"
// '500':
// description: Unexpected server error
// schema:
// "$ref": "#/definitions/Error"

// CreateBucket represents the API handler to create a new bucket.
func CreateBucket(c *gin.Context) {
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: creating bucket")

// capture body from API request
input := new(types.Bucket)

err := c.Bind(input)
if err != nil {
retErr := fmt.Errorf("unable to decode JSON for bucket %s: %w", input.BucketName, err)

util.HandleError(c, http.StatusBadRequest, retErr)

return
}
l.Debugf("bucket name: %s", input.BucketName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
expressions should not be cuddled with blocks (wsl)

err = storage.FromGinContext(c).CreateBucket(ctx, input)
if err != nil {
retErr := fmt.Errorf("unable to create bucket: %w", err)
util.HandleError(c, http.StatusInternalServerError, retErr)
return
}

c.Status(http.StatusCreated)
}

// swagger:operation DELETE /api/v1/admin/storage/bucket admin DeleteBucket
//
// Delete a bucket
//
// ---
// produces:
// - application/json
// parameters:
// - in: body
// name: body
// description: The bucket name to be deleted
// required: true
// schema:
// type: object
// properties:
// bucketName:
// type: string
// security:
// - ApiKeyAuth: []
// responses:
// '200':
// description: Successfully deleted the bucket
// '400':
// description: Invalid request payload
// schema:
// "$ref": "#/definitions/Error"
// '500':
// description: Unexpected server error
// schema:
// "$ref": "#/definitions/Error"

// DeleteBucket represents the API handler to delete a bucket.
func DeleteBucket(c *gin.Context) {
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: deleting bucket")

// capture body from API request
input := new(types.Bucket)

err := c.Bind(input)
if err != nil {
retErr := fmt.Errorf("unable to decode JSON for bucket %s: %w", input.BucketName, err)

util.HandleError(c, http.StatusBadRequest, retErr)

return
}

err = storage.FromGinContext(c).DeleteBucket(ctx, input)
if err != nil {
retErr := fmt.Errorf("unable to delete bucket: %w", err)
util.HandleError(c, http.StatusInternalServerError, retErr)
return
}

c.Status(http.StatusOK)
}

// swagger:operation GET /api/v1/admin/storage/bucket/lifecycle admin GetBucketLifecycle
//
// # Get bucket lifecycle configuration
//
// ---
// produces:
// - application/json
// parameters:
// - in: query
// name: bucketName
// description: The name of the bucket
// required: true
// type: string
//
// security:
// - ApiKeyAuth: []
//
// responses:
//
// '200':
// description: Successfully retrieved the bucket lifecycle configuration
// '400':
// description: Invalid request payload
// schema:
// "$ref": "#/definitions/Error"
// '500':
// description: Unexpected server error
// schema:
// "$ref": "#/definitions/Error"
func GetBucketLifecycle(c *gin.Context) {
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: getting bucket lifecycle configuration")

// capture query parameters from API request
bucketName := c.Query("bucketName")

if bucketName == "" {
retErr := fmt.Errorf("bucketName is required")
util.HandleError(c, http.StatusBadRequest, retErr)
return
}

input := &types.Bucket{
BucketName: bucketName,
}

lifecycleConfig, err := storage.FromGinContext(c).GetBucketLifecycle(ctx, input)
if err != nil {
retErr := fmt.Errorf("unable to get bucket lifecycle configuration: %w", err)
util.HandleError(c, http.StatusInternalServerError, retErr)
return
}

c.JSON(http.StatusOK, lifecycleConfig)
}

// swagger:operation PUT /api/v1/admin/storage/bucket/lifecycle admin AdminSetBucketLifecycle
//
// Set bucket lifecycle configuration
//
// ---
// produces:
// - application/json
// parameters:
// - in: body
// name: body
// description: The bucket lifecycle configuration
// required: true
// schema:
// type: object
// properties:
// bucketName:
// type: string
// lifecycleConfig:
// type: string
// security:
// - ApiKeyAuth: []
// responses:
// '200':
// description: Successfully set the bucket lifecycle configuration
// '400':
// description: Invalid request payload
// schema:
// "$ref": "#/definitions/Error"
// '500':
// description: Unexpected server error
// schema:
// "$ref": "#/definitions/Error"

// SetBucketLifecycle represents the API handler to set bucket lifecycle configuration.
func SetBucketLifecycle(c *gin.Context) {
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: setting bucket lifecycle configuration")

// capture body from API request
input := new(types.Bucket)

err := c.Bind(input)
if err != nil {
retErr := fmt.Errorf("unable to decode JSON for bucket %s: %w", input.BucketName, err)

util.HandleError(c, http.StatusBadRequest, retErr)

return
}

err = storage.FromGinContext(c).SetBucketLifecycle(ctx, input)
if err != nil {
retErr := fmt.Errorf("unable to set bucket lifecycle configuration: %w", err)
util.HandleError(c, http.StatusInternalServerError, retErr)
return
}

c.Status(http.StatusOK)
}

// swagger:operation GET /api/v1/admin/storage/bucket/download admin DownloadObject
//
// # Download an object from a bucket
//
// ---
// produces:
// - application/json
// parameters:
// - in: query
// name: bucketName
// description: The name of the bucket
// required: true
// type: string
// - in: query
// name: objectName
// description: The name of the object
// required: true
// type: string
//
// security:
// - ApiKeyAuth: []
//
// responses:
//
// '200':
// description: Successfully downloaded the object
// '400':
// description: Invalid request payload
// schema:
// "$ref": "#/definitions/Error"
// '500':
// description: Unexpected server error
// schema:
// "$ref": "#/definitions/Error"
//
// DownloadObject represents the API handler to download an object from a bucket.
func DownloadObject(c *gin.Context) {
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: downloading object")

// capture body from API request
input := new(types.Object)

err := c.Bind(input)
if err != nil {
retErr := fmt.Errorf("unable to decode JSON for object %s: %w", input.ObjectName, err)

util.HandleError(c, http.StatusBadRequest, retErr)

return
}
if input.Bucket.BucketName == "" || input.ObjectName == "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
if statements should only be cuddled with assignments (wsl)

retErr := fmt.Errorf("bucketName and objectName are required")
util.HandleError(c, http.StatusBadRequest, retErr)
return
}
if input.FilePath == "" {
retErr := fmt.Errorf("file path is required")
util.HandleError(c, http.StatusBadRequest, retErr)
return
}
err = storage.FromGinContext(c).Download(ctx, input)
if err != nil {
retErr := fmt.Errorf("unable to download object: %w", err)
util.HandleError(c, http.StatusInternalServerError, retErr)
return
}

c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("File has been downloaded to %s", input.FilePath)})
}

// swagger:operation GET /api/v1/admin/storage/presign admin GetPresignedURL
//
// # Generate a presigned URL for an object
//
// ---
// produces:
// - application/json
// parameters:
// - in: query
// name: bucketName
// description: The name of the bucket
// required: true
// type: string
// - in: query
// name: objectName
// description: The name of the object
// required: true
// type: string
//
// security:
// - ApiKeyAuth: []
//
// responses:
//
// '200':
// description: Successfully generated the presigned URL
// '400':
// description: Invalid request payload
// schema:
// "$ref": "#/definitions/Error"
// '500':
// description: Unexpected server error
// schema:
// "$ref": "#/definitions/Error"
func GetPresignedURL(c *gin.Context) {
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: generating presigned URL")

// capture query parameters from API request
bucketName := c.Query("bucketName")
objectName := c.Query("objectName")

if bucketName == "" || objectName == "" {
retErr := fmt.Errorf("bucketName and objectName are required")
util.HandleError(c, http.StatusBadRequest, retErr)
return
}

input := &types.Object{
Bucket: types.Bucket{BucketName: bucketName},
ObjectName: objectName,
}

url, err := storage.FromGinContext(c).PresignedGetObject(ctx, input)
if err != nil || url == "" {
retErr := fmt.Errorf("unable to generate presigned URL: %w", err)
util.HandleError(c, http.StatusBadRequest, retErr)
return
}

c.JSON(http.StatusOK, url)
}
Loading
Loading