Moved merged secret list into store
This commit is contained in:
parent
298dcd5a50
commit
4d43195479
3 changed files with 25 additions and 83 deletions
|
@ -1,33 +0,0 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/model"
|
||||
)
|
||||
|
||||
func (db *datastore) GetMergedSecretList(repo *model.Repo) ([]*model.Secret, error) {
|
||||
var (
|
||||
secrets []*model.Secret
|
||||
)
|
||||
|
||||
repoSecs, err := db.GetSecretList(repo)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, secret := range repoSecs {
|
||||
secrets = append(secrets, secret.Secret())
|
||||
}
|
||||
|
||||
teamSecs, err := db.GetTeamSecretList(repo.Owner)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, secret := range teamSecs {
|
||||
secrets = append(secrets, secret.Secret())
|
||||
}
|
||||
|
||||
return secrets, nil
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/drone/drone/model"
|
||||
"github.com/franela/goblin"
|
||||
)
|
||||
|
||||
func TestSecrets(t *testing.T) {
|
||||
db := openTest()
|
||||
defer db.Close()
|
||||
|
||||
s := From(db)
|
||||
g := goblin.Goblin(t)
|
||||
g.Describe("Secrets", func() {
|
||||
|
||||
// before each test be sure to purge the package
|
||||
// table data from the database.
|
||||
g.BeforeEach(func() {
|
||||
db.Exec(rebind("DELETE FROM secrets"))
|
||||
db.Exec(rebind("DELETE FROM team_secrets"))
|
||||
})
|
||||
|
||||
g.It("Should list all secrets", func() {
|
||||
teamSec := &model.TeamSecret{
|
||||
Key: "octocat",
|
||||
Name: "foo",
|
||||
Value: "team",
|
||||
}
|
||||
|
||||
repoSec := &model.RepoSecret{
|
||||
RepoID: 1,
|
||||
Name: "foo",
|
||||
Value: "repo",
|
||||
}
|
||||
|
||||
s.SetSecret(repoSec)
|
||||
s.SetTeamSecret(teamSec)
|
||||
|
||||
secrets, err := s.GetMergedSecretList(&model.Repo{ID: 1, Owner: "octocat"})
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(len(secrets)).Equal(2)
|
||||
})
|
||||
})
|
||||
}
|
|
@ -82,9 +82,6 @@ type Store interface {
|
|||
// DeleteTeamSecret deletes the named team secret.
|
||||
DeleteTeamSecret(*model.TeamSecret) error
|
||||
|
||||
// GetMergedSecretList gets a list of repo and team secrets
|
||||
GetMergedSecretList(*model.Repo) ([]*model.Secret, error)
|
||||
|
||||
// GetBuild gets a build by unique ID.
|
||||
GetBuild(int64) (*model.Build, error)
|
||||
|
||||
|
@ -250,7 +247,31 @@ func DeleteTeamSecret(c context.Context, s *model.TeamSecret) error {
|
|||
}
|
||||
|
||||
func GetMergedSecretList(c context.Context, r *model.Repo) ([]*model.Secret, error) {
|
||||
return FromContext(c).GetMergedSecretList(r)
|
||||
var (
|
||||
secrets []*model.Secret
|
||||
)
|
||||
|
||||
repoSecs, err := FromContext(c).GetSecretList(r)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, secret := range repoSecs {
|
||||
secrets = append(secrets, secret.Secret())
|
||||
}
|
||||
|
||||
teamSecs, err := FromContext(c).GetTeamSecretList(r.Owner)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, secret := range teamSecs {
|
||||
secrets = append(secrets, secret.Secret())
|
||||
}
|
||||
|
||||
return secrets, nil
|
||||
}
|
||||
|
||||
func GetBuild(c context.Context, id int64) (*model.Build, error) {
|
||||
|
|
Loading…
Reference in a new issue