Skip to content

Commit

Permalink
s3 peer ui v0
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Nov 16, 2023
1 parent 68f5fb6 commit 154c216
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 126 deletions.
8 changes: 6 additions & 2 deletions flow/connectors/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,12 @@ func GetConnector(ctx context.Context, peer *protos.Peer) (Connector, error) {
return nil, fmt.Errorf("missing sqlserver config for %s peer %s", peer.Type.String(), peer.Name)
}
return connsqlserver.NewSQLServerConnector(ctx, sqlServerConfig)
// case protos.DBType_S3:
// return conns3.NewS3Connector(ctx, config.GetS3Config())
case protos.DBType_S3:
s3Config := peer.GetS3Config()
if s3Config == nil {
return nil, fmt.Errorf("missing s3 config for %s peer %s", peer.Type.String(), peer.Name)
}
return conns3.NewS3Connector(ctx, s3Config)
// case protos.DBType_EVENTHUB:
// return connsqlserver.NewSQLServerConnector(ctx, config.GetSqlserverConfig())
default:
Expand Down
6 changes: 6 additions & 0 deletions ui/app/api/peers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const constructPeer = (
type: DBType.BIGQUERY,
bigqueryConfig: config as BigqueryConfig,
};
case 'S3':
return {
name,
type: DBType.S3,
s3Config: config as S3Config,
};
default:
return;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/mirrors/create/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const blankQRepSetting = {
waitBetweenBatchesSeconds: 30,
writeMode: undefined,
stagingPath: '',
numRowsPerPartition: 0,
numRowsPerPartition: 100000,
setupWatermarkTableOnDestination: false,
dstTableFullResync: false,
};
1 change: 0 additions & 1 deletion ui/app/mirrors/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default function CreateMirrors() {
const [config, setConfig] = useState<CDCConfig | QRepConfig>(blankCDCSetting);
const [peers, setPeers] = useState<Peer[]>([]);
const [rows, setRows] = useState<TableMapRow[]>([]);
const [validSource, setValidSource] = useState<boolean>(false);
const [sourceSchema, setSourceSchema] = useState('public');
const [qrepQuery, setQrepQuery] =
useState<string>(`-- Here's a sample template:
Expand Down
17 changes: 17 additions & 0 deletions ui/app/peers/create/[peerType]/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
UCreatePeerResponse,
UValidatePeerResponse,
} from '@/app/dto/PeersDTO';
import { S3Config } from '@/grpc_generated/peers';
import { Dispatch, SetStateAction } from 'react';
import { bqSchema, pgSchema, s3Schema, sfSchema } from './schema';

Expand All @@ -17,6 +18,15 @@ const validateFields = (
setMessage({ ok: false, msg: 'Peer name is required' });
return false;
}

if (type === 'S3') {
const s3Valid = S3Validation(config as S3Config);
if (s3Valid.length > 0) {
setMessage({ ok: false, msg: s3Valid });
return false;
}
}

let validationErr: string | undefined;
switch (type) {
case 'POSTGRES':
Expand Down Expand Up @@ -74,6 +84,13 @@ export const handleValidate = async (
setLoading(false);
};

const S3Validation = (config: S3Config): string => {
if (!config.secretAccessKey && !config.accessKeyId && !config.roleArn) {
return 'Either both access key and secret or role ARN is required';
}
return '';
};

// API call to create peer
export const handleCreate = async (
type: string,
Expand Down
3 changes: 3 additions & 0 deletions ui/app/peers/create/[peerType]/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PeerConfig } from '@/app/dto/PeersDTO';
import { PeerSetter } from '@/components/ConfigForm';
import { blankBigquerySetting } from './bq';
import { blankPostgresSetting } from './pg';
import { blankS3Setting } from './s3';
import { blankSnowflakeSetting } from './sf';

export interface PeerSetting {
Expand All @@ -22,6 +23,8 @@ export const getBlankSetting = (dbType: string): PeerConfig => {
return blankSnowflakeSetting;
case 'BIGQUERY':
return blankBigquerySetting;
case 'S3':
return blankS3Setting;
default:
return blankPostgresSetting;
}
Expand Down
54 changes: 30 additions & 24 deletions ui/app/peers/create/[peerType]/helpers/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,60 @@ export const s3Setting: PeerSetting[] = [
label: 'Bucket URL',
stateHandler: (value, setter) =>
setter((curr) => ({ ...curr, url: value })),
tips: 'The URL of the S3/GCS bucket. It begins with s3://',
tips: 'The URL of your existing S3/GCS bucket along with a prefix of your choice. It begins with s3://',
helpfulLink:
'https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-bucket-intro.html#accessing-a-bucket-using-S3-format',
default: 's3://<bucket_name>/<prefix_name>',
},
{
label: 'Access Key ID',
stateHandler: (value, setter) =>
setter((curr) => ({ ...curr, accessKeyID: parseInt(value, 10) })),
tips: 'Specifies the TCP/IP port or local Unix domain socket file extension on which postgres is listening for connections from client applications.',
setter((curr) => ({ ...curr, accessKeyId: value })),
optional: true,
tips: 'The AWS access key ID associated with your account. In case of GCS, this is the HMAC access key ID.',
helpfulLink:
'https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html',
},
{
label: 'Secret Access Key',
stateHandler: (value, setter) =>
setter((curr) => ({ ...curr, secretAccessKey: value })),
tips: 'Specify the user that we should use to connect to this host.',
helpfulLink: 'https://www.postgresql.org/docs/8.0/user-manag.html',
},
{
label: 'Role ARN',
stateHandler: (value, setter) =>
setter((curr) => ({ ...curr, roleArn: value })),
type: 'password',
tips: 'Password associated with the user you provided.',
helpfulLink: 'https://www.postgresql.org/docs/current/auth-password.html',
tips: 'The AWS secret access key associated with your account. In case of GCS, this is the HMAC secret.',
helpfulLink:
'https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html',
optional: true,
},
{
label: 'Region',
stateHandler: (value, setter) =>
setter((curr) => ({ ...curr, region: value })),
tips: 'Specify which database to associate with this peer.',
helpfulLink:
'https://www.postgresql.org/docs/current/sql-createdatabase.html',
optional: true,
tips: 'The region where your bucket is located. For example, us-east-1. In case of GCS, this will be set to auto, which detects where your bucket it.',
},
{
label: 'Endpoint',
label: 'Role ARN',
stateHandler: (value, setter) =>
setter((curr) => ({ ...curr, endpoint: value })),
setter((curr) => ({ ...curr, roleArn: value })),
type: 'password',
tips: 'You may set this instead of the access key ID and secret.',
helpfulLink:
'https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns',
optional: true,
tips: '',
},
];

export const blankS3Config: S3Config = {
url: '',
export const blankS3Setting: S3Config = {
url: 's3://<bucket_name>/<prefix_name>',
accessKeyId: undefined,
secretAccessKey: undefined,
roleArn: undefined,
region: undefined,
endpoint: undefined,
metadataDb: undefined,
endpoint: '',
metadataDb: {
host: '',
port: 5432,
user: 'postgres',
password: '',
database: 'postgres',
transactionSnapshot: '',
},
};
14 changes: 11 additions & 3 deletions ui/app/peers/create/[peerType]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import S3ConfigForm from '@/components/S3Form';
import { Button } from '@/lib/Button';
import { ButtonGroup } from '@/lib/ButtonGroup';
import { Label } from '@/lib/Label';
import { LayoutMain, RowWithTextField } from '@/lib/Layout';
import { RowWithTextField } from '@/lib/Layout';
import { Panel } from '@/lib/Panel';
import { TextField } from '@/lib/TextField';
import { Tooltip } from '@/lib/Tooltip';
Expand Down Expand Up @@ -58,7 +58,15 @@ export default function CreateConfig({
};

return (
<LayoutMain alignSelf='center' justifySelf='center' width='xxLarge'>
<div
style={{
display: 'flex',
flexDirection: 'column',
alignSelf: 'center',
justifySelf: 'center',
width: '45%',
}}
>
<Panel>
<Label variant='title3'>
Setup a new{' '}
Expand Down Expand Up @@ -147,6 +155,6 @@ export default function CreateConfig({
)}
</Panel>
</Panel>
</LayoutMain>
</div>
);
}
4 changes: 2 additions & 2 deletions ui/app/peers/create/[peerType]/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ export const s3Schema = z.object({
required_error: 'URL is required',
})
.min(1, { message: 'URL must be non-empty' })
.refine((url) => url.startsWith('s3:/'), {
message: 'URL must start with s3:/',
.refine((url) => url.startsWith('s3://'), {
message: 'URL must start with s3://',
}),
accessKeyId: z
.string({
Expand Down
Loading

0 comments on commit 154c216

Please sign in to comment.