/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import { useState } from 'react'; import { SupersetTheme, t } from '@superset-ui/core'; import { AntdButton, AntdSelect } from 'src/components'; import InfoTooltip from 'src/components/InfoTooltip'; import FormLabel from 'src/components/Form/FormLabel'; import Icons from 'src/components/Icons'; import { FieldPropTypes } from '../../types'; import { infoTooltip, labelMarginBottom, CredentialInfoForm } from '../styles'; enum CredentialInfoOptions { JsonUpload, CopyPaste, } // These are the columns that are going to be added to encrypted extra, they differ in name based // on the engine, however we want to use the same component for each of them. Make sure to add the // the engine specific name here. export const encryptedCredentialsMap = { gsheets: 'service_account_info', bigquery: 'credentials_info', }; const castStringToBoolean = (optionValue: string) => optionValue === 'true'; export const EncryptedField = ({ changeMethods, isEditMode, db, editNewDb, }: FieldPropTypes) => { const [uploadOption, setUploadOption] = useState( CredentialInfoOptions.JsonUpload.valueOf(), ); const [fileToUpload, setFileToUpload] = useState( null, ); const [isPublic, setIsPublic] = useState(true); const showCredentialsInfo = db?.engine === 'gsheets' ? !isEditMode && !isPublic : !isEditMode; const isEncrypted = isEditMode && db?.masked_encrypted_extra !== '{}'; const encryptedField = db?.engine && encryptedCredentialsMap[db.engine]; const encryptedValue = typeof db?.parameters?.[encryptedField] === 'object' ? JSON.stringify(db?.parameters?.[encryptedField]) : db?.parameters?.[encryptedField]; return ( {db?.engine === 'gsheets' && (
labelMarginBottom(theme)} required > {t('Type of Google Sheets allowed')} setIsPublic(castStringToBoolean(value)) } > {t('Publicly shared sheets only')} {t('Public and privately shared sheets')}
)} {showCredentialsInfo && ( <> {t('How do you want to enter service account credentials?')} setUploadOption(option)} > {t('Upload JSON file')} {t('Copy and Paste JSON credentials')} )} {uploadOption === CredentialInfoOptions.CopyPaste || isEditMode || editNewDb ? (
{t('Service Account')}