Skip to content

feat(tags): Add support to bulk assign tags - #74

Merged
Rutvik G (rutvik-gs) merged 3 commits into
feat/tagsfrom
feat/tags-11-bulk-assign
Jul 30, 2026
Merged

feat(tags): Add support to bulk assign tags#74
Rutvik G (rutvik-gs) merged 3 commits into
feat/tagsfrom
feat/tags-11-bulk-assign

Conversation

@rutvik-gs

@rutvik-gs Rutvik G (rutvik-gs) commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Problem

censys tags assign can only take assets one at a time. The platform already exposes an async bulk endpoint to assign tags in bulk by running a cenql query.

The mode boundary matters as bulk must never be inferred from a missing argument, because guessing wrong here
tags a very large number of assets.

Technical Changes

Bulk rides as flags on the existing assign verb, not a bulk-assign subcommand — the async
path renders a different payload (TagOperation vs per-asset results), which splits cleanly in
Run.

  • internal/command/tags/assign.go--query, --max-assets, --wait/-w, --timeout,
    --yes/-y. Modes are mutually exclusive in PreRun and bulk-only flags without --query are
    typed errors, not silent no-ops. Bulk always confirms (tag, query, effective cap) unless
    --yes, and refuses in a non-TTY without it. --wait maps the terminal status onto the exit
    code: succeeded/limit_reached → 0 (the latter warns), failed/cancelled → non-zero with
    the payload still rendered.
  • internal/command/tags/operationwait.go (new) — wait plumbing that operations get owned
    privately: parseWaitFlags, waitForOperation, terminal-status → exit code, track hints.
    operations_get.go moves onto it; TAGS-12 reuses it.
  • internal/app/tags/bulk.go (new) — BulkAssign: rejects a blank query, resolves a tag name
    via the existing resolveTagID, submits, maps the operation. TAGS-12's BulkUnassign joins it.
  • internal/pkg/clients/censys/tags.go — BulkCreateTagAssignments. Mocks regenerated; no
    SDK bump needed.
  • internal/command/tags/{short,utils}.go, internal/app/tags/operations.go — shared
    helpers extracted, no behavior change: renderOperationDetail, confirmAction (the block
    delete/unassign each copied), printNote, mapOperationResult.
  • --timeout 0 on operations get --wait expired before the first poll. It now means "no limit",
    matching the global --timeout-http; a negative value is a typed error.
  • --quiet is now honored for the index-lag notes in assign/unassign, which printed
    unconditionally. Aborts and errors still always print — outcomes, not notes.

How to Test

go build ./... && go test ./internal/... && make cover-check   # 61.1%, threshold 30%
CENCLI_ENABLE_E2E_TESTS=true go test ./cmd/cencli/e2e -run 'TestE2E/tags' -v

Live, on a throwaway tag (bulk mutates at scale, so nothing below is automated):

TAG=tags11-$(date +%s) && ./bin/censys tags create $TAG
./bin/censys tags assign $TAG --query 'host.services.port: 22' --max-assets 25 --yes
./bin/censys tags operations get $TAG <op-id>                        # track hint from above
./bin/censys tags assign $TAG --query 'host.services.port: 22' --max-assets 25 --wait --yes
./bin/censys tags assign $TAG --query 'host.ip: *' --max-assets 5 --wait --yes   # limit_reach
./bin/censys tags assign $TAG --query 'host.ip: *' --wait --yes                  # Ctrl-C mid-poll
./bin/censys tags assign $TAG --query 'host.services.port: 22' --max-assets 5    # interactive
./bin/censys tags delete $TAG --yes

@rutvik-gs Rutvik G (rutvik-gs) changed the title Feat/tags 11 bulk assign feat(tags): Add support to bulk assign tags Jul 28, 2026
@rutvik-gs
Rutvik G (rutvik-gs) marked this pull request as ready for review July 29, 2026 13:01
@rutvik-gs
Rutvik G (rutvik-gs) requested a review from a team as a code owner July 29, 2026 13:01

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@rutvik-gs
Rutvik G (rutvik-gs) merged commit 669fd2d into feat/tags Jul 30, 2026
2 checks passed
@btschwartz12
Ben Schwartz (btschwartz12) deleted the feat/tags-11-bulk-assign branch July 30, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants