-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(instance): import file for cloud-init #1525
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5688179
feat(instance): import file for cloud-init
jtherin 7bea59e
fix: add io.Reader support for @file
jtherin 8ba2d7c
Merge branch 'master' into importfile
remyleone d4ba7ff
Merge branch 'master' into importfile
remyleone f2c55ca
Add a test
remyleone bf3d3a4
Fix
remyleone 5f9aca8
Fix
remyleone 329fd93
Add documentation
remyleone ae3ea21
Merge branch 'master' into importfile
remyleone 313004c
Merge branch 'master' into importfile
remyleone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should return an error and not fail silently ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate.go line 48 et 78 also execute getValuesForFieldByName, log an info and continue.
It would not be too much to log the same info many times ?