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
20 changes: 13 additions & 7 deletions .claude/skills/development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,18 @@ there, later, and not in this repository's CI.
`develop` but not released. The source is the controllers and meshObjects of `../meshfed-release`
(*meshcloud-internal*).

**The provider implements the client's interfaces.** Its tests plug the mocks of its
`internal/clientmock` into `client.Client`, so a method added to a `Mesh…Client` interface stops
the provider compiling at its next bump. Put a method only the CLI calls on a new `client.Client`
field instead: an interface of its own, or a concrete type such as `*client.RawClient` when nothing
mocks it. `client.New` sets the field for every caller, while the provider's mock client fills the
struct by field name and leaves a new field unset.
**The provider implements the client's interfaces.** Every kind's client is a type alias named
after the kind for one of three generic interfaces, each of which adds to the one before:
`client.MeshObjectReadOnlyClient[M, Filter]` with Read, List and ListSeq,
`client.MeshObjectImmutableClient[M, Filter]` with Create and Delete, and
`client.MeshObjectClient[M, Filter]` with Update. The alias takes the level that the API docs offer
for the kind. The tests of the provider plug the mocks of its `internal/clientmock` into
`client.Client`, so a method added to a `Mesh…Client` interface stops the provider compiling at
its next bump. An action of a kind is a method of the object, such as `run.Abort(ctx)`, which
follows a link of the object's `_links` through `hal.Links` and states the link's rel, method,
payload and result type once. Put anything else only the CLI
calls on a new `client.Client` field, which the provider's mock client leaves unset, or in a
function of `client`, such as `client.WithKindAndApiVersion`.

