Skip to content
Merged
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
4 changes: 4 additions & 0 deletions cmd/harness_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ var harnessConfigShowCmd = &cobra.Command{
fmt.Printf("Content Hash: %s\n", truncateHash(hc.ContentHash))
fmt.Printf("Scope: %s\n", hc.Scope)
fmt.Printf("Files: %d\n", len(hc.Files))
if hc.SourceURL != "" {
fmt.Printf("Source URL: %s\n", hc.SourceURL)
}
return nil
}
}
Expand Down Expand Up @@ -834,6 +837,7 @@ func init() {
harnessConfigCmd.AddCommand(harnessConfigShowCmd)
harnessConfigCmd.AddCommand(harnessConfigDeleteCmd)
harnessConfigCmd.AddCommand(harnessConfigInstallCmd)
harnessConfigCmd.AddCommand(harnessConfigUpdateCmd)

// Flags for list command
harnessConfigListCmd.Flags().Bool("hub", false, "Include Hub results")
Expand Down
197 changes: 197 additions & 0 deletions cmd/harness_config_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"context"
"fmt"
"time"

"github.com/GoogleCloudPlatform/scion/pkg/config"
"github.com/GoogleCloudPlatform/scion/pkg/hubclient"
"github.com/spf13/cobra"
)

var harnessConfigUpdateCmd = &cobra.Command{
Use: "update [name]",
Short: "Re-import a harness-config from its source URL",
Long: `Re-imports a harness-config from its stored source URL, pulling the latest
version from the remote source.

If --url is provided, it overrides (and updates) the stored source URL.
Use --all to re-import all harness-configs that have a stored source URL.

Examples:
scion harness-config update my-claude
scion harness-config update my-claude --url https://github.com/org/repo/tree/main/harness-configs/claude
scion harness-config update --all`,
Args: cobra.MaximumNArgs(1),
RunE: runHarnessConfigUpdate,
}

func runHarnessConfigUpdate(cmd *cobra.Command, args []string) error {
urlOverride, _ := cmd.Flags().GetString("url")
all, _ := cmd.Flags().GetBool("all")

if len(args) == 0 && !all {
return fmt.Errorf("specify a harness-config name or use --all")
}
if all && urlOverride != "" {
return fmt.Errorf("--all and --url cannot be used together")
}

var gp string
if projectPath != "" {
resolved, err := config.GetResolvedProjectDir(projectPath)
if err != nil {
return fmt.Errorf("failed to resolve project path %q: %w", projectPath, err)
}
gp = resolved
} else if projectDir, err := config.GetResolvedProjectDir(""); err == nil {
gp = projectDir
}
Comment on lines +55 to +64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If projectPath is explicitly provided by the user, any error encountered while resolving the project directory should be handled and returned rather than silently ignored. Silently ignoring the error can lead to unexpected behavior or confusing error messages later in the execution.

Suggested change
var gp string
if projectPath != "" {
resolved, err := config.GetResolvedProjectDir(projectPath)
if err == nil {
gp = resolved
}
} else if projectDir, err := config.GetResolvedProjectDir(""); err == nil {
gp = projectDir
}
var gp string
if projectPath != "" {
resolved, err := config.GetResolvedProjectDir(projectPath)
if err != nil {
return fmt.Errorf("failed to resolve project directory %q: %w", projectPath, err)
}
gp = resolved
} else if projectDir, err := config.GetResolvedProjectDir(""); err == nil {
gp = projectDir
}


hubCtx, err := CheckHubAvailabilityWithOptions(gp, true)
if err != nil {
return err
}
if hubCtx == nil {
return fmt.Errorf("Hub is not available. The update command requires a Hub connection.")

Check failure on line 71 in cmd/harness_config_update.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1005: error strings should not end with punctuation or newlines (staticcheck)
}

PrintUsingHub(hubCtx.Endpoint)

ctx, cancel := context.WithTimeout(cmd.Context(), 120*time.Second)
defer cancel()

if all {
return updateAllHarnessConfigs(ctx, hubCtx)
}

name := args[0]
return updateSingleHarnessConfig(ctx, hubCtx, name, urlOverride)
}

func updateSingleHarnessConfig(ctx context.Context, hubCtx *HubContext, name, urlOverride string) error {
resp, err := hubCtx.Client.HarnessConfigs().List(ctx, &hubclient.ListHarnessConfigsOptions{
Name: name,
Status: "active",
})
if err != nil {
return fmt.Errorf("failed to search Hub: %w", err)
}
Comment on lines +92 to +94

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Add a nil check for resp to prevent a potential nil pointer dereference if the API client returns a nil response without an error.

	if err != nil {
		return fmt.Errorf("failed to search Hub: %w", err)
	}
	if resp == nil {
		return fmt.Errorf("failed to search Hub: received empty response")
	}

if resp == nil {
return fmt.Errorf("harness-config %q not found on Hub", name)
}

var match *hubclient.HarnessConfig
for i := range resp.HarnessConfigs {
if resp.HarnessConfigs[i].Name == name || resp.HarnessConfigs[i].Slug == name {
match = &resp.HarnessConfigs[i]
break
}
}
if match == nil {
return fmt.Errorf("harness-config %q not found on Hub", name)
}

sourceURL := urlOverride
if sourceURL == "" {
sourceURL = match.SourceURL
}
if sourceURL == "" {
return fmt.Errorf("harness-config %q has no stored source URL. Use --url to specify one.", name)

Check failure on line 115 in cmd/harness_config_update.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1005: error strings should not end with punctuation or newlines (staticcheck)
}

if !isJSONOutput() {
fmt.Printf("Updating %q from %s...\n", name, sourceURL)
}

result, err := hubCtx.Client.HarnessConfigs().Reimport(ctx, match.ID, urlOverride)
if err != nil {
return fmt.Errorf("reimport failed: %w", err)
}
Comment on lines +122 to +125

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The Reimport call can potentially return a nil result even if err is nil. To prevent a potential nil pointer dereference panic when accessing result.Count or result.HarnessConfigs, add a nil check for result.

result, err := hubCtx.Client.HarnessConfigs().Reimport(ctx, match.ID, urlOverride)
	if err != nil {
		return fmt.Errorf("reimport failed: %w", err)
	}
	if result == nil {
		return fmt.Errorf("reimport failed: received empty response from Hub")
	}

if result == nil {
return fmt.Errorf("reimport returned no result for %q", name)
}

if isJSONOutput() {
return outputJSON(ActionResult{
Status: "success",
Command: "harness-config update",
Message: fmt.Sprintf("Updated %d harness-config(s)", result.Count),
Details: map[string]interface{}{
"name": name,
"imported": result.HarnessConfigs,
"count": result.Count,
},
})
}

fmt.Printf("Updated %d harness-config(s): %v\n", result.Count, result.HarnessConfigs)
return nil
}

func updateAllHarnessConfigs(ctx context.Context, hubCtx *HubContext) error {
resp, err := hubCtx.Client.HarnessConfigs().List(ctx, &hubclient.ListHarnessConfigsOptions{
Status: "active",
})
if err != nil {
return fmt.Errorf("failed to list harness-configs: %w", err)
}
Comment on lines +151 to +153

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Add a nil check for resp to prevent a potential nil pointer dereference if the API client returns a nil response without an error.

Suggested change
if err != nil {
return fmt.Errorf("failed to list harness-configs: %w", err)
}
if err != nil {
return fmt.Errorf("failed to list harness-configs: %w", err)
}
if resp == nil {
return fmt.Errorf("failed to list harness-configs: received empty response")
}

if resp == nil {
return fmt.Errorf("no harness-configs found")
}

var updated, skipped, failed int
jsonOut := isJSONOutput()
for _, hc := range resp.HarnessConfigs {
if hc.SourceURL == "" {
skipped++
continue
}
if !jsonOut {
fmt.Printf("Updating %q from %s...\n", hc.Name, hc.SourceURL)
}
_, err := hubCtx.Client.HarnessConfigs().Reimport(ctx, hc.ID, "")
if err != nil {
if !jsonOut {
fmt.Printf(" Failed: %s\n", err)
}
failed++
continue
}
if !jsonOut {
fmt.Printf(" Done.\n")
}
updated++
}

if jsonOut {
return outputJSON(ActionResult{
Status: "success",
Command: "harness-config update --all",
Message: fmt.Sprintf("Updated %d, skipped %d (no source URL), failed %d", updated, skipped, failed),
})
}

fmt.Printf("\nUpdated %d, skipped %d (no source URL), failed %d\n", updated, skipped, failed)
return nil
}

func init() {
harnessConfigUpdateCmd.Flags().String("url", "", "Override the stored source URL")
harnessConfigUpdateCmd.Flags().Bool("all", false, "Update all harness-configs that have a stored source URL")
}
7 changes: 7 additions & 0 deletions harnesses/antigravity/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ capabilities:
oauth_token: { support: "yes", reason: "Via gnome-keyring population from AGY_KEYRING_TOKEN secret" }
vertex_ai: { support: "yes", reason: "Enterprise/GCP mode via AGY_KEYRING_TOKEN + GOOGLE_CLOUD_PROJECT" }

no_auth:
behavior: drop-to-shell
message: |
This agent started without credentials.
Run: agy auth login
Then follow the prompts to authenticate.

auth:
types:
oauth-token:
Expand Down
3 changes: 1 addition & 2 deletions pkg/ent/entc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/jackc/pgx/v5/stdlib"

"github.com/GoogleCloudPlatform/scion/pkg/ent"
"github.com/GoogleCloudPlatform/scion/pkg/ent/migrate"
)

// PoolConfig holds connection pool settings applied to the underlying
Expand Down Expand Up @@ -171,7 +170,7 @@ func applyKeepalives(params map[string]string) {

// AutoMigrate runs automatic schema migration on the given client.
func AutoMigrate(ctx context.Context, client *ent.Client) error {
if err := client.Schema.Create(ctx, migrate.WithDropIndex(true), migrate.WithDropColumn(true)); err != nil {
if err := client.Schema.Create(ctx); err != nil {
return fmt.Errorf("running auto-migration: %w", err)
}
return nil
Expand Down
13 changes: 12 additions & 1 deletion pkg/ent/harnessconfig.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/ent/harnessconfig/harnessconfig.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading