Skip to content

Commit 3ad1fbf

Browse files
authored
Remove license catalog check for version resolution (#265)
1 parent ec14f45 commit 3ad1fbf

11 files changed

Lines changed: 146 additions & 272 deletions

File tree

cmd/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ func startEmulator(ctx context.Context, rt runtime.Runtime, cfg *env.Env, tel *t
205205
})
206206
}
207207
update.NotifyUpdate(ctx, sink, update.NotifyOptions{GitHubToken: cfg.GitHubToken})
208-
return container.Start(ctx, rt, sink, opts, false)
208+
_, err = container.Start(ctx, rt, sink, opts, false)
209+
return err
209210
}
210211

211212
// instrumentCommands walks the Cobra command tree and wraps every RunE with telemetry emission.

cmd/snapshot.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ func newSnapshotCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cob
6363
func buildStarter(cfg *env.Env, rt runtime.Runtime, appConfig *config.Config, logger log.Logger, tel *telemetry.Client) snapshot.Starter {
6464
return func(ctx context.Context, sink output.Sink) error {
6565
opts := buildStartOptions(cfg, appConfig, logger, tel, false)
66-
return container.Start(ctx, rt, sink, opts, false)
66+
_, err := container.Start(ctx, rt, sink, opts, false)
67+
return err
6768
}
6869
}
6970

internal/api/catalog_version_test.go

Lines changed: 0 additions & 121 deletions
This file was deleted.

internal/api/client.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10-
"net/url"
1110
"strings"
1211
"time"
1312

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

3129
type AuthRequest struct {
@@ -341,44 +339,3 @@ func (c *PlatformClient) GetLicense(ctx context.Context, licReq *LicenseRequest)
341339
}
342340
}
343341

344-
type catalogVersionResponse struct {
345-
EmulatorType string `json:"emulator_type"`
346-
Version string `json:"version"`
347-
}
348-
349-
func (c *PlatformClient) GetLatestCatalogVersion(ctx context.Context, emulatorType string) (string, error) {
350-
reqURL := fmt.Sprintf("%s/v1/license/catalog/%s/version", c.baseURL, url.PathEscape(emulatorType))
351-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)
352-
if err != nil {
353-
return "", fmt.Errorf("failed to create request: %w", err)
354-
}
355-
356-
resp, err := c.httpClient.Do(req)
357-
if err != nil {
358-
return "", fmt.Errorf("failed to get catalog version: %w", err)
359-
}
360-
defer func() {
361-
if err := resp.Body.Close(); err != nil {
362-
c.logger.Error("failed to close response body: %v", err)
363-
}
364-
}()
365-
366-
if resp.StatusCode != http.StatusOK {
367-
return "", fmt.Errorf("failed to get catalog version: status %d", resp.StatusCode)
368-
}
369-
370-
var versionResp catalogVersionResponse
371-
if err := json.NewDecoder(resp.Body).Decode(&versionResp); err != nil {
372-
return "", fmt.Errorf("failed to decode response: %w", err)
373-
}
374-
375-
if versionResp.EmulatorType == "" || versionResp.Version == "" {
376-
return "", fmt.Errorf("incomplete catalog response: emulator_type=%q version=%q", versionResp.EmulatorType, versionResp.Version)
377-
}
378-
379-
if versionResp.EmulatorType != emulatorType {
380-
return "", fmt.Errorf("unexpected emulator_type: got=%q want=%q", versionResp.EmulatorType, emulatorType)
381-
}
382-
383-
return versionResp.Version, nil
384-
}

internal/container/label.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import (
1111
"github.com/localstack/lstk/internal/log"
1212
)
1313

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

5555
hostname, _ := os.Hostname()

internal/container/restart.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ func Restart(ctx context.Context, rt runtime.Runtime, sink output.Sink, stopOpts
1111
if err := Stop(ctx, rt, sink, startOpts.Containers, stopOpts); err != nil {
1212
return err
1313
}
14-
return Start(ctx, rt, sink, startOpts, interactive)
14+
_, err := Start(ctx, rt, sink, startOpts, interactive)
15+
return err
1516
}

0 commit comments

Comments
 (0)