openziti / ziti

The parent project for OpenZiti. Here you will find the executables for a fully zero trust, application embedded, programmable network @OpenZiti
https://openziti.io
Apache License 2.0
2.9k stars 165 forks source link

output-request-json doesn't #2569

Open qrkourier opened 15 hours ago

qrkourier commented 15 hours ago
$ ziti edge list edge-routers --output-request-json 'tags.foo = "bar"'       
╭────┬──────┬────────┬───────────────┬──────┬────────────╮
│ ID │ NAME │ ONLINE │ ALLOW TRANSIT │ COST │ ATTRIBUTES │
├────┼──────┼────────┼───────────────┼──────┼────────────┤
╰────┴──────┴────────┴───────────────┴──────┴────────────╯
results: none
dovholuknf commented 15 hours ago

doesn't state it explicitly, but it'll work just add --verbose

qrkourier commented 15 hours ago

Noted and confirmed. How shall we unconfuse future users on this point? My naive expectation was that --output-request-json would output the request JSON.

emoscardini commented 15 hours ago

You don't need the --verbose flag that's a completely different function, but the functionality of --output-request-json is a bit confusing since it doesn't return anything while doing list . Performing other functions does return output:

ziti edge create edge-router test --output-request-json
POST to https://127.0.0.1/edge/management/v1/edge-routers
{
    "appData": null,
    "cost": 0,
    "disabled": false,
    "isTunnelerEnabled": false,
    "name": "test",
    "noTraversal": false,
    "roleAttributes": null,
    "tags": {}
}
New edge router test created with id: 2apaydtbK

Also noticed that if you do a DELETE, the output actually shows POST instead of DELETE:

ziti edge delete edge-router test --output-request-json
POST to https://127.0.0.1/edge/management/v1/edge-routers/2apaydtbK
[]
delete of edge-router with id 2apaydtbK: OK

I would expect the list to show a simple GET & the endpoint it used.

qrkourier commented 13 hours ago

It appears that the necessity of --verbose is inconsistent across the CLI's CRUD commands and uniformly required for the edge list command. However, a few types do not print the request JSON even when both flags are set: --output-request-json --verbose. Those types that always fail are auth-policies, cas, and ext-jwt-signers.

❯ while read
do
        if unbuffer ~/go/bin/ziti edge list $REPLY --output-request-json |& grep -q RESTY
        then
                echo -e "INFO: $REPLY succeeded with --output-request-json"
        elif unbuffer ~/go/bin/ziti edge list $REPLY --output-request-json --verbose |& grep -q RESTY
        then
                echo -e "WARN: $REPLY succeeded with --verbose --output-request-json" >&2
        else
                echo -e "ERROR: $REPLY failed" >&2
        fi
done< <(awk -F'"' '/\.AddCommand\(new(Sub)?ListCmdForEntityType/ {print $2}' ./ziti/cmd/edge/list.go | sort -u)
WARN: api-sessions succeeded with --verbose --output-request-json
WARN: authenticators succeeded with --verbose --output-request-json
ERROR: auth-policies failed
ERROR: cas failed
WARN: configs succeeded with --verbose --output-request-json
ERROR: config-type failed
WARN: config-types succeeded with --verbose --output-request-json
WARN: edge-router-policies succeeded with --verbose --output-request-json
WARN: edge-router-role-attributes succeeded with --verbose --output-request-json
WARN: edge-routers succeeded with --verbose --output-request-json
WARN: enrollments succeeded with --verbose --output-request-json
ERROR: ext-jwt-signers failed
WARN: identities succeeded with --verbose --output-request-json
WARN: identity-role-attributes succeeded with --verbose --output-request-json
WARN: posture-check-role-attributes succeeded with --verbose --output-request-json
WARN: posture-checks succeeded with --verbose --output-request-json
WARN: posture-check-types succeeded with --verbose --output-request-json
WARN: service-edge-router-policies succeeded with --verbose --output-request-json
WARN: service-policies succeeded with --verbose --output-request-json
WARN: service-role-attributes succeeded with --verbose --output-request-json
WARN: services succeeded with --verbose --output-request-json
WARN: sessions succeeded with --verbose --output-request-json
WARN: summary succeeded with --verbose --output-request-json
WARN: terminators succeeded with --verbose --output-request-json
WARN: transit-routers succeeded with --verbose --output-request-json