Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
fix: make inspect print JSON (#437)
Browse files Browse the repository at this point in the history
Unwrap any signed content

```
$ duffle inspect helloworld:0.1.1 --insecure
{
    "name": "helloworld",
    "version": "0.1.1",
    "description": "",
    "invocationImages": [
        {
            "imageType": "docker",
            "image": "cnab/helloworld:0.1.1"
        }
    ],
    "images": [],
    "parameters": {
        "port": {
            "type": "int",
            "defaultValue": 8080,
            "required": false,
            "metadata": {},
            "destination": null
        }
    },
    "credentials": null
}
```

Closes #336
  • Loading branch information
technosophos authored Nov 16, 2018
1 parent 789fd11 commit 065c7c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cmd/duffle/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"io"
"os"

"github.com/spf13/cobra"
)
Expand All @@ -29,20 +28,19 @@ func newInspectCmd(w io.Writer) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
bundleName := args[0]

bundle, err := loadOrPullBundle(bundleName, insecure)
bundleFile, err := loadOrPullBundle(bundleName, insecure)
if err != nil {
return err
}

f, err := os.Open(bundle)
bun, err := loadBundle(bundleFile, insecure)
if err != nil {
return err
}
defer f.Close()

io.Copy(w, f)
_, err = bun.WriteTo(w)

return nil
return err
},
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func (b Bundle) WriteFile(dest string, mode os.FileMode) error {
return ioutil.WriteFile(dest, d, mode)
}

// WriteTo writes unsigned JSON to an io.Writer using the standard formatting.
func (b Bundle) WriteTo(w io.Writer) (int64, error) {
d, err := json.MarshalIndent(b, "", " ")
if err != nil {
return 0, err
}
l, err := w.Write(d)
return int64(l), err
}

// LocationRef specifies a location within the invocation package
type LocationRef struct {
Path string `json:"path" toml:"path"`
Expand Down

0 comments on commit 065c7c6

Please sign in to comment.