|
| 1 | +// @flow |
| 2 | + |
| 3 | +import type { LocationDetails } from '../../../../types/config'; |
| 4 | +import React from 'react'; |
| 5 | + |
| 6 | +type Props = { |
| 7 | + details: LocationDetails, |
| 8 | + onChange: (details: LocationDetails) => void, |
| 9 | + editingExisting: boolean, |
| 10 | +}; |
| 11 | + |
| 12 | +type State = { |
| 13 | + serverSideEncryption: boolean, |
| 14 | + bucketMatch: boolean, |
| 15 | + accessKey: string, |
| 16 | + secretKey: string, |
| 17 | + bucketName: string, |
| 18 | +}; |
| 19 | + |
| 20 | +const INIT_STATE: State = { |
| 21 | + serverSideEncryption: false, |
| 22 | + bucketMatch: false, |
| 23 | + accessKey: '', |
| 24 | + secretKey: '', |
| 25 | + bucketName: '', |
| 26 | +}; |
| 27 | + |
| 28 | +export default class LocationDetailsAws extends React.Component<Props, State> { |
| 29 | + constructor(props: Props) { |
| 30 | + super(props); |
| 31 | + this.state = Object.assign({}, INIT_STATE, this.props.details); |
| 32 | + // XXX disable changing it if not provided |
| 33 | + this.state.secretKey = ''; |
| 34 | + } |
| 35 | + |
| 36 | + onChange = (e: SyntheticInputEvent<HTMLInputElement>) => { |
| 37 | + const target = e.target; |
| 38 | + const value = target.type === 'checkbox' ? target.checked : target.value; |
| 39 | + this.setState({ [target.name]: value }); |
| 40 | + } |
| 41 | + |
| 42 | + updateForm = () => { |
| 43 | + if (this.props.onChange) { |
| 44 | + this.props.onChange(this.state); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + componentDidMount() { |
| 49 | + this.updateForm(); |
| 50 | + } |
| 51 | + |
| 52 | + shouldComponentUpdate(nextProps: Props, nextState: State) { |
| 53 | + return this.state !== nextState; |
| 54 | + } |
| 55 | + |
| 56 | + componentDidUpdate() { |
| 57 | + this.updateForm(); |
| 58 | + } |
| 59 | + |
| 60 | + render() { |
| 61 | + return ( |
| 62 | + <div> |
| 63 | + <fieldset className="form-group"> |
| 64 | + <label htmlFor="accessKey">AWS Access Key</label> |
| 65 | + <input |
| 66 | + name="accessKey" |
| 67 | + id="accessKey" |
| 68 | + className="form-control" |
| 69 | + type="text" |
| 70 | + placeholder="AKI5HMPCLRB86WCKTN2C" |
| 71 | + value={this.state.accessKey} |
| 72 | + onChange={this.onChange} |
| 73 | + autoComplete="off" |
| 74 | + /> |
| 75 | + </fieldset> |
| 76 | + <fieldset className="form-group"> |
| 77 | + <label htmlFor="secretKey">AWS Secret Key</label> |
| 78 | + <input |
| 79 | + name="secretKey" |
| 80 | + id="secretKey" |
| 81 | + className="form-control" |
| 82 | + type="password" |
| 83 | + placeholder="QFvIo6l76oe9xgCAw1N/zlPFtdTSZXMMUuANeXc6" |
| 84 | + value={this.state.secretKey} |
| 85 | + onChange={this.onChange} |
| 86 | + autoComplete="new-password" |
| 87 | + /> |
| 88 | + <small> |
| 89 | + Your credentials are encrypted in transit, then at rest using your |
| 90 | + Zenko instance's RSA key pair so that we're unable to see them. |
| 91 | + </small> |
| 92 | + </fieldset> |
| 93 | + <fieldset className="form-group"> |
| 94 | + <label htmlFor="bucketName">Target Bucket Name</label> |
| 95 | + <input |
| 96 | + name="bucketName" |
| 97 | + id="bucketName" |
| 98 | + className="form-control" |
| 99 | + type="text" |
| 100 | + placeholder="Bucket Name" |
| 101 | + value={this.state.bucketName} |
| 102 | + onChange={this.onChange} |
| 103 | + autoComplete="off" |
| 104 | + /> |
| 105 | + </fieldset> |
| 106 | + <fieldset className="form-group"> |
| 107 | + <label className="form-check-label"> |
| 108 | + <input |
| 109 | + name="bucketMatch" |
| 110 | + className="form-check-input" |
| 111 | + type="checkbox" |
| 112 | + value={this.state.bucketMatch} |
| 113 | + checked={this.state.bucketMatch} |
| 114 | + disabled={this.props.editingExisting} |
| 115 | + onChange={this.onChange} /> |
| 116 | + <span>Write objects without prefix</span><br /> |
| 117 | + <small> Use this option for mirroring. <br /> </small> |
| 118 | + <small>Store objects in the target bucket without a source-bucket prefix.</small> |
| 119 | + { |
| 120 | + this.state.bucketMatch && |
| 121 | + <div> |
| 122 | + <small className="text-danger"> |
| 123 | + <i className="fa fa-exclamation-circle"></i> |
| 124 | + Storing multiple buckets in a location with this option enabled can lead to data loss. |
| 125 | + </small> |
| 126 | + </div> |
| 127 | + } |
| 128 | + </label> |
| 129 | + </fieldset> |
| 130 | + <fieldset className="form-group"> |
| 131 | + <label className="form-check-label"> |
| 132 | + <input |
| 133 | + name="serverSideEncryption" |
| 134 | + className="form-check-input" |
| 135 | + type="checkbox" |
| 136 | + value={this.state.serverSideEncryption} |
| 137 | + checked={this.state.serverSideEncryption} |
| 138 | + onChange={this.onChange} /> |
| 139 | + <span>Server-Side Encryption</span> |
| 140 | + </label> |
| 141 | + </fieldset> |
| 142 | + </div> |
| 143 | + ); |
| 144 | + } |
| 145 | +} |
0 commit comments