Skip to content

Commit 1703fd2

Browse files
authored
Merge pull request #60 from coollabsio/next
Next
2 parents 4ad94e2 + bd65345 commit 1703fd2

File tree

9 files changed

+50
-30
lines changed

9 files changed

+50
-30
lines changed

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This is a CLI tool for interacting with the Coolify API, built with Go using the
99
### API Specification
1010
This CLI is a client for the Coolify API. The API specification is defined in the OpenAPI schema:
1111
- **Source**: https://github.com/coollabsio/coolify/blob/v4.x/openapi.json
12+
- **Raw JSON**: https://raw.githubusercontent.com/coollabsio/coolify/refs/heads/v4.x/openapi.json
1213
- **Base Path**: `/api/v1/`
1314
- **Authentication**: Bearer token (API tokens from Coolify dashboard at `/security/api-tokens`)
1415

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,14 @@ Commands can use `server` or `servers` interchangeably.
149149
- `--build-time` - Available at build time
150150
- `--is-literal` - Treat value as literal (don't interpolate variables)
151151
- `--is-multiline` - Value is multiline
152-
- `coolify app env update <app_uuid> <env_uuid>` - Update an environment variable
152+
- `coolify app env update <app_uuid>` - Update an environment variable
153+
- `--key <key>` - Variable key (required)
154+
- `--value <value>` - Variable value (required)
155+
- `--preview` - Available in preview deployments
156+
- `--build-time` - Available at build time
157+
- `--is-literal` - Treat value as literal (don't interpolate variables)
158+
- `--is-multiline` - Value is multiline
159+
- `--runtime` - Available at runtime
153160
- `coolify app env delete <app_uuid> <env_uuid>` - Delete an environment variable
154161
- `coolify app env sync <app_uuid>` - Sync environment variables from a .env file
155162
- `--file <path>` - Path to .env file (required)
@@ -232,7 +239,13 @@ Commands can use `server` or `servers` interchangeably.
232239
- `coolify service env get <service_uuid> <env_uuid_or_key>` - Get a specific environment variable
233240
- `coolify service env create <service_uuid>` - Create a new environment variable
234241
- Same flags as application environment variables
235-
- `coolify service env update <service_uuid> <env_uuid>` - Update an environment variable
242+
- `coolify service env update <service_uuid>` - Update an environment variable
243+
- `--key <key>` - Variable key (required)
244+
- `--value <value>` - Variable value (required)
245+
- `--build-time` - Available at build time
246+
- `--is-literal` - Treat value as literal (don't interpolate variables)
247+
- `--is-multiline` - Value is multiline
248+
- `--runtime` - Available at runtime
236249
- `coolify service env delete <service_uuid> <env_uuid>` - Delete an environment variable
237250
- `coolify service env sync <service_uuid>` - Sync environment variables from a .env file
238251
- `--file <path>` - Path to .env file (required)

cmd/application/env/update.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,26 @@ import (
1212

1313
func NewUpdateEnvCommand() *cobra.Command {
1414
cmd := &cobra.Command{
15-
Use: "update <app_uuid> <env_uuid>",
15+
Use: "update <app_uuid>",
1616
Short: "Update an environment variable",
17-
Long: `Update an existing environment variable. First UUID is the application, second is the specific environment variable to update.`,
18-
Args: cli.ExactArgs(2, "<uuid1> <uuid2>"),
17+
Long: `Update an existing environment variable. UUID is the application.`,
18+
Args: cli.ExactArgs(1, "<app_uuid>"),
1919
RunE: func(cmd *cobra.Command, args []string) error {
2020
ctx := cmd.Context()
2121
appUUID := args[0]
22-
envUUID := args[1]
2322

2423
client, err := cli.GetAPIClient(cmd)
2524
if err != nil {
2625
return fmt.Errorf("failed to get API client: %w", err)
2726
}
2827

29-
req := &models.EnvironmentVariableUpdateRequest{
30-
UUID: envUUID,
28+
// Check minimum version requirement
29+
if err := cli.CheckMinimumVersion(ctx, client, "4.0.0-beta.469"); err != nil {
30+
return err
3131
}
3232

33+
req := &models.EnvironmentVariableUpdateRequest{}
34+
3335
if cmd.Flags().Changed("key") {
3436
key, _ := cmd.Flags().GetString("key")
3537
req.Key = &key
@@ -59,8 +61,11 @@ func NewUpdateEnvCommand() *cobra.Command {
5961
req.IsRuntime = &isRuntime
6062
}
6163

62-
if req.Key == nil && req.Value == nil && req.IsBuildTime == nil && req.IsPreview == nil && req.IsLiteral == nil && req.IsMultiline == nil && req.IsRuntime == nil {
63-
return fmt.Errorf("at least one field must be provided to update")
64+
if req.Key == nil {
65+
return fmt.Errorf("--key is required")
66+
}
67+
if req.Value == nil {
68+
return fmt.Errorf("--value is required")
6469
}
6570

6671
appSvc := service.NewApplicationService(client)

cmd/service/env/update.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,26 @@ import (
1212

1313
func NewUpdateCommand() *cobra.Command {
1414
cmd := &cobra.Command{
15-
Use: "update <service_uuid> <env_uuid>",
15+
Use: "update <service_uuid>",
1616
Short: "Update an environment variable",
17-
Long: `Update an existing environment variable. First UUID is the service, second is the specific environment variable to update.`,
18-
Args: cli.ExactArgs(2, "<uuid1> <uuid2>"),
17+
Long: `Update an existing environment variable. UUID is the service.`,
18+
Args: cli.ExactArgs(1, "<service_uuid>"),
1919
RunE: func(cmd *cobra.Command, args []string) error {
2020
ctx := cmd.Context()
2121
serviceUUID := args[0]
22-
envUUID := args[1]
2322

2423
client, err := cli.GetAPIClient(cmd)
2524
if err != nil {
2625
return fmt.Errorf("failed to get API client: %w", err)
2726
}
2827

29-
req := &models.ServiceEnvironmentVariableUpdateRequest{
30-
UUID: envUUID,
28+
// Check minimum version requirement
29+
if err := cli.CheckMinimumVersion(ctx, client, "4.0.0-beta.469"); err != nil {
30+
return err
3131
}
3232

33+
req := &models.ServiceEnvironmentVariableUpdateRequest{}
34+
3335
// Only set fields that were provided
3436
if cmd.Flags().Changed("key") {
3537
key, _ := cmd.Flags().GetString("key")
@@ -56,9 +58,11 @@ func NewUpdateCommand() *cobra.Command {
5658
req.IsRuntime = &isRuntime
5759
}
5860

59-
// Check if at least one field is being updated
60-
if req.Key == nil && req.Value == nil && req.IsBuildTime == nil && req.IsLiteral == nil && req.IsMultiline == nil && req.IsRuntime == nil {
61-
return fmt.Errorf("at least one field must be provided to update (--key, --value, --build-time, --is-literal, --is-multiline, or --runtime)")
61+
if req.Key == nil {
62+
return fmt.Errorf("--key is required")
63+
}
64+
if req.Value == nil {
65+
return fmt.Errorf("--value is required")
6266
}
6367

6468
serviceSvc := service.NewService(client)

internal/models/application.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ type EnvironmentVariableCreateRequest struct {
125125

126126
// EnvironmentVariableUpdateRequest represents the request to update an environment variable
127127
type EnvironmentVariableUpdateRequest struct {
128-
UUID string `json:"uuid"`
129128
Key *string `json:"key,omitempty"`
130129
Value *string `json:"value,omitempty"`
131130
IsBuildTime *bool `json:"is_build_time,omitempty"`

internal/models/service.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ type ServiceEnvironmentVariableCreateRequest struct {
100100

101101
// ServiceEnvironmentVariableUpdateRequest represents the request to update a service environment variable
102102
type ServiceEnvironmentVariableUpdateRequest struct {
103-
UUID string `json:"uuid"`
104103
Key *string `json:"key,omitempty"`
105104
Value *string `json:"value,omitempty"`
106105
IsBuildTime *bool `json:"is_build_time,omitempty"`
@@ -115,6 +114,4 @@ type ServiceEnvBulkUpdateRequest struct {
115114
}
116115

117116
// ServiceEnvBulkUpdateResponse represents the response from service bulk update
118-
type ServiceEnvBulkUpdateResponse struct {
119-
Message string `json:"message,omitempty"`
120-
}
117+
type ServiceEnvBulkUpdateResponse []ServiceEnvironmentVariable

internal/service/application_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,10 @@ func TestApplicationService_UpdateEnv(t *testing.T) {
737737
client := api.NewClient(server.URL, "test-token")
738738
svc := NewApplicationService(client)
739739

740+
newKey := "API_KEY"
740741
newValue := "newsecret456"
741742
req := &models.EnvironmentVariableUpdateRequest{
742-
UUID: "env-uuid-1",
743+
Key: &newKey,
743744
Value: &newValue,
744745
}
745746

@@ -760,9 +761,10 @@ func TestApplicationService_UpdateEnv_Error(t *testing.T) {
760761
client := api.NewClient(server.URL, "test-token")
761762
svc := NewApplicationService(client)
762763

764+
newKey := "API_KEY"
763765
newValue := "newsecret456"
764766
req := &models.EnvironmentVariableUpdateRequest{
765-
UUID: "env-uuid-1",
767+
Key: &newKey,
766768
Value: &newValue,
767769
}
768770

internal/service/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ func (s *Service) DeleteEnv(ctx context.Context, serviceUUID, envUUID string) er
157157
}
158158

159159
// BulkUpdateEnvs updates multiple environment variables in a single request
160-
func (s *Service) BulkUpdateEnvs(ctx context.Context, serviceUUID string, req *models.ServiceEnvBulkUpdateRequest) (*models.ServiceEnvBulkUpdateResponse, error) {
160+
func (s *Service) BulkUpdateEnvs(ctx context.Context, serviceUUID string, req *models.ServiceEnvBulkUpdateRequest) (models.ServiceEnvBulkUpdateResponse, error) {
161161
var response models.ServiceEnvBulkUpdateResponse
162162
err := s.client.Patch(ctx, fmt.Sprintf("services/%s/envs/bulk", serviceUUID), req, &response)
163163
if err != nil {
164164
return nil, fmt.Errorf("failed to bulk update environment variables for service %s: %w", serviceUUID, err)
165165
}
166-
return &response, nil
166+
return response, nil
167167
}

internal/service/service_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ func TestService_UpdateEnv(t *testing.T) {
330330

331331
newKey := "UPDATED_VAR"
332332
env, err := svc.UpdateEnv(context.Background(), "service-uuid-123", &models.ServiceEnvironmentVariableUpdateRequest{
333-
UUID: "env-123",
334-
Key: &newKey,
333+
Key: &newKey,
335334
})
336335

337336
require.NoError(t, err)

0 commit comments

Comments
 (0)