-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
126 lines (100 loc) · 4.45 KB
/
interface.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2015 The LUCI Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"context"
"errors"
"net/url"
)
// ErrNoConfig is returned if requested config does not exist.
var ErrNoConfig = errors.New("no such config")
// Meta is metadata about a single configuration file.
type Meta struct {
// ConfigSet is the config set name (e.g. "projects/<id>") this config
// belongs to.
ConfigSet Set `json:"configSet,omitempty"`
// Path is the filename relative to the root of the config set,
// without leading slash, e.g. "luci-scheduler.cfg".
Path string `json:"path,omitempty"`
// ContentHash can be used to quickly check that content didn't change.
ContentHash string `json:"contentHash,omitempty"`
// Revision is git SHA1 of a repository the config was fetched from.
Revision string `json:"revision,omitempty"`
// ViewURL is the URL surfaced for viewing the config.
ViewURL string `json:"view_url,omitempty"`
}
// Config is a configuration file along with its metadata.
type Config struct {
Meta
// Error is not nil if there where troubles fetching this config. Used only
// by functions that operate with multiple configs at once, such as
// GetProjectConfigs and GetRefConfigs.
Error error `json:"error,omitempty"`
// Content is the actual body of the config file.
Content string `json:"content,omitempty"`
}
// RepoType is the type of the repo the Project is stored in.
type RepoType string
const (
// GitilesRepo means a repo is backed by the Gitiles service.
GitilesRepo RepoType = "GITILES"
// UnknownRepo means a repo is backed by an unknown service.
// It may be an invalid repo.
UnknownRepo RepoType = "UNKNOWN"
)
// Project is a project registered in the luci-config service.
type Project struct {
// ID is unique project identifier.
ID string
// Name is a short friendly display name of the project.
Name string
// RepoType specifies in what kind of storage projects configs are stored.
RepoType RepoType
// RepoUrl is the location of this project code repository. May be nil if
// unknown or cannot be parsed.
RepoURL *url.URL
}
// Interface represents low-level pull-based LUCI Config API.
//
// This is roughly a wrapper over LUCI Config RPC interface, and all methods
// are generally slow and depend on available of LUCI Config service. They
// *must not* be used in a hot path of requests.
//
// Transient errors are tagged with transient.Tag.
type Interface interface {
// GetConfig returns a config at a path in a config set or ErrNoConfig
// if missing. If metaOnly is true, returned Config struct has only Meta set
// (and the call is faster).
GetConfig(ctx context.Context, configSet Set, path string, metaOnly bool) (*Config, error)
// GetConfigByHash returns the contents of a config, as identified by its
// content hash, or ErrNoConfig if missing.
GetConfigByHash(ctx context.Context, contentHash string) (string, error)
// GetConfigSetLocation returns the URL location of a config set.
GetConfigSetLocation(ctx context.Context, configSet Set) (*url.URL, error)
// GetProjectConfigs returns all the configs at the given path in all
// projects that have such config. If metaOnly is true, returned Config
// structs have only Meta set (and the call is faster).
GetProjectConfigs(ctx context.Context, path string, metaOnly bool) ([]Config, error)
// GetProjects returns all the registered projects in the configuration
// service.
GetProjects(ctx context.Context) ([]Project, error)
// GetRefConfigs returns the config at the given path in all refs of all
// projects that have such config. If metaOnly is true, returned Config
// structs have only Meta set (and the call is faster).
GetRefConfigs(ctx context.Context, path string, metaOnly bool) ([]Config, error)
// GetRefs returns the list of refs for a project.
GetRefs(ctx context.Context, projectID string) ([]string, error)
// ListFiles returns the list of files for a config set.
ListFiles(ctx context.Context, configSet Set) ([]string, error)
}