mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-21 20:46:50 +00:00
wip enable pluggable secret and registry backends
This commit is contained in:
38
plugins/registry/builtin.go
Normal file
38
plugins/registry/builtin.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/model"
|
||||
)
|
||||
|
||||
type builtin struct {
|
||||
store model.RegistryStore
|
||||
}
|
||||
|
||||
// New returns a new local registry service.
|
||||
func New(store model.RegistryStore) model.RegistryService {
|
||||
return &builtin{store}
|
||||
}
|
||||
|
||||
func (b *builtin) RegistryFind(repo *model.Repo, name string) (*model.Registry, error) {
|
||||
return b.store.RegistryFind(repo, name)
|
||||
}
|
||||
|
||||
func (b *builtin) RegistryList(repo *model.Repo) ([]*model.Registry, error) {
|
||||
return b.store.RegistryList(repo)
|
||||
}
|
||||
|
||||
func (b *builtin) RegistryCreate(repo *model.Repo, in *model.Registry) error {
|
||||
return b.store.RegistryCreate(in)
|
||||
}
|
||||
|
||||
func (b *builtin) RegistryUpdate(repo *model.Repo, in *model.Registry) error {
|
||||
return b.store.RegistryUpdate(in)
|
||||
}
|
||||
|
||||
func (b *builtin) RegistryDelete(repo *model.Repo, addr string) error {
|
||||
registry, err := b.RegistryFind(repo, addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.store.RegistryDelete(registry)
|
||||
}
|
1
plugins/registry/builtin_test.go
Normal file
1
plugins/registry/builtin_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package registry
|
46
plugins/registry/plugin.go
Normal file
46
plugins/registry/plugin.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/drone/drone/model"
|
||||
"github.com/drone/drone/plugins/internal"
|
||||
)
|
||||
|
||||
type plugin struct {
|
||||
endpoint string
|
||||
}
|
||||
|
||||
// NewRemote returns a new remote registry service.
|
||||
func NewRemote(endpoint string) model.RegistryService {
|
||||
return &plugin{endpoint}
|
||||
}
|
||||
|
||||
func (p *plugin) RegistryFind(repo *model.Repo, name string) (*model.Registry, error) {
|
||||
path := fmt.Sprintf("%s/registry/%s/%s/%s", p.endpoint, repo.Owner, repo.Name, name)
|
||||
out := new(model.Registry)
|
||||
err := internal.Send("GET", path, nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (p *plugin) RegistryList(repo *model.Repo) ([]*model.Registry, error) {
|
||||
path := fmt.Sprintf("%s/registry/%s/%s", p.endpoint, repo.Owner, repo.Name)
|
||||
out := []*model.Registry{}
|
||||
err := internal.Send("GET", path, nil, out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (p *plugin) RegistryCreate(repo *model.Repo, in *model.Registry) error {
|
||||
path := fmt.Sprintf("%s/registry/%s/%s", p.endpoint, repo.Owner, repo.Name)
|
||||
return internal.Send("PATCH", path, in, nil)
|
||||
}
|
||||
|
||||
func (p *plugin) RegistryUpdate(repo *model.Repo, in *model.Registry) error {
|
||||
path := fmt.Sprintf("%s/registry/%s/%s/%s", p.endpoint, repo.Owner, repo.Name, in.Address)
|
||||
return internal.Send("PATCH", path, in, nil)
|
||||
}
|
||||
|
||||
func (p *plugin) RegistryDelete(repo *model.Repo, name string) error {
|
||||
path := fmt.Sprintf("%s/registry/%s/%s/%s", p.endpoint, repo.Owner, repo.Name, name)
|
||||
return internal.Send("DELETE", path, nil, nil)
|
||||
}
|
1
plugins/registry/plugin_test.go
Normal file
1
plugins/registry/plugin_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package registry
|
Reference in New Issue
Block a user