Skip to content

Add ecctl project create and ecctl project delete commands#755

Open
Kushmaro wants to merge 5 commits intomasterfrom
add-project-create-delete-commands
Open

Add ecctl project create and ecctl project delete commands#755
Kushmaro wants to merge 5 commits intomasterfrom
add-project-create-delete-commands

Conversation

@Kushmaro
Copy link
Contributor

@Kushmaro Kushmaro commented Mar 5, 2026

Summary

  • Add ecctl project create command with --type, --name, --region, and --tier flags to create serverless projects via the Serverless Projects API
  • Add ecctl project delete <id> command with optional --type flag (auto-detects project type when omitted)
  • Accept search as an alias for elasticsearch project type across all project commands
  • Add --tier flag for observability (complete/logs_essentials) and security (complete/essentials) projects; returns a clear error when used with elasticsearch
  • Update global --region flag description to cover both Hosted and Serverless
  • Include unit tests, text formatter template, regenerated bindata.go, and reference docs

Test plan

  • make lint passes with 0 issues
  • make unit passes — all new cmd/project tests pass (create and delete)
  • make bindata regenerated successfully
  • make docs regenerated successfully
  • Manual verification: ecctl project create --help shows correct flags
  • Manual verification: ecctl project delete --help shows correct usage
  • Manual verification: create/delete operations work against a live environment

Made with Cursor

Extend the serverless project management capabilities with create and
delete operations against the Serverless Projects API.

- Add `ecctl project create` with --type, --name, --region, and --tier flags
- Add `ecctl project delete <id>` with optional --type flag and auto-detection
- Accept "search" as alias for "elasticsearch" project type across all commands
- Reject --tier for elasticsearch projects with a clear error message
- For observability projects, --tier sets the product_tier field
- For security projects, --tier sets all product_types to the given tier
- Update global --region flag description for Hosted and Serverless
- Add text formatter template for create output
- Add unit tests for both commands
- Regenerate bindata.go and docs

Made-with: Cursor
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds serverless project lifecycle support to ecctl by introducing project create and project delete, expanding project type handling (including search alias), and updating formatting/templates and reference docs accordingly.

Changes:

  • Implement pkg/project support for creating and deleting serverless projects (plus search type alias and --tier handling).
  • Add new CLI commands ecctl project create / ecctl project delete with unit tests and a new text formatter template.
  • Regenerate bindata and update reference docs/TOC for the new commands and updated flags.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/project/project.go Adds create/delete API calls, type alias handling, and shared request helper updates.
cmd/project/create.go Introduces ecctl project create command and flags.
cmd/project/create_test.go Adds unit tests for create behavior, aliasing, and tier validation.
cmd/project/delete.go Introduces ecctl project delete with optional type autodetection.
cmd/project/delete_test.go Adds unit tests for delete behavior with explicit and autodetected types.
cmd/project/list.go Updates --type help text to include search alias.
cmd/project/list_test.go Updates expected validation error message for type aliasing.
cmd/root.go Updates global --region flag description to include Serverless.
pkg/formatter/templates/text/project/create.gotmpl Adds text output template for project create.
pkg/formatter/templates/bindata.go Regenerates embedded template assets to include the new create template.
docs/reference/toc.yml Adds reference doc entries for create/delete commands.
docs/reference/ecctl_project*.md Adds new command docs and updates existing project docs/flags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Address Copilot review comments on PR #755:

- Remove local --region flag from project create command; reuse the
  persistent flag inherited from root. The create command's region
  validation is handled by CreateParams.Validate().
- Add pagination support to listByType so that all projects are fetched
  across multiple pages. This fixes project delete auto-detection when
  the target project isn't on the first page.
- Update reference docs to reflect removed local --region flag.

Made-with: Cursor
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Kushmaro added 2 commits March 6, 2026 12:24
- Add `ecctl project show <id>` command to fetch a single serverless
  project by ID, with optional --type flag for explicit type or
  auto-detection via listing all projects.
