-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo_factory.go
45 lines (38 loc) · 1.11 KB
/
repo_factory.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
package main
import (
"github.com/spf13/viper"
"net/http"
"github.com/theupdateframework/notary"
"github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/tuf/data"
)
const remoteConfigField = "api"
// RepoFactory takes a GUN and returns an initialized client.Repository, or an error.
type RepoFactory func(gun data.GUN) (client.Repository, error)
// ConfigureRepo takes in the configuration parameters and returns a repoFactory that can
// initialize new client.Repository objects with the correct upstreams and password
// retrieval mechanisms.
func ConfigureRepo(v *viper.Viper, retriever notary.PassRetriever, onlineOperation bool) RepoFactory {
localRepo := func(gun data.GUN) (client.Repository, error) {
var rt http.RoundTripper
trustPin, err := getTrustPinning(v)
if err != nil {
return nil, err
}
if onlineOperation {
rt, err = getTransport(v, gun, admin)
if err != nil {
return nil, err
}
}
return client.NewFileCachedRepository(
v.GetString("trust_dir"),
gun,
getRemoteTrustServer(v),
rt,
retriever,
trustPin,
)
}
return localRepo
}