-
Notifications
You must be signed in to change notification settings - Fork 18
/
spec.go
165 lines (139 loc) · 5.76 KB
/
spec.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package toi
import (
"encoding/json"
"fmt"
"github.com/mandelsoft/goutils/errors"
"github.com/open-component-model/ocm/pkg/common"
"github.com/open-component-model/ocm/pkg/contexts/credentials"
"github.com/open-component-model/ocm/pkg/contexts/credentials/cpi"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes"
)
const (
TypeTOIPackage = "toiPackage"
PackageSpecificationMimeType = "application/vnd.toi.ocm.software.package.v1+yaml"
TypeYAML = resourcetypes.OCM_YAML
AdditionalResourceConfigFile = "configFile"
AdditionalResourceCredentialsFile = "credentialsFile"
)
const (
TypeTOIExecutor = "toiExecutor"
ExecutorSpecificationMimeType = "application/vnd.toi.ocm.software.executor.v1+yaml"
)
type PackageSpecification struct {
CredentialsRequest `json:",inline"`
Template json.RawMessage `json:"configTemplate,omitempty"`
Libraries []metav1.ResourceReference `json:"templateLibraries,omitempty"`
Scheme json.RawMessage `json:"configScheme,omitempty"`
Executors []Executor `json:"executors"`
Description string `json:"description"`
AdditionalResources map[string]*AdditionalResource `json:"additionalResources,omitempty"`
}
type AdditionalResource struct {
*metav1.ResourceReference `json:",inline"`
Content json.RawMessage `json:"content,omitempty"`
}
type Executor struct {
Actions []string `json:"actions,omitempty"`
ResourceRef *metav1.ResourceReference `json:"resourceRef,omitempty"`
Image *Image `json:"image,omitempty"`
CredentialMapping map[string]string `json:"credentialMapping,omitempty"`
ParameterMapping json.RawMessage `json:"parameterMapping,omitempty"`
Config json.RawMessage `json:"config,omitempty"`
Outputs map[string]string `json:"outputs,omitempty"`
}
func (e *Executor) Name() string {
if e.ResourceRef != nil {
return e.ResourceRef.String()
}
if e.Image != nil {
return e.Image.String()
}
return "unspecified executor"
}
type Image struct {
Ref string `json:"ref"`
Digest string `json:"digest"`
}
func (i *Image) String() string {
r := "<noref>"
if i.Ref != "" {
r = i.Ref
}
if i.Digest != "" {
r += "@" + i.Digest
}
return r
}
////////////////////////////////////////////////////////////////////////////////
type ExecutorSpecification struct {
CredentialsRequest `json:",inline"`
Actions []string `json:"actions,omitempty"`
Image *Image `json:"image,omitempty"`
ImageRef *metav1.ResourceReference `json:"imageRef,omitempty"`
Template json.RawMessage `json:"configTemplate,omitempty"`
Libraries []metav1.ResourceReference `json:"templateLibraries,omitempty"`
Scheme json.RawMessage `json:"configScheme,omitempty"`
Outputs map[string]OutputSpec `json:"outputs,omitempty"`
}
type OutputSpec struct {
Description string `json:"description,omitempty"`
}
////////////////////////////////////////////////////////////////////////////////
type CredentialsRequest struct {
Credentials map[string]CredentialsRequestSpec `json:"credentials,omitempty"`
}
type CredentialsRequestSpec struct {
// ConsumerId specified to consumer id the credentials are used for
ConsumerId credentials.ConsumerIdentity `json:"consumerId,omitempty"`
// Description described the usecase the credentials will be used for
Description string `json:"description"`
// Properties describes the meaning of the used properties for this
// credential set.
Properties common.Properties `json:"properties"`
// Optional set to true make the request optional
Optional bool `json:"optional,omitempty"`
}
var ErrUndefined error = errors.New("nil reference")
func (s *CredentialsRequestSpec) Match(o *CredentialsRequestSpec) error {
if o == nil {
return ErrUndefined
}
if !s.ConsumerId.Equals(o.ConsumerId) {
return fmt.Errorf("consumer id mismatch")
}
for k := range o.Properties {
if _, ok := s.Properties[k]; !ok {
return fmt.Errorf("property %q not declared", k)
}
}
if s.Optional && !o.Optional {
return fmt.Errorf("cannot be optional")
}
return nil
}
type Credentials struct {
Credentials map[string]CredentialSpec `json:"credentials,omitempty"`
// Forwarded may define a list of consumer ids, which should be taken from the
// local configuration and forwarded to the TOI executor in addition to the
// credentials explicitly requested by the installation package.
Forwarded []ForwardSpec `json:"forwardedConsumers,omitempty"`
}
type CredentialSpec struct {
// ConsumerId specifies the consumer id to look for the credentials
ConsumerId credentials.ConsumerIdentity `json:"consumerId,omitempty"`
// ConsumerType is the optional type used for matching the credentials
ConsumerType string `json:"consumerType,omitempty"`
// Reference refers to credentials store in some other repo
Reference *cpi.GenericCredentialsSpec `json:"reference,omitempty"`
// Credentials are direct credentials (one of Reference or Credentials must be set)
Credentials common.Properties `json:"credentials,omitempty"`
// TargetConsumerId specifies the consumer id to feed with these credentials
TargetConsumerId credentials.ConsumerIdentity `json:"targetConsumerId,omitempty"`
}
type ForwardSpec struct {
// ConsumerId specifies the consumer id to look for the credentials
ConsumerId credentials.ConsumerIdentity `json:"consumerId"`
// ConsumerType is the optional type used for matching the credentials
ConsumerType string `json:"consumerType,omitempty"`
}