- Add text formatter template and reference docs for the show command.
- Fix URL escaping for pagination cursor in listByType: use url.Parse
  with Query().Set() instead of fmt.Sprintf to handle special chars.
- Canonicalize project type in resolveProjectType via ValidateType()
  instead of a raw ProjectType cast.
- Refactor resolveProjectType to be reusable across delete and show.

Made-with: Cursor
- Add Endpoints map to Project struct so `project show` displays
  endpoint URLs (elasticsearch, kibana, apm, ingest) from the API
- Add sortKeys template function for deterministic endpoint ordering
- Remove CLOUD_ID from project show text output (less relevant for
  serverless)
- Add maxPages=100 safety limit to listByType pagination loop to
  prevent infinite loops from a misbehaving API

Made-with: Cursor
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if p.Tier != "" {
pt, _ := ValidateType(p.Type)
if pt == Elasticsearch {
merr = merr.Append(errors.New("--tier is not supported for elasticsearch projects"))
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateParams.Validate returns an error string that includes the CLI flag name (--tier). Since this is in pkg/project (a reusable package), it’s better for the error message to be CLI-agnostic (e.g., refer to the field/concept "tier" rather than a flag) and let the command layer map it to flags if needed.

Suggested change
merr = merr.Append(errors.New("--tier is not supported for elasticsearch projects"))
merr = merr.Append(errors.New("tier is not supported for elasticsearch projects"))

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +63
createCmd.Flags().String("type", "", "Project type (elasticsearch/search, observability, security) (required)")
createCmd.Flags().String("name", "", "Project name (required)")
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The create command help strings embed "(required)" in the flag descriptions, but the rest of the codebase relies on MarkFlagRequired without adding this suffix in the description (e.g., cmd/user/create.go). For consistency in generated docs/help output, drop the "(required)" text and keep MarkFlagRequired as the single source of truth.

Suggested change
createCmd.Flags().String("type", "", "Project type (elasticsearch/search, observability, security) (required)")
createCmd.Flags().String("name", "", "Project name (required)")
createCmd.Flags().String("type", "", "Project type (elasticsearch/search, observability, security)")
createCmd.Flags().String("name", "", "Project name")

Copilot uses AI. Check for mistakes.
- Remove "--" prefix from tier validation error message in pkg/project
  so the reusable package doesn't reference CLI flag syntax
- Remove "(required)" suffix from --type and --name flag descriptions
  to match codebase convention of relying on MarkFlagRequired

Made-with: Cursor
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +534 to +536
var page ListResponse
if err := json.Unmarshal(body, &page); err != nil {
return nil, fmt.Errorf("failed to decode response: %w", err)
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In listByType, the var page ListResponse declaration shadows the loop counter variable page from for page := 0; .... This compiles, but it’s easy to misread and can lead to subtle mistakes if the loop counter is referenced after the shadowing point. Consider renaming one of the variables (e.g., pageNum for the counter or respPage for the response).

Copilot uses AI. Check for mistakes.
Comment on lines +203 to +207
if p.Tier != "" {
pt, _ := ValidateType(p.Type)
if pt == Elasticsearch {
merr = merr.Append(errors.New("tier is not supported for elasticsearch projects"))
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateParams.Validate calls ValidateType(p.Type) but intentionally ignores the returned error (pt, _ := ...). This makes the validation logic harder to follow and can mask why tier validation didn’t run when type is invalid. Either validate type here and append the error to merr, or avoid calling ValidateType and compare the raw type string (including the search alias) explicitly.

Suggested change
if p.Tier != "" {
pt, _ := ValidateType(p.Type)
if pt == Elasticsearch {
merr = merr.Append(errors.New("tier is not supported for elasticsearch projects"))
}
pt, err := ValidateType(p.Type)
if err != nil {
merr = merr.Append(err)
} else if p.Tier != "" && pt == Elasticsearch {
merr = merr.Append(errors.New("tier is not supported for elasticsearch projects"))

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants