Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as React from 'react';
import { useState, useEffect, useCallback } from 'react'
import { useFormikContext } from 'formik';

import { FormikFormGroup } from 'components/common';
import type { GeoIpConfigType } from 'components/maps/configurations/types';
import { Button, Input } from 'components/bootstrap';

const ABSGeoIpFormGroup = () => {
const { values, setFieldValue } = useFormikContext<GeoIpConfigType>();
const isKeySet = values.key && 'is_set' in values.key;
const [isCreate] = useState(() => !isKeySet);
const [showResetPasswordButton, setShowResetPasswordButton] = useState(isKeySet);

const setAccessKey = useCallback(
(nextAccessKey) => {
setFieldValue('key', { set_value: nextAccessKey });
},
[setFieldValue],
);

useEffect(() => {
if (isKeySet) {
setAccessKey({ keep_value: true });
}
}, [isKeySet, setAccessKey]);

const toggleAccountKeyReset = useCallback(() => {
if (showResetPasswordButton) {
setAccessKey({ delete_value: true });
setShowResetPasswordButton(false);

return;
}

setAccessKey({ keep_value: true });
setShowResetPasswordButton(true);
}, [setAccessKey, showResetPasswordButton]);

return (
<>
<FormikFormGroup
name="container"
type="text"
label="Azure Blob Container Name"
help="Your Azure Blob Container name."
labelClassName=""
required
wrapperClassName=""
/>
<FormikFormGroup
name="account_name"
type="text"
label="Azure account"
placeholder="your-account-name"
help="The name of your Azure storage account."
required
labelClassName=""
wrapperClassName=""
/>
{showResetPasswordButton ? (
<Input id="azure_account_reset" label="Azure Account Key" labelClassName="col-sm-3" wrapperClassName="col-sm-9">
<Button onClick={toggleAccountKeyReset}>Reset password</Button>
</Input>
) : (
<Input
name="key"
id="key"
type="password"
label="Azure account key"
onChange={({ target: { value } }) => setAccessKey(value)}
buttonAfter={
!isCreate ? (
<Button type="button" onClick={toggleAccountKeyReset}>
Undo Reset
</Button>
) : undefined
}
placeholder="****************"
help="The account key for your Azure storage account."
required
/>
)}
</>
)
}

export default ABSGeoIpFormGroup
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import { useFormikContext } from 'formik';

import { FormikInput, InputOptionalInfo } from 'components/common';
import GCSSetupInfo from 'components/gcs/GCSSetupInfo';
import type { GeoIpConfigType } from 'components/maps/configurations/types';

const GCSGeoIpFormGroup = () => {
const { values } = useFormikContext<GeoIpConfigType>();

return (
<>
<GCSSetupInfo />
<FormikInput
id="gcs_project_id"
type="text"
disabled={!values.enabled}
label={
<>
Googe Cloud Storage Project ID <InputOptionalInfo />
</>
}
name="gcs_project_id"
/>
</>
)
}

export default GCSGeoIpFormGroup
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,18 @@
*/
import React, { useEffect, useState } from 'react';
import { Field, Form, Formik } from 'formik';
import isEqual from 'lodash/isEqual';

import { IfPermitted, Select, TimeUnitInput, ModalSubmit, InputOptionalInfo } from 'components/common';
import { Button, Col, Input, Modal, Row } from 'components/bootstrap';
import FormikInput from 'components/common/FormikInput';
import { DocumentationLink } from 'components/support';
import useSendTelemetry from 'logic/telemetry/useSendTelemetry';
import { TELEMETRY_EVENT_TYPE } from 'logic/telemetry/Constants';
import GCSSetupInfo from 'components/gcs/GCSSetupInfo';

export type GeoVendorType = 'MAXMIND' | 'IPINFO';
export type TimeUnit = 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS';

const CLOUD_STORAGE_OPTION = {
GCS: 'gcs',
S3: 's3',
} as const;

export type GeoIpConfigType = {
enabled: boolean;
enforce_graylog_schema: boolean;
db_vendor_type: GeoVendorType;
city_db_path: string;
asn_db_path: string;
refresh_interval_unit: TimeUnit;
refresh_interval: number;
pull_from_cloud?: (typeof CLOUD_STORAGE_OPTION)[keyof typeof CLOUD_STORAGE_OPTION];
gcs_project_id?: string;
};

export type OptionType = {
value: string;
label: string;
};
import type { GeoVendorType, GeoIpConfigType, OptionType } from 'components/maps/configurations/types';
import { CLOUD_STORAGE_OPTION } from 'components/maps/configurations/types';
import GCSGeoIpFormGroup from 'components/maps/configurations/GCSGeoIpFormGroup';
import ABSGeoIpFormGroup from 'components/maps/configurations/ABSGeoIpFormGroup';

type Props = {
config?: GeoIpConfigType;
Expand All @@ -74,8 +53,10 @@ const GeoIpResolverConfig = ({ config = defaultConfig, updateConfig }: Props) =>
const sendTelemetry = useSendTelemetry();

useEffect(() => {
setCurConfig({ ...config });
}, [config]);
if (!isEqual(curConfig, config)) {
setCurConfig({ ...config });
}
}, [config, curConfig]);

const resetConfig = () => {
setCurConfig(config);
Expand Down Expand Up @@ -103,6 +84,7 @@ const GeoIpResolverConfig = ({ config = defaultConfig, updateConfig }: Props) =>
const cloudStorageOptions: OptionType[] = [
{ value: CLOUD_STORAGE_OPTION.S3, label: 'S3' },
{ value: CLOUD_STORAGE_OPTION.GCS, label: 'Google Cloud Storage' },
{ value: CLOUD_STORAGE_OPTION.ABS, label: 'Azure Blob Storage' },
];

const activeVendorType = (type: GeoVendorType) => availableVendorTypes().filter((t) => t.value === type)[0].label;
Expand Down Expand Up @@ -256,20 +238,10 @@ const GeoIpResolverConfig = ({ config = defaultConfig, updateConfig }: Props) =>
</Field>

{values.pull_from_cloud === CLOUD_STORAGE_OPTION.GCS && (
<>
<GCSSetupInfo />
<FormikInput
id="gcs_project_id"
type="text"
disabled={!values.enabled}
label={
<>
Googe Cloud Storage Project ID <InputOptionalInfo />
</>
}
name="gcs_project_id"
/>
</>
<GCSGeoIpFormGroup />
)}
{values.pull_from_cloud === CLOUD_STORAGE_OPTION.ABS && (
<ABSGeoIpFormGroup />
)}
</Modal.Body>
<Modal.Footer>
Expand Down
50 changes: 50 additions & 0 deletions graylog2-web-interface/src/components/maps/configurations/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

export type GeoVendorType = 'MAXMIND' | 'IPINFO';
export type TimeUnit = 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS';
export const CLOUD_STORAGE_OPTION = {
GCS: 'gcs',
S3: 's3',
ABS: 'abs'
} as const;

export type EncryptedValue =
| { is_set: boolean }
| { set_value: string }
| { keep_value: boolean }
| { delete_value: boolean };

export type GeoIpConfigType = {
enabled: boolean;
enforce_graylog_schema: boolean;
db_vendor_type: GeoVendorType;
city_db_path: string;
asn_db_path: string;
refresh_interval_unit: TimeUnit;
refresh_interval: number;
pull_from_cloud?: (typeof CLOUD_STORAGE_OPTION)[keyof typeof CLOUD_STORAGE_OPTION];
gcs_project_id?: string;
key?: EncryptedValue;
account_name?: string;
container?: string;
};

export type OptionType = {
value: string;
label: string;
};
Loading