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
71 changes: 71 additions & 0 deletions .github/workflows/bump-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Bump SDK and Create PR

on:
schedule:
- cron: "0 2 * * *" # daily at 02:00 UTC
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
bump-sdk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.CENSYS_ARTIFACT_RELEASER_APP_ID }}
private-key: ${{ secrets.CENSYS_ARTIFACT_RELEASER_PRIVATE_KEY }}
repositories: |
cencli

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true

- name: Configure git
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

- name: Create branch and bump SDK
id: bump
run: |
BRANCH="bump-sdk-$(date +%Y%m%d%H%M%S)"
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
git checkout -b $BRANCH

go get github.com/censys/censys-sdk-go@latest
go mod tidy

if git diff --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi

- name: Commit and push changes
if: steps.bump.outputs.has_changes == 'true'
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
git add go.mod go.sum
git commit -m "chore: bump SDK version"
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push origin HEAD

- name: Create pull request
if: steps.bump.outputs.has_changes == 'true'
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
gh pr create \
--base main \
--head ${{ steps.bump.outputs.branch }} \
--title "chore: bump SDK version" \
--body "Automated bump of SDK version"
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: E2E Tests

on:
pull_request:
branches: [ main ]
branches: [ main, release/* ]
paths-ignore:
- '**/*.md'
- '.github/**'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-check-gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PR - Ensure Generated Code is Up-to-Date

on:
pull_request:
branches: [ main ]
branches: [ main, release/* ]
paths:
- '**/*.go'
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PR - Lint

on:
pull_request:
branches: [ main ]
branches: [ main, release/* ]
paths:
- '**/*.go'
workflow_dispatch:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Run Tests and Check Coverage

on:
pull_request:
branches: [ main ]
branches: [ main, release/* ]
paths:
- '**/*.go'
push:
branches: [ main ]
branches: [ main, release/* ]
paths-ignore:
- '**/*.md'
workflow_dispatch:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The `view` command allows you to fetch information about a particular host, cert

![view](examples/view/view.gif)

You can also use the `--short` flag to render output using templates, which can be customized. See the [templating documentation](./docs/commands/VIEW.md#templates) for more details.
You can also use `-O short` (or `--output-format short`) to render output using templates, which can be customized. See the [templating documentation](./docs/commands/VIEW.md#templates) for more details.

### Search

Expand All @@ -116,6 +116,8 @@ This is a WIP. See the [history command docs](./docs/commands/HISTORY.md) for mo

### Other Commands

- `$ censys org`: manage and view organization details. See the [org command docs](./docs/commands/ORG.md) for more details.
- `$ censys credits`: display credit details for your free user Censys account. See the [credits command docs](./docs/commands/CREDITS.md) for more details.
- `$ censys completion <bash|zsh|fish|powershell>`: generates shell completion scripts
- `$ censys version`: prints version information

Expand Down
43 changes: 41 additions & 2 deletions cmd/cencli/e2e/fixtures/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,22 @@ var aggregateFixtures = []Fixture{
},
},
{
Name: "basic-raw",
Args: []string{"host.services.protocol=SSH", "host.services.port", "-n", "5", "--raw"},
Name: "output-short-default",
Args: []string{"host.services.protocol=SSH", "host.services.port", "-n", "5"},
ExitCode: 0,
Timeout: 5 * time.Second,
NeedsAuth: true,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertHas200(t, stderr)
// Default output is short format (table), just verify it has content
assert.Greater(t, len(stdout), 0)
assert.Contains(t, string(stdout), "host.services.protocol=SSH")
assert.Contains(t, string(stdout), "host.services.port")
},
},
{
Name: "output-json",
Args: []string{"host.services.protocol=SSH", "host.services.port", "-n", "5", "--output-format", "json"},
ExitCode: 0,
Timeout: 5 * time.Second,
NeedsAuth: true,
Expand All @@ -48,4 +62,29 @@ var aggregateFixtures = []Fixture{
assert.Len(t, v, 5)
},
},
{
Name: "output-yaml",
Args: []string{"host.services.protocol=SSH", "host.services.port", "-n", "3", "--output-format", "yaml"},
ExitCode: 0,
Timeout: 5 * time.Second,
NeedsAuth: true,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertHas200(t, stderr)
// Verify YAML output format
assert.Contains(t, string(stdout), "key:")
assert.Contains(t, string(stdout), "count:")
},
},
{
Name: "output-template-unsupported",
Args: []string{"host.services.protocol=SSH", "host.services.port", "--output-format", "template"},
ExitCode: 2,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
// Should fail with error about unsupported output format
assert.Contains(t, string(stderr), "template")
assert.Contains(t, string(stderr), "not supported")
},
},
}
29 changes: 27 additions & 2 deletions cmd/cencli/e2e/fixtures/censeye.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,21 @@ var censeyeFixtures = []Fixture{
},
},
{
Name: "basic-raw",
Args: []string{"145.131.8.169", "--raw"},
Name: "output-short-default",
Args: []string{"145.131.8.169", "--rarity-min", "2", "--rarity-max", "125"},
ExitCode: 0,
Timeout: 12 * time.Second,
NeedsAuth: true,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertHas200(t, stderr)
// Default output is short format (table), just verify it has content
assert.Greater(t, len(stdout), 0)
assert.Contains(t, string(stdout), "=== CensEye Results for 145.131.8.169 ===")
},
},
{
Name: "output-json",
Args: []string{"145.131.8.169", "--output-format", "json"},
ExitCode: 0,
Timeout: 12 * time.Second,
NeedsAuth: true,
Expand All @@ -50,4 +63,16 @@ var censeyeFixtures = []Fixture{
assert.Greater(t, len(v), 1)
},
},
{
Name: "output-template-unsupported",
Args: []string{"145.131.8.169", "--output-format", "template"},
ExitCode: 2,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
// Should fail with error about unsupported output format
assert.Contains(t, string(stderr), "template")
assert.Contains(t, string(stderr), "not supported")
},
},
}
37 changes: 37 additions & 0 deletions cmd/cencli/e2e/fixtures/credits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fixtures

