feat(secrets): allow description-only updates and show global secrets
Enables updating secret descriptions without changing the value by making the data field optional during updates. Displays global secrets as read-only in org/user/repo secret pages for visibility. Adds validation to require data only when creating new secrets. Updates locale strings for the new functionality.
This commit is contained in:
@@ -322,10 +322,11 @@ func (f *AddKeyForm) Validate(req *http.Request, errs binding.Errors) binding.Er
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
}
|
||||
|
||||
// AddSecretForm for adding secrets
|
||||
// AddSecretForm for adding or updating secrets
|
||||
// Note: Data is optional when updating (to allow description-only updates)
|
||||
type AddSecretForm struct {
|
||||
Name string `binding:"Required;MaxSize(255)"`
|
||||
Data string `binding:"Required;MaxSize(65535)"`
|
||||
Data string `binding:"MaxSize(65535)"`
|
||||
Description string `binding:"MaxSize(65535)"`
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,11 @@ package secrets
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitcaddy.com/server/v3/models/db"
|
||||
secret_model "code.gitcaddy.com/server/v3/models/secret"
|
||||
"code.gitcaddy.com/server/v3/modules/util"
|
||||
)
|
||||
|
||||
func CreateOrUpdateSecret(ctx context.Context, ownerID, repoID int64, name, data, description string) (*secret_model.Secret, bool, error) {
|
||||
@@ -25,6 +27,10 @@ func CreateOrUpdateSecret(ctx context.Context, ownerID, repoID int64, name, data
|
||||
}
|
||||
|
||||
if len(s) == 0 {
|
||||
// Creating new secret - data is required
|
||||
if data == "" {
|
||||
return nil, false, fmt.Errorf("%w: secret value is required for new secrets", util.ErrInvalidArgument)
|
||||
}
|
||||
s, err := secret_model.InsertEncryptedSecret(ctx, ownerID, repoID, name, data, description)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
@@ -32,6 +38,7 @@ func CreateOrUpdateSecret(ctx context.Context, ownerID, repoID int64, name, data
|
||||
return s, true, nil
|
||||
}
|
||||
|
||||
// Updating existing secret - data is optional (description-only update allowed)
|
||||
if err := secret_model.UpdateSecret(ctx, s[0].ID, data, description); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -55,6 +62,10 @@ func CreateOrUpdateGlobalSecret(ctx context.Context, name, data, description str
|
||||
}
|
||||
|
||||
if len(s) == 0 {
|
||||
// Creating new secret - data is required
|
||||
if data == "" {
|
||||
return nil, false, fmt.Errorf("%w: secret value is required for new secrets", util.ErrInvalidArgument)
|
||||
}
|
||||
// Insert with ownerID=0, repoID=0 for global secret
|
||||
s, err := secret_model.InsertEncryptedSecret(ctx, 0, 0, name, data, description)
|
||||
if err != nil {
|
||||
@@ -63,6 +74,7 @@ func CreateOrUpdateGlobalSecret(ctx context.Context, name, data, description str
|
||||
return s, true, nil
|
||||
}
|
||||
|
||||
// Updating existing secret - data is optional (description-only update allowed)
|
||||
if err := secret_model.UpdateSecret(ctx, s[0].ID, data, description); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user