From 5224f42495013c2e4ac8abcdf3deabebf4d4cf08 Mon Sep 17 00:00:00 2001 From: Andrei Jiroh Halili Date: Mon, 22 Jul 2024 11:34:31 +0800 Subject: [PATCH] feat(golinks): add migrations for API keys on database and export Slack app manifest as YAML files Signed-off-by: Andrei Jiroh Halili --- apps/golinks-v2/app-manifest.yml | 34 ++++++++++++ apps/golinks-v2/dev-manifest.yml | 52 +++++++++++++++++++ .../migrations/0006_api-keys-support.sql | 35 +++++++++++++ apps/golinks-v2/prisma/schema.prisma | 36 ++++++++----- 4 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 apps/golinks-v2/app-manifest.yml create mode 100644 apps/golinks-v2/dev-manifest.yml create mode 100644 apps/golinks-v2/migrations/0006_api-keys-support.sql diff --git a/apps/golinks-v2/app-manifest.yml b/apps/golinks-v2/app-manifest.yml new file mode 100644 index 0000000..353c72c --- /dev/null +++ b/apps/golinks-v2/app-manifest.yml @@ -0,0 +1,34 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/slackapi/manifest-schema/main/manifest.schema.json +display_information: + name: golinks service by ajhalili2006 + description: "Access Andrei Jiroh's golinks service API via Slack" + background_color: "#22CCE3" +features: + app_home: + home_tab_enabled: true + messages_tab_enabled: false + messages_tab_read_only_enabled: false + bot_user: + display_name: slack.go.andreijiroh.xyz + always_online: true + slash_commands: + - command: /go + url: https://go.andreijiroh.xyz/api/slack/slash-commands/go + description: Access the golinks service API via Slack + usage_hint: "[command] [args]" + should_escape: true + - command: /ping + url: https://go.andreijiroh.xyz/api/slack/slash-commands/ping + description: Check if the backend is reachable + should_escape: true +oauth_config: + redirect_urls: + - https://go.andreijiroh.xyz/auth/slack/callback + - https://golinks-next-production.ajhalili2006.workers.dev/auth/slack/callback + scopes: + bot: + - commands +settings: + org_deploy_enabled: true + socket_mode_enabled: false + token_rotation_enabled: false diff --git a/apps/golinks-v2/dev-manifest.yml b/apps/golinks-v2/dev-manifest.yml new file mode 100644 index 0000000..f743a13 --- /dev/null +++ b/apps/golinks-v2/dev-manifest.yml @@ -0,0 +1,52 @@ +display_information: + name: localdev.go.andreijiroh.xyz + description: Access Andrei Jiroh's golinks service API via Slack + background_color: "#1710e3" + long_description: "Access @ajhalili2006's golinks API service via /go Slack + slash command (add -dev or -stg to access staging or local dev instances).\r + + \r + + Learn more about this service at + https://wiki.andreijiroh.xyz/garden/tools/golinks-slackbot." +features: + app_home: + home_tab_enabled: true + messages_tab_enabled: true + messages_tab_read_only_enabled: false + bot_user: + display_name: slack.go-next.andreijiroh.xyz + always_online: true + slash_commands: + - command: /go-dev + url: https://stellapent-cier.fawn-cod.ts.net/api/slack/slash-commands/go + description: Access the golinks service API via Slack + usage_hint: "[command] [args]" + should_escape: true + - command: /ping-dev + url: https://stellapent-cier.fawn-cod.ts.net/api/slack/slash-commands/ping + description: Check if everything's up + should_escape: false + - command: /go-stg + url: https://staging.go-next.andreijiroh.xyz/api/slack/slash-commands/go + description: Access the golinks service API via Slack from staging environment. + usage_hint: "[command] [args]" + should_escape: true + - command: /ping-stg + url: https://staging.go-next.andreijiroh.xyz/api/slack/slash-commands/ping + description: Check if everything's up on staging environment + should_escape: true +oauth_config: + redirect_urls: + - https://stellapent-cier.fawn-cod.ts.net/slack/callback + scopes: + bot: + - commands + - im:write +settings: + interactivity: + is_enabled: true + request_url: https://stellpanet-cier.fawn-cod.ts.net/api/slack/interactive-feed + org_deploy_enabled: true + socket_mode_enabled: false + token_rotation_enabled: false diff --git a/apps/golinks-v2/migrations/0006_api-keys-support.sql b/apps/golinks-v2/migrations/0006_api-keys-support.sql new file mode 100644 index 0000000..07945a6 --- /dev/null +++ b/apps/golinks-v2/migrations/0006_api-keys-support.sql @@ -0,0 +1,35 @@ +-- CreateTable +CREATE TABLE "SlackBotToken" ( + "teamId" TEXT NOT NULL PRIMARY KEY, + "enterprise_install" BOOLEAN NOT NULL DEFAULT false, + "token" TEXT NOT NULL, + "created_on" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_on" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "ApiToken" ( + "id" TEXT NOT NULL PRIMARY KEY, + "token" TEXT NOT NULL, + "userId" TEXT NOT NULL, + CONSTRAINT "ApiToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "username" TEXT NOT NULL, + "email" TEXT, + "site_admin" BOOLEAN NOT NULL DEFAULT false, + "created_on" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_on" DATETIME NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "SlackBotToken_teamId_key" ON "SlackBotToken"("teamId"); + +-- CreateIndex +CREATE UNIQUE INDEX "ApiToken_token_key" ON "ApiToken"("token"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); diff --git a/apps/golinks-v2/prisma/schema.prisma b/apps/golinks-v2/prisma/schema.prisma index 69dd8e6..6e774f2 100644 --- a/apps/golinks-v2/prisma/schema.prisma +++ b/apps/golinks-v2/prisma/schema.prisma @@ -9,6 +9,7 @@ generator client { datasource db { provider = "sqlite" url = env("DATABASE_URL") + relationMode = "foreignKeys" } model GoLink { @@ -44,16 +45,27 @@ model WikiLinks { updated_on DateTime @updatedAt() } -//model ApiToken { -// id String @id @default(uuid()) -// token String @unique -// user User @relation(fields: [userId], references: [id]) -// userId Int -//} +model SlackBotToken { + teamId String @id @unique + enterprise_install Boolean @default(false) + token String + created_on DateTime @default(now()) + updated_on DateTime @updatedAt() +} + +model ApiToken { + id String @id @default(uuid()) + token String @unique + user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade) + userId String +} -//model User { -// id String @id -// username String @unique -// site_admin Boolean @default(false) -// ApiToken ApiToken[] -//} +model User { + id String @id + username String @unique + email String? + site_admin Boolean @default(false) + tokens ApiToken[] + created_on DateTime @default(now()) + updated_on DateTime @updatedAt() +} -- knotmirror 0.0.1