-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(instance): import file for cloud-init (#1525)
* feat(instance): import file for cloud-init * fix: add io.Reader support for @file Co-authored-by: Rémy Léone <[email protected]>
- Loading branch information
Showing
15 changed files
with
573 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package core | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/scaleway/scaleway-sdk-go/strcase" | ||
) | ||
|
||
// loadArgsFileContent will hydrate args with default values. | ||
func loadArgsFileContent(cmd *Command, cmdArgs interface{}) error { | ||
for _, argSpec := range cmd.ArgSpecs { | ||
if !argSpec.CanLoadFile { | ||
continue | ||
} | ||
|
||
fieldName := strcase.ToPublicGoName(argSpec.Name) | ||
fieldValues, err := getValuesForFieldByName(reflect.ValueOf(cmdArgs), strings.Split(fieldName, ".")) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
for _, v := range fieldValues { | ||
switch i := v.Interface().(type) { | ||
case io.Reader: | ||
b, err := ioutil.ReadAll(i) | ||
if err != nil { | ||
return fmt.Errorf("could not read argument: %s", err) | ||
} | ||
|
||
if strings.HasPrefix(string(b), "@") { | ||
content, err := ioutil.ReadFile(string(b)[1:]) | ||
if err != nil { | ||
return fmt.Errorf("could not open requested file: %s", err) | ||
} | ||
test := bytes.NewBuffer(content) | ||
v.Set(reflect.ValueOf(test)) | ||
} | ||
case *string: | ||
if strings.HasPrefix(*i, "@") { | ||
content, err := ioutil.ReadFile((*i)[1:]) | ||
if err != nil { | ||
return fmt.Errorf("could not open requested file: %s", err) | ||
} | ||
v.SetString(string(content)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
...al/namespaces/instance/v1/testdata/test-user-data-file-upload-on-cloud-init.cassette.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
internal/namespaces/instance/v1/testdata/test-user-data-file-upload-on-cloud-init.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 | ||
🟩🟩🟩 STDOUT️ 🟩🟩🟩️ | ||
✅ Success. | ||
🟩🟩🟩 JSON STDOUT 🟩🟩🟩 | ||
{ | ||
"message": "Success", | ||
"details": "" | ||
} |
211 changes: 211 additions & 0 deletions
211
...al/namespaces/instance/v1/testdata/test-user-data-file-upload-on-random-key.cassette.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
internal/namespaces/instance/v1/testdata/test-user-data-file-upload-on-random-key.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 | ||
🟩🟩🟩 STDOUT️ 🟩🟩🟩️ | ||
✅ Success. | ||
🟩🟩🟩 JSON STDOUT 🟩🟩🟩 | ||
{ | ||
"message": "Success", | ||
"details": "" | ||
} |