Reading the pre-import history takes both paths, since the import merge re-roots the files under
`client/`:
Expand All @@ -138,7 +144,7 @@ git log -- client/client.go client.go # a path-limited log from client/ alone
git blame client/client.go # traverses the merge on its own
```

**`client/` does not log in.** `client.Authorization` produces a bearer token and replaces one that
**`client/` does not log in.** `http.Authorization` produces a bearer token and replaces one that
came back 401; resolving a credential, minting a token, caching it and refreshing it is `pkg/auth`.
Both front ends build their client through `auth.ResolveClient`, so the endpoint and the
authorization always agree with what was resolved. Do **not** add a login exchange anywhere else: a
Expand Down
13 changes: 6 additions & 7 deletions .claude/skills/meshobject-command/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ the `help-text` rule of the `development` skill.

## Leaf

- `list` lists the kind with `flags.Run[M](cmd, filter)` of `internal.ListFlags`, which pages through
`client.Raw.List[M]`.
- `list` lists the kind with `flags.Run(cmd, meshStack.<Kind>, filter)` of `internal.ListFlags`,
which pages through the kind's `List`.
- `show` shows one object.
- A sub-resource or an action is named after its path element in the API: `buildingblockrun logs`
for `…/logs`, `buildingblock trigger-run` for `…/trigger-run`.
Expand All @@ -65,11 +65,10 @@ and a `cmd/internal/markdown` template next to the command.
- A command gets its client from `internal.ResolveClient`, or for the session itself from
`auth.ResolveSession(ctx, internal.ResolveClientOptions(...))` and `Session.Client`. A
`ResolveClientOptionsModifier` such as `internal.SkipVersionCheck` adapts the resolution.
- What the CLI writes as meshStack sent it goes through `client.Raw`: `List[M]` with the kind's
list filter struct, `Get[M]` for one object or a sub-resource below it, and `DoRequest` for any
other path. `M` is the Go type of the kind's typed client, which `client.New` registers with
`Raw`; register a kind there before a command reads it.
- A list filter struct holds every query parameter the API docs give its endpoint, a repeated one
- The CLI writes an object as meshStack sent it through `client.WithKindAndApiVersion`. A
sub-resource or an action is a method of the typed object, such as `run.Logs`, which follows a
link of its `Links`. Add such a method in `client/` for a new one. Any other path goes through `client.Client.HttpClient`, joined onto `client.Client.Endpoint`.
- A filter struct holds every query parameter the API docs give its endpoint, a repeated one
as a slice. A parameter the command always sends, such as `includeAllPublished`, is a field the
command sets. Any other client method only the CLI calls goes on a new `client.Client` field, so
the Terraform provider's mocks keep compiling.
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ linters:
checks:
- all
- -ST1000
# SA4023 crashes on a type with a generic method, as client.RawClient has: go1.27.0 loses
# SA4023 crashes on a type with a generic method, as hal.Link has: go1.27.0 loses
# the order of methods in the export data (golang/go#81188). Enable it again with go1.27.2.
- -SA4023
# Replaces the default list, so that ClientId, BaseUrl and Uuid stand as the meshObject
Expand Down
40 changes: 5 additions & 35 deletions client/api_key.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package client

import (
"context"
"time"

"github.com/meshcloud/meshstack-cli/client/internal"
"github.com/meshcloud/meshstack-cli/client/types"
)

type MeshApiKeyMetadata = MeshObjectByUuidMetadata

type MeshApiKey struct {
Metadata MeshApiKeyMetadata `json:"metadata" tfsdk:"metadata"`
Spec MeshApiKeySpec `json:"spec" tfsdk:"spec"`
Status *MeshApiKeyStatus `json:"status,omitzero" tfsdk:"status"`
}

type MeshApiKeyMetadata struct {
Uuid *string `json:"uuid,omitzero" tfsdk:"uuid"`
OwnedByWorkspace string `json:"ownedByWorkspace" tfsdk:"owned_by_workspace"`
func (k MeshApiKey) meshObjectId() string {
return k.Metadata.meshObjectId()
}

type MeshApiKeySpec struct {
Expand All @@ -33,33 +32,4 @@ type MeshApiKeyStatus struct {
ExpiresAt time.Time `json:"expiresAt,omitzero" tfsdk:"-"`
}

type MeshApiKeyClient interface {
Create(ctx context.Context, apiKey *MeshApiKey) (*MeshApiKey, error)
Read(ctx context.Context, uuid string) (*MeshApiKey, error)
Update(ctx context.Context, uuid string, apiKey *MeshApiKey) (*MeshApiKey, error)
Delete(ctx context.Context, uuid string) error
}

type meshApiKeyClient struct {
meshObject internal.MeshObjectClient[MeshApiKey]
}

func newApiKeyClient(ctx context.Context, httpClient internal.HttpClient) MeshApiKeyClient {
return meshApiKeyClient{internal.NewMeshObjectClient[MeshApiKey](ctx, httpClient, "v1-preview")}
}

func (c meshApiKeyClient) Create(ctx context.Context, apiKey *MeshApiKey) (*MeshApiKey, error) {
return c.meshObject.Post(ctx, apiKey)
}

func (c meshApiKeyClient) Read(ctx context.Context, uuid string) (*MeshApiKey, error) {
return c.meshObject.Get(ctx, uuid)
}

func (c meshApiKeyClient) Update(ctx context.Context, uuid string, apiKey *MeshApiKey) (*MeshApiKey, error) {
return c.meshObject.Put(ctx, uuid, apiKey)
}

func (c meshApiKeyClient) Delete(ctx context.Context, uuid string) error {
return c.meshObject.Delete(ctx, uuid)
}
type MeshApiKeyClient = MeshObjectClient[MeshApiKey, NoFilter]
53 changes: 8 additions & 45 deletions client/building_block_definition.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package client

import (
"context"

"github.com/meshcloud/meshstack-cli/client/http"
"github.com/meshcloud/meshstack-cli/client/internal"
"github.com/meshcloud/meshstack-cli/client/types"
"github.com/meshcloud/meshstack-cli/client/types/enum"
"github.com/meshcloud/meshstack-cli/client/types/hal"
)

type MeshBuildingBlockType string
Expand Down Expand Up @@ -129,58 +126,24 @@ type MeshBuildingBlockDefinitionStatus struct {
LatestReleasedVersion *int64 `json:"latestReleasedVersion"`
LatestReleasedVersionUuid *string `json:"latestReleasedVersionUuid"`
RedactedForNonOwnerAccess bool `json:"redactedForNonOwnerAccess"`
Lifecycle MeshLifecycle `json:"lifecycle"`
}

type MeshBuildingBlockDefinition struct {
Metadata MeshBuildingBlockDefinitionMetadata `json:"metadata"`
Spec MeshBuildingBlockDefinitionSpec `json:"spec"`
Status *MeshBuildingBlockDefinitionStatus `json:"status,omitzero"`
Links hal.Links `json:"_links,omitzero"`
}

type MeshBuildingBlockDefinitionClient interface {
List(ctx context.Context, workspaceIdentifier *string) ([]MeshBuildingBlockDefinition, error)
Read(ctx context.Context, uuid string) (*MeshBuildingBlockDefinition, error)
Create(ctx context.Context, definition MeshBuildingBlockDefinition) (*MeshBuildingBlockDefinition, error)
Update(ctx context.Context, uuid string, definition MeshBuildingBlockDefinition) (*MeshBuildingBlockDefinition, error)
Delete(ctx context.Context, uuid string) error
}

type meshBuildingBlockDefinitionClient struct {
meshObject internal.MeshObjectClient[MeshBuildingBlockDefinition]
}

func newBuildingBlockDefinitionClient(ctx context.Context, httpClient internal.HttpClient) meshBuildingBlockDefinitionClient {
return meshBuildingBlockDefinitionClient{
meshObject: internal.NewMeshObjectClient[MeshBuildingBlockDefinition](ctx, httpClient, "v1"),
}
}
type MeshBuildingBlockDefinitionClient = MeshObjectClient[MeshBuildingBlockDefinition, MeshBuildingBlockDefinitionFilter]

type MeshBuildingBlockDefinitionListFilter struct {
type MeshBuildingBlockDefinitionFilter struct {
OwnedByWorkspace *string `json:"ownedByWorkspace"`
// IncludeAllPublished adds the definitions published to the whole platform to the workspace's own.
IncludeAllPublished bool `json:"includeAllPublished"`
Sort SortCriteria `json:"sort"`
}

func (c meshBuildingBlockDefinitionClient) List(ctx context.Context, workspaceIdentifier *string) ([]MeshBuildingBlockDefinition, error) {
return c.meshObject.List(ctx, http.WithUrlQuery(MeshBuildingBlockDefinitionListFilter{
OwnedByWorkspace: workspaceIdentifier,
IncludeAllPublished: true,
}))
}

func (c meshBuildingBlockDefinitionClient) Read(ctx context.Context, uuid string) (*MeshBuildingBlockDefinition, error) {
return c.meshObject.Get(ctx, uuid)
}

func (c meshBuildingBlockDefinitionClient) Create(ctx context.Context, definition MeshBuildingBlockDefinition) (*MeshBuildingBlockDefinition, error) {
return c.meshObject.Post(ctx, definition)
}

func (c meshBuildingBlockDefinitionClient) Update(ctx context.Context, uuid string, definition MeshBuildingBlockDefinition) (*MeshBuildingBlockDefinition, error) {
return c.meshObject.Put(ctx, uuid, definition)
IncludeAllPublished bool `json:"includeAllPublished"`
}

func (c meshBuildingBlockDefinitionClient) Delete(ctx context.Context, uuid string) error {
return c.meshObject.Delete(ctx, uuid)
func (d MeshBuildingBlockDefinition) meshObjectId() string {
return *d.Metadata.Uuid
}
70 changes: 15 additions & 55 deletions client/building_block_definition_version.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package client

import (
"context"
"encoding/json/jsontext"
"errors"
"fmt"
"uuid"

"github.com/meshcloud/meshstack-cli/client/http"
"github.com/meshcloud/meshstack-cli/client/internal"
"github.com/meshcloud/meshstack-cli/client/types"
"github.com/meshcloud/meshstack-cli/client/types/enum"
"github.com/meshcloud/meshstack-cli/client/types/hal"
"github.com/meshcloud/meshstack-cli/internal/json"
)

Expand Down Expand Up @@ -181,9 +177,9 @@
}

type MeshBuildingBlockDefinitionVersionMetadata struct {
Uuid string `json:"uuid"`
OwnedByWorkspace string `json:"ownedByWorkspace"`
CreatedOn string `json:"createdOn"`
Uuid *string `json:"uuid,omitzero"`
OwnedByWorkspace string `json:"ownedByWorkspace"`
CreatedOn string `json:"createdOn,omitzero"`
}

type MeshBuildingBlockDefinitionVersionSpec struct {
Expand All @@ -201,63 +197,27 @@
}

type MeshBuildingBlockDefinitionVersionStatus struct {
State MeshBuildingBlockDefinitionVersionState `json:"state" tfsdk:"state"`
UsageCount *int64 `json:"usageCount,omitzero" tfsdk:"usage_count"`
State MeshBuildingBlockDefinitionVersionState `json:"state" tfsdk:"state"`
UsageCount *int64 `json:"usageCount,omitzero" tfsdk:"usage_count"`
RedactedForNonOwnerAccess bool `json:"redactedForNonOwnerAccess" tfsdk:"-"`
Lifecycle MeshLifecycle `json:"lifecycle" tfsdk:"-"`
}

type MeshBuildingBlockDefinitionVersion struct {
Metadata MeshBuildingBlockDefinitionVersionMetadata `json:"metadata" tfsdk:"metadata"`
Spec MeshBuildingBlockDefinitionVersionSpec `json:"spec" tfsdk:"spec"`
Status *MeshBuildingBlockDefinitionVersionStatus `json:"status,omitzero" tfsdk:"status"`
Links hal.Links `json:"_links,omitzero" tfsdk:"-"`
}

// MeshBuildingBlockDefinitionVersionClient has no Get and no Delete: a caller always reads all
// versions of a definition with List, and the versions are deleted together with their definition.
type MeshBuildingBlockDefinitionVersionClient interface {
List(ctx context.Context, buildingBlockDefinitionUuid string) ([]MeshBuildingBlockDefinitionVersion, error)
Create(ctx context.Context, ownedByWorkspace string, versionSpec MeshBuildingBlockDefinitionVersionSpec) (*MeshBuildingBlockDefinitionVersion, error)
Update(ctx context.Context, uuid, ownedByWorkspace string, versionSpec MeshBuildingBlockDefinitionVersionSpec) (*MeshBuildingBlockDefinitionVersion, error)
}

type meshBuildingBlockDefinitionVersionClient struct {
meshObject internal.MeshObjectClient[MeshBuildingBlockDefinitionVersion]
}

func newBuildingBlockDefinitionVersionClient(ctx context.Context, httpClient internal.HttpClient) meshBuildingBlockDefinitionVersionClient {
return meshBuildingBlockDefinitionVersionClient{
meshObject: internal.NewMeshObjectClient[MeshBuildingBlockDefinitionVersion](ctx, httpClient, "v1"),
}
}
type MeshBuildingBlockDefinitionVersionClient = MeshObjectClient[MeshBuildingBlockDefinitionVersion, MeshBuildingBlockDefinitionVersionFilter]

type MeshBuildingBlockDefinitionVersionListFilter struct {
BuildingBlockDefinitionUuid uuid.UUID `json:"buildingBlockDefinitionUuid,omitzero"`
type MeshBuildingBlockDefinitionVersionFilter struct {
BuildingBlockDefinitionUuid string `json:"buildingBlockDefinitionUuid,omitzero"`
}

func (c meshBuildingBlockDefinitionVersionClient) List(ctx context.Context, buildingBlockDefinitionUuid string) ([]MeshBuildingBlockDefinitionVersion, error) {
definitionUuid, err := uuid.Parse(buildingBlockDefinitionUuid)
if err != nil {
return nil, fmt.Errorf("building block definition %q: %w", buildingBlockDefinitionUuid, err)
}
return c.meshObject.List(ctx, http.WithUrlQuery(MeshBuildingBlockDefinitionVersionListFilter{
BuildingBlockDefinitionUuid: definitionUuid,
}))
func (v MeshBuildingBlockDefinitionVersion) meshObjectId() string {
return *v.Metadata.Uuid
}

func (c meshBuildingBlockDefinitionVersionClient) Create(ctx context.Context, ownedByWorkspace string, versionSpec MeshBuildingBlockDefinitionVersionSpec) (*MeshBuildingBlockDefinitionVersion, error) {
return c.meshObject.Post(ctx, MeshBuildingBlockDefinitionVersion{
Metadata: MeshBuildingBlockDefinitionVersionMetadata{
OwnedByWorkspace: ownedByWorkspace,
},
Spec: versionSpec,
})
}

func (c meshBuildingBlockDefinitionVersionClient) Update(ctx context.Context, uuid, ownedByWorkspace string, versionSpec MeshBuildingBlockDefinitionVersionSpec) (*MeshBuildingBlockDefinitionVersion, error) {
return c.meshObject.Put(ctx, uuid, MeshBuildingBlockDefinitionVersion{
Metadata: MeshBuildingBlockDefinitionVersionMetadata{
Uuid: uuid,
OwnedByWorkspace: ownedByWorkspace,
},
Spec: versionSpec,
})
}
func (MeshBuildingBlockDefinitionVersion) meshObjectNoSortQuery() {}

Check failure on line 223 in client/building_block_definition_version.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a nested comment explaining why this function is empty or complete the implementation.

See more on https://sonarcloud.io/project/issues?id=meshcloud_meshstack-cli&issues=AaISO5azz3Um4WZvTpEv&open=AaISO5azz3Um4WZvTpEv&pullRequest=114
59 changes: 7 additions & 52 deletions client/building_block_definition_version_implementation.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package client

import (
"encoding/json/jsontext"
"fmt"

"github.com/meshcloud/meshstack-cli/client/types"
"github.com/meshcloud/meshstack-cli/client/types/enum"
"github.com/meshcloud/meshstack-cli/client/types/variant"
"github.com/meshcloud/meshstack-cli/internal/json"
"github.com/meshcloud/meshstack-cli/client/types/polymorph"
)

type MeshBuildingBlockImplementationType string
Expand Down Expand Up @@ -67,52 +63,11 @@ type MeshBuildingBlockDefinitionAzureDevOpsPipelineImplementation struct {
}

type MeshBuildingBlockDefinitionImplementation struct {
Type enum.Entry[MeshBuildingBlockImplementationType] `json:"type" tfsdk:"-"`
Manual *MeshBuildingBlockDefinitionManualImplementation `json:"manual,omitzero" tfsdk:"manual"`
GithubWorkflows *MeshBuildingBlockDefinitionGitHubWorkflowsImplementation `json:"githubWorkflows,omitzero" tfsdk:"github_workflows"`
AzureDevOpsPipeline *MeshBuildingBlockDefinitionAzureDevOpsPipelineImplementation `json:"azureDevOpsPipeline,omitzero" tfsdk:"azure_devops_pipeline"`
GitlabPipeline *MeshBuildingBlockDefinitionGitLabPipelineImplementation `json:"gitlabPipeline,omitzero" tfsdk:"gitlab_pipeline"`
Terraform *MeshBuildingBlockDefinitionTerraformImplementation `json:"terraform,omitzero" tfsdk:"terraform"`
}

// InferType accepts a version without any variant: meshStack answers that way to a workspace that
// may only consume the definition.
func (m MeshBuildingBlockDefinitionImplementation) InferType() (enum.Entry[MeshBuildingBlockImplementationType], error) {
result, err := variant.InferType(
variant.NewCandidate(MeshBuildingBlockImplementationTypeManual, m.Manual != nil),
variant.NewCandidate(MeshBuildingBlockImplementationTypeTerraform, m.Terraform != nil),
variant.NewCandidate(MeshBuildingBlockImplementationTypeGithubWorkflows, m.GithubWorkflows != nil),
variant.NewCandidate(MeshBuildingBlockImplementationTypeGitlabPipeline, m.GitlabPipeline != nil),
variant.NewCandidate(MeshBuildingBlockImplementationTypeAzureDevOpsPipeline, m.AzureDevOpsPipeline != nil),
)
if err != nil {
return "", fmt.Errorf("cannot infer implementation type: %w", err)
}
return result, nil
}

func (m MeshBuildingBlockDefinitionImplementation) MarshalJSONTo(enc *jsontext.Encoder) error {
type wrapped MeshBuildingBlockDefinitionImplementation
w := wrapped(m)
if len(w.Type) == 0 {
inferred, err := m.InferType()
if err != nil {
return err
}
w.Type = inferred
}
return json.MarshalEncode(enc, w, enc.Options())
}
polymorph.Polymorph[MeshBuildingBlockDefinitionImplementation, MeshBuildingBlockImplementationType]

func (m *MeshBuildingBlockDefinitionImplementation) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
type wrapped MeshBuildingBlockDefinitionImplementation
var target wrapped
if err := json.UnmarshalDecode(dec, &target, dec.Options()); err != nil {
return err
}
*m = MeshBuildingBlockDefinitionImplementation(target)
if m.Type == MeshBuildingBlockImplementationTypeManual {
m.Manual = &MeshBuildingBlockDefinitionManualImplementation{}
}
return nil
Manual *MeshBuildingBlockDefinitionManualImplementation `json:"manual,omitzero" polymorph:"manual" tfsdk:"manual"`
GithubWorkflows *MeshBuildingBlockDefinitionGitHubWorkflowsImplementation `json:"githubWorkflows,omitzero" polymorph:"githubWorkflows" tfsdk:"github_workflows"`
AzureDevOpsPipeline *MeshBuildingBlockDefinitionAzureDevOpsPipelineImplementation `json:"azureDevOpsPipeline,omitzero" polymorph:"azureDevOpsPipeline" tfsdk:"azure_devops_pipeline"`
GitlabPipeline *MeshBuildingBlockDefinitionGitLabPipelineImplementation `json:"gitlabPipeline,omitzero" polymorph:"gitlabPipeline" tfsdk:"gitlab_pipeline"`
Terraform *MeshBuildingBlockDefinitionTerraformImplementation `json:"terraform,omitzero" polymorph:"terraform" tfsdk:"terraform"`
}
Loading
Loading