MCPcopy
hub / github.com/perkeep/perkeep / newFromConfig

Function newFromConfig

pkg/blobserver/remote/remote.go:66–99  ·  view source on GitHub ↗
(_ blobserver.Loader, config jsonconfig.Obj)

Source from the content-addressed store, hash-verified

64}
65
66func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (storage blobserver.Storage, err error) {
67 url := config.RequiredString("url")
68 auth := config.RequiredString("auth")
69 skipStartupCheck := config.OptionalBool("skipStartupCheck", false)
70 trustedCert := config.OptionalString("trustedCert", "")
71 if err := config.Validate(); err != nil {
72 return nil, err
73 }
74
75 client, err := client.New(
76 client.OptionServer(url),
77 client.OptionTrustedCert(trustedCert),
78 )
79 if err != nil {
80 return nil, err
81 }
82 if err = client.SetupAuthFromString(auth); err != nil {
83 return nil, err
84 }
85 sto := &remoteStorage{
86 client: client,
87 }
88 if !skipStartupCheck {
89 // Do a quick dummy operation to check that our credentials are
90 // correct.
91 // TODO(bradfitz,mpl): skip this operation smartly if it turns out this is annoying/slow for whatever reason.
92 c := make(chan blob.SizedRef, 1)
93 err = sto.EnumerateBlobs(context.TODO(), c, "", 1)
94 if err != nil {
95 return nil, err
96 }
97 }
98 return sto, nil
99}
100
101func (sto *remoteStorage) Close() error {
102 return sto.client.Close()

Callers

nothing calls this directly

Calls 5

EnumerateBlobsMethod · 0.95
NewFunction · 0.92
OptionServerFunction · 0.92
OptionTrustedCertFunction · 0.92
SetupAuthFromStringMethod · 0.80

Tested by

no test coverage detected