-
Notifications
You must be signed in to change notification settings - Fork 107
/
notary.go
50 lines (40 loc) · 1.15 KB
/
notary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package harbor
import (
"github.com/goharbor/harbor-operator/pkg/config"
"github.com/ovh/configstore"
"github.com/pkg/errors"
)
const NotaryMigrationGithubCredentialsConfigKey = "notary-migration-github-credentials"
const NotaryMigrationGithubSourceConfigKey = "notary-migration-github-source"
type GithubSource struct {
Owner string `json:"owner"`
Repository string `json:"repository"`
Path string `json:"path"`
Reference string `json:"reference"`
}
func (r *Reconciler) GetDefaultNotaryMigrationSource() (*GithubSource, error) {
defaultSource := GithubSource{
Owner: "theupdateframework",
Repository: "notary",
Path: "/migrations/server/postgresql",
Reference: "v0.6.1",
}
item, err := configstore.Filter().
Slice(NotaryMigrationGithubSourceConfigKey).
Unmarshal(func() interface{} {
copy := defaultSource
return ©
}).
GetFirstItem()
if err != nil {
if config.IsNotFound(err, NotaryMigrationGithubSourceConfigKey) {
return &defaultSource, nil
}
return nil, err
}
config, err := item.Unmarshaled()
if err != nil {
return nil, errors.Wrap(err, "invalid")
}
return config.(*GithubSource), nil
}