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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Enhancements:
- build(dockerfile-rust): add wasm tools to the rust docker container ([#1552](https://github.com/fastly/cli/pull/1552))
- feat(env): add detection for workspace ID ([#1560](https://github.com/fastly/cli/pull/1560))

### Bug fixes:
- fix(compute): clarify fastly.toml error message when file not found ([#1556](https://github.com/fastly/cli/pull/1556))
Expand Down
4 changes: 4 additions & 0 deletions pkg/argparser/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ var (
FlagJSONName = "json"
// FlagJSONDesc is the flag description.
FlagJSONDesc = "Render output as JSON"
// FlagNGWAFWorkspaceID is the workspace ID.
FlagNGWAFWorkspaceID = "workspace-id"
// FlagNGWAFWorkspaceIDDesc is the workspace ID flag description.
FlagNGWAFWorkspaceIDDesc = "Alphanumeric string identifying the NGWAF Workspace (falls back to FASTLY_WORKSPACE_ID)"
// FlagServiceIDName is the flag name.
FlagServiceIDName = "service-id"
// FlagServiceIDDesc is the flag description.
Expand Down
20 changes: 20 additions & 0 deletions pkg/argparser/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ func (sv *OptionalCustomerID) Parse() error {
return nil
}

// OptionalWorkspaceID represents a Fastly NGWAF Workspace ID.
type OptionalWorkspaceID struct {
OptionalString
}

// Parse returns a workspace ID either from a flag or from a user defined
// environment variable (see pkg/env/env.go).
//
// NOTE: Will fallback to FASTLY_WORKSPACE_ID environment variable if no flag value set.
func (sv *OptionalWorkspaceID) Parse() error {
if sv.Value == "" {
if e := os.Getenv(env.WorkspaceID); e != "" {
sv.Value = e
return nil
}
return fsterr.ErrNoWorkspaceID
}
return nil
}

// AutoCloneFlagOpts enables easy configuration of the --autoclone flag defined
// via the RegisterAutoCloneFlag constructor.
type AutoCloneFlagOpts struct {
Expand Down
3 changes: 3 additions & 0 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const (
// collection related to a Wasm binary.
// Set to "true" to disable all forms of data collection.
WasmMetadataDisable = "FASTLY_WASM_METADATA_DISABLE"

// WorkspaceID is the env we look for in Workspace related commands if none is provided.
WorkspaceID = "FASTLY_WORKSPACE_ID"
)

// Parse transforms the local environment data structure into a map type.
Expand Down
7 changes: 7 additions & 0 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ var ErrNoCustomerID = RemediationError{
Remediation: CustomerIDRemediation,
}

// ErrNoWorkspaceID means no --workspace-id or FASTLY_WORKSPACE_ID environment
// variable found.
var ErrNoWorkspaceID = RemediationError{
Inner: fmt.Errorf("error reading workspace ID: no workspace ID found"),
Remediation: WorkspaceIDRemediation,
}

// ErrMissingManifestVersion means an invalid manifest (fastly.toml) has been used.
var ErrMissingManifestVersion = RemediationError{
Inner: fmt.Errorf("no manifest_version found in the fastly.toml"),
Expand Down
6 changes: 6 additions & 0 deletions pkg/errors/remediation_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ var CustomerIDRemediation = strings.Join([]string{
"Please provide one via the --customer-id flag, or by setting the FASTLY_CUSTOMER_ID environment variable",
}, " ")

// WorkspaceIDRemediation suggests provide a customer ID via --workspace-id flag
// or via environment variable.
var WorkspaceIDRemediation = strings.Join([]string{
"Please provide one via the --workspace-id flag, or by setting the FASTLY_WORKSPACE_ID environment variable",
}, " ")

// ExistingDirRemediation suggests moving to another directory and retrying.
var ExistingDirRemediation = strings.Join([]string{
"Please create a new directory and initialize a new project using:",
Expand Down
Loading