1// Copyright (C) 2019 Storj Labs, Inc.
2// See LICENSE for copying information.
3
4package trust
5
6import (
7	"context"
8
9	"github.com/zeebo/errs"
10)
11
12var (
13	// ErrStaticSource is an error class for static source errors.
14	ErrStaticSource = errs.Class("static source")
15)
16
17// StaticURLSource is a trust source that returns an explicitly trusted URL.
18type StaticURLSource struct {
19	URL SatelliteURL
20}
21
22// NewStaticURLSource takes an explicitly trusted URL and returns a new StaticURLSource.
23func NewStaticURLSource(satelliteURL string) (*StaticURLSource, error) {
24	url, err := ParseSatelliteURL(satelliteURL)
25	if err != nil {
26		return nil, ErrStaticSource.Wrap(err)
27	}
28	return &StaticURLSource{URL: url}, nil
29}
30
31// String implements the Source interface and returns the static trusted URL.
32func (source *StaticURLSource) String() string {
33	return source.URL.String()
34}
35
36// Static implements the Source interface. It returns true.
37func (source *StaticURLSource) Static() bool { return true }
38
39// FetchEntries returns a trust entry for the explicitly trusted Satellite URL.
40// The entry is authoritative.
41func (source *StaticURLSource) FetchEntries(ctx context.Context) ([]Entry, error) {
42	return []Entry{
43		{SatelliteURL: source.URL, Authoritative: true},
44	}, nil
45}
46