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
15 changes: 8 additions & 7 deletions .claude/skills/development/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: development
description: How the meshStack CLI's Go code is laid out and built - where a command, its logic and an HTTP call go, and what the client and settings must keep. Use when writing, changing or reviewing Go code here - a new command or package, a change to client/, pkg/ or internal/http, an HTTP request, a new setting or dependency, or a depguard or forbidigo finding.
description: How the meshStack CLI's Go code is laid out and built - where a command, its logic and an HTTP call go, and what the client and settings must keep. Use when writing, changing or reviewing Go code here - a new command or package, a change to client/, client/http or pkg/, an HTTP request, a new setting or dependency, or a depguard or forbidigo finding.
---

# Developing the meshStack CLI
Expand Down Expand Up @@ -145,25 +145,26 @@ authorization always agree with what was resolved. Do **not** add a login exchan
second one gets a static token and starts returning 401 once it expires, and for a browser login it
would end the user's session.

**`client/` does not own HTTP.** The client, the request options and the retry policy are
`internal/http`, because `internal/oidc` and `pkg/auth` need them and Go's internal rule closes
`client/internal` to both. Its names carry no `Http` prefix: `http.Client`, `http.Error`.
**HTTP is `client/http`.** The client, the request options and the retry policy are there, because
`internal/oidc` and `pkg/auth` need them as well, and another module calls `client.New` with them.
No exported name of `client/` may use an `internal/` type, because another module cannot name it.
Its names carry no `Http` prefix: `http.Client`, `http.Error`.

**Every request names the front end and version that sent it.** `http.NewClient` takes an
`http.UserAgent`, which `auth.ResolveSessionOptions` embeds: the front end sets its `GitHubRepo` and
`Version` once, the CLI in `cmd/internal.ResolveClientOptions`, and the release check reads the same
two. So code below `cmd/` takes its client from its caller, and a command that needs one for
anything but a meshStack client calls `internal.ResolveClientOptions().HttpClient()`. `forbidigo`
keeps `http.UserAgent` to those options, and the transport to `internal/http`.
keeps `http.UserAgent` to those options, and the transport to `client/http`.

**`net/http` is always imported as `gohttp`**, which `importas` settles. That leaves the plain name
to `internal/http`, and `net/http` to the status and method constants and to the loopback server.
to `client/http`, and `net/http` to the status and method constants and to the loopback server.
The `forbidigo` rule matches on the type rather than the written name, so it catches `gohttp.Client`
and leaves `http.Client` alone.

**Logging goes through `slog`'s default logger**, on which each front end installs its own handler:
`cmd/meshstack` a `charmbracelet/log` one, the Terraform provider a `tflog` bridge. A handler
installed that late constrains every log call, and `internal/http/logging.go` states how.
installed that late constrains every log call, and `client/http/logging.go` states how.
</rules>

## Settings
Expand Down
28 changes: 11 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ linters:
- gosec
text: G101
path: _test\.go
- path: internal/http/
- path: client/http/
linters:
- forbidigo
text: one HTTP client
# The options of a session carry the user agent the front end sets.
- path: (internal/http/|internal/auth/session\.go|internal/testutil/|_test\.go)
- path: (client/http/|internal/auth/session\.go|internal/testutil/|_test\.go)
linters:
- forbidigo
text: user agent of the front end
Expand Down Expand Up @@ -130,17 +130,17 @@ linters:
- gosec

