-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARTESCA-3019: Add oracle cloud object storage support
- Loading branch information
1 parent
1c4afa9
commit 0064ee3
Showing
5 changed files
with
254 additions
and
2 deletions.
There are no files selected for viewing
190 changes: 190 additions & 0 deletions
190
src/react/locations/LocationDetails/LocationDetailsOracle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import { Input } from '@scality/core-ui/dist/components/inputv2/inputv2'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { LocationDetailsFormProps } from '.'; | ||
import { | ||
FormGroup, | ||
FormSection, | ||
} from '@scality/core-ui/dist/components/form/Form.component'; | ||
import { Checkbox } from '@scality/core-ui/dist/components/checkbox/Checkbox.component'; | ||
|
||
type State = { | ||
bucketMatch: boolean; | ||
accessKey: string; | ||
secretKey: string; | ||
bucketName: string; | ||
namespace: string; | ||
region: string; | ||
endpoint: string; | ||
}; | ||
const INIT_STATE: State = { | ||
bucketMatch: false, | ||
accessKey: '', | ||
secretKey: '', | ||
bucketName: '', | ||
namespace: '', | ||
region: '', | ||
endpoint: '', | ||
}; | ||
|
||
export const oracleCloudEndpointBuilder = (namespace: string, region: string) => | ||
`https://${namespace}.compat.objectstorage.${region}.oraclecloud.com`; | ||
|
||
export default function LocationDetailsOracle({ | ||
details, | ||
editingExisting, | ||
onChange, | ||
}: LocationDetailsFormProps) { | ||
const [formState, setFormState] = useState<State>(() => { | ||
return { | ||
...Object.assign({}, INIT_STATE, details, { secretKey: '' }), | ||
}; | ||
}); | ||
const onFormItemChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const target = e.target; | ||
const value = target.type === 'checkbox' ? target.checked : target.value; | ||
if (target.name === 'namespace' || target.name === 'region') { | ||
setFormState({ | ||
...formState, | ||
[target.name]: value, | ||
endpoint: oracleCloudEndpointBuilder( | ||
target.name === 'namespace' ? (value as string) : formState.namespace, | ||
target.name === 'region' ? (value as string) : formState.region, | ||
), | ||
}); | ||
} else { | ||
setFormState({ ...formState, [target.name]: value }); | ||
} | ||
|
||
if (onChange) { | ||
//remove the namespace and region from the formState | ||
//as it is not part of the LocationS3Details | ||
const { namespace, region, ...rest } = formState; | ||
onChange({ ...rest, [target.name]: value }); | ||
} | ||
}; | ||
|
||
//TODO check why the tests expect onChange to be called on mount | ||
useEffect(() => { | ||
const { namespace, region, ...rest } = formState; | ||
onChange({ ...rest, endpoint: formState.endpoint }); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<FormSection> | ||
<FormGroup | ||
id="namespace" | ||
label="Namespace" | ||
content={ | ||
<Input | ||
id="namespace" | ||
name="namespace" | ||
type="text" | ||
value={formState.namespace} | ||
onChange={onFormItemChange} | ||
placeholder="object_storage_namespace" | ||
/> | ||
} | ||
required | ||
labelHelpTooltip="The namespace of the object storage." | ||
helpErrorPosition="bottom" | ||
/> | ||
<FormGroup | ||
id="region" | ||
label="Region" | ||
content={ | ||
<Input | ||
id="region" | ||
name="region" | ||
type="text" | ||
value={formState.region} | ||
onChange={onFormItemChange} | ||
placeholder="eu-paris-1" | ||
/> | ||
} | ||
required | ||
labelHelpTooltip="The region of the object storage." | ||
helpErrorPosition="bottom" | ||
/> | ||
<FormGroup | ||
id="accessKey" | ||
content={ | ||
<Input | ||
name="accessKey" | ||
id="accessKey" | ||
type="text" | ||
placeholder="AKI5HMPCLRB86WCKTN2C" | ||
value={formState.accessKey} | ||
onChange={onFormItemChange} | ||
autoComplete="off" | ||
/> | ||
} | ||
required | ||
label="Access Key" | ||
helpErrorPosition="bottom" | ||
/> | ||
|
||
<FormGroup | ||
id="secretKey" | ||
label="Secret Key" | ||
required | ||
labelHelpTooltip="Your credentials are encrypted in transit, then at rest using your instance's RSA key pair so that we're unable to see them." | ||
helpErrorPosition="bottom" | ||
content={ | ||
<Input | ||
name="secretKey" | ||
id="secretKey" | ||
type="password" | ||
placeholder="QFvIo6l76oe9xgCAw1N/zlPFtdTSZXMMUuANeXc6" | ||
value={formState.secretKey} | ||
onChange={onFormItemChange} | ||
autoComplete="new-password" | ||
/> | ||
} | ||
/> | ||
<FormGroup | ||
id="bucketName" | ||
label="Target Bucket Name" | ||
help="The Target Bucket on your location needs to have Versioning enabled." | ||
required | ||
content={ | ||
<Input | ||
name="bucketName" | ||
id="bucketName" | ||
type="text" | ||
placeholder="bucket-name" | ||
value={formState.bucketName} | ||
onChange={onFormItemChange} | ||
autoComplete="off" | ||
disabled={editingExisting} | ||
/> | ||
} | ||
helpErrorPosition="bottom" | ||
/> | ||
</FormSection> | ||
<FormSection> | ||
<FormGroup | ||
label="" | ||
direction="vertical" | ||
id="bucketMatch" | ||
content={ | ||
<Checkbox | ||
name="bucketMatch" | ||
disabled={editingExisting} | ||
checked={formState.bucketMatch} | ||
onChange={onFormItemChange} | ||
label={'Write objects without prefix'} | ||
/> | ||
} | ||
helpErrorPosition="bottom" | ||
help="Your objects will be stored in the target bucket without a source-bucket prefix." | ||
error={ | ||
formState.bucketMatch | ||
? 'Storing multiple buckets in a location with this option enabled can lead to data loss.' | ||
: undefined | ||
} | ||
/> | ||
</FormSection> | ||
</> | ||
); | ||
} |
47 changes: 47 additions & 0 deletions
47
src/react/locations/LocationDetails/__tests__/LocationDetailsOracle.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { Wrapper } from '../../../utils/testUtil'; | ||
import LocationDetailsOracle from '../LocationDetailsOracle'; | ||
import { ORACLE_CLOUD_LOCATION_KEY } from '../../../../types/config'; | ||
|
||
const selectors = { | ||
namespaceSelector: () => screen.getByLabelText(/Namespace/), | ||
regionSelector: () => screen.getByLabelText(/Region/), | ||
targetBucketSelector: () => screen.getByLabelText(/Target Bucket Name/), | ||
accessKeySelector: () => screen.getByLabelText(/Access Key/), | ||
secretKeySelector: () => screen.getByLabelText(/Secret Key/), | ||
}; | ||
const props = { | ||
details: {}, | ||
onChange: () => {}, | ||
locationType: ORACLE_CLOUD_LOCATION_KEY, | ||
}; | ||
const namespace = 'namespace'; | ||
const region = 'eu-paris-1'; | ||
describe('class <LocationDetailsOracle />', () => { | ||
it('should call onChange on mount', async () => { | ||
//S | ||
let location = {}; | ||
render( | ||
//@ts-ignore | ||
<LocationDetailsOracle {...props} onChange={(l) => (location = l)} />, | ||
{ wrapper: Wrapper }, | ||
); | ||
waitFor(() => { | ||
expect(selectors.namespaceSelector()).toBeInTheDocument(); | ||
}); | ||
//E | ||
await userEvent.type(selectors.namespaceSelector(), namespace); | ||
await userEvent.type(selectors.regionSelector(), region); | ||
await userEvent.type(selectors.targetBucketSelector(), 'target-bucket'); | ||
await userEvent.type(selectors.accessKeySelector(), 'accessKey'); | ||
await userEvent.type(selectors.secretKeySelector(), 'secretKey'); | ||
expect(location).toEqual({ | ||
bucketMatch: false, | ||
endpoint: `https://${namespace}.compat.objectstorage.${region}.oraclecloud.com`, | ||
bucketName: 'target-bucket', | ||
accessKey: 'accessKey', | ||
secretKey: 'secretKey', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters