Skip to content

Commit 56ea2b5

Browse files
network: get content from file when arg=@/path is provided (#43)
This adds feature similar to `curl` where you can pass content of a file via the `arg=@/path/to/file` syntax. This can be useful while uploading custom certificate via cloudmonkey. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 4a9db7a commit 56ea2b5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cmd/network.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"net/http"
3030
"net/http/cookiejar"
3131
"net/url"
32+
"os"
3233
"sort"
3334
"strings"
3435
"time"
@@ -174,6 +175,17 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
174175
if strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"") {
175176
value = value[1 : len(value)-1]
176177
}
178+
if strings.HasPrefix(value, "@") {
179+
possibleFileName := value[1:]
180+
if fileInfo, err := os.Stat(possibleFileName); err == nil && !fileInfo.IsDir() {
181+
bytes, err := ioutil.ReadFile(possibleFileName)
182+
config.Debug()
183+
if err == nil {
184+
value = string(bytes)
185+
config.Debug("Content for argument ", key, " read from file: ", possibleFileName, " is: ", value)
186+
}
187+
}
188+
}
177189
params.Add(key, value)
178190
}
179191
}

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
307307
case "verifycert":
308308
c.Core.VerifyCert = value == "true"
309309
case "debug":
310-
if value == "true" {
310+
if value == "true" || value == "on" {
311311
EnableDebugging()
312312
} else {
313313
DisableDebugging()

0 commit comments

Comments
 (0)