import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/censys/cencli/cmd/cencli/e2e/fixtures/golden"
"github.com/censys/cencli/internal/app/credits"
)

var creditsFixtures = []Fixture{
{
Name: "help",
Args: []string{"--help"},
ExitCode: 0,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertGoldenFile(t, golden.CreditsHelpStdout, stdout, 0)
},
},
{
Name: "basic",
Args: []string{"--output-format", "json"},
ExitCode: 0,
Timeout: 5 * time.Second,
NeedsAuth: true,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertHas200(t, stderr)
data := unmarshalJSONAny[credits.UserCreditDetails](t, stdout)
assert.Greater(t, data.Balance, int64(0))
assert.NotNil(t, data.ResetsAt)
},
},
}
2 changes: 2 additions & 0 deletions cmd/cencli/e2e/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ func Fixtures() map[string][]Fixture {
"search": searchFixtures,
"censeye": censeyeFixtures,
"history": historyFixtures,
"credits": creditsFixtures,
"org": orgFixtures,
}
}
5 changes: 3 additions & 2 deletions cmd/cencli/e2e/fixtures/golden/aggregate_help.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Usage:
Examples:
censys aggregate "host.services.protocol=SSH" "host.services.port"
censys aggregate -c <your-collection-id> "services.service_name:HTTP" "services.port"
censys aggregate "services.service_name:HTTP" "services.port" --output-format json

Flags:
-c, --collection-id string collection to aggregate within (optional)
Expand All @@ -16,13 +17,13 @@ Flags:
-i, --interactive display results in an interactive table (TUI)
-n, --num-buckets int number of buckets to split results into (default 25)
-o, --org-id string override the configured organization ID
-r, --raw output raw data

Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|ndjson|tree) (default "json")
-O, --output-format string output format (json|yaml|tree|short|template) (default "short")
-q, --quiet suppress non-essential output
-S, --streaming enable streaming output mode (NDJSON) for commands that support it
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

7 changes: 4 additions & 3 deletions cmd/cencli/e2e/fixtures/golden/censeye_help.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Usage:
Examples:
censys censeye 8.8.8.8
censys censeye --rarity-min 2 --rarity-max 25 1.1.1.1
censys censeye --raw --include-url 192.168.1.1
censys censeye --interactive 192.168.1.1
censys censeye --output-format json --include-url 192.168.1.1

Flags:
-h, --help help for censeye
Expand All @@ -19,13 +20,13 @@ Flags:
-o, --org-id string override the configured organization ID
-M, --rarity-max int maximum host count for interesting results (must be non-zero) (default 100)
-m, --rarity-min int minimum host count for interesting results (must be non-zero) (default 2)
-r, --raw output raw data

Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|ndjson|tree) (default "json")
-O, --output-format string output format (json|yaml|tree|short|template) (default "short")
-q, --quiet suppress non-essential output
-S, --streaming enable streaming output mode (NDJSON) for commands that support it
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

23 changes: 23 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/credits_help.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Display credit details for your Free user Censys account.

Note: This command only shows free user credits. If you want to see organization credits,
run "censys org credits" instead.

Usage:
censys credits [flags]

Examples:
censys credits # Show free user credits

Flags:
-h, --help help for credits

Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|tree|short|template) (default "short")
-q, --quiet suppress non-essential output
-S, --streaming enable streaming output mode (NDJSON) for commands that support it
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

10 changes: 10 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ var (
HistoryHelpStdout []byte
//go:embed root.out
RootStdout []byte
//go:embed credits_help.out
CreditsHelpStdout []byte
//go:embed org_details_help.out
OrgDetailsHelpStdout []byte
//go:embed org_members_help.out
OrgMembersHelpStdout []byte
//go:embed org_credits_help.out
OrgCreditsHelpStdout []byte
//go:embed org_help.out
OrgHelpStdout []byte
)
3 changes: 2 additions & 1 deletion cmd/cencli/e2e/fixtures/golden/history_help.out
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|ndjson|tree) (default "json")
-O, --output-format string output format (json|yaml|tree|short|template) (default "json")
-q, --quiet suppress non-essential output
-S, --streaming enable streaming output mode (NDJSON) for commands that support it
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

Loading