From 49c4e63980be79249d9aab3eb07888848b84b0aa Mon Sep 17 00:00:00 2001 From: Marc Campbell Date: Sun, 17 May 2026 09:54:51 -0600 Subject: [PATCH 1/2] properly handle app type in api --- client/app.go | 43 +++++++++++++++++++++++++++++++++++++++--- client/app_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 client/app_test.go diff --git a/client/app.go b/client/app.go index 5da634d9c..1ce0211ca 100644 --- a/client/app.go +++ b/client/app.go @@ -3,6 +3,9 @@ package client import ( "context" + "github.com/pkg/errors" + "github.com/replicatedhq/replicated/pkg/kotsclient" + "github.com/replicatedhq/replicated/pkg/platformclient" "github.com/replicatedhq/replicated/pkg/types" ) @@ -49,13 +52,47 @@ func (c *Client) ListApps(excludeChannels bool) ([]types.AppAndChannels, error) } func (c *Client) GetApp(appID string) (interface{}, error) { - return nil, nil + app, _, err := c.GetAppType(context.TODO(), appID, true) + if err != nil { + return nil, err + } + return app, nil } func (c *Client) CreateApp(appOptions interface{}) (interface{}, error) { - return nil, nil + switch opts := appOptions.(type) { + case string: + return c.KotsClient.CreateKOTSApp(context.TODO(), opts) + case kotsclient.CreateKOTSAppRequest: + return c.KotsClient.CreateKOTSApp(context.TODO(), opts.Name) + case *kotsclient.CreateKOTSAppRequest: + if opts == nil { + return nil, errors.New("create app options cannot be nil") + } + return c.KotsClient.CreateKOTSApp(context.TODO(), opts.Name) + case platformclient.AppOptions: + return c.PlatformClient.CreateApp(&opts) + case *platformclient.AppOptions: + if opts == nil { + return nil, errors.New("create app options cannot be nil") + } + return c.PlatformClient.CreateApp(opts) + default: + return nil, errors.Errorf("unsupported app options type %T", appOptions) + } } func (c *Client) DeleteApp(appID string) error { - return nil + app, appType, err := c.GetAppType(context.TODO(), appID, true) + if err != nil { + return err + } + + if appType == "platform" { + return c.PlatformClient.DeleteApp(app.ID) + } else if appType == "kots" { + return c.KotsClient.DeleteKOTSApp(context.TODO(), app.ID) + } + + return errors.Errorf("unknown app type %q", appType) } diff --git a/client/app_test.go b/client/app_test.go new file mode 100644 index 000000000..126c19b73 --- /dev/null +++ b/client/app_test.go @@ -0,0 +1,47 @@ +package client + +import ( + "testing" + + "github.com/replicatedhq/replicated/pkg/kotsclient" + "github.com/replicatedhq/replicated/pkg/platformclient" + "github.com/stretchr/testify/require" +) + +func newTestClient(origin string) Client { + platformHTTPClient := platformclient.NewHTTPClient(origin, "fake-api-key") + return Client{ + PlatformClient: platformHTTPClient, + KotsClient: &kotsclient.VendorV3Client{HTTPClient: *platformHTTPClient}, + } +} + +func TestClientGetAppReturnsBackendError(t *testing.T) { + c := newTestClient("http://%") + + app, err := c.GetApp("app-id") + require.Nil(t, app) + require.Error(t, err) +} + +func TestClientCreateAppRejectsUnsupportedOptions(t *testing.T) { + c := newTestClient("http://127.0.0.1") + + app, err := c.CreateApp(struct{}{}) + require.Nil(t, app) + require.ErrorContains(t, err, "unsupported app options type") +} + +func TestClientCreateAppRejectsNilOptions(t *testing.T) { + c := newTestClient("http://127.0.0.1") + + app, err := c.CreateApp((*platformclient.AppOptions)(nil)) + require.Nil(t, app) + require.ErrorContains(t, err, "create app options cannot be nil") +} + +func TestClientDeleteAppReturnsLookupError(t *testing.T) { + c := newTestClient("http://%") + + require.Error(t, c.DeleteApp("app-id")) +} From c12f109e989bbb567516e1282a1d076aa276171f Mon Sep 17 00:00:00 2001 From: Marc Campbell Date: Mon, 18 May 2026 14:16:06 -0700 Subject: [PATCH 2/2] fix: remove ambiguous string case from CreateApp Co-Authored-By: Claude Sonnet 4.6 (1M context) --- client/app.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/app.go b/client/app.go index 1ce0211ca..45333fb3c 100644 --- a/client/app.go +++ b/client/app.go @@ -61,8 +61,6 @@ func (c *Client) GetApp(appID string) (interface{}, error) { func (c *Client) CreateApp(appOptions interface{}) (interface{}, error) { switch opts := appOptions.(type) { - case string: - return c.KotsClient.CreateKOTSApp(context.TODO(), opts) case kotsclient.CreateKOTSAppRequest: return c.KotsClient.CreateKOTSApp(context.TODO(), opts.Name) case *kotsclient.CreateKOTSAppRequest: