-
Notifications
You must be signed in to change notification settings - Fork 361
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
upcoming: [M3-7670] - Add and handle ACLB Account Capability #10098
Changes from all commits
da8f236
8469837
adee378
63a5251
5f7397d
e3d82a4
7e80308
1c0128f
415867b
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,5 @@ | ||
--- | ||
"@linode/api-v4": Upcoming Features | ||
--- | ||
|
||
Add `Akamai Cloud Load Balancer` to `AccountCapability` type ([#10098](https://github.com/linode/manager/pull/10098)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Upcoming Features | ||
--- | ||
|
||
Handle ACLB Account Capability ([#10098](https://github.com/linode/manager/pull/10098)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useFlags } from 'src/hooks/useFlags'; | ||
import { useAccount } from 'src/queries/account'; | ||
import { isFeatureEnabled } from 'src/utilities/accountCapabilities'; | ||
|
||
/** | ||
* Hook to help determine if the Akamai Cloud Load Balancer should be shown. | ||
* | ||
* @returns true if Akamai Cloud Load Balancer should be shown for the current user | ||
*/ | ||
export const useIsACLBEnabled = () => { | ||
const { data: account } = useAccount(); | ||
const flags = useFlags(); | ||
|
||
const isACLBEnabled = isFeatureEnabled( | ||
'Akamai Cloud Load Balancer', | ||
Boolean(flags.aglb), | ||
account?.capabilities ?? [] | ||
); | ||
|
||
return { isACLBEnabled }; | ||
}; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,23 @@ | ||
import { isFeatureEnabled } from './accountCapabilities'; | ||
|
||
const isObjectStorageEnabled = isFeatureEnabled('Object Storage'); | ||
describe('isFeatureEnabled', () => { | ||
it('returns `false` when both the flag is off and the item is not in account capabilities', () => { | ||
expect(isFeatureEnabled('Object Storage', false, [])).toBe(false); | ||
}); | ||
|
||
describe('isObjectStorageEnabled', () => { | ||
beforeEach(() => { | ||
vi.resetModules(); | ||
it('returns `true` when the flag is on, but the capability is not present', () => { | ||
expect(isFeatureEnabled('Object Storage', true, [])).toBe(true); | ||
}); | ||
describe('when "Object Storage EAP" is NOT in beta_programs...', () => { | ||
it("returns `false` when OBJ isn't enabled for the environment", () => { | ||
expect(isObjectStorageEnabled(false, [])).toBe(false); | ||
expect(isObjectStorageEnabled(false, ['Hello', 'World'] as any)).toBe( | ||
false | ||
); | ||
}); | ||
|
||
it('returns `true` when OBJ is enabled for the environment', () => { | ||
expect(isObjectStorageEnabled(true, [])).toBe(true); | ||
expect(isObjectStorageEnabled(true, ['Hello', 'World'] as any)).toBe( | ||
true | ||
); | ||
}); | ||
it('returns `true` when the flag is off, but the account capability is present', () => { | ||
expect(isFeatureEnabled('Object Storage', false, ['Object Storage'])).toBe( | ||
true | ||
); | ||
}); | ||
|
||
describe('when "Object Storage EAP" IS in beta_programs', () => { | ||
it('returns `true` if OBJ is disabled for environment', () => { | ||
expect(isObjectStorageEnabled(false, ['Object Storage'])).toBe(true); | ||
expect( | ||
isObjectStorageEnabled(false, [ | ||
'Hello', | ||
'World', | ||
'Object Storage', | ||
] as any) | ||
).toBe(true); | ||
}); | ||
it('returns `true` if OBJ is enabled for environment', () => { | ||
expect(isObjectStorageEnabled(false, ['Object Storage'])).toBe(true); | ||
expect( | ||
isObjectStorageEnabled(false, [ | ||
'Hello', | ||
'World', | ||
'Object Storage', | ||
] as any) | ||
).toBe(true); | ||
}); | ||
it('returns `true` when both the flag is on and the account capability is present', () => { | ||
expect(isFeatureEnabled('Object Storage', true, ['Object Storage'])).toBe( | ||
true | ||
); | ||
}); | ||
}); |
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. I de-ramda-ifyed this and tried to make the comment more useful. 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. I'd been confused by |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,22 @@ | ||
import { AccountCapability } from '@linode/api-v4/lib/account'; | ||
import { curry } from 'ramda'; | ||
import type { AccountCapability } from '@linode/api-v4'; | ||
|
||
/** | ||
* Determines if a feature should be enabled. If the feature is returned from account.capabilities or if it is explicitly enabled | ||
* in an environment variable (from Jenkins or .env), enable the feature. | ||
* Determines if a feature should be enabled. | ||
* | ||
* Curried to make later feature functions easier to write. Usage: | ||
* @returns true if the feature is returned from account.capabilities **or** if it is explicitly enabled | ||
* by a feature flag | ||
* | ||
* const isMyFeatureEnabled = isFeatureEnabled('Feature two'); | ||
* isMyFeatureEnabled(ENV_VAR, account.capabilities) | ||
* We use "or" instead of "and" here to allow us to enable features in "lower" environments | ||
* without needing the customer capability. | ||
* | ||
* or, since we have access to environment variables from this file: | ||
* | ||
* const isMyFeatureEnabled = isFeatureEnabled('feature name', ENV_VAR); | ||
* | ||
* isMyFeatureEnabled(['Feature one', 'Feature two']) // true | ||
* If you need to launch a production feature, but have it be gated, | ||
* you would turn the flag *off* for that environment, but have the API return | ||
* the account capability. | ||
*/ | ||
|
||
export const isFeatureEnabled = curry( | ||
( | ||
featureName: AccountCapability, | ||
environmentVar: boolean, | ||
capabilities: AccountCapability[] | ||
) => { | ||
return environmentVar || capabilities.indexOf(featureName) > -1; | ||
} | ||
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.
|
||
); | ||
export const isFeatureEnabled = ( | ||
featureName: AccountCapability, | ||
isFeatureFlagEnabled: boolean, | ||
capabilities: AccountCapability[] | ||
) => { | ||
return isFeatureFlagEnabled || capabilities.includes(featureName); | ||
}; |
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.
I like this, should be make this a pattern to follow?
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.
I like it! It's a nice simple abstraction. I did it just incase we need to change how
isACLBEnabled
is determined