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 (
|
2020-08-11 15:50:01 +01:00
|
|
|
// ErrStaticSource is an error class for static source errors.
|
2019-11-15 23:57:40 +00:00
|
|
|
ErrStaticSource = errs.Class("static source")
|
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// StaticURLSource is a trust source that returns an explicitly trusted URL.
|
2019-11-16 00:59:32 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01: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
|
|
|
|
}
|