-
Notifications
You must be signed in to change notification settings - Fork 939
chore: Make deployment admin page show better durations #6856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
be736f2
8a20218
44160dd
9177fea
933539e
0b3f76e
f4a0826
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { optionValue } from "./OptionsTable" | ||
import { DeploymentOption } from "api/types" | ||
|
||
const defaultOption: DeploymentOption = { | ||
name: "", | ||
description: "", | ||
flag: "", | ||
flag_shorthand: "", | ||
value: "", | ||
hidden: false, | ||
} | ||
|
||
describe("optionValue", () => { | ||
it.each<{ | ||
option: DeploymentOption | ||
expected: string | string[] | unknown | ||
}>([ | ||
{ | ||
option: { | ||
...defaultOption, | ||
name: "Max Token Lifetime", | ||
value: 3600 * 1e9, | ||
}, | ||
expected: "1 hour", | ||
}, | ||
{ | ||
option: { | ||
...defaultOption, | ||
name: "Max Token Lifetime", | ||
value: 24 * 3600 * 1e9, | ||
}, | ||
expected: "1 day", | ||
}, | ||
{ | ||
option: { | ||
...defaultOption, | ||
name: "Session Duration", | ||
value: 3600 * 1e9, | ||
}, | ||
expected: "1 hour", | ||
}, | ||
{ | ||
option: { | ||
...defaultOption, | ||
name: "Session Duration", | ||
value: 24 * 3600 * 1e9, | ||
}, | ||
expected: "1 day", | ||
}, | ||
{ | ||
option: { | ||
...defaultOption, | ||
name: "Strict-Transport-Security", | ||
value: 1000, | ||
}, | ||
expected: "1000s", | ||
}, | ||
{ | ||
option: { | ||
...defaultOption, | ||
name: "OIDC Group Mapping", | ||
value: { | ||
"123": "foo", | ||
"456": "bar", | ||
"789": "baz", | ||
}, | ||
}, | ||
expected: [`"123"->"foo"`, `"456"->"bar"`, `"789"->"baz"`], | ||
}, | ||
])(`[$option.name]optionValue($option.value)`, ({ option, expected }) => { | ||
expect(optionValue(option)).toEqual(expected) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { | |
} from "components/DeploySettingsLayout/Option" | ||
import { FC } from "react" | ||
import { DisabledBadge } from "./Badges" | ||
import { intervalToDuration, formatDuration } from "date-fns" | ||
|
||
const OptionsTable: FC<{ | ||
options: DeploymentOption[] | ||
|
@@ -34,7 +35,11 @@ const OptionsTable: FC<{ | |
</TableHead> | ||
<TableBody> | ||
{Object.values(options).map((option) => { | ||
if (option.value === null || option.value === "") { | ||
if ( | ||
option.value === null || | ||
option.value === "" || | ||
option.value === undefined | ||
) { | ||
return null | ||
} | ||
return ( | ||
|
@@ -45,7 +50,7 @@ const OptionsTable: FC<{ | |
</TableCell> | ||
|
||
<TableCell> | ||
<OptionValue>{option.value}</OptionValue> | ||
<OptionValue>{optionValue(option)}</OptionValue> | ||
</TableCell> | ||
</TableRow> | ||
) | ||
|
@@ -56,6 +61,31 @@ const OptionsTable: FC<{ | |
) | ||
} | ||
|
||
// optionValue is a helper function to format the value of a specific deployment options | ||
export function optionValue( | ||
option: DeploymentOption, | ||
): string[] | string | unknown { | ||
switch (option.name) { | ||
case "Max Token Lifetime": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's up with this empty case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't case blocks fall through to each other? These two cases are handled the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :D I had to google that - you're right. Down the road, I wonder if we should type
This would give us some additional type safety. Not something to worry about in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Totally makes sense. I didn't know the "typescript" way to do this. |
||
case "Session Duration": | ||
// intervalToDuration takes ms, so convert nanoseconds to ms | ||
return formatDuration( | ||
intervalToDuration({ start: 0, end: (option.value as number) / 1e6 }), | ||
) | ||
case "Strict-Transport-Security": | ||
if (option.value === 0) { | ||
return "Disabled" | ||
} | ||
return (option.value as number).toString() + "s" | ||
case "OIDC Group Mapping": | ||
return Object.entries(option.value as Record<string, string>).map( | ||
([key, value]) => `"${key}"->"${value}"`, | ||
) | ||
default: | ||
return option.value | ||
} | ||
} | ||
|
||
Emyrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const useStyles = makeStyles((theme) => ({ | ||
table: { | ||
"& td": { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
apikey.go
, we check to see if--max-token-lifetime
is unset. I think we'll have to adjust this logic now that we aren't usingtime.Duration(math.MaxInt64)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, I hate this maxint buisness. We should have just used 0 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can bring back in "unset" if we need later.