2019-11-15 23:57:40 +00:00
|
|
|
// 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")
|
|
|
|
)
|
|
|
|
|
2019-11-16 00:59:32 +00:00
|
|
|
// StaticURLSource is a trust source that returns an explicitly trusted URL
|
|
|
|
type StaticURLSource struct {
|
|
|
|
URL SatelliteURL
|
2019-11-15 23:57:40 +00:00
|
|
|
}
|
|
|
|
|
2019-11-16 00:59:32 +00:00
|
|
|
// NewStaticURLSource takes an explicitly trusted URL and returns a new StaticURLSource.
|
|
|
|
func NewStaticURLSource(satelliteURL string) (*StaticURLSource, error) {
|
2019-11-15 23:57:40 +00:00
|
|
|
url, err := ParseSatelliteURL(satelliteURL)
|
|
|
|
if err != nil {
|
|
|
|
return nil, ErrStaticSource.Wrap(err)
|
|
|
|
}
|
2019-11-16 00:59:32 +00:00
|
|
|
return &StaticURLSource{URL: url}, nil
|
2019-11-15 23:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// String implements the Source interface and returns the static trusted URL
|
2019-11-16 00:59:32 +00:00
|
|
|
func (source *StaticURLSource) String() string {
|
|
|
|
return source.URL.String()
|
2019-11-15 23:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Static implements the Source interface. It returns true.
|
2019-11-16 00:59:32 +00:00
|
|
|
func (source *StaticURLSource) Static() bool { return true }
|
2019-11-15 23:57:40 +00:00
|
|
|
|
|
|
|
// FetchEntries returns a trust entry for the explicitly trusted Satellite URL.
|
|
|
|
// The entry is authoritative.
|
2019-11-16 00:59:32 +00:00
|
|
|
func (source *StaticURLSource) FetchEntries(ctx context.Context) ([]Entry, error) {
|
2019-11-15 23:57:40 +00:00
|
|
|
return []Entry{
|
2019-11-16 00:59:32 +00:00
|
|
|
{SatelliteURL: source.URL, Authoritative: true},
|
2019-11-15 23:57:40 +00:00
|
|
|
}, nil
|
|
|
|
}
|