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

Commit

Permalink
Added snapctl config file option
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyfay authored and IRCody committed Mar 4, 2016
1 parent 5b48baa commit 8a31dfd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
28 changes: 27 additions & 1 deletion cmd/snapctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ limitations under the License.
package main

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand All @@ -30,6 +33,25 @@ import (
"github.com/intelsdi-x/snap/core/ctypes"
)

type config struct {
RestAPI restAPIConfig `json:"rest"`
}
type restAPIConfig struct {
Password *string `json:"rest-auth-pwd"`
}

func (c *config) loadConfig(path string) error {
b, err := ioutil.ReadFile(path)
if err != nil {
return errors.New("Unable to read config. File might not exist.")
}
err = json.Unmarshal(b, &c)
if err != nil {
return errors.New("Invalid config")
}
return nil
}

func getConfig(ctx *cli.Context) {
pDetails := filepath.SplitList(ctx.Args().First())
var ptyp string
Expand Down Expand Up @@ -69,12 +91,16 @@ func getConfig(ctx *cli.Context) {
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
defer w.Flush()
r := pClient.GetPluginConfig(ptyp, pname, strconv.Itoa(pver))
if r.Err != nil {
fmt.Println("Error requesting info: ", r.Err)
os.Exit(1)
}
printFields(w, false, 0,
"NAME",
"VALUE",
"TYPE",
)
r := pClient.GetPluginConfig(ptyp, pname, strconv.Itoa(pver))
for k, v := range r.Table() {
switch t := v.(type) {
case ctypes.ConfigValueInt:
Expand Down
4 changes: 3 additions & 1 deletion examples/configs/snap-config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"flags": {
"log-level": 1,
"plugin-trust": 0,
"auto-discover": "build/plugin"
"auto-discover": "build/plugin",
"rest-auth": true,
"rest-auth-pwd": "example"
},
"plugins": {
"all": {
Expand Down
5 changes: 5 additions & 0 deletions examples/configs/snapctl-config-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rest": {
"rest-auth-pwd": "example"
}
}

0 comments on commit 8a31dfd

Please sign in to comment.