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
52 changes: 17 additions & 35 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ linters:
# field order follows what reads well, not what packs tightest
- fieldalignment

recvcheck:
# Extends the built-in exclusion of UnmarshalJSON to its json/v2 counterpart.
exclusions:
- "*.UnmarshalJSONFrom"

staticcheck:
checks:
- all
Expand Down Expand Up @@ -219,6 +224,14 @@ linters:
depguard:
rules:

# The $ keeps encoding/json/v2 and encoding/json/jsontext out of the match.
json:
files:
- $all
deny:
- pkg: encoding/json$
desc: Use encoding/json/v2 and internal/json instead

# cobra is used in cmd/ and nowhere else.
cmd:
files:
Expand All @@ -236,14 +249,12 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- log/slog
# the deny on encoding/json matches its subpackages too; a listing yields raw items
# a listing yields raw items, and reads a field out of one, such as the uuid a run
# listing needs per block
- encoding/json/jsontext
# and reads a field out of a raw item, such as the uuid a run listing needs per block
- encoding/json/v2
# no direct access to internal/
- github.com/meshcloud/meshstack-cli/pkg
Expand All @@ -261,8 +272,6 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- log/slog
Expand All @@ -279,13 +288,10 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- log/slog
# the deny on encoding/json matches its subpackages too; a request body is checked as
# JSON, and api-docs writes a part of the OpenAPI document
# a request body is checked as JSON, and api-docs writes a part of the OpenAPI document
- encoding/json/jsontext
- encoding/json/v2
- github.com/meshcloud/meshstack-cli/cmd/internal
Expand Down Expand Up @@ -313,8 +319,6 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- log/slog
Expand All @@ -336,8 +340,6 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- log/slog
Expand All @@ -358,8 +360,6 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- log/slog
Expand Down Expand Up @@ -395,14 +395,11 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- log/slog
# the deny on encoding/json matches its subpackages too; a listing writes raw items
# a listing writes raw items, and a command that shows one object marshals it
- encoding/json/jsontext
# and a command that shows one object marshals it, or writes it as Markdown
- encoding/json/v2
- github.com/meshcloud/meshstack-cli/cmd/internal/markdown
- github.com/meshcloud/meshstack-cli/cmd/internal/color
Expand Down Expand Up @@ -435,8 +432,6 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- encoding/json/v2
Expand All @@ -455,8 +450,6 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- log/slog
Expand All @@ -471,9 +464,6 @@ linters:
- "**/internal/json/*.go"
- "!$test"
list-mode: strict
deny:
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- encoding/json/v2
Expand Down Expand Up @@ -501,8 +491,6 @@ linters:
deny:
- pkg: log
desc: Use log/slog instead
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- encoding/json/v2
Expand All @@ -518,9 +506,6 @@ linters:
files:
- "**/internal/testutil/**/*.go"
list-mode: strict
deny:
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- encoding/json/v2
Expand Down Expand Up @@ -556,9 +541,6 @@ linters:
files:
- "$test"
list-mode: strict
deny:
- pkg: encoding/json
desc: Use encoding/json/v2 and internal/json instead
allow:
- $gostd
- encoding/json/v2
Expand Down
2 changes: 1 addition & 1 deletion client/building_block_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type meshBuildingBlockDefinitionClient struct {

func newBuildingBlockDefinitionClient(ctx context.Context, httpClient internal.HttpClient) meshBuildingBlockDefinitionClient {
return meshBuildingBlockDefinitionClient{
meshObject: internal.NewMeshObjectClient[MeshBuildingBlockDefinition](ctx, httpClient, "v1-preview"),
meshObject: internal.NewMeshObjectClient[MeshBuildingBlockDefinition](ctx, httpClient, "v1"),
}
}

Expand Down
11 changes: 6 additions & 5 deletions client/building_block_definition_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"encoding/json/jsontext"
"encoding/json/v2"
"errors"
"fmt"
Expand Down Expand Up @@ -121,8 +122,8 @@ type MeshBuildingBlockDefinitionInput struct {
IsEnvironment bool `json:"isEnvironment" tfsdk:"is_environment"`
IsSensitive bool `json:"isSensitive" tfsdk:"-"`
// Argument and DefaultValue hold a [types.Secret] when IsSensitive is true and a [types.Any]
// otherwise. [types.Variant] decodes into X first, so UnmarshalJSON moves a non-sensitive value
// that also decodes as a Secret over to Y.
// otherwise. [types.Variant] decodes into X first, so UnmarshalJSONFrom moves a non-sensitive
// value that also decodes as a Secret over to Y.
Argument types.SecretOrAny `json:"argument" tfsdk:"argument"`
DefaultValue types.SecretOrAny `json:"defaultValue" tfsdk:"default_value"`
UpdateableByConsumer bool `json:"updateableByConsumer" tfsdk:"updateable_by_consumer"`
Expand All @@ -141,10 +142,10 @@ type MeshBuildingBlockDefinitionInput struct {
DisplayOrder int64 `json:"displayOrder" tfsdk:"display_order"`
}

func (m *MeshBuildingBlockDefinitionInput) UnmarshalJSON(bytes []byte) error {
func (m *MeshBuildingBlockDefinitionInput) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
type wrapped MeshBuildingBlockDefinitionInput
var target wrapped
if err := json.Unmarshal(bytes, &target); err != nil {
if err := json.UnmarshalDecode(dec, &target, dec.Options()); err != nil {
return err
}
*m = MeshBuildingBlockDefinitionInput(target)
Expand Down Expand Up @@ -223,7 +224,7 @@ type meshBuildingBlockDefinitionVersionClient struct {

func newBuildingBlockDefinitionVersionClient(ctx context.Context, httpClient internal.HttpClient) meshBuildingBlockDefinitionVersionClient {
return meshBuildingBlockDefinitionVersionClient{
meshObject: internal.NewMeshObjectClient[MeshBuildingBlockDefinitionVersion](ctx, httpClient, "v1-preview"),
meshObject: internal.NewMeshObjectClient[MeshBuildingBlockDefinitionVersion](ctx, httpClient, "v1"),
}
}

Expand Down
11 changes: 6 additions & 5 deletions client/building_block_definition_version_implementation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

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

Expand Down Expand Up @@ -90,23 +91,23 @@ func (m MeshBuildingBlockDefinitionImplementation) InferType() (enum.Entry[MeshB
return result, nil
}

func (m MeshBuildingBlockDefinitionImplementation) MarshalJSON() ([]byte, error) {
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 nil, err
return err
}
w.Type = inferred
}
return json.Marshal(w, wireCompatibility)
return json.MarshalEncode(enc, w, enc.Options())
}

func (m *MeshBuildingBlockDefinitionImplementation) UnmarshalJSON(bytes []byte) error {
func (m *MeshBuildingBlockDefinitionImplementation) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
type wrapped MeshBuildingBlockDefinitionImplementation
var target wrapped
if err := json.Unmarshal(bytes, &target); err != nil {
if err := json.UnmarshalDecode(dec, &target, dec.Options()); err != nil {
return err
}
*m = MeshBuildingBlockDefinitionImplementation(target)
Expand Down
4 changes: 4 additions & 0 deletions client/building_block_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type MeshBuildingBlockRun struct {
Links MeshBuildingBlockRunLinks `json:"_links,omitzero"`
}

func (run MeshBuildingBlockRun) IsRunning() bool {
return run.Status == "PENDING" || run.Status == "IN_PROGRESS"
}

type MeshBuildingBlockRunMetadata struct {
Uuid string `json:"uuid"`
CreatedAt time.Time `json:"createdAt"`
Expand Down
Loading
Loading