diff --git a/.envrc.local.template b/.envrc.local.template index e3dc630b1bc2435935ea9d67bc6369475c0646f6..e1b33e749543c20673c4f75dfe30e58a1977807f 100644 --- a/.envrc.local.template +++ b/.envrc.local.template @@ -1,25 +1,10 @@ # The environment where the application is running, e.g. 'local', 'staging', 'production'. export ENVIRONMENT=local -# URL of the chat instance -export OWNCLOUD_BASE_URL=https://local.cloud.holi.social - -# Admin username for the chat instance -export CHAT_ADMIN_USERNAME=admin - -# Admin password for the chat instance -export CHAT_ADMIN_PASSWORD=password - # OIDC issuer for the chat instance (i.e. Ory) export CHAT_OIDC_ISSUER=https://dev-auth.holi.social -export CHAT_INTEGRATION_DB_HOST=localhost -export CHAT_INTEGRATION_DB_NAME=chat-integration-local -export CHAT_INTEGRATION_DB_USERNAME=postgres -export CHAT_INTEGRATION_DB_PASSWORD=password -export CHAT_INTEGRATION_DB_PORT=8087 - -# Used by @databases/pg-migrations CLI to automatically maintain the local database schema. -export DATABASE_URL=postgresql://$CHAT_INTEGRATION_DB_USERNAME:$CHAT_INTEGRATION_DB_PASSWORD@$CHAT_INTEGRATION_DB_HOST:$CHAT_INTEGRATION_DB_PORT/$CHAT_INTEGRATION_DB_NAME - -export DB_CONTAINER_NAME=chat-postgres \ No newline at end of file +# Chat environment variables +export CHAT_SERVER_URL="http://192.168.180.44:8008" +export CHAT_ADMIN_USERNAME="" +export CHAT_ADMIN_ACCESS_TOKEN="" \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index e4a4f29da6ce2f430ae896db84882e5a32d27bfc..6483eeda899d30c2fc7569979d5e87b5ff6b56c6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,14 +1,5 @@ // The environment where the application is running, e.g. 'local', 'staging', 'production'. export const ENVIRONMENT = process.env.ENVIRONMENT -// The URL of the chat instance being used by the application. -export const OWNCLOUD_BASE_URL = process.env.OWNCLOUD_BASE_URL - -// The username of the admin user for the chat instance. -export const CHAT_ADMIN_USERNAME = process.env.CHAT_ADMIN_USERNAME - -// The password of the admin user for the chat instance. -export const CHAT_ADMIN_PASSWORD = process.env.CHAT_ADMIN_PASSWORD - // The issuer URL for the OpenID Connect provider used by the chat instance. export const CHAT_OIDC_ISSUER = process.env.CHAT_OIDC_ISSUER diff --git a/src/constants.ts b/src/constants.ts index f8fc7b536ce4e23ee53745a09013376e7c7bc0ae..05be9b15de7c71715961b6e2ccd863831b574f99 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,12 +1,3 @@ -// The prefix used for Holi resources. -export const HOLI_PREFIX = 'holi' - -// The email domain used for Holi users. -export const HOLI_EMAIL_DOMAIN = 'holi.team' - -// The maximum space quota (i.e. 2GB) -export const MAX_SPACE_QUOTA = 2147483648 - -export const HOLI_CHAT_SERVER_URL = 'http://192.168.180.44:8008' -export const HOLI_CHAT_ADMIN_ID = '@chat-admin:local.chat.holi.social' -export const HOLI_CHAT_ADMIN_ACCESS_TOKEN = '' +export const CHAT_SERVER_URL = process.env.CHAT_SERVER_URL +export const CHAT_ADMIN_USERNAME = process.env.CHAT_ADMIN_USERNAME +export const CHAT_ADMIN_ACCESS_TOKEN = process.env.CHAT_ADMIN_ACCESS_TOKEN diff --git a/src/helpers/_chatClient.ts b/src/helpers/_chatClient.ts index 939a1ff1f4f4b4f32726d1a1debd91b7769ec355..2436bd32fddc956386fa3880037315e132cc500f 100644 --- a/src/helpers/_chatClient.ts +++ b/src/helpers/_chatClient.ts @@ -1,13 +1,13 @@ -import { HOLI_CHAT_ADMIN_ACCESS_TOKEN, HOLI_CHAT_ADMIN_ID, HOLI_CHAT_SERVER_URL } from '../constants' +import { CHAT_ADMIN_ACCESS_TOKEN, CHAT_ADMIN_USERNAME, CHAT_SERVER_URL } from '../constants' import { ClientEvent, MatrixClient, MatrixScheduler, SyncState, createClient } from 'matrix-js-sdk' export let chatClient: MatrixClient export const startChatClient = async () => { chatClient = createClient({ - baseUrl: HOLI_CHAT_SERVER_URL, - userId: HOLI_CHAT_ADMIN_ID, - accessToken: HOLI_CHAT_ADMIN_ACCESS_TOKEN, + baseUrl: CHAT_SERVER_URL, + userId: CHAT_ADMIN_USERNAME, + accessToken: CHAT_ADMIN_ACCESS_TOKEN, timelineSupport: true, scheduler: new MatrixScheduler(), }) diff --git a/src/helpers/createSpace.ts b/src/helpers/createSpace.ts index 21f7a58dd74bd4116c992f49ea5ffd4596445ee6..67c2de92ba9f76e5bd1d0305e52b62dfface83ef 100644 --- a/src/helpers/createSpace.ts +++ b/src/helpers/createSpace.ts @@ -1,7 +1,7 @@ import { Preset, Visibility, EventType, RoomType } from 'matrix-js-sdk' import { chatClient } from './_chatClient' -import { HOLI_CHAT_SERVER_URL } from '../constants' +import { CHAT_SERVER_URL } from '../constants' import { SpacePayload } from '../types' import { ChatRoomEvent } from './type' @@ -53,7 +53,7 @@ export const addGeneralRoomToSpaceContainer = async ( await chatClient.sendStateEvent( parentSpaceRoomId, EventType.SpaceChild, - { via: [HOLI_CHAT_SERVER_URL] }, + { via: [CHAT_SERVER_URL] }, generalSpaceRoomId ) } diff --git a/src/helpers/inviteUserToSpace.ts b/src/helpers/inviteUserToSpace.ts index 5d860e7da9b50841eff25ece98c3c7136557deea..272acb94c1420cdeb4d91804dd384ff79924c67c 100644 --- a/src/helpers/inviteUserToSpace.ts +++ b/src/helpers/inviteUserToSpace.ts @@ -1,4 +1,4 @@ -import { HOLI_CHAT_ADMIN_ACCESS_TOKEN, HOLI_CHAT_SERVER_URL } from '../constants' +import { CHAT_ADMIN_ACCESS_TOKEN, CHAT_SERVER_URL } from '../constants' import { SpaceUserAddedDataPayload } from '../types' import { getMatrixUserId, getRoomIdsForHoliSpace } from './rooms' @@ -9,10 +9,10 @@ export const inviteUserToSpace = async ({ const roomsToInvite = await getRoomIdsForHoliSpace(holiSpaceId, 'general') return roomsToInvite.map(async (roomId) => { - await fetch(`${HOLI_CHAT_SERVER_URL}/_synapse/admin/v1/join/${roomId}`, { + await fetch(`${CHAT_SERVER_URL}/_synapse/admin/v1/join/${roomId}`, { method: 'POST', headers: { - Authorization: `Bearer ${HOLI_CHAT_ADMIN_ACCESS_TOKEN}`, + Authorization: `Bearer ${CHAT_ADMIN_ACCESS_TOKEN}`, }, body: JSON.stringify({ user_id: getMatrixUserId(identity), diff --git a/src/helpers/rooms.ts b/src/helpers/rooms.ts index c1bcf61b4063b299b6db73d8c6bdbc86994b493d..de9da675cbaa1ad2f6b8b8b6a44808f38d0f089e 100644 --- a/src/helpers/rooms.ts +++ b/src/helpers/rooms.ts @@ -1,15 +1,15 @@ -import { HOLI_CHAT_ADMIN_ACCESS_TOKEN, HOLI_CHAT_SERVER_URL } from '../constants' +import { CHAT_ADMIN_ACCESS_TOKEN, CHAT_SERVER_URL } from '../constants' import { ChatRoomEvent } from './type' export const getMatrixUserId = (holiIdentity: string) => `@${holiIdentity}:local.chat.holi.social` export const getRooms = async (searchTerm?: string) => { const resp = await fetch( - `${HOLI_CHAT_SERVER_URL}/_synapse/admin/v1/rooms${searchTerm ? `?search_term=${searchTerm}` : ''}`, + `${CHAT_SERVER_URL}/_synapse/admin/v1/rooms${searchTerm ? `?search_term=${searchTerm}` : ''}`, { method: 'GET', headers: { - Authorization: `Bearer ${HOLI_CHAT_ADMIN_ACCESS_TOKEN}`, + Authorization: `Bearer ${CHAT_ADMIN_ACCESS_TOKEN}`, }, } ) @@ -20,10 +20,10 @@ export const getRooms = async (searchTerm?: string) => { } export const getRoomSharedData = async (roomId: string) => { - const resp = await fetch(`${HOLI_CHAT_SERVER_URL}/_synapse/admin/v1/rooms/${roomId}/state`, { + const resp = await fetch(`${CHAT_SERVER_URL}/_synapse/admin/v1/rooms/${roomId}/state`, { method: 'GET', headers: { - Authorization: `Bearer ${HOLI_CHAT_ADMIN_ACCESS_TOKEN}`, + Authorization: `Bearer ${CHAT_ADMIN_ACCESS_TOKEN}`, }, }) @@ -83,10 +83,10 @@ interface DeleteStatus { export const awaitDeletionComplete = async (roomId, delete_id) => { const getDeleteStatus = async (deleteId: string) => { - const resp = await fetch(`${HOLI_CHAT_SERVER_URL}/_synapse/admin/v2/rooms/delete_status/${deleteId}`, { + const resp = await fetch(`${CHAT_SERVER_URL}/_synapse/admin/v2/rooms/delete_status/${deleteId}`, { method: 'GET', headers: { - Authorization: `Bearer ${HOLI_CHAT_ADMIN_ACCESS_TOKEN}`, + Authorization: `Bearer ${CHAT_ADMIN_ACCESS_TOKEN}`, }, }) @@ -105,10 +105,10 @@ export const awaitDeletionComplete = async (roomId, delete_id) => { } export const initRoomDeletion = async (roomId: string) => { - const resp = await fetch(`${HOLI_CHAT_SERVER_URL}/_synapse/admin/v2/rooms/${roomId}`, { + const resp = await fetch(`${CHAT_SERVER_URL}/_synapse/admin/v2/rooms/${roomId}`, { method: 'DELETE', headers: { - Authorization: `Bearer ${HOLI_CHAT_ADMIN_ACCESS_TOKEN}`, + Authorization: `Bearer ${CHAT_ADMIN_ACCESS_TOKEN}`, }, body: JSON.stringify({ purge: true, diff --git a/terraform/common/function.tf b/terraform/common/function.tf index 5a485b5b52fb8d5768035ccc16721ce8ddd80083..6b08b46a5d3cb814c87ee37431e25477d794953f 100644 --- a/terraform/common/function.tf +++ b/terraform/common/function.tf @@ -55,8 +55,8 @@ data "google_secret_manager_secret" "chat_admin_username_development" { project = data.terraform_remote_state.holi_infra_state.outputs.shared_project_id } -data "google_secret_manager_secret" "chat_admin_password_development" { - secret_id = "CHAT_ADMIN_PASSWORD_DEVELOPMENT" +data "google_secret_manager_secret" "chat_admin_access_token_development" { + secret_id = "CHAT_ADMIN_ACCESS_TOKEN_DEVELOPMENT" project = data.terraform_remote_state.holi_infra_state.outputs.shared_project_id } @@ -65,8 +65,8 @@ data "google_secret_manager_secret" "chat_admin_username_production" { project = data.terraform_remote_state.holi_infra_state.outputs.shared_project_id } -data "google_secret_manager_secret" "chat_admin_password_production" { - secret_id = "CHAT_ADMIN_PASSWORD_PRODUCTION" +data "google_secret_manager_secret" "chat_admin_access_token_production" { + secret_id = "CHAT_ADMIN_ACCESS_TOKEN_PRODUCTION" project = data.terraform_remote_state.holi_infra_state.outputs.shared_project_id } @@ -96,13 +96,7 @@ resource "google_cloudfunctions2_function" "holi-chat-integration-staging" { environment_variables = { ENVIRONMENT = "staging" CHAT_OIDC_ISSUER = "https://dev-auth.holi.social" - OWNCLOUD_BASE_URL = "https://development.cloud.holi.social" - CHAT_INTEGRATION_DB_HOST = data.terraform_remote_state.holi_infra_state.outputs.database_ip_address_development - CHAT_INTEGRATION_DB_PORT = local.chat_integration_database_port - CHAT_INTEGRATION_DB_NAME = google_sql_database.database_development.name - CHAT_INTEGRATION_DB_USERNAME = google_sql_user.chat_integration_db_user_development.name - CHAT_INTEGRATION_DB_PASSWORD = google_sql_user.chat_integration_db_user_development.password - INSTANCE_CONNECTION_NAME = data.terraform_remote_state.holi_infra_state.outputs.database_name_development + CHAT_SERVER_URL = "https://development-chat.holi.social" } vpc_connector = data.terraform_remote_state.holi_infra_state.outputs.vpc_access_connector_name vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY" @@ -118,9 +112,9 @@ resource "google_cloudfunctions2_function" "holi-chat-integration-staging" { } secret_environment_variables { - key = "CHAT_ADMIN_PASSWORD" + key = "CHAT_ADMIN_ACCESS_TOKEN" project_id = data.terraform_remote_state.holi_infra_state.outputs.shared_project_id - secret = data.google_secret_manager_secret.chat_admin_password_development.secret_id + secret = data.google_secret_manager_secret.chat_admin_access_token_development.secret_id version = "latest" } } @@ -159,13 +153,7 @@ resource "google_cloudfunctions2_function" "holi-chat-integration-production" { environment_variables = { ENVIRONMENT = "production" CHAT_OIDC_ISSUER = "https://auth.holi.social" - OWNCLOUD_BASE_URL = "https://production.cloud.holi.social" - CHAT_INTEGRATION_DB_HOST = data.terraform_remote_state.holi_infra_state.outputs.database_ip_address_production - CHAT_INTEGRATION_DB_PORT = local.chat_integration_database_port - CHAT_INTEGRATION_DB_NAME = google_sql_database.database_production.name - CHAT_INTEGRATION_DB_USERNAME = google_sql_user.chat_integration_db_user_production.name - CHAT_INTEGRATION_DB_PASSWORD = google_sql_user.chat_integration_db_user_production.password - INSTANCE_CONNECTION_NAME = data.terraform_remote_state.holi_infra_state.outputs.database_name_production + CHAT_SERVER_URL = "https://chat.holi.social" } vpc_connector = data.terraform_remote_state.holi_infra_state.outputs.vpc_access_connector_name vpc_connector_egress_settings = "PRIVATE_RANGES_ONLY" @@ -181,9 +169,9 @@ resource "google_cloudfunctions2_function" "holi-chat-integration-production" { } secret_environment_variables { - key = "CHAT_ADMIN_PASSWORD" + key = "CHAT_ADMIN_ACCESS_TOKEN" project_id = data.terraform_remote_state.holi_infra_state.outputs.shared_project_id - secret = data.google_secret_manager_secret.chat_admin_password_production.secret_id + secret = data.google_secret_manager_secret.chat_admin_access_token_production.secret_id version = "latest" } }