settings:
# The process has one HTTP client, built in internal/http.
# The process has one HTTP client, built in client/http.
forbidigo:
analyze-types: true
forbid:
# Anchored to the package, as net/http has more methods named Get, such as Header.Get.
- pattern: ^http\.(Client|DefaultClient|Transport|DefaultTransport|Get|Head|Post|PostForm)$
pkg: ^net/http$
msg: the process has one HTTP client, built in internal/http; take it from there rather than making another
msg: the process has one HTTP client, built in client/http; take it from there rather than making another
# A user agent made anywhere else drifts from the one the front end names itself by.
- pattern: ^http\.UserAgent$
pkg: ^github\.com/meshcloud/meshstack-cli/internal/http$
pkg: ^github\.com/meshcloud/meshstack-cli/client/http$
msg: a client carries the user agent of the front end; take the client from your caller, or from auth.ResolveSessionOptions.HttpClient
# A test that sleeps for real is slow, and flaky once the machine is slower than the
# sleep assumed. synctest.Sleep panics outside a bubble, so it cannot be used the same way.
Expand Down Expand Up @@ -308,9 +308,6 @@ linters:
- encoding/json/v2
- github.com/meshcloud/meshstack-cli/cmd/internal
- github.com/meshcloud/meshstack-cli/client
# the request options client.Raw.DoRequest takes, which pkg/ does not expose: they are for the
# CLI alone
- github.com/meshcloud/meshstack-cli/internal/http
# the API docs choose the version of a request
- github.com/meshcloud/meshstack-cli/internal/apidocs
# a full URL picks the stored profile whose endpoint holds it, and has to fit an endpoint
Expand All @@ -334,8 +331,7 @@ linters:
allow:
- $gostd
- log/slog
# the proxy that serves the state to tofu. It needs the request options of
# client.Raw.DoRequest, and pkg/ does not expose them, because they are for the CLI alone.
# the proxy that serves the state to tofu
- github.com/meshcloud/meshstack-cli/internal/tfstate
- github.com/meshcloud/meshstack-cli/cmd/internal
- github.com/meshcloud/meshstack-cli/pkg/setting
Expand Down Expand Up @@ -432,7 +428,7 @@ linters:
- github.com/charmbracelet/colorprofile

# The package the Terraform provider consumes most directly, so it reaches nothing
# beyond the standard library and the three packages below.
# beyond the standard library and the packages below.
client:
files:
# Both patterns are needed: '**/dir/**/*.go' only matches files in
Expand All @@ -450,9 +446,7 @@ linters:
- encoding/json/jsontext
- log/slog
- github.com/meshcloud/meshstack-cli/client
- github.com/meshcloud/meshstack-cli/internal/http
- github.com/meshcloud/meshstack-cli/internal/json
- github.com/meshcloud/meshstack-cli/internal/version

pkg:
files:
Expand All @@ -470,9 +464,9 @@ linters:
- github.com/meshcloud/meshstack-cli/internal

# client reaches these two, so whatever they may import, client gets.
internal-http:
client-http:
files:
- "**/internal/http/*.go"
- "**/client/http/*.go"
- "**/internal/json/*.go"
- "!$test"
list-mode: strict
Expand All @@ -482,9 +476,9 @@ linters:
- encoding/json/jsontext
- github.com/meshcloud/meshstack-cli/internal/json

