/
restricted.go
287 lines (222 loc) · 9.47 KB
/
restricted.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Copyright 2012-2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuc
import (
"time"
"github.com/juju/charm/v12"
"github.com/juju/errors"
"github.com/juju/names/v5"
"github.com/juju/juju/core/application"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/payloads"
"github.com/juju/juju/core/secrets"
"github.com/juju/juju/rpc/params"
)
// ErrRestrictedContext indicates a method is not implemented in the given context.
var ErrRestrictedContext = errors.NotImplementedf("not implemented for restricted context")
// RestrictedContext is a base implementation for restricted contexts to embed,
// so that an error is returned for methods that are not explicitly
// implemented.
type RestrictedContext struct{}
// ConfigSettings implements hooks.Context.
func (*RestrictedContext) ConfigSettings() (charm.Settings, error) { return nil, ErrRestrictedContext }
// GoalState implements hooks.Context.
func (*RestrictedContext) GoalState() (*application.GoalState, error) {
return &application.GoalState{}, ErrRestrictedContext
}
// GetCharmState implements jujuc.unitCharmStateContext.
func (*RestrictedContext) GetCharmState() (map[string]string, error) {
return nil, ErrRestrictedContext
}
// GetCharmStateValue implements jujuc.unitCharmStateContext.
func (*RestrictedContext) GetCharmStateValue(string) (string, error) {
return "", ErrRestrictedContext
}
// DeleteCharmStateValue implements jujuc.unitCharmStateContext.
func (*RestrictedContext) DeleteCharmStateValue(string) error {
return ErrRestrictedContext
}
// SetCharmStateValue implements jujuc.unitCharmStateContext.
func (*RestrictedContext) SetCharmStateValue(string, string) error {
return ErrRestrictedContext
}
// UnitStatus implements hooks.Context.
func (*RestrictedContext) UnitStatus() (*StatusInfo, error) {
return nil, ErrRestrictedContext
}
// SetPodSpec implements hooks.Context.
func (c *RestrictedContext) SetPodSpec(specYaml string) error {
return ErrRestrictedContext
}
// GetPodSpec implements hooks.Context.
func (c *RestrictedContext) GetPodSpec() (string, error) {
return "", ErrRestrictedContext
}
// SetRawK8sSpec implements hooks.Context.
func (c *RestrictedContext) SetRawK8sSpec(specYaml string) error {
return ErrRestrictedContext
}
// GetRawK8sSpec implements hooks.Context.
func (c *RestrictedContext) GetRawK8sSpec() (string, error) {
return "", ErrRestrictedContext
}
// CloudSpec implements hooks.Context.
func (c *RestrictedContext) CloudSpec() (*params.CloudSpec, error) {
return nil, ErrRestrictedContext
}
// SetUnitStatus implements hooks.Context.
func (*RestrictedContext) SetUnitStatus(StatusInfo) error { return ErrRestrictedContext }
// ApplicationStatus implements hooks.Context.
func (*RestrictedContext) ApplicationStatus() (ApplicationStatusInfo, error) {
return ApplicationStatusInfo{}, ErrRestrictedContext
}
// SetApplicationStatus implements hooks.Context.
func (*RestrictedContext) SetApplicationStatus(StatusInfo) error {
return ErrRestrictedContext
}
// AvailabilityZone implements hooks.Context.
func (*RestrictedContext) AvailabilityZone() (string, error) { return "", ErrRestrictedContext }
// RequestReboot implements hooks.Context.
func (*RestrictedContext) RequestReboot(prio RebootPriority) error {
return ErrRestrictedContext
}
// PublicAddress implements hooks.Context.
func (*RestrictedContext) PublicAddress() (string, error) { return "", ErrRestrictedContext }
// PrivateAddress implements hooks.Context.
func (*RestrictedContext) PrivateAddress() (string, error) { return "", ErrRestrictedContext }
// OpenPortRange implements hooks.Context.
func (*RestrictedContext) OpenPortRange(string, network.PortRange) error {
return ErrRestrictedContext
}
// ClosePortRange implements hooks.Context.
func (*RestrictedContext) ClosePortRange(string, network.PortRange) error {
return ErrRestrictedContext
}
// OpenedPortRanges implements hooks.Context.
func (*RestrictedContext) OpenedPortRanges() network.GroupedPortRanges { return nil }
// NetworkInfo implements hooks.Context.
func (*RestrictedContext) NetworkInfo(bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error) {
return map[string]params.NetworkInfoResult{}, ErrRestrictedContext
}
// IsLeader implements hooks.Context.
func (*RestrictedContext) IsLeader() (bool, error) { return false, ErrRestrictedContext }
// LeaderSettings implements hooks.Context.
func (*RestrictedContext) LeaderSettings() (map[string]string, error) {
return nil, ErrRestrictedContext
}
// WriteLeaderSettings implements hooks.Context.
func (*RestrictedContext) WriteLeaderSettings(map[string]string) error { return ErrRestrictedContext }
// AddMetric implements hooks.Context.
func (*RestrictedContext) AddMetric(string, string, time.Time) error { return ErrRestrictedContext }
// AddMetricLabels implements hooks.Context.
func (*RestrictedContext) AddMetricLabels(string, string, time.Time, map[string]string) error {
return ErrRestrictedContext
}
// StorageTags implements hooks.Context.
func (*RestrictedContext) StorageTags() ([]names.StorageTag, error) { return nil, ErrRestrictedContext }
// Storage implements hooks.Context.
func (*RestrictedContext) Storage(names.StorageTag) (ContextStorageAttachment, error) {
return nil, ErrRestrictedContext
}
// HookStorage implements hooks.Context.
func (*RestrictedContext) HookStorage() (ContextStorageAttachment, error) {
return nil, ErrRestrictedContext
}
// AddUnitStorage implements hooks.Context.
func (*RestrictedContext) AddUnitStorage(map[string]params.StorageConstraints) error {
return ErrRestrictedContext
}
// DownloadResource implements hooks.Context.
func (ctx *RestrictedContext) DownloadResource(name string) (filePath string, _ error) {
return "", ErrRestrictedContext
}
// GetPayload implements hooks.Context.
func (ctx *RestrictedContext) GetPayload(class, id string) (*payloads.Payload, error) {
return nil, ErrRestrictedContext
}
// TrackPayload implements hooks.Context.
func (ctx *RestrictedContext) TrackPayload(payload payloads.Payload) error {
return ErrRestrictedContext
}
// UntrackPayload implements hooks.Context.
func (ctx *RestrictedContext) UntrackPayload(class, id string) error {
return ErrRestrictedContext
}
// SetPayloadStatus implements hooks.Context.
func (ctx *RestrictedContext) SetPayloadStatus(class, id, status string) error {
return ErrRestrictedContext
}
// ListPayloads implements hooks.Context.
func (ctx *RestrictedContext) ListPayloads() ([]string, error) {
return nil, ErrRestrictedContext
}
// FlushPayloads pushes the hook context data out to state.
func (ctx *RestrictedContext) FlushPayloads() error {
return ErrRestrictedContext
}
// Relation implements hooks.Context.
func (*RestrictedContext) Relation(id int) (ContextRelation, error) {
return nil, ErrRestrictedContext
}
// RelationIds implements hooks.Context.
func (*RestrictedContext) RelationIds() ([]int, error) { return nil, ErrRestrictedContext }
// HookRelation implements hooks.Context.
func (*RestrictedContext) HookRelation() (ContextRelation, error) {
return nil, ErrRestrictedContext
}
// RemoteUnitName implements hooks.Context.
func (*RestrictedContext) RemoteUnitName() (string, error) { return "", ErrRestrictedContext }
// RemoteApplicationName implements hooks.Context.
func (*RestrictedContext) RemoteApplicationName() (string, error) { return "", ErrRestrictedContext }
// ActionParams implements hooks.Context.
func (*RestrictedContext) ActionParams() (map[string]interface{}, error) {
return nil, ErrRestrictedContext
}
// UpdateActionResults implements hooks.Context.
func (*RestrictedContext) UpdateActionResults(keys []string, value interface{}) error {
return ErrRestrictedContext
}
// LogActionMessage implements hooks.Context.
func (*RestrictedContext) LogActionMessage(string) error { return ErrRestrictedContext }
// SetActionMessage implements hooks.Context.
func (*RestrictedContext) SetActionMessage(string) error { return ErrRestrictedContext }
// SetActionFailed implements hooks.Context.
func (*RestrictedContext) SetActionFailed() error { return ErrRestrictedContext }
// UnitWorkloadVersion implements hooks.Context.
func (*RestrictedContext) UnitWorkloadVersion() (string, error) {
return "", ErrRestrictedContext
}
// SetUnitWorkloadVersion implements hooks.Context.
func (*RestrictedContext) SetUnitWorkloadVersion(string) error {
return ErrRestrictedContext
}
// WorkloadName implements hooks.Context.
func (*RestrictedContext) WorkloadName() (string, error) {
return "", ErrRestrictedContext
}
// GetSecret implements runner.Context.
func (ctx *RestrictedContext) GetSecret(*secrets.URI, string, bool, bool) (secrets.SecretValue, error) {
return nil, ErrRestrictedContext
}
// CreateSecret implements runner.Context.
func (ctx *RestrictedContext) CreateSecret(args *SecretCreateArgs) (*secrets.URI, error) {
return nil, ErrRestrictedContext
}
// UpdateSecret implements runner.Context.
func (ctx *RestrictedContext) UpdateSecret(*secrets.URI, *SecretUpdateArgs) error {
return ErrRestrictedContext
}
func (ctx *RestrictedContext) RemoveSecret(*secrets.URI, *int) error {
return ErrRestrictedContext
}
func (ctx *RestrictedContext) SecretMetadata() (map[string]SecretMetadata, error) {
return nil, ErrRestrictedContext
}
// GrantSecret implements runner.Context.
func (c *RestrictedContext) GrantSecret(*secrets.URI, *SecretGrantRevokeArgs) error {
return ErrRestrictedContext
}
// RevokeSecret implements runner.Context.
func (c *RestrictedContext) RevokeSecret(*secrets.URI, *SecretGrantRevokeArgs) error {
return ErrRestrictedContext
}