-
Notifications
You must be signed in to change notification settings - Fork 390
/
static_source.go
45 lines (36 loc) · 1.22 KB
/
static_source.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package trust
import (
"context"
"github.com/zeebo/errs"
)
var (
// ErrStaticSource is an error class for static source errors
ErrStaticSource = errs.Class("static source")
)
// StaticURLSource is a trust source that returns an explicitly trusted URL
type StaticURLSource struct {
URL SatelliteURL
}
// NewStaticURLSource takes an explicitly trusted URL and returns a new StaticURLSource.
func NewStaticURLSource(satelliteURL string) (*StaticURLSource, error) {
url, err := ParseSatelliteURL(satelliteURL)
if err != nil {
return nil, ErrStaticSource.Wrap(err)
}
return &StaticURLSource{URL: url}, nil
}
// String implements the Source interface and returns the static trusted URL
func (source *StaticURLSource) String() string {
return source.URL.String()
}
// Static implements the Source interface. It returns true.
func (source *StaticURLSource) Static() bool { return true }
// FetchEntries returns a trust entry for the explicitly trusted Satellite URL.
// The entry is authoritative.
func (source *StaticURLSource) FetchEntries(ctx context.Context) ([]Entry, error) {
return []Entry{
{SatelliteURL: source.URL, Authoritative: true},
}, nil
}