Skip to content
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

proto1: update to operate over stdin #36

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sam-berning
Copy link
Contributor

Issue #, if available:

#35

Description of changes:

Change proto1 to operate over stdin instead of over the command line.

Adds a new flag to the proto1 command, --input-file, which allows users to specify an alternate input file instead of stdin.

Also, removes the command line arguments from the subcommands of proto1.

Tested with a sample setting extension:

$ echo '{"setting-version": "v1", "value": {"name": "foo"}}' | ./target/debug/proto1-test proto1 set

$ echo '{"setting-version": "v1", "value": {"name": 1}}' | ./target/debug/proto1-test proto1 set
[2024-02-15T23:44:00Z ERROR bottlerocket_settings_sdk::model::erased] error=Failed to deserialize 'target-value' input as settings value version 'v1': invalid type: integer `1`, expected a string
    Value: {
      "name": 1
    }
[2024-02-15T23:44:00Z ERROR bottlerocket_settings_sdk::extension::proto1] error=Set operation failed: Failed to deserialize 'target-value' input as settings value version 'v1': invalid type: integer `1`, expected a string
    Value: {
      "name": 1
    }
[2024-02-15T23:44:00Z ERROR bottlerocket_settings_sdk::extension::proto1] error=Set operation failed: Failed to deserialize 'target-value' input as settings value version 'v1': invalid type: integer `1`, expected a string
    Value: {
      "name": 1
    }
Set operation failed: Failed to deserialize 'target-value' input as settings value version 'v1': invalid type: integer `1`, expected a string
Value: {
  "name": 1
}
$ echo '{"setting-version": "v1", "value": {"name": "foo"}}' > input_file.json
$ ./target/debug/proto1-test proto1 --input-file input_file.json set

$

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

It's possible for proto1's command line interface to exceed the OS's
maximum argument length (128 KiB) if the JSON values passed into the
command are particularly large.

So instead of getting arguments from the command line, we parse them as
an equivalent JSON structure from a provided file. By default, this is
from stdin, but this can be overridden with the --input-file flag.

Signed-off-by: Sam Berning <bernings@amazon.com>
Signed-off-by: Sam Berning <bernings@amazon.com>
pub arg: Vec<serde_json::Value>,
}

pub mod input {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe add a doc comment here just for sanity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants