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
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ func startEmulator(ctx context.Context, rt runtime.Runtime, cfg *env.Env, tel *t
})
}
update.NotifyUpdate(ctx, sink, update.NotifyOptions{GitHubToken: cfg.GitHubToken})
return container.Start(ctx, rt, sink, opts, false)
_, err = container.Start(ctx, rt, sink, opts, false)
return err
}

// instrumentCommands walks the Cobra command tree and wraps every RunE with telemetry emission.
Expand Down
3 changes: 2 additions & 1 deletion cmd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func newSnapshotCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cob
func buildStarter(cfg *env.Env, rt runtime.Runtime, appConfig *config.Config, logger log.Logger, tel *telemetry.Client) snapshot.Starter {
return func(ctx context.Context, sink output.Sink) error {
opts := buildStartOptions(cfg, appConfig, logger, tel, false)
return container.Start(ctx, rt, sink, opts, false)
_, err := container.Start(ctx, rt, sink, opts, false)
return err
}
}

Expand Down
121 changes: 0 additions & 121 deletions internal/api/catalog_version_test.go

This file was deleted.

43 changes: 0 additions & 43 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"

Expand All @@ -25,7 +24,6 @@ type PlatformAPI interface {
ExchangeAuthRequest(ctx context.Context, id, exchangeToken string) (string, error)
GetLicenseToken(ctx context.Context, bearerToken string) (string, error)
GetLicense(ctx context.Context, req *LicenseRequest) (*LicenseResponse, error)
GetLatestCatalogVersion(ctx context.Context, emulatorType string) (string, error)
}

type AuthRequest struct {
Expand Down Expand Up @@ -341,44 +339,3 @@ func (c *PlatformClient) GetLicense(ctx context.Context, licReq *LicenseRequest)
}
}

type catalogVersionResponse struct {
EmulatorType string `json:"emulator_type"`
Version string `json:"version"`
}

func (c *PlatformClient) GetLatestCatalogVersion(ctx context.Context, emulatorType string) (string, error) {
reqURL := fmt.Sprintf("%s/v1/license/catalog/%s/version", c.baseURL, url.PathEscape(emulatorType))
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)
if err != nil {
return "", fmt.Errorf("failed to create request: %w", err)
}

resp, err := c.httpClient.Do(req)
if err != nil {
return "", fmt.Errorf("failed to get catalog version: %w", err)
}
defer func() {
if err := resp.Body.Close(); err != nil {
c.logger.Error("failed to close response body: %v", err)
}
}()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("failed to get catalog version: status %d", resp.StatusCode)
}

var versionResp catalogVersionResponse
if err := json.NewDecoder(resp.Body).Decode(&versionResp); err != nil {
return "", fmt.Errorf("failed to decode response: %w", err)
}

if versionResp.EmulatorType == "" || versionResp.Version == "" {
return "", fmt.Errorf("incomplete catalog response: emulator_type=%q version=%q", versionResp.EmulatorType, versionResp.Version)
}

if versionResp.EmulatorType != emulatorType {
return "", fmt.Errorf("unexpected emulator_type: got=%q want=%q", versionResp.EmulatorType, emulatorType)
}

return versionResp.Version, nil
}
18 changes: 9 additions & 9 deletions internal/container/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
"github.com/localstack/lstk/internal/log"
)

func ResolveAndCacheLabel(ctx context.Context, opts StartOptions, labelCh chan<- string) {
label, ok := ResolveEmulatorLabel(ctx, opts.PlatformClient, opts.Containers, opts.AuthToken, opts.Logger)
// ResolveAndCacheLabel resolves the plan label using the version returned by Start
// and caches it for subsequent runs. resolvedVersion is the version extracted from
// image inspection; it may be empty if Start returned early (e.g. already running).
func ResolveAndCacheLabel(ctx context.Context, opts StartOptions, resolvedVersion string, labelCh chan<- string) {
label, ok := ResolveEmulatorLabel(ctx, opts.PlatformClient, opts.Containers, opts.AuthToken, resolvedVersion, opts.Logger)
if ok {
config.CachePlanLabel(label)
}
Expand All @@ -25,7 +28,8 @@ const NoLicenseLabel = "LocalStack (No license)"
// to build a label like "LocalStack Ultimate". Falls back to
// NoLicenseLabel when the plan cannot be determined. The returned bool
// is true only when a real plan was resolved (i.e. the result is worth caching).
func ResolveEmulatorLabel(ctx context.Context, client api.PlatformAPI, containers []config.ContainerConfig, token string, logger log.Logger) (string, bool) {
// resolvedVersion is the version from post-pull image inspection for "latest" containers.
func ResolveEmulatorLabel(ctx context.Context, client api.PlatformAPI, containers []config.ContainerConfig, token, resolvedVersion string, logger log.Logger) (string, bool) {
if len(containers) == 0 || token == "" {
return NoLicenseLabel, false
}
Expand All @@ -42,14 +46,10 @@ func ResolveEmulatorLabel(ctx context.Context, client api.PlatformAPI, container
if c.Type == config.EmulatorSnowflake {
return "LocalStack", false
}
apiCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
v, err := client.GetLatestCatalogVersion(apiCtx, string(c.Type))
cancel()
if err != nil {
logger.Info("could not resolve catalog version for header: %v", err)
if resolvedVersion == "" {
return NoLicenseLabel, false
}
tag = v
tag = resolvedVersion
}

hostname, _ := os.Hostname()
Expand Down
3 changes: 2 additions & 1 deletion internal/container/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ func Restart(ctx context.Context, rt runtime.Runtime, sink output.Sink, stopOpts
if err := Stop(ctx, rt, sink, startOpts.Containers, stopOpts); err != nil {
return err
}
return Start(ctx, rt, sink, startOpts, interactive)
_, err := Start(ctx, rt, sink, startOpts, interactive)
return err
}
Loading
Loading