Skip to content

Commit 2a69a0f

Browse files
Merge pull request #85 from radu-matei/remove-output-fields
Remove fields from outputs
2 parents 7e4ad62 + d637259 commit 2a69a0f

File tree

6 files changed

+65
-75
lines changed

6 files changed

+65
-75
lines changed

action/action.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func setOutputsOnClaim(claim *claim.Claim, outputs map[string]string) error {
122122
return nil
123123
}
124124

125-
for outputName, v := range claim.Bundle.Outputs.Fields {
125+
for outputName, v := range claim.Bundle.Outputs {
126126
name := v.Definition
127127
if name == "" {
128128
return fmt.Errorf("invalid bundle: no definition set for output %q", outputName)
@@ -223,7 +223,7 @@ func opFromClaim(action string, stateless bool, c *claim.Claim, ii bundle.Invoca
223223

224224
var outputs []string
225225
if c.Bundle.Outputs != nil {
226-
for _, v := range c.Bundle.Outputs.Fields {
226+
for _, v := range c.Bundle.Outputs {
227227
outputs = append(outputs, v.Path)
228228
}
229229
}

action/action_test.go

+31-33
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,10 @@ func mockBundle() *bundle.Bundle {
116116
Type: []interface{}{"string", "boolean"},
117117
},
118118
},
119-
Outputs: &bundle.OutputsDefinition{
120-
Fields: map[string]bundle.OutputDefinition{
121-
"some-output": {
122-
Path: "/tmp/some/path",
123-
Definition: "ParamOne",
124-
},
119+
Outputs: map[string]bundle.Output{
120+
"some-output": {
121+
Path: "/tmp/some/path",
122+
Definition: "ParamOne",
125123
},
126124
},
127125
Parameters: map[string]bundle.Parameter{
@@ -335,9 +333,9 @@ func TestSetOutputsOnClaim(t *testing.T) {
335333

336334
// Non strings given a good type should also work
337335
t.Run("null succeeds", func(t *testing.T) {
338-
field := c.Bundle.Outputs.Fields["some-output"]
339-
field.Definition = "NullParam"
340-
c.Bundle.Outputs.Fields["some-output"] = field
336+
o := c.Bundle.Outputs["some-output"]
337+
o.Definition = "NullParam"
338+
c.Bundle.Outputs["some-output"] = o
341339
output := map[string]string{
342340
"/tmp/some/path": "null",
343341
}
@@ -346,9 +344,9 @@ func TestSetOutputsOnClaim(t *testing.T) {
346344
})
347345

348346
t.Run("boolean succeeds", func(t *testing.T) {
349-
field := c.Bundle.Outputs.Fields["some-output"]
350-
field.Definition = "BooleanParam"
351-
c.Bundle.Outputs.Fields["some-output"] = field
347+
o := c.Bundle.Outputs["some-output"]
348+
o.Definition = "BooleanParam"
349+
c.Bundle.Outputs["some-output"] = o
352350
output := map[string]string{
353351
"/tmp/some/path": "true",
354352
}
@@ -357,9 +355,9 @@ func TestSetOutputsOnClaim(t *testing.T) {
357355
})
358356

359357
t.Run("object succeeds", func(t *testing.T) {
360-
field := c.Bundle.Outputs.Fields["some-output"]
361-
field.Definition = "ObjectParam"
362-
c.Bundle.Outputs.Fields["some-output"] = field
358+
o := c.Bundle.Outputs["some-output"]
359+
o.Definition = "ObjectParam"
360+
c.Bundle.Outputs["some-output"] = o
363361
output := map[string]string{
364362
"/tmp/some/path": "{}",
365363
}
@@ -368,9 +366,9 @@ func TestSetOutputsOnClaim(t *testing.T) {
368366
})
369367

370368
t.Run("array succeeds", func(t *testing.T) {
371-
field := c.Bundle.Outputs.Fields["some-output"]
369+
field := c.Bundle.Outputs["some-output"]
372370
field.Definition = "ArrayParam"
373-
c.Bundle.Outputs.Fields["some-output"] = field
371+
c.Bundle.Outputs["some-output"] = field
374372
output := map[string]string{
375373
"/tmp/some/path": "[]",
376374
}
@@ -379,9 +377,9 @@ func TestSetOutputsOnClaim(t *testing.T) {
379377
})
380378

381379
t.Run("number succeeds", func(t *testing.T) {
382-
field := c.Bundle.Outputs.Fields["some-output"]
380+
field := c.Bundle.Outputs["some-output"]
383381
field.Definition = "NumberParam"
384-
c.Bundle.Outputs.Fields["some-output"] = field
382+
c.Bundle.Outputs["some-output"] = field
385383
output := map[string]string{
386384
"/tmp/some/path": "3.14",
387385
}
@@ -390,9 +388,9 @@ func TestSetOutputsOnClaim(t *testing.T) {
390388
})
391389

392390
t.Run("integer as number succeeds", func(t *testing.T) {
393-
field := c.Bundle.Outputs.Fields["some-output"]
391+
field := c.Bundle.Outputs["some-output"]
394392
field.Definition = "NumberParam"
395-
c.Bundle.Outputs.Fields["some-output"] = field
393+
c.Bundle.Outputs["some-output"] = field
396394
output := map[string]string{
397395
"/tmp/some/path": "372",
398396
}
@@ -401,9 +399,9 @@ func TestSetOutputsOnClaim(t *testing.T) {
401399
})
402400

403401
t.Run("integer succeeds", func(t *testing.T) {
404-
field := c.Bundle.Outputs.Fields["some-output"]
405-
field.Definition = "IntegerParam"
406-
c.Bundle.Outputs.Fields["some-output"] = field
402+
o := c.Bundle.Outputs["some-output"]
403+
o.Definition = "IntegerParam"
404+
c.Bundle.Outputs["some-output"] = o
407405
output := map[string]string{
408406
"/tmp/some/path": "372",
409407
}
@@ -415,9 +413,9 @@ func TestSetOutputsOnClaim(t *testing.T) {
415413
func TestSetOutputsOnClaim_MultipleTypes(t *testing.T) {
416414
c := newClaim()
417415
c.Bundle = mockBundle()
418-
field := c.Bundle.Outputs.Fields["some-output"]
419-
field.Definition = "BooleanAndIntegerParam"
420-
c.Bundle.Outputs.Fields["some-output"] = field
416+
o := c.Bundle.Outputs["some-output"]
417+
o.Definition = "BooleanAndIntegerParam"
418+
c.Bundle.Outputs["some-output"] = o
421419

422420
t.Run("BooleanOrInteger, so boolean succeeds", func(t *testing.T) {
423421
output := map[string]string{
@@ -442,9 +440,9 @@ func TestSetOutputsOnClaim_MultipleTypes(t *testing.T) {
442440
func TestSetOutputsOnClaim_MultipleTypesWithString(t *testing.T) {
443441
c := newClaim()
444442
c.Bundle = mockBundle()
445-
field := c.Bundle.Outputs.Fields["some-output"]
446-
field.Definition = "StringAndBooleanParam"
447-
c.Bundle.Outputs.Fields["some-output"] = field
443+
o := c.Bundle.Outputs["some-output"]
444+
o.Definition = "StringAndBooleanParam"
445+
c.Bundle.Outputs["some-output"] = o
448446

449447
t.Run("null succeeds", func(t *testing.T) {
450448
output := map[string]string{
@@ -467,9 +465,9 @@ func TestSetOutputsOnClaim_MismatchType(t *testing.T) {
467465
c := newClaim()
468466
c.Bundle = mockBundle()
469467

470-
field := c.Bundle.Outputs.Fields["some-output"]
471-
field.Definition = "BooleanParam"
472-
c.Bundle.Outputs.Fields["some-output"] = field
468+
o := c.Bundle.Outputs["some-output"]
469+
o.Definition = "BooleanParam"
470+
c.Bundle.Outputs["some-output"] = o
473471

474472
t.Run("error case: content type does not match output definition", func(t *testing.T) {
475473
invalidParsableOutput := map[string]string{

bundle/bundle.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Bundle struct {
2727
Actions map[string]Action `json:"actions,omitempty" mapstructure:"actions"`
2828
Parameters map[string]Parameter `json:"parameters,omitempty" mapstructure:"parameters"`
2929
Credentials map[string]Credential `json:"credentials,omitempty" mapstructure:"credentials"`
30-
Outputs *OutputsDefinition `json:"outputs,omitempty" mapstructure:"outputs"`
30+
Outputs map[string]Output `json:"outputs,omitempty" mapstructure:"outputs"`
3131
Definitions definition.Definitions `json:"definitions,omitempty" mapstructure:"definitions"`
3232
License string `json:"license,omitempty" mapstructure:"license"`
3333
RequiredExtensions []string `json:"requiredExtensions,omitempty" mapstructure:"requiredExtensions"`

bundle/bundle_test.go

+29-33
Original file line numberDiff line numberDiff line change
@@ -376,47 +376,45 @@ func TestReadCustomAndRequiredExtensions(t *testing.T) {
376376

377377
func TestOutputs_Marshall(t *testing.T) {
378378
bundleJSON := `
379-
{
380-
"outputs": {
381-
"fields" : {
382-
"clientCert": {
383-
"contentEncoding": "base64",
384-
"contentMediaType": "application/x-x509-user-cert",
385-
"path": "/cnab/app/outputs/clientCert",
386-
"definition": "clientCert"
387-
},
388-
"hostName": {
389-
"applyTo": [
390-
"install"
391-
],
392-
"description": "the hostname produced installing the bundle",
393-
"path": "/cnab/app/outputs/hostname",
394-
"definition": "hostType"
395-
},
396-
"port": {
397-
"path": "/cnab/app/outputs/port",
398-
"definition": "portType"
399-
}
400-
}
379+
{
380+
"outputs":{
381+
"clientCert":{
382+
"contentEncoding":"base64",
383+
"contentMediaType":"application/x-x509-user-cert",
384+
"path":"/cnab/app/outputs/clientCert",
385+
"definition":"clientCert"
386+
},
387+
"hostName":{
388+
"applyTo":[
389+
"install"
390+
],
391+
"description":"the hostname produced installing the bundle",
392+
"path":"/cnab/app/outputs/hostname",
393+
"definition":"hostType"
394+
},
395+
"port":{
396+
"path":"/cnab/app/outputs/port",
397+
"definition":"portType"
398+
}
401399
}
402-
}`
400+
}`
403401

404402
bundle, err := Unmarshal([]byte(bundleJSON))
405403
assert.NoError(t, err, "should have unmarshalled the bundle")
406404
require.NotNil(t, bundle.Outputs, "test must fail, not outputs found")
407-
assert.Equal(t, 3, len(bundle.Outputs.Fields))
405+
assert.Equal(t, 3, len(bundle.Outputs))
408406

409-
clientCert, ok := bundle.Outputs.Fields["clientCert"]
407+
clientCert, ok := bundle.Outputs["clientCert"]
410408
require.True(t, ok, "expected clientCert to exist as an output")
411409
assert.Equal(t, "clientCert", clientCert.Definition)
412410
assert.Equal(t, "/cnab/app/outputs/clientCert", clientCert.Path, "clientCert path was not the expected value")
413411

414-
hostName, ok := bundle.Outputs.Fields["hostName"]
412+
hostName, ok := bundle.Outputs["hostName"]
415413
require.True(t, ok, "expected hostname to exist as an output")
416414
assert.Equal(t, "hostType", hostName.Definition)
417415
assert.Equal(t, "/cnab/app/outputs/hostname", hostName.Path, "hostName path was not the expected value")
418416

419-
port, ok := bundle.Outputs.Fields["port"]
417+
port, ok := bundle.Outputs["port"]
420418
require.True(t, ok, "expected port to exist as an output")
421419
assert.Equal(t, "portType", port.Definition)
422420
assert.Equal(t, "/cnab/app/outputs/port", port.Path, "port path was not the expected value")
@@ -517,12 +515,10 @@ func TestBundleMarshallAllThings(t *testing.T) {
517515
},
518516
},
519517
},
520-
Outputs: &OutputsDefinition{
521-
Fields: map[string]OutputDefinition{
522-
"clientCert": {
523-
Path: "/cnab/app/outputs/blah",
524-
Definition: "clientCert",
525-
},
518+
Outputs: map[string]Output{
519+
"clientCert": {
520+
Path: "/cnab/app/outputs/blah",
521+
Definition: "clientCert",
526522
},
527523
},
528524
}

bundle/outputs.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package bundle
22

3-
type OutputsDefinition struct {
4-
Fields map[string]OutputDefinition `json:"fields" mapstructure:"fields"`
5-
}
6-
7-
type OutputDefinition struct {
3+
type Output struct {
84
Definition string `json:"definition" mapstructure:"definition"`
95
ApplyTo []string `json:"applyTo,omitempty" mapstructure:"applyTo,omitempty"`
106
Description string `json:"description,omitempty" mapstructure:"description"`
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"credentials":{"password":{"description":"a password","env":"PASSWORD","path":"/cnab/app/path"}},"definitions":{"clientCert":{"contentEncoding":"base64","type":"string"},"enabledType":{"default":false,"type":"boolean"},"hostType":{"default":"locahost.localdomain","type":"string"},"portType":{"default":1234,"type":"integer"},"productKeyType":{"type":"string"},"replicaCountType":{"default":3,"type":"integer"}},"description":"something","images":{"server":{"description":"complicated","image":"nginx:1.0","imageType":"docker"}},"invocationImages":[{"image":"deislabs/invocation-image:1.0","imageType":"docker","labels":{"os":"Linux"}}],"license":"MIT License","name":"testBundle","outputs":{"fields":{"clientCert":{"definition":"clientCert","path":"/cnab/app/outputs/blah"}}},"parameters":{"enabled":{"definition":"enabledType","destination":{"env":"ENABLED"}},"host":{"definition":"hostType","destination":{"env":"HOST"},"required":true},"port":{"definition":"portType","destination":{"env":"PORT"},"required":true},"productKey":{"definition":"productKeyType","destination":{"env":"PRODUCT_KEY"}},"replicaCount":{"definition":"replicaCountType","destination":{"env":"REPLICA_COUNT"}}},"schemaVersion":"v1.0.0-WD","version":"1.0"}
1+
{"credentials":{"password":{"description":"a password","env":"PASSWORD","path":"/cnab/app/path"}},"definitions":{"clientCert":{"contentEncoding":"base64","type":"string"},"enabledType":{"default":false,"type":"boolean"},"hostType":{"default":"locahost.localdomain","type":"string"},"portType":{"default":1234,"type":"integer"},"productKeyType":{"type":"string"},"replicaCountType":{"default":3,"type":"integer"}},"description":"something","images":{"server":{"description":"complicated","image":"nginx:1.0","imageType":"docker"}},"invocationImages":[{"image":"deislabs/invocation-image:1.0","imageType":"docker","labels":{"os":"Linux"}}],"license":"MIT License","name":"testBundle","outputs":{"clientCert":{"definition":"clientCert","path":"/cnab/app/outputs/blah"}},"parameters":{"enabled":{"definition":"enabledType","destination":{"env":"ENABLED"}},"host":{"definition":"hostType","destination":{"env":"HOST"},"required":true},"port":{"definition":"portType","destination":{"env":"PORT"},"required":true},"productKey":{"definition":"productKeyType","destination":{"env":"PRODUCT_KEY"}},"replicaCount":{"definition":"replicaCountType","destination":{"env":"REPLICA_COUNT"}}},"schemaVersion":"v1.0.0-WD","version":"1.0"}

0 commit comments

Comments
 (0)