Skip to content

Commit

Permalink
upcoming: [M3-8613] - Restrict Image Upload to regions with Object St…
Browse files Browse the repository at this point in the history
…orage (linode#11038)

* limit upload regions based on feature flag

* add flag to disallow non-obj regions

* update cypress test to use compatible region

* Added changeset: Restrict Image Upload to regions with Object Storage

---------

Co-authored-by: Banks Nussman <banks@nussman.us>
  • Loading branch information
bnussman-akamai and bnussman authored Oct 8, 2024
1 parent c0d8900 commit 1922af4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Restrict Image Upload to regions with Object Storage ([#11038](https://github.com/linode/manager/pull/11038))
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const assertProcessing = (label: string, id: string) => {
* @param label - Label to apply to uploaded image.
*/
const uploadImage = (label: string) => {
const region = chooseRegion();
const region = chooseRegion({ capabilities: ['Object Storage'] });
const upload = 'machine-images/test-image.gz';
cy.visitWithLogin('/images/create/upload');
getClick('[id="label"][data-testid="textfield-input"]').type(label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const RegionSelect = <
disabledRegions: disabledRegionsFromProps,
errorText,
helperText,
ignoreAccountAvailability,
label,
onChange,
placeholder,
Expand All @@ -67,7 +68,7 @@ export const RegionSelect = <
const {
data: accountAvailability,
isLoading: accountAvailabilityLoading,
} = useAllAccountAvailabilitiesQuery();
} = useAllAccountAvailabilitiesQuery(!ignoreAccountAvailability);

const regionOptions = getRegionOptions({
currentCapability,
Expand All @@ -86,6 +87,7 @@ export const RegionSelect = <
acc[region.id] = disabledRegionsFromProps[region.id];
}
if (
!ignoreAccountAvailability &&
isRegionOptionUnavailable({
accountAvailabilityData: accountAvailability,
currentCapability,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,18 @@ export interface RegionSelectProps<
* The specified capability to filter the regions on. Any region that does not have the `currentCapability` will not appear in the RegionSelect dropdown.
* Only use `undefined` for situations where there is no relevant capability for the RegionSelect - this will not filter any of the regions passed in.
* Otherwise, a capability should always be passed in.
*
* See `ImageUpload.tsx` for an example of a RegionSelect with an undefined `currentCapability` - there is no capability associated with Images yet.
*/
currentCapability: Capabilities | undefined;
/**
* A key/value object for disabling regions by their ID.
*/
disabledRegions?: Record<string, DisableRegionOption>;
helperText?: string;
/**
* Ignores account availability information when rendering region options
* @default false
*/
ignoreAccountAvailability?: boolean;
label?: string;
regionFilter?: RegionFilterValue;
regions: Region[];
Expand Down
1 change: 1 addition & 0 deletions packages/manager/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface Flags {
databases: boolean;
dbaasV2: BetaFeatureFlag;
disableLargestGbPlans: boolean;
disallowImageUploadToNonObjRegions: boolean;
gecko2: GeckoFeatureFlag;
gpuv2: gpuV2;
imageServiceGen2: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,21 @@ export const ImageUpload = () => {
<Controller
render={({ field, fieldState }) => (
<RegionSelect
currentCapability={
flags.disallowImageUploadToNonObjRegions
? 'Object Storage'
: undefined
}
disabled={
isImageCreateRestricted || form.formState.isSubmitting
}
textFieldProps={{
inputRef: field.ref,
onBlur: field.onBlur,
}}
currentCapability={undefined}
disableClearable
errorText={fieldState.error?.message}
ignoreAccountAvailability
label="Region"
onChange={(e, region) => field.onChange(region.id)}
regionFilter="core" // Images service will not be supported for Gecko Beta
Expand Down

0 comments on commit 1922af4

Please sign in to comment.