Skip to content

Commit

Permalink
internal/rest/client: Add the client GetExtensions client function
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Feb 16, 2024
1 parent 5967d8e commit d28ee6e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions internal/rest/client/extensions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package client

import (
"context"
"time"

"github.com/canonical/lxd/shared/api"
"github.com/canonical/microcluster/internal/rest/types"
)

// GetExtensions returns the runtime extensions of the MicroCluster deployment.
func (c *Client) GetExtensions(ctx context.Context, extensionVendor string, extensionName string) ([]types.RuntimeExtension, error) {
queryCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()

endpoint := api.NewURL().Path("extensions")
if extensionVendor != "" {
endpoint = endpoint.WithQuery("vendor", extensionVendor)
}

if extensionName != "" {
endpoint = endpoint.WithQuery("extension", extensionName)
}

extensions := []types.RuntimeExtension{}
err := c.QueryStruct(queryCtx, "GET", PublicEndpoint, endpoint, nil, &extensions)

return extensions, err
}

0 comments on commit d28ee6e

Please sign in to comment.