-
Notifications
You must be signed in to change notification settings - Fork 62
/
manifest_options.go
70 lines (60 loc) · 2.31 KB
/
manifest_options.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
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file expect in compliance with the License.
package manifest
import (
"kraftkit.sh/config"
)
// ManifestOptions contains a set of additional configuration necessary for the
// underlying ManifestProvider implementation that are not attributes of the
// provider itself.
type ManifestOptions struct {
// cacheDir sets the location of component archives which are stored locally.
cacheDir string
// auths is an internal property set by a ManifestOption which is used by the
// Manifest to access information a bout itself aswell as downloading a given
// resource
auths map[string]config.AuthConfig
// update is a switch to enable or prevent remote connections when
// instantiating a Manifest(Index) or when probing sources, versions, etc.
update bool
// opts saves the options that were used to instantiated this ManifestOptions
// struct.
opts []ManifestOption
}
type ManifestOption func(*ManifestOptions)
// NewManifestOptions returns an instantiated ManifestOptions based on variable
// input number of ManifestOption methods.
func NewManifestOptions(opts ...ManifestOption) *ManifestOptions {
mopts := ManifestOptions{
opts: opts, // Save the list of options in case they are required elsewhere.
}
for _, opt := range opts {
opt(&mopts)
}
return &mopts
}
// WithAuthConfig sets any required authentication necessary for accessing the
// manifest.
func WithAuthConfig(auths map[string]config.AuthConfig) ManifestOption {
return func(mopts *ManifestOptions) {
mopts.auths = auths
}
}
// WithCacheDir is an option which helps find cached Manifest Channel or Version
// resources. When set to a directory, the fixed structure of this directory
// should allow us to look up (and also store) resources here for later use.
func WithCacheDir(dir string) ManifestOption {
return func(mopts *ManifestOptions) {
mopts.cacheDir = dir
}
}
// WithUpdate is an option to indicate that remote network connections
// can be made when instantiating a Manifest(Index) or to allow probing remote
// sources to determine versions, etc.
func WithUpdate(update bool) ManifestOption {
return func(mopts *ManifestOptions) {
mopts.update = update
}
}