-
Notifications
You must be signed in to change notification settings - Fork 0
feat(env): adding env var commands to cli #90
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
Open
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,37 @@ | ||
| ## runware serverless apps env | ||
|
|
||
| Manage plain-text environment variables for an application | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Manage plain-text environment variables on a serverless application. | ||
|
|
||
| These are not organisation secrets. Values are returned by list and set. | ||
| Use 'serverless secrets' for encrypted secrets attached as env vars. | ||
|
|
||
| ``` | ||
| runware serverless apps env [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help help for env | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --debug Show full debug output | ||
| -F, --format string CLI output format: table, json, yaml (default "table") | ||
| --transport string Transport protocol: ws (WebSocket) or http (REST) (default "ws") | ||
| -v, --verbose Show request/response details | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [runware serverless apps](runware_serverless_apps.md) - Manage deployed serverless applications | ||
| * [runware serverless apps env list](runware_serverless_apps_env_list.md) - List environment variables for a serverless application | ||
| * [runware serverless apps env set](runware_serverless_apps_env_set.md) - Create or update an environment variable | ||
| * [runware serverless apps env unset](runware_serverless_apps_env_unset.md) - Remove an environment variable | ||
|
|
This file contains hidden or 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,45 @@ | ||
| ## runware serverless apps env list | ||
|
|
||
| List environment variables for a serverless application | ||
|
|
||
| ### Synopsis | ||
|
|
||
| List plain-text environment variables for an application, including values. | ||
|
|
||
| To list encrypted secrets attached to an application, use 'serverless secrets attachments'. | ||
|
|
||
| ``` | ||
| runware serverless apps env list <appId> [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| # list environment variables | ||
| runware serverless apps env list my-app | ||
|
|
||
| # page through results | ||
| runware serverless apps env list my-app --limit 20 --cursor <nextCursor> | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| --cursor string Pagination cursor from a previous nextCursor | ||
| -h, --help help for list | ||
| --limit int Maximum number of environment variables to return (1-100) | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --debug Show full debug output | ||
| -F, --format string CLI output format: table, json, yaml (default "table") | ||
| --transport string Transport protocol: ws (WebSocket) or http (REST) (default "ws") | ||
| -v, --verbose Show request/response details | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [runware serverless apps env](runware_serverless_apps_env.md) - Manage plain-text environment variables for an application | ||
|
|
This file contains hidden or 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,54 @@ | ||
| ## runware serverless apps env set | ||
|
|
||
| Create or update an environment variable | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Create or update one plain-text environment variable. | ||
|
|
||
| Prefer --value-file so the value is not visible in process lists; use | ||
| --value-file - to read from stdin. | ||
|
|
||
| The server rejects (HTTP 422) reserved platform names, names that collide | ||
| with an attached secret's injected env var, and adding a binding past the | ||
| 100-variable-plus-secret ceiling. Overwriting an existing key is always | ||
| allowed. | ||
|
|
||
| ``` | ||
| runware serverless apps env set <appId> <key> [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| # set an environment variable | ||
| runware serverless apps env set my-app MY_KEY --value hello | ||
|
|
||
| # read the value from a file | ||
| runware serverless apps env set my-app MY_KEY --value-file ./value.txt | ||
|
|
||
| # read the value from stdin | ||
| printf '%s' "$MY_VALUE" | runware serverless apps env set my-app MY_KEY --value-file - | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help help for set | ||
| --value string Variable value (visible in process lists; prefer --value-file) | ||
| --value-file string Read variable value from a file, or - for stdin | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --debug Show full debug output | ||
| -F, --format string CLI output format: table, json, yaml (default "table") | ||
| --transport string Transport protocol: ws (WebSocket) or http (REST) (default "ws") | ||
| -v, --verbose Show request/response details | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [runware serverless apps env](runware_serverless_apps_env.md) - Manage plain-text environment variables for an application | ||
|
|
This file contains hidden or 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,38 @@ | ||
| ## runware serverless apps env unset | ||
|
|
||
| Remove an environment variable | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Remove one plain-text environment variable from an application. | ||
|
|
||
| ``` | ||
| runware serverless apps env unset <appId> <key> [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| # remove an environment variable | ||
| runware serverless apps env unset my-app MY_KEY | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help help for unset | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --debug Show full debug output | ||
| -F, --format string CLI output format: table, json, yaml (default "table") | ||
| --transport string Transport protocol: ws (WebSocket) or http (REST) (default "ws") | ||
| -v, --verbose Show request/response details | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [runware serverless apps env](runware_serverless_apps_env.md) - Manage plain-text environment variables for an application | ||
|
|
This file contains hidden or 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,133 @@ | ||
| package serverless | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log/slog" | ||
| "net/http" | ||
|
|
||
| "github.com/runware/runware-cli/internal/api/serverless/gen" | ||
| "github.com/runware/runware-cli/internal/api/transport" | ||
| ) | ||
|
|
||
| // EnvironmentVariable is a plain-text deployment environment variable. | ||
| type EnvironmentVariable = gen.EnvironmentVariable | ||
|
|
||
| // EnvironmentVariableUpdate is the request body for updateDeploymentEnvironmentVariable. | ||
| type EnvironmentVariableUpdate = gen.EnvironmentVariableUpdate | ||
|
|
||
| // ListDeploymentEnvironmentVariablesParams are optional filters for | ||
| // ListDeploymentEnvironmentVariables. | ||
| type ListDeploymentEnvironmentVariablesParams = gen.ListDeploymentEnvironmentVariablesParams | ||
|
|
||
| // ListDeploymentEnvironmentVariables returns a page of plain-text environment | ||
| // variables for a deployment. Values are included in the response. | ||
| func (c *Client) ListDeploymentEnvironmentVariables(ctx context.Context, deploymentID string, params *ListDeploymentEnvironmentVariablesParams) (Page[EnvironmentVariable], error) { | ||
| if c.apiKey == "" { | ||
| return Page[EnvironmentVariable]{}, transport.ErrNoAPIKey | ||
| } | ||
|
|
||
| resp, err := c.inner.ListDeploymentEnvironmentVariablesWithResponse(ctx, deploymentID, params) | ||
| if err != nil { | ||
| return Page[EnvironmentVariable]{}, fmt.Errorf("list environment variables: %w", err) | ||
| } | ||
|
|
||
| if c.logger != nil && c.logger.Enabled(ctx, slog.LevelDebug) { | ||
| c.logger.Debug("serverless response", //nolint:errcheck,gosec | ||
| "path", "/v1/deployments/"+deploymentID+"/environment-variables", | ||
| "status", resp.StatusCode(), | ||
| "body", string(resp.Body), | ||
| ) | ||
| } | ||
|
|
||
| switch resp.StatusCode() { | ||
| case http.StatusOK: | ||
| if resp.JSON200 == nil { | ||
| return pageOf[EnvironmentVariable](nil, nil), nil | ||
| } | ||
| return pageOf(resp.JSON200.Data, resp.JSON200.NextCursor), nil | ||
| case http.StatusUnauthorized: | ||
| return Page[EnvironmentVariable]{}, problemToError(resp.ApplicationproblemJSON401, http.StatusUnauthorized) | ||
| case http.StatusForbidden: | ||
| return Page[EnvironmentVariable]{}, problemToError(resp.ApplicationproblemJSON403, http.StatusForbidden) | ||
| case http.StatusNotFound: | ||
| return Page[EnvironmentVariable]{}, problemToError(resp.ApplicationproblemJSON404, http.StatusNotFound) | ||
| default: | ||
| return Page[EnvironmentVariable]{}, problemFromBody(resp.Body, resp.StatusCode()) | ||
| } | ||
| } | ||
|
|
||
| // UpdateDeploymentEnvironmentVariable creates or replaces one plain-text | ||
| // environment variable on a deployment. | ||
| func (c *Client) UpdateDeploymentEnvironmentVariable(ctx context.Context, deploymentID, key string, body EnvironmentVariableUpdate) (*EnvironmentVariable, error) { | ||
| if c.apiKey == "" { | ||
| return nil, transport.ErrNoAPIKey | ||
| } | ||
|
|
||
| resp, err := c.inner.UpdateDeploymentEnvironmentVariableWithResponse(ctx, deploymentID, key, body) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("update environment variable: %w", err) | ||
| } | ||
|
|
||
| if c.logger != nil && c.logger.Enabled(ctx, slog.LevelDebug) { | ||
| c.logger.Debug("serverless response", //nolint:errcheck,gosec | ||
| "path", "/v1/deployments/"+deploymentID+"/environment-variables/"+key, | ||
| "status", resp.StatusCode(), | ||
| "body", string(resp.Body), | ||
| ) | ||
| } | ||
|
|
||
| switch resp.StatusCode() { | ||
| case http.StatusOK: | ||
| if resp.JSON200 == nil { | ||
| return nil, fmt.Errorf("update environment variable: empty 200 response") | ||
| } | ||
| return resp.JSON200, nil | ||
| case http.StatusBadRequest: | ||
| return nil, problemToError(resp.ApplicationproblemJSON400, http.StatusBadRequest) | ||
| case http.StatusUnauthorized: | ||
| return nil, problemToError(resp.ApplicationproblemJSON401, http.StatusUnauthorized) | ||
| case http.StatusForbidden: | ||
| return nil, problemToError(resp.ApplicationproblemJSON403, http.StatusForbidden) | ||
| case http.StatusNotFound: | ||
| return nil, problemToError(resp.ApplicationproblemJSON404, http.StatusNotFound) | ||
| case http.StatusUnprocessableEntity: | ||
| return nil, problemToError(resp.ApplicationproblemJSON422, http.StatusUnprocessableEntity) | ||
| default: | ||
| return nil, problemFromBody(resp.Body, resp.StatusCode()) | ||
| } | ||
| } | ||
|
|
||
| // DeleteDeploymentEnvironmentVariable removes one plain-text environment | ||
| // variable from a deployment. | ||
| func (c *Client) DeleteDeploymentEnvironmentVariable(ctx context.Context, deploymentID, key string) error { | ||
| if c.apiKey == "" { | ||
| return transport.ErrNoAPIKey | ||
| } | ||
|
|
||
| resp, err := c.inner.DeleteDeploymentEnvironmentVariableWithResponse(ctx, deploymentID, key) | ||
| if err != nil { | ||
| return fmt.Errorf("delete environment variable: %w", err) | ||
| } | ||
|
|
||
| if c.logger != nil && c.logger.Enabled(ctx, slog.LevelDebug) { | ||
| c.logger.Debug("serverless response", //nolint:errcheck,gosec | ||
| "path", "/v1/deployments/"+deploymentID+"/environment-variables/"+key, | ||
| "status", resp.StatusCode(), | ||
| "body", string(resp.Body), | ||
| ) | ||
| } | ||
|
|
||
| switch resp.StatusCode() { | ||
| case http.StatusNoContent: | ||
| return nil | ||
| case http.StatusUnauthorized: | ||
| return problemToError(resp.ApplicationproblemJSON401, http.StatusUnauthorized) | ||
| case http.StatusForbidden: | ||
| return problemToError(resp.ApplicationproblemJSON403, http.StatusForbidden) | ||
| case http.StatusNotFound: | ||
| return problemToError(resp.ApplicationproblemJSON404, http.StatusNotFound) | ||
| default: | ||
| return problemFromBody(resp.Body, resp.StatusCode()) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.