From d23a7e41f3d46039785bb13ace1be79c942fac51 Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Wed, 11 Sep 2024 13:29:43 +0800 Subject: [PATCH] misc: addressed comments --- .env.example | 4 +- backend/src/lib/config/env.ts | 4 +- backend/src/server/routes/v1/slack-router.ts | 16 +++- backend/src/services/slack/slack-service.ts | 8 +- .../slack-integration.mdx | 88 ++++++++++++++++++ ...-slack-integration-app-credential-form.png | Bin ...dmin-slack-integration-app-credentials.png | Bin .../admin-slack-integration-app-summary.png | Bin ...slack-integration-app-workspace-select.png | Bin .../admin-slack-integration-create-app.png | Bin .../admin-slack-integration-overview.png | Bin .../org-slack-integration-add-form.png | Bin .../org-slack-integration-authenticate.png | Bin .../org-slack-integration-created.png | Bin .../org-slack-integration-initial-add.png | Bin .../org-slack-integration-overview.png | Bin .../org-slack-integration-workspace.png | Bin .../project-slack-integration-config.png | Bin .../project-slack-integration-overview.png | Bin .../project-slack-integration-select.png | Bin docs/mint.json | 10 +- .../self-hosting/guides/slack-integration.mdx | 82 ---------------- .../SlackIntegrationForm.tsx | 9 +- .../admin/DashboardPage/IntegrationPanel.tsx | 2 +- 24 files changed, 125 insertions(+), 98 deletions(-) create mode 100644 docs/documentation/platform/workflow-integrations/slack-integration.mdx rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/admin-slack-integration-app-credential-form.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/admin-slack-integration-app-credentials.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/admin-slack-integration-app-summary.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/admin-slack-integration-app-workspace-select.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/admin-slack-integration-create-app.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/admin-slack-integration-overview.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/org-slack-integration-add-form.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/org-slack-integration-authenticate.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/org-slack-integration-created.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/org-slack-integration-initial-add.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/org-slack-integration-overview.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/org-slack-integration-workspace.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/project-slack-integration-config.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/project-slack-integration-overview.png (100%) rename docs/images/{self-hosting/guides => platform/workflow-integrations}/slack-integration/project-slack-integration-select.png (100%) delete mode 100644 docs/self-hosting/guides/slack-integration.mdx diff --git a/.env.example b/.env.example index e8f85c080..6489a1cc2 100644 --- a/.env.example +++ b/.env.example @@ -73,5 +73,5 @@ PLAIN_WISH_LABEL_IDS= SSL_CLIENT_CERTIFICATE_HEADER_KEY= -SLACK_CLIENT_ID= -SLACK_CLIENT_SECRET= +WORKFLOW_SLACK_CLIENT_ID= +WORKFLOW_SLACK_CLIENT_SECRET= diff --git a/backend/src/lib/config/env.ts b/backend/src/lib/config/env.ts index 3edfb10f1..73a246433 100644 --- a/backend/src/lib/config/env.ts +++ b/backend/src/lib/config/env.ts @@ -147,8 +147,8 @@ const envSchema = z PLAIN_WISH_LABEL_IDS: zpStr(z.string().optional()), DISABLE_AUDIT_LOG_GENERATION: zodStrBool.default("false"), SSL_CLIENT_CERTIFICATE_HEADER_KEY: zpStr(z.string().optional()).default("x-ssl-client-cert"), - SLACK_CLIENT_ID: zpStr(z.string()).optional(), - SLACK_CLIENT_SECRET: zpStr(z.string()).optional() + WORKFLOW_SLACK_CLIENT_ID: zpStr(z.string()).optional(), + WORKFLOW_SLACK_CLIENT_SECRET: zpStr(z.string()).optional() }) .transform((data) => ({ ...data, diff --git a/backend/src/server/routes/v1/slack-router.ts b/backend/src/server/routes/v1/slack-router.ts index 99e878bf8..0601e2d1f 100644 --- a/backend/src/server/routes/v1/slack-router.ts +++ b/backend/src/server/routes/v1/slack-router.ts @@ -1,3 +1,4 @@ +import slugify from "@sindresorhus/slugify"; import { z } from "zod"; import { SlackIntegrationsSchema, WorkflowIntegrationsSchema } from "@app/db/schemas"; @@ -34,7 +35,12 @@ export const registerSlackRouter = async (server: FastifyZodProvider) => { } ], querystring: z.object({ - slug: z.string(), + slug: z + .string() + .trim() + .refine((v) => slugify(v) === v, { + message: "Slug must be a valid slug" + }), description: z.string().optional() }), response: { @@ -282,7 +288,13 @@ export const registerSlackRouter = async (server: FastifyZodProvider) => { id: z.string() }), body: z.object({ - slug: z.string().optional(), + slug: z + .string() + .trim() + .refine((v) => slugify(v) === v, { + message: "Slug must be a valid slug" + }) + .optional(), description: z.string().optional() }), response: { diff --git a/backend/src/services/slack/slack-service.ts b/backend/src/services/slack/slack-service.ts index 8a0a1a7d3..d4a3ebe4d 100644 --- a/backend/src/services/slack/slack-service.ts +++ b/backend/src/services/slack/slack-service.ts @@ -138,8 +138,8 @@ export const slackServiceFactory = ({ const appCfg = getConfig(); const serverCfg = await getServerCfg(); - let slackClientId = appCfg.SLACK_CLIENT_ID as string; - let slackClientSecret = appCfg.SLACK_CLIENT_SECRET as string; + let slackClientId = appCfg.WORKFLOW_SLACK_CLIENT_ID as string; + let slackClientSecret = appCfg.WORKFLOW_SLACK_CLIENT_SECRET as string; const decrypt = await kmsService.decryptWithRootKey(); @@ -244,7 +244,7 @@ export const slackServiceFactory = ({ const installer = await getSlackInstaller(); const url = await installer.generateInstallUrl({ - scopes: ["chat:write.public", "chat:write", "channels:read", "groups:read", "im:read", "mpim:read"], + scopes: ["chat:write.public", "chat:write", "channels:read", "groups:read"], metadata: JSON.stringify({ slug, description, @@ -278,7 +278,7 @@ export const slackServiceFactory = ({ const installer = await getSlackInstaller(); const url = await installer.generateInstallUrl({ - scopes: ["chat:write.public", "chat:write", "channels:read", "groups:read", "im:read", "mpim:read"], + scopes: ["chat:write.public", "chat:write", "channels:read", "groups:read"], metadata: JSON.stringify({ id, orgId: slackIntegration.orgId diff --git a/docs/documentation/platform/workflow-integrations/slack-integration.mdx b/docs/documentation/platform/workflow-integrations/slack-integration.mdx new file mode 100644 index 000000000..2941cb2ad --- /dev/null +++ b/docs/documentation/platform/workflow-integrations/slack-integration.mdx @@ -0,0 +1,88 @@ +--- +title: "Slack integration" +description: "Learn how to setup Slack integration" +--- + +This guide will provide step by step instructions on how to configure Slack integration for your Infisical projects. + + + + ## Configure admin settings + Note that this step only has to be done once for the entire instance. + + + + Before anything else, you need to setup the Slack app to be used by + your Infisical instance. Because you're self-hosting, you will need to + create this Slack application as demonstrated in the preceding step. + ![admin-settings-slack-overview](/images/platform/workflow-integrations/slack-integration/admin-slack-integration-overview.png) + + + Click the "Create Slack app" button. This will open up a new window with the + custom app creation flow on Slack. + ![admin-slack-create-app](/images/platform/workflow-integrations/slack-integration/admin-slack-integration-create-app.png) + + Select the Slack workspace you want to integrate with Infisical. + + ![admin-slack-app-workspace-select](/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-workspace-select.png) + + The configuration values of your custom Slack app will be pre-filled for you. You can view or edit the app manifest by clicking **Edit Configurations**. + ![admin-slack-app-summary](/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-summary.png) + + Once everything's confirmed, press Create. + + + + Copy the Client ID and Client Secret values from your newly created custom Slack app and add them to Infisical. + ![admin-slack-app-credentials](/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-credentials.png) + ![admin-slack-app-credentials-form](/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-credential-form.png) + Complete the admin setup by pressing Save. + + + + +## Create Slack workflow integration + + + + In order to use Slack integration in your projects, you will first have to + configure a Slack workflow integration in your organization. + ![org-slack-overview](/images/platform/workflow-integrations/slack-integration/org-slack-integration-overview.png) + + + Press "Add" and select "Slack" as the platform. + ![org-slack-initial-add](/images/platform/workflow-integrations/slack-integration/org-slack-integration-initial-add.png) + + Give your Slack integration a descriptive alias. You will use this to select the Slack integration for your project. + ![org-slack-add-form](/images/platform/workflow-integrations/slack-integration/org-slack-integration-add-form.png) + + Press **Connect Slack**. This opens up the Slack app installation flow. Select the Slack workspace you want to install the custom Slack app to and press **Allow**. + ![org-slack-authenticate](/images/platform/workflow-integrations/slack-integration/org-slack-integration-authenticate.png) + + Your Slack bot will then be added to your selected Slack workspace. This completes the workflow integration creation flow. Your projects in the organization can now use this Slack integration to send real-time updates to your Slack workspace. + ![org-slack-workspace](/images/platform/workflow-integrations/slack-integration/org-slack-integration-workspace.png) + ![org-slack-created](/images/platform/workflow-integrations/slack-integration/org-slack-integration-created.png) + + + + + +## Configure project to use Slack workflow integration + + + + ![project-slack-overview](/images/platform/workflow-integrations/slack-integration/project-slack-integration-overview.png) + + + Your project will send notifications to the connected Slack workspace of the + selected Slack integration when the configured events are triggered. + ![project-slack-select](/images/platform/workflow-integrations/slack-integration/project-slack-integration-select.png) + + + ![project-slack-select](/images/platform/workflow-integrations/slack-integration/project-slack-integration-config.png) + You now have a working native integration with Slack! + + + + + diff --git a/docs/images/self-hosting/guides/slack-integration/admin-slack-integration-app-credential-form.png b/docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-credential-form.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/admin-slack-integration-app-credential-form.png rename to docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-credential-form.png diff --git a/docs/images/self-hosting/guides/slack-integration/admin-slack-integration-app-credentials.png b/docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-credentials.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/admin-slack-integration-app-credentials.png rename to docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-credentials.png diff --git a/docs/images/self-hosting/guides/slack-integration/admin-slack-integration-app-summary.png b/docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-summary.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/admin-slack-integration-app-summary.png rename to docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-summary.png diff --git a/docs/images/self-hosting/guides/slack-integration/admin-slack-integration-app-workspace-select.png b/docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-workspace-select.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/admin-slack-integration-app-workspace-select.png rename to docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-app-workspace-select.png diff --git a/docs/images/self-hosting/guides/slack-integration/admin-slack-integration-create-app.png b/docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-create-app.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/admin-slack-integration-create-app.png rename to docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-create-app.png diff --git a/docs/images/self-hosting/guides/slack-integration/admin-slack-integration-overview.png b/docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-overview.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/admin-slack-integration-overview.png rename to docs/images/platform/workflow-integrations/slack-integration/admin-slack-integration-overview.png diff --git a/docs/images/self-hosting/guides/slack-integration/org-slack-integration-add-form.png b/docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-add-form.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/org-slack-integration-add-form.png rename to docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-add-form.png diff --git a/docs/images/self-hosting/guides/slack-integration/org-slack-integration-authenticate.png b/docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-authenticate.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/org-slack-integration-authenticate.png rename to docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-authenticate.png diff --git a/docs/images/self-hosting/guides/slack-integration/org-slack-integration-created.png b/docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-created.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/org-slack-integration-created.png rename to docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-created.png diff --git a/docs/images/self-hosting/guides/slack-integration/org-slack-integration-initial-add.png b/docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-initial-add.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/org-slack-integration-initial-add.png rename to docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-initial-add.png diff --git a/docs/images/self-hosting/guides/slack-integration/org-slack-integration-overview.png b/docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-overview.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/org-slack-integration-overview.png rename to docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-overview.png diff --git a/docs/images/self-hosting/guides/slack-integration/org-slack-integration-workspace.png b/docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-workspace.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/org-slack-integration-workspace.png rename to docs/images/platform/workflow-integrations/slack-integration/org-slack-integration-workspace.png diff --git a/docs/images/self-hosting/guides/slack-integration/project-slack-integration-config.png b/docs/images/platform/workflow-integrations/slack-integration/project-slack-integration-config.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/project-slack-integration-config.png rename to docs/images/platform/workflow-integrations/slack-integration/project-slack-integration-config.png diff --git a/docs/images/self-hosting/guides/slack-integration/project-slack-integration-overview.png b/docs/images/platform/workflow-integrations/slack-integration/project-slack-integration-overview.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/project-slack-integration-overview.png rename to docs/images/platform/workflow-integrations/slack-integration/project-slack-integration-overview.png diff --git a/docs/images/self-hosting/guides/slack-integration/project-slack-integration-select.png b/docs/images/platform/workflow-integrations/slack-integration/project-slack-integration-select.png similarity index 100% rename from docs/images/self-hosting/guides/slack-integration/project-slack-integration-select.png rename to docs/images/platform/workflow-integrations/slack-integration/project-slack-integration-select.png diff --git a/docs/mint.json b/docs/mint.json index e391a58d1..ad299adb6 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -169,6 +169,12 @@ "documentation/platform/kms/aws-hsm" ] }, + { + "group": "Workflow Integrations", + "pages": [ + "documentation/platform/workflow-integrations/slack-integration" + ] + }, "documentation/platform/secret-sharing" ] }, @@ -250,10 +256,6 @@ "self-hosting/guides/custom-certificates" ] }, - { - "group": "Workflow Integrations", - "pages": ["self-hosting/guides/slack-integration"] - }, { "group": "Reference architectures", "pages": ["self-hosting/reference-architectures/aws-ecs"] diff --git a/docs/self-hosting/guides/slack-integration.mdx b/docs/self-hosting/guides/slack-integration.mdx deleted file mode 100644 index 791a591ad..000000000 --- a/docs/self-hosting/guides/slack-integration.mdx +++ /dev/null @@ -1,82 +0,0 @@ ---- -title: "Slack integration" -description: "Learn how to setup Slack integration in your self-hosted instance." ---- - -This guide will provide step by step instructions on how to configure Slack integration for your Infisical projects. - -## Configure admin settings - -Note that this step only has to be done once for the entire instance. - - - - Before anything else, you need to setup the Slack app to be used by - your Infisical instance. Because you're self-hosting, you will need to - create this Slack application as demonstrated in the preceding step. - ![admin-settings-slack-overview](/images/self-hosting/guides/slack-integration/admin-slack-integration-overview.png) - - - Click the "Create Slack app" button. This will open up a new window with the - custom app creation flow on Slack. - ![admin-slack-create-app](/images/self-hosting/guides/slack-integration/admin-slack-integration-create-app.png) - - Select the Slack workspace you want to integrate with Infisical. - - ![admin-slack-app-workspace-select](/images/self-hosting/guides/slack-integration/admin-slack-integration-app-workspace-select.png) - - The configuration values of your custom Slack app will be pre-filled for you. You can view or edit the app manifest by clicking **Edit Configurations**. - ![admin-slack-app-summary](/images/self-hosting/guides/slack-integration/admin-slack-integration-app-summary.png) - - Once everything's confirmed, press Create. - - - - Copy the Client ID and Client Secret values from your newly created custom Slack app and add them to Infisical. - ![admin-slack-app-credentials](/images/self-hosting/guides/slack-integration/admin-slack-integration-app-credentials.png) - ![admin-slack-app-credentials-form](/images/self-hosting/guides/slack-integration/admin-slack-integration-app-credential-form.png) - Complete the admin setup by pressing Save. - - - -## Create Slack workflow integration - - - - In order to use Slack integration in your projects, you will first have to - configure a Slack workflow integration in your organization. - ![org-slack-overview](/images/self-hosting/guides/slack-integration/org-slack-integration-overview.png) - - - Press "Add" and select "Slack" as the platform. - ![org-slack-initial-add](/images/self-hosting/guides/slack-integration/org-slack-integration-initial-add.png) - - Give your Slack integration a descriptive alias. You will use this to select the Slack integration for your project. - ![org-slack-add-form](/images/self-hosting/guides/slack-integration/org-slack-integration-add-form.png) - - Press **Connect Slack**. This opens up the Slack app installation flow. Select the Slack workspace you want to install the custom Slack app to and press **Allow**. - ![org-slack-authenticate](/images/self-hosting/guides/slack-integration/org-slack-integration-authenticate.png) - - Your Slack bot will then be added to your selected Slack workspace. This completes the workflow integration creation flow. Your projects in the organization can now use this Slack integration to send real-time updates to your Slack workspace. - ![org-slack-workspace](/images/self-hosting/guides/slack-integration/org-slack-integration-workspace.png) - ![org-slack-created](/images/self-hosting/guides/slack-integration/org-slack-integration-created.png) - - - - -## Configure project to use Slack workflow integration - - - - ![project-slack-overview](/images/self-hosting/guides/slack-integration/project-slack-integration-overview.png) - - - Your project will send notifications to the connected Slack workspace of the - selected Slack integration when the configured events are triggered. - ![project-slack-select](/images/self-hosting/guides/slack-integration/project-slack-integration-select.png) - - - ![project-slack-select](/images/self-hosting/guides/slack-integration/project-slack-integration-config.png) - You now have a working native integration with Slack! - - diff --git a/frontend/src/views/Settings/OrgSettingsPage/components/OrgWorkflowIntegrationTab/SlackIntegrationForm.tsx b/frontend/src/views/Settings/OrgSettingsPage/components/OrgWorkflowIntegrationTab/SlackIntegrationForm.tsx index 87a49647e..281061db4 100644 --- a/frontend/src/views/Settings/OrgSettingsPage/components/OrgWorkflowIntegrationTab/SlackIntegrationForm.tsx +++ b/frontend/src/views/Settings/OrgSettingsPage/components/OrgWorkflowIntegrationTab/SlackIntegrationForm.tsx @@ -2,6 +2,7 @@ import { useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; import { useRouter } from "next/router"; import { zodResolver } from "@hookform/resolvers/zod"; +import slugify from "@sindresorhus/slugify"; import axios from "axios"; import { z } from "zod"; @@ -21,7 +22,13 @@ type Props = { }; const slackFormSchema = z.object({ - slug: z.string(), + slug: z + .string() + .trim() + .min(1) + .refine((v) => slugify(v) === v, { + message: "Alias must be a valid slug" + }), description: z.string().optional() }); diff --git a/frontend/src/views/admin/DashboardPage/IntegrationPanel.tsx b/frontend/src/views/admin/DashboardPage/IntegrationPanel.tsx index 33c4a7639..b07dde77e 100644 --- a/frontend/src/views/admin/DashboardPage/IntegrationPanel.tsx +++ b/frontend/src/views/admin/DashboardPage/IntegrationPanel.tsx @@ -42,7 +42,7 @@ const getCustomSlackAppCreationUrl = () => oauth_config: { redirect_urls: [`${window.origin}/api/v1/workflow-integrations/slack/oauth_redirect`], scopes: { - bot: ["chat:write.public", "chat:write"] + bot: ["chat:write.public", "chat:write", "channels:read", "groups:read"] } }, settings: {