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
feat: add support for new constraint operators #289
Conversation
src/strategy/strategy.ts
Outdated
} | ||
default: | ||
return false; | ||
} |
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.
Instead of a switch on the Operator-enum I am tempted to instead create a small handler function per operator and just execute that function.
Example for contains:
const handler = (values: string[], contextValue) =>
values.some((val) => contextValue.includes(val.trim()))
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.
Also, we should probably pre-map the values by trimming them, making the handler work on pure data.
values.map((v) => v.trim())
src/helpers.ts
Outdated
|
||
const prefix = info | ||
? info.username | ||
: `generated-${Math.round(Math.random() * 1000000)}-${process.pid}`; |
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.
opt.semgrep.node_insecure_random_generator: crypto.pseudoRandomBytes()/Math.random() is a cryptographically weak random number generator.
(at-me in a reply with help
or ignore
)
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.
@sonatype-lift ignore
b8b57ef
to
b697e11
Compare
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.
This looks really good. Adds a lot of value to constraints :)
const DateOperator = (constraint: Constraint, context: Context) => { | ||
const { operator } = constraint; | ||
const value = new Date(constraint.value as string); | ||
const currentTime = context.currentTime ? new Date(context.currentTime) : new Date(); |
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 might want to move this to the creation of the context.
(+) The benefit will be that the date and time will not change between multiple constriants within the same feature toggle.
(-) The downside would be that we would have to create the currentTime date instance on the context, even when a use is not using any constraints that uses date operators.
5e8bc8a
to
24ed1ed
Compare
No description provided.