mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
113 lines
3.0 KiB
Go
113 lines
3.0 KiB
Go
package gpgkey
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
gpgkeypkg "github.com/hanzoai/cd/pkg/apiclient/gpgkey"
|
|
appsv1 "github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
"github.com/hanzoai/cd/util/db"
|
|
"github.com/hanzoai/cd/util/rbac"
|
|
"github.com/hanzoai/cd/util/sourceintegrity"
|
|
)
|
|
|
|
// Server provides a service of type GPGKeyService
|
|
type Server struct {
|
|
db db.DB
|
|
enf *rbac.Enforcer
|
|
}
|
|
|
|
// NewServer returns a new instance of the service with type GPGKeyService
|
|
func NewServer(db db.DB, enf *rbac.Enforcer) *Server {
|
|
return &Server{
|
|
db: db,
|
|
enf: enf,
|
|
}
|
|
}
|
|
|
|
// List a list of GnuPG public keys in the configuration
|
|
func (s *Server) List(ctx context.Context, _ *gpgkeypkg.GnuPGPublicKeyQuery) (*appsv1.GnuPGPublicKeyList, error) {
|
|
if err := s.enf.EnforceErr(ctx.Value("claims"), rbac.ResourceGPGKeys, rbac.ActionGet, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
keys, err := s.db.ListConfiguredGPGPublicKeys(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
keyList := &appsv1.GnuPGPublicKeyList{}
|
|
for _, v := range keys {
|
|
// Remove key's data from list result to save some bytes
|
|
v.KeyData = ""
|
|
keyList.Items = append(keyList.Items, *v)
|
|
}
|
|
return keyList, nil
|
|
}
|
|
|
|
// Get retrieves a single GPG public key from the configuration
|
|
func (s *Server) Get(ctx context.Context, q *gpgkeypkg.GnuPGPublicKeyQuery) (*appsv1.GnuPGPublicKey, error) {
|
|
if err := s.enf.EnforceErr(ctx.Value("claims"), rbac.ResourceGPGKeys, rbac.ActionGet, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
keyID, err := sourceintegrity.KeyID(q.KeyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
keys, err := s.db.ListConfiguredGPGPublicKeys(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if key, ok := keys[keyID]; ok {
|
|
return key, nil
|
|
}
|
|
|
|
return nil, fmt.Errorf("no such key: %s", keyID)
|
|
}
|
|
|
|
// Create adds one or more GPG public keys to the server's configuration
|
|
func (s *Server) Create(ctx context.Context, q *gpgkeypkg.GnuPGPublicKeyCreateRequest) (*gpgkeypkg.GnuPGPublicKeyCreateResponse, error) {
|
|
if err := s.enf.EnforceErr(ctx.Value("claims"), rbac.ResourceGPGKeys, rbac.ActionCreate, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
keyData := strings.TrimSpace(q.Publickey.KeyData)
|
|
if keyData == "" {
|
|
return nil, errors.New("submitted key data is empty")
|
|
}
|
|
|
|
added, skipped, err := s.db.AddGPGPublicKey(ctx, q.Publickey.KeyData)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
items := make([]appsv1.GnuPGPublicKey, 0)
|
|
for _, k := range added {
|
|
items = append(items, *k)
|
|
}
|
|
|
|
response := &gpgkeypkg.GnuPGPublicKeyCreateResponse{
|
|
Created: &appsv1.GnuPGPublicKeyList{Items: items},
|
|
Skipped: skipped,
|
|
}
|
|
|
|
return response, nil
|
|
}
|
|
|
|
// Delete removes a single GPG public key from the server's configuration
|
|
func (s *Server) Delete(ctx context.Context, q *gpgkeypkg.GnuPGPublicKeyQuery) (*gpgkeypkg.GnuPGPublicKeyResponse, error) {
|
|
if err := s.enf.EnforceErr(ctx.Value("claims"), rbac.ResourceGPGKeys, rbac.ActionDelete, ""); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err := s.db.DeleteGPGPublicKey(ctx, q.KeyID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &gpgkeypkg.GnuPGPublicKeyResponse{}, nil
|
|
}
|