Skip to content

Commit 54d3feb

Browse files
committed
remove cap.maxmaxversions
Signed-off-by: Doug Davis <duglin@gmail.com>
1 parent c5146dc commit 54d3feb

File tree

5 files changed

+12
-83
lines changed

5 files changed

+12
-83
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,8 @@ TODOs:
144144
- add tests for immutable attributes - in particular extensions
145145
- see if we can add RESOURCEid to Versions so we don't need special logic
146146
to exclude them in the code (e.g. in rID's updatefn and validateobj)
147+
- why are "capabilities" and "model" readonly?
148+
- allow any model change, verify entities
149+
- make sure that maxversions=0 when we only support 1 means sitcky must be false
150+
- add "relaxednames" to attr aspects
151+
- add ":" to map key names

registry/capabilities.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
type Capabilities struct {
1313
EnforceCompatibility bool `json:"enforcecompatibility"`
1414
Flags []string `json:"flags"`
15-
MaxMaxVersions int `json:"maxmaxversions"`
1615
Mutable []string `json:"mutable"`
1716
Pagination bool `json:"pagination"`
1817
Schemas []string `json:"schemas"`
@@ -37,7 +36,6 @@ type OfferedItem struct {
3736
type Offered struct {
3837
EnforceCompatibility OfferedCapability `json:"enforcecompatibility,omitempty"`
3938
Flags OfferedCapability `json:"flags,omitempty"`
40-
MaxMaxVersions OfferedCapability `json:"maxmaxversions,omitempty"`
4139
Mutable OfferedCapability `json:"mutable,omitempty"`
4240
Pagination OfferedCapability `json:"pagination,omitempty"`
4341
Schemas OfferedCapability `json:"schemas,omitempty"`
@@ -62,7 +60,6 @@ var AllowableSpecVersions = ArrayToLower([]string{"0.5"})
6260
var DefaultCapabilities = &Capabilities{
6361
EnforceCompatibility: false,
6462
Flags: AllowableFlags,
65-
MaxMaxVersions: 0,
6663
Mutable: AllowableMutable,
6764
Pagination: false,
6865
Schemas: AllowableSchemas,
@@ -103,9 +100,6 @@ func GetOffered() *Offered {
103100
},
104101
Enum: String2AnySlice(AllowableFlags),
105102
},
106-
MaxMaxVersions: OfferedCapability{
107-
Type: "uinteger",
108-
},
109103
Mutable: OfferedCapability{
110104
Type: "string",
111105
Enum: String2AnySlice(AllowableMutable),
@@ -210,10 +204,6 @@ func (c *Capabilities) Validate() error {
210204
return err
211205
}
212206

213-
if c.MaxMaxVersions < 0 {
214-
return fmt.Errorf(`"maxmaxversions" must be an unsigned integer`)
215-
}
216-
217207
c.Mutable, err = CleanArray(c.Mutable, AllowableMutable, "mutable")
218208
if err != nil {
219209
return err
@@ -275,10 +265,6 @@ func (c *Capabilities) FlagEnabled(str string) bool {
275265
return ArrayContainsAnyCase(c.Flags, str)
276266
}
277267

278-
func (c *Capabilities) MaxMaxVersionsEnabled(ver int) bool {
279-
return ver >= 0 && (c.MaxMaxVersions == 0 || (ver > 0 && ver <= c.MaxMaxVersions))
280-
}
281-
282268
func (c *Capabilities) MutableEnabled(str string) bool {
283269
return ArrayContainsAnyCase(c.Mutable, str)
284270
}

registry/model.go

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func (m *Model) AddGroupModel(plural string, singular string) (*GroupModel, erro
443443
return nil, fmt.Errorf("Can't add a GroupModel with an empty plural name")
444444
}
445445
if singular == "" {
446-
return nil, fmt.Errorf("Can't add a GroupModel with an empty sigular name")
446+
return nil, fmt.Errorf("Can't add a GroupModel with an empty singular name")
447447
}
448448

449449
if err := IsValidModelName(plural); err != nil {
@@ -1040,30 +1040,17 @@ func (gm *GroupModel) AddResourceModelFull(rm *ResourceModel) (*ResourceModel, e
10401040
return nil, fmt.Errorf("Can't add a group with an empty plural name")
10411041
}
10421042
if rm.Singular == "" {
1043-
return nil, fmt.Errorf("Can't add a group with an empty sigular name")
1043+
return nil, fmt.Errorf("Can't add a group with an empty singular name")
10441044
}
10451045

1046-
rm.GroupModel = gm
1047-
1048-
cap := DefaultCapabilities
1049-
reg := rm.GroupModel.Model.Registry
1050-
if reg != nil && reg.Capabilities != nil {
1051-
cap = reg.Capabilities
1052-
}
1053-
1054-
if !cap.MaxMaxVersionsEnabled(rm.MaxVersions) {
1055-
if cap.MaxMaxVersions == 0 {
1056-
return nil, fmt.Errorf(`"maxversions"(%d) must be >= 0`,
1057-
rm.MaxVersions)
1058-
} else {
1059-
return nil, fmt.Errorf("'maxversions'(%d) must be between 1 and %d",
1060-
rm.MaxVersions, cap.MaxMaxVersions)
1061-
}
1046+
if rm.MaxVersions < 0 {
1047+
return nil, fmt.Errorf(`"maxversions"(%d) must be >= 0`,
1048+
rm.MaxVersions)
10621049
}
10631050

10641051
if rm.MaxVersions == 1 && rm.GetSetDefaultSticky() != false {
1065-
return nil, fmt.Errorf("'setdefaultversionsticky' must be 'false' since " +
1066-
"'maxversions' is '1'")
1052+
return nil, fmt.Errorf("'setdefaultversionsticky' must be 'false' " +
1053+
"since 'maxversions' is '1'")
10671054
}
10681055

10691056
if err := IsValidModelName(rm.Plural); err != nil {
@@ -1814,21 +1801,6 @@ func (rm *ResourceModel) Verify(rmName string) error {
18141801
return err
18151802
}
18161803

1817-
cap := DefaultCapabilities
1818-
reg := rm.GroupModel.Model.Registry
1819-
if reg != nil && reg.Capabilities != nil {
1820-
cap = reg.Capabilities
1821-
}
1822-
1823-
if !cap.MaxMaxVersionsEnabled(rm.MaxVersions) {
1824-
if cap.MaxMaxVersions == 0 {
1825-
return fmt.Errorf(`"maxversions"(%d) must be >= 0`, rm.MaxVersions)
1826-
} else {
1827-
return fmt.Errorf("'maxversions'(%d) must be between 1 and %d",
1828-
rm.MaxVersions, cap.MaxMaxVersions)
1829-
}
1830-
}
1831-
18321804
// TODO: verify the Resources data are model compliant
18331805
// Only do this if we have a Regsitry. It assumes that if we have
18341806
// no Registry then we're not connected to a backend and there's no data

tests/capabilities_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func TestCapabilitySimple(t *testing.T) {
2929
"setdefaultversionid",
3030
"specversion"
3131
],
32-
"maxmaxversions": 0,
3332
"mutable": [
3433
"capabilities",
3534
"entities",
@@ -72,7 +71,6 @@ func TestCapabilitySimple(t *testing.T) {
7271
"setdefaultversionid",
7372
"specversion"
7473
],
75-
"maxmaxversions": 0,
7674
"mutable": [
7775
"capabilities",
7876
"entities",
@@ -102,7 +100,6 @@ func TestCapabilitySimple(t *testing.T) {
102100
Exp: `{
103101
"enforcecompatibility": false,
104102
"flags": [],
105-
"maxmaxversions": 0,
106103
"mutable": [],
107104
"pagination": false,
108105
"schemas": [
@@ -121,7 +118,6 @@ func TestCapabilitySimple(t *testing.T) {
121118
Exp: `{
122119
"enforcecompatibility": false,
123120
"flags": [],
124-
"maxmaxversions": 0,
125121
"mutable": [
126122
"capabilities",
127123
"entities",
@@ -144,7 +140,6 @@ func TestCapabilitySimple(t *testing.T) {
144140
Exp: `{
145141
"enforcecompatibility": false,
146142
"flags": [],
147-
"maxmaxversions": 0,
148143
"mutable": [
149144
"capabilities",
150145
"entities",
@@ -167,7 +162,6 @@ func TestCapabilitySimple(t *testing.T) {
167162
Exp: `{
168163
"enforcecompatibility": false,
169164
"flags": [],
170-
"maxmaxversions": 0,
171165
"mutable": [
172166
"capabilities",
173167
"entities",
@@ -190,7 +184,6 @@ func TestCapabilitySimple(t *testing.T) {
190184
Exp: `{
191185
"enforcecompatibility": false,
192186
"flags": [],
193-
"maxmaxversions": 0,
194187
"mutable": [],
195188
"pagination": false,
196189
"schemas": [
@@ -283,7 +276,6 @@ func TestCapabilityPath(t *testing.T) {
283276
"setdefaultversionid",
284277
"specversion"
285278
],
286-
"maxmaxversions": 0,
287279
"mutable": [
288280
"capabilities",
289281
"entities",
@@ -318,7 +310,6 @@ func TestCapabilityPath(t *testing.T) {
318310
`{
319311
"enforcecompatibility": false,
320312
"flags": [],
321-
"maxmaxversions": 0,
322313
"mutable": [],
323314
"pagination": false,
324315
"schemas": [
@@ -347,7 +338,6 @@ func TestCapabilityPath(t *testing.T) {
347338
xHTTP(t, reg, "GET", "/capabilities", ``, 200, `{
348339
"enforcecompatibility": false,
349340
"flags": [],
350-
"maxmaxversions": 0,
351341
"mutable": [],
352342
"pagination": false,
353343
"schemas": [
@@ -365,7 +355,6 @@ func TestCapabilityPath(t *testing.T) {
365355
xHTTP(t, reg, "PUT", "/capabilities", `{
366356
"enforcecompatibility": null,
367357
"flags": null,
368-
"maxmaxversions": null,
369358
"mutable": null,
370359
"pagination": null,
371360
"schemas": null,
@@ -375,7 +364,6 @@ func TestCapabilityPath(t *testing.T) {
375364
`{
376365
"enforcecompatibility": false,
377366
"flags": [],
378-
"maxmaxversions": 0,
379367
"mutable": [],
380368
"pagination": false,
381369
"schemas": [
@@ -392,7 +380,6 @@ func TestCapabilityPath(t *testing.T) {
392380
xHTTP(t, reg, "GET", "/capabilities", ``, 200, `{
393381
"enforcecompatibility": false,
394382
"flags": [],
395-
"maxmaxversions": 0,
396383
"mutable": [],
397384
"pagination": false,
398385
"schemas": [
@@ -414,7 +401,6 @@ func TestCapabilityPath(t *testing.T) {
414401
"nodefaultversionsticky", "noepoch", "noreadonly", "offered", "schema",
415402
"setdefaultversionid", "specversion"
416403
],
417-
"maxmaxversions": 0,
418404
"mutable": [ "capabilities", "entities", "model" ],
419405
"pagination": false,
420406
"schemas": [ "xregistry-json/0.5" ],
@@ -438,7 +424,6 @@ func TestCapabilityPath(t *testing.T) {
438424
"setdefaultversionid",
439425
"specversion"
440426
],
441-
"maxmaxversions": 0,
442427
"mutable": [
443428
"capabilities",
444429
"entities",
@@ -472,7 +457,6 @@ func TestCapabilityPath(t *testing.T) {
472457
"setdefaultversionid",
473458
"specversion"
474459
],
475-
"maxmaxversions": 0,
476460
"mutable": [
477461
"capabilities",
478462
"entities",
@@ -496,7 +480,6 @@ func TestCapabilityPath(t *testing.T) {
496480
`{
497481
"enforcecompatibility": false,
498482
"flags": [],
499-
"maxmaxversions": 0,
500483
"mutable": [],
501484
"pagination": false,
502485
"schemas": [
@@ -513,7 +496,6 @@ func TestCapabilityPath(t *testing.T) {
513496
xHTTP(t, reg, "GET", "/capabilities", ``, 200, `{
514497
"enforcecompatibility": false,
515498
"flags": [],
516-
"maxmaxversions": 0,
517499
"mutable": [],
518500
"pagination": false,
519501
"schemas": [
@@ -533,7 +515,6 @@ func TestCapabilityPath(t *testing.T) {
533515
}`, 200, `{
534516
"enforcecompatibility": false,
535517
"flags": [],
536-
"maxmaxversions": 0,
537518
"mutable": [],
538519
"pagination": false,
539520
"schemas": [
@@ -556,7 +537,6 @@ func TestCapabilityPath(t *testing.T) {
556537
}`, 200, `{
557538
"enforcecompatibility": false,
558539
"flags": [],
559-
"maxmaxversions": 0,
560540
"mutable": [],
561541
"pagination": false,
562542
"schemas": [
@@ -625,7 +605,6 @@ func TestCapabilityAttr(t *testing.T) {
625605
"capabilities": {
626606
"enforcecompatibility": false,
627607
"flags": [],
628-
"maxmaxversions": 0,
629608
"mutable": [],
630609
"pagination": false,
631610
"schemas": [
@@ -645,7 +624,6 @@ func TestCapabilityAttr(t *testing.T) {
645624
xHTTP(t, reg, "PUT", "/?inline=capabilities", `{ "capabilities": {
646625
"enforcecompatibility": null,
647626
"flags": null,
648-
"maxmaxversions": null,
649627
"mutable": null,
650628
"pagination": null,
651629
"schemas": null,
@@ -667,7 +645,6 @@ func TestCapabilityAttr(t *testing.T) {
667645
xHTTP(t, reg, "GET", "/capabilities", ``, 200, `{
668646
"enforcecompatibility": false,
669647
"flags": [],
670-
"maxmaxversions": 0,
671648
"mutable": [],
672649
"pagination": false,
673650
"schemas": [
@@ -690,7 +667,6 @@ func TestCapabilityAttr(t *testing.T) {
690667
"nodefaultversionsticky", "noepoch", "noreadonly", "offered", "schema",
691668
"setdefaultversionid", "specversion"
692669
],
693-
"maxmaxversions": 0,
694670
"mutable": [ "capabilities", "entities", "model" ],
695671
"pagination": false,
696672
"schemas": [ "xregistry-json/0.5" ],
@@ -725,7 +701,6 @@ func TestCapabilityAttr(t *testing.T) {
725701
"setdefaultversionid",
726702
"specversion"
727703
],
728-
"maxmaxversions": 0,
729704
"mutable": [
730705
"capabilities",
731706
"entities",
@@ -748,7 +723,6 @@ func TestCapabilityAttr(t *testing.T) {
748723
xHTTP(t, reg, "PUT", "/?inline=capabilities", `{ "capabilities": {
749724
"enforcecompatibility": false,
750725
"flags": [],
751-
"maxmaxversions": 0,
752726
"mutable": [],
753727
"pagination": false,
754728
"schemas": ["xregistry-json"],
@@ -768,7 +742,6 @@ func TestCapabilityAttr(t *testing.T) {
768742
"capabilities": {
769743
"enforcecompatibility": false,
770744
"flags": [],
771-
"maxmaxversions": 0,
772745
"mutable": [],
773746
"pagination": false,
774747
"schemas": [
@@ -786,7 +759,6 @@ func TestCapabilityAttr(t *testing.T) {
786759
xHTTP(t, reg, "GET", "/capabilities", ``, 200, `{
787760
"enforcecompatibility": false,
788761
"flags": [],
789-
"maxmaxversions": 0,
790762
"mutable": [],
791763
"pagination": false,
792764
"schemas": [
@@ -837,7 +809,6 @@ func TestCapabilityFlagsOff(t *testing.T) {
837809
xHTTP(t, reg, "PUT", "/capabilities", `{"mutable":["*"]}`, 200, `{
838810
"enforcecompatibility": false,
839811
"flags": [],
840-
"maxmaxversions": 0,
841812
"mutable": [
842813
"capabilities",
843814
"entities",
@@ -971,9 +942,6 @@ func TestCapabilityOffered(t *testing.T) {
971942
"specversion"
972943
]
973944
},
974-
"maxmaxversions": {
975-
"type": "uinteger"
976-
},
977945
"mutable": {
978946
"type": "string",
979947
"enum": [

tests/export_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func TestExportBasic(t *testing.T) {
5151
"setdefaultversionid",
5252
"specversion"
5353
],
54-
"maxmaxversions": 0,
5554
"mutable": [
5655
"capabilities",
5756
"entities",
@@ -571,7 +570,6 @@ func TestExportBasic(t *testing.T) {
571570
"setdefaultversionid",
572571
"specversion"
573572
],
574-
"maxmaxversions": 0,
575573
"mutable": [
576574
"capabilities",
577575
"entities",

0 commit comments

Comments
 (0)