You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/10/17 00:43:55 UTC

[GitHub] [superset] eschutho commented on a change in pull request #16856: feat: DBC UI Snowflake Form

eschutho commented on a change in pull request #16856:
URL: https://github.com/apache/superset/pull/16856#discussion_r730112341



##########
File path: superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm/EncryptedField.tsx
##########
@@ -0,0 +1,198 @@
+/**
+ * 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 React, { useState } from 'react';
+import { SupersetTheme, t } from '@superset-ui/core';
+import { Select, Button } from 'src/common/components';
+import InfoTooltip from 'src/components/InfoTooltip';
+import FormLabel from 'src/components/Form/FormLabel';
+import { DeleteFilled } from '@ant-design/icons';
+import { FieldPropTypes } from '.';
+import { infoTooltip, labelMarginBotton, 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<number>(
+    CredentialInfoOptions.jsonUpload.valueOf(),
+  );
+  const [fileToUpload, setFileToUpload] = useState<string | null | undefined>(
+    null,
+  );
+  const [isPublic, setIsPublic] = useState<boolean>(true);
+  const showCredentialsInfo =
+    db?.engine === 'gsheets' ? !isEditMode && !isPublic : !isEditMode;
+  // a database that has an optional encrypted field has an encrypted_extra that is an empty object, this checks for that.
+  const isEncrypted = isEditMode && db?.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 (
+    <CredentialInfoForm>
+      {db?.engine === 'gsheets' && (
+        <div className="catalog-type-select">
+          <FormLabel
+            css={(theme: SupersetTheme) => labelMarginBotton(theme)}
+            required
+          >
+            {t('Type of Google Sheets allowed')}
+          </FormLabel>
+          <Select
+            style={{ width: '100%' }}
+            defaultValue={isEncrypted ? 'false' : 'true'}
+            onChange={(value: string) =>
+              setIsPublic(castStringToBoolean(value))
+            }
+          >
+            <Select.Option value="true" key={1}>
+              {t('Publicly shared sheets only')}
+            </Select.Option>
+            <Select.Option value="false" key={2}>
+              {t('Public and privately shared sheets')}
+            </Select.Option>
+          </Select>
+        </div>
+      )}
+      {showCredentialsInfo && (
+        <>
+          <FormLabel required>
+            {t('How∂ do you want to enter service account credentials?')}

Review comment:
       nit, weird character after How here

##########
File path: superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm/EncryptedField.tsx
##########
@@ -0,0 +1,198 @@
+/**
+ * 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 React, { useState } from 'react';
+import { SupersetTheme, t } from '@superset-ui/core';
+import { Select, Button } from 'src/common/components';
+import InfoTooltip from 'src/components/InfoTooltip';
+import FormLabel from 'src/components/Form/FormLabel';
+import { DeleteFilled } from '@ant-design/icons';
+import { FieldPropTypes } from '.';
+import { infoTooltip, labelMarginBotton, 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<number>(
+    CredentialInfoOptions.jsonUpload.valueOf(),
+  );
+  const [fileToUpload, setFileToUpload] = useState<string | null | undefined>(
+    null,
+  );
+  const [isPublic, setIsPublic] = useState<boolean>(true);
+  const showCredentialsInfo =
+    db?.engine === 'gsheets' ? !isEditMode && !isPublic : !isEditMode;
+  // a database that has an optional encrypted field has an encrypted_extra that is an empty object, this checks for that.
+  const isEncrypted = isEditMode && db?.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 (
+    <CredentialInfoForm>
+      {db?.engine === 'gsheets' && (

Review comment:
       did we ever find a way not to compare engines but do this more programmatically based on db attributes?

##########
File path: superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm/EncryptedField.tsx
##########
@@ -0,0 +1,198 @@
+/**
+ * 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 React, { useState } from 'react';
+import { SupersetTheme, t } from '@superset-ui/core';
+import { Select, Button } from 'src/common/components';
+import InfoTooltip from 'src/components/InfoTooltip';
+import FormLabel from 'src/components/Form/FormLabel';
+import { DeleteFilled } from '@ant-design/icons';
+import { FieldPropTypes } from '.';
+import { infoTooltip, labelMarginBotton, 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<number>(
+    CredentialInfoOptions.jsonUpload.valueOf(),
+  );
+  const [fileToUpload, setFileToUpload] = useState<string | null | undefined>(
+    null,
+  );
+  const [isPublic, setIsPublic] = useState<boolean>(true);
+  const showCredentialsInfo =
+    db?.engine === 'gsheets' ? !isEditMode && !isPublic : !isEditMode;
+  // a database that has an optional encrypted field has an encrypted_extra that is an empty object, this checks for that.
+  const isEncrypted = isEditMode && db?.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 (
+    <CredentialInfoForm>
+      {db?.engine === 'gsheets' && (

Review comment:
       Super!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org