Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/runware_serverless_apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ runware serverless apps [flags]
* [runware serverless apps builds](runware_serverless_apps_builds.md) - Inspect application builds
* [runware serverless apps delete](runware_serverless_apps_delete.md) - Delete a serverless application
* [runware serverless apps endpoints](runware_serverless_apps_endpoints.md) - List endpoints for a serverless application
* [runware serverless apps env](runware_serverless_apps_env.md) - Manage plain-text environment variables for an application
* [runware serverless apps list](runware_serverless_apps_list.md) - List serverless applications
* [runware serverless apps logs](runware_serverless_apps_logs.md) - Show logs for a serverless application
* [runware serverless apps resume](runware_serverless_apps_resume.md) - Resume a stopped serverless application
Expand Down
37 changes: 37 additions & 0 deletions docs/runware_serverless_apps_env.md
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

45 changes: 45 additions & 0 deletions docs/runware_serverless_apps_env_list.md
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

54 changes: 54 additions & 0 deletions docs/runware_serverless_apps_env_set.md
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

38 changes: 38 additions & 0 deletions docs/runware_serverless_apps_env_unset.md
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

133 changes: 133 additions & 0 deletions internal/api/serverless/env.go
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),
)
}
Comment thread
Ryank90 marked this conversation as resolved.

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())
}
}
Loading