Skip to content

feat: expose --format json for token creation cmd#26286

Merged
praveen-influx merged 2 commits intomainfrom
praveen/token-response-format
Apr 18, 2025
Merged

feat: expose --format json for token creation cmd#26286
praveen-influx merged 2 commits intomainfrom
praveen/token-response-format

Conversation

@praveen-influx
Copy link
Copy Markdown
Contributor

closes: #25913

Test

cargo run -- create token --admin --format json
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s
     Running `target/debug/influxdb3 create token --admin --format json`
{
  "hashed_token": "c0d5ab879856384becbd77b326e0d160a01ca9270c4c38599a65be99f236d55bfd21360da8e1042e181a68df44c9c1663a8dd384067814fd215322a5ad3aea61",
  "help_msg": "HTTP requests require the following header: \"Authorization: Bearer apiv3_MjgUZqQRNbzQgt6byYic8t1K_H9crv0d5ZS_bWhJxZxB6FSeXetjFni-X2vEiXFN7DGU0WaIjnGd-fu6-NHQRA\"",
  "token": "apiv3_MjgUZqQRNbzQgt6byYic8t1K_H9crv0d5ZS_bWhJxZxB6FSeXetjFni-X2vEiXFN7DGU0WaIjnGd-fu6-NHQRA"
}

I've also included help_msg, although I suspect if someone is choosing to use --format json they're already aware of how to set HTTP authorization but I still added it just to make sure it clearly indicates how to set it up. It can be removed if we decide that it is not required as part of this payload.

@praveen-influx praveen-influx requested a review from a team April 17, 2025 15:39
@hiltontj
Copy link
Copy Markdown
Contributor

Is it important to include the hashed_token?

I think we used to do that because the server needed to be started with it as a CLI argument, but that is no longer the case.

@praveen-influx
Copy link
Copy Markdown
Contributor Author

Is it important to include the hashed_token?

It isn't really, just something you could potentially use to check if the hash is present in the result from influxdb3 show token (only useful whilst debugging).

Copy link
Copy Markdown
Contributor

@hiltontj hiltontj left a comment

Choose a reason for hiding this comment

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

I had one request in a comment below.

Otherwise, I don't know if exposing the hashed_token is a great idea. I don't think it necessarily constitutes a vulnerability but it is an implementation detail that (I think) needn't be exposed to the user.

Comment on lines +2945 to +2947
let value: Value =
serde_json::from_str(&result).expect("token creation response should be in json format");
assert!(value.get("token").is_some());
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.

Would be good to have the test check that the token from the response can be used to authenticate a request.

@praveen-influx praveen-influx requested a review from hiltontj April 17, 2025 18:32
@praveen-influx
Copy link
Copy Markdown
Contributor Author

I don't know if exposing the hashed_token is a great idea

I've taken it out now.

@praveen-influx praveen-influx merged commit b41a2d9 into main Apr 18, 2025
12 checks passed
@praveen-influx praveen-influx deleted the praveen/token-response-format branch April 18, 2025 07:06
hiltontj pushed a commit that referenced this pull request May 2, 2025
* feat: expose `--format json` for token creation cmd

closes: #25913

* refactor: address feedback
mgattozzi pushed a commit that referenced this pull request Sep 8, 2025
This is mainly a port of the same functionality from core. Because
the code has moved in this area in enterprise, this is manually copied
over with few adjustments to match the change in API.

core PR: #26286
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.

Add --format json for influxdb3 create token command

2 participants