Skip to content

Commit

Permalink
Implement service and model changes for global/organization registries
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Jul 2, 2024
1 parent d72a44d commit 315a3c4
Show file tree
Hide file tree
Showing 18 changed files with 638 additions and 84 deletions.
6 changes: 6 additions & 0 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4376,9 +4376,15 @@ const docTemplate = `{
"id": {
"type": "integer"
},
"org_id": {
"type": "integer"
},
"password": {
"type": "string"
},
"repo_id": {
"type": "integer"
},
"username": {
"type": "string"
}
Expand Down
44 changes: 22 additions & 22 deletions pipeline/rpc/proto/woodpecker.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions server/model/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ var (
// Registry represents a docker registry with credentials.
type Registry struct {
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'repo_id'"`
Address string `json:"address" xorm:"UNIQUE(s) INDEX 'address'"`
OrgID int64 `json:"org_id" xorm:"NOT NULL DEFAULT 0 UNIQUE(s) INDEX 'org_id'"`
RepoID int64 `json:"repo_id" xorm:"NOT NULL DEFAULT 0 UNIQUE(s) INDEX 'repo_id'"`
Address string `json:"address" xorm:"NOT NULL UNIQUE(s) INDEX 'address'"`
Username string `json:"username" xorm:"varchar(2000) 'username'"`
Password string `json:"password" xorm:"TEXT 'password'"`
} // @name Registry
Expand All @@ -39,6 +40,21 @@ func (r Registry) TableName() string {
return "registries"
}

// Global secret.
func (r Registry) IsGlobal() bool {
return r.RepoID == 0 && r.OrgID == 0
}

// Organization secret.
func (r Registry) IsOrganization() bool {
return r.RepoID == 0 && r.OrgID != 0
}

// Repository secret.
func (r Registry) IsRepository() bool {
return r.RepoID != 0 && r.OrgID == 0
}

// Validate validates the registry information.
func (r *Registry) Validate() error {
switch {
Expand All @@ -58,6 +74,7 @@ func (r *Registry) Validate() error {
func (r *Registry) Copy() *Registry {
return &Registry{
ID: r.ID,
OrgID: r.OrgID,
RepoID: r.RepoID,
Address: r.Address,
Username: r.Username,
Expand Down
4 changes: 2 additions & 2 deletions server/pipeline/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func parsePipeline(forge forge.Forge, store store.Store, currentPipeline *model.
}

secretService := server.Config.Services.Manager.SecretServiceFromRepo(repo)
secs, err := secretService.SecretListPipeline(repo, currentPipeline, &model.ListOptions{All: true})
secs, err := secretService.SecretListPipeline(repo, currentPipeline)
if err != nil {
log.Error().Err(err).Msgf("error getting secrets for %s#%d", repo.FullName, currentPipeline.Number)
}

registryService := server.Config.Services.Manager.RegistryServiceFromRepo(repo)
regs, err := registryService.RegistryList(repo, &model.ListOptions{All: true})
regs, err := registryService.RegistryListPipeline(repo, currentPipeline)
if err != nil {
log.Error().Err(err).Msgf("error getting registry credentials for %s#%d", repo.FullName, currentPipeline.Number)
}
Expand Down
Loading

0 comments on commit 315a3c4

Please sign in to comment.