internal-version:
client-types-version:
files:
- "**/internal/version/*.go"
- "**/client/types/version/*.go"
- "!$test"
list-mode: strict
deny:
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The binary gets its name from its directory, `cmd/meshstack`, which is what `tas

**Load the `development` skill before you write or review Go code here.** It holds the package
layout, the split of a command into a front end in `cmd/` and its logic in `internal/`, the command
tree, the dependency policy, and what `client/`, `internal/http` and the settings must keep.
tree, the dependency policy, and what `client/`, `client/http` and the settings must keep.

[`skills/meshstack-cli`](skills/meshstack-cli/SKILL.md) is the skill for those who **use** the CLI;
other repositories link to it. A change to what a command does, prints or needs updates it in the
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 @@ -3,10 +3,10 @@ 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/internal/http"
)

type MeshBuildingBlockType string
Expand Down
2 changes: 1 addition & 1 deletion client/building_block_definition_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"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/internal/http"
)

type MeshBuildingBlockDefinitionVersionState string
Expand Down
2 changes: 1 addition & 1 deletion client/building_block_run_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
gohttp "net/http"
"net/url"

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

// Link is a HAL link. meshStack sends the link of an action only while the caller may take it.
Expand Down
2 changes: 1 addition & 1 deletion client/building_block_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"errors"

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

type MeshBuildingBlockRunnerImplementationType string
Expand Down
2 changes: 1 addition & 1 deletion client/building_block_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"fmt"
"slices"

"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/internal/http"
)

type BuildingBlockLifecycleState string
Expand Down
6 changes: 2 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ 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/version"
"github.com/meshcloud/meshstack-cli/client/types/xurl"
"github.com/meshcloud/meshstack-cli/internal/http"
"github.com/meshcloud/meshstack-cli/internal/version"
)

var MinMeshStackVersion = version.MustParse("2026.47.0")

// Version is re-exported because MinMeshStackVersion is one and internal/version is closed to
// another module.
type Version = version.Version

type HttpError = http.Error
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

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

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package http_test drives the client from the outside, so that it can parse answers into the
// types real callers declare. internal/http may not import any of them.
// types real callers declare. client/http may not import any of them.
package http_test

import (
Expand All @@ -19,8 +19,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/meshcloud/meshstack-cli/client/http"
"github.com/meshcloud/meshstack-cli/client/types/xurl"
"github.com/meshcloud/meshstack-cli/internal/http"
"github.com/meshcloud/meshstack-cli/internal/logs"
"github.com/meshcloud/meshstack-cli/internal/oidc/jwt"
"github.com/meshcloud/meshstack-cli/internal/testutil/fakemeshstack"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

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

// TestJsonLogRedactsTheToken uses a handler that encodes attributes as JSON rather than
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion client/internal/mesh_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"unicode"

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

type HttpClient struct {
Expand Down
2 changes: 1 addition & 1 deletion client/landingzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package client
import (
"context"

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

type MeshLandingZone struct {
Expand Down
4 changes: 2 additions & 2 deletions client/mesh_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"fmt"

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

// MeshFeatureFlag names an optional meshStack capability. /mesh/info reports each one as a bool of
Expand Down
2 changes: 1 addition & 1 deletion client/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,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/internal/http"
)

type MeshPlatform struct {
Expand Down
2 changes: 1 addition & 1 deletion client/platform_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package client
import (
"context"

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

type MeshPlatformType struct {
Expand Down
2 changes: 1 addition & 1 deletion client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package client
import (
"context"

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

type MeshProject struct {
Expand Down
2 changes: 1 addition & 1 deletion client/project_group_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package client
import (
"context"

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

type MeshProjectGroupBinding struct {
Expand Down
2 changes: 1 addition & 1 deletion client/project_user_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,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/enum"
"github.com/meshcloud/meshstack-cli/internal/http"
)

type MeshProjectUserBinding struct {
Expand Down
6 changes: 2 additions & 4 deletions client/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"
"uuid"

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

type ListOptions = internal.ListOptions
Expand All @@ -21,9 +21,7 @@ type Page = internal.Page
// SortCriteria holds one `property,(asc|desc)` criterion per element, such as createdAt,desc.
type SortCriteria []string

// RawClient answers with the JSON meshStack sent, for the CLI, which writes it out as it came. It
// is the CLI's alone: DoRequest takes the options of internal/http, which Go's internal rule closes
// to the Terraform provider.
// RawClient answers with the JSON meshStack sent, for the CLI, which writes it out as it came.
type RawClient struct {
httpClient internal.HttpClient
apis map[reflect.Type]rawApi
Expand Down
2 changes: 1 addition & 1 deletion client/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/meshcloud/meshstack-cli/client/http"
"github.com/meshcloud/meshstack-cli/client/internal"
"github.com/meshcloud/meshstack-cli/client/types/xurl"
"github.com/meshcloud/meshstack-cli/internal/http"
"github.com/meshcloud/meshstack-cli/internal/testutil/fakemeshstack"
)

Expand Down
2 changes: 1 addition & 1 deletion client/service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,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/internal/http"
)

type MeshServiceInstance struct {
Expand Down
2 changes: 1 addition & 1 deletion client/tenant_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"errors"
"fmt"

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

type TenantLifecycleState string
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading