From 37ab7e52487ce932480e2a1f95cbd4f9f973e6d0 Mon Sep 17 00:00:00 2001 From: Robert Bond Date: Wed, 26 Jun 2024 11:31:54 +0000 Subject: [PATCH 1/4] check test --- .env.local | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.env.local b/.env.local index 203d6120..c927d73a 100644 --- a/.env.local +++ b/.env.local @@ -95,4 +95,27 @@ AZURE_PEDW_CONTAINER = "pedwapplications" AZURE_PEDW_QUEUE_ENDPOINT = https://$AZURE_STORAGE_ACCOUNT_NAME.queue.core.windows.net //gov.notify -NOTIFY_API_KEY = pedwnextauthkey-90f93710-9dae-423e-aea1-11eccd0dc132-0c9469d9-d671-444d-9e9d-3e5a62001043 \ No newline at end of file +NOTIFY_API_KEY = pedwnextauthkey-90f93710-9dae-423e-aea1-11eccd0dc132-0c9469d9-d671-444d-9e9d-3e5a62001043 + + +# //Bastion access to vnet vms +# [13:56] Suter, Matthew (COOG - DDAT - IT Services) +# Login is PEDWAdmin +# [13:57] Suter, Matthew (COOG - DDAT - IT Services) +# Pwd is -PK2_NQ-HuD2AFp + + +# [13:41] Suter, Matthew (COOG - DDAT - IT Services) +# so the admin login is PEDWSqlAdminPP +# [13:41] Suter, Matthew (COOG - DDAT - IT Services) +# password is rvJDj4ekfGSgwQpWTA38tDVJvFfSMbvmNGxd3YcII0M= + + + +# @Microsoft.KeyVault(SecretUri=https://test-pedw-kv.vault.azure.net/secrets/PEDW-FrontEnd-Test-AppReg-Secrate/) + + +# [12:24] Thompson, Phil (COOG - Planning & Environment Decisions Wales) +# {"pinswg_name":"48181 Planning Appeal E PROOF8.pdf","pinswg_DocumentIds@odata.bind":"/incidents(6CD13EF8-5BC9-ED11-A997-00224800E98C)","pinswg_isharedocumentlocations":"846040009","pinswg_isharedocumentclassification":"846040000","pinswg_uploadurl":"https://pedwinternalprod.blob.core.windows.net/crm-file-upload/6CD13EF8-5BC9-ED11-A997-00224800E98C/48181 Planning Appeal E PROOF8.pdf"} +# [12:25] Thompson, Phil (COOG - Planning & Environment Decisions Wales) +# https://crm2016.llc.gov.wales/PEDW/api/data/v8.2/pinswg_documents \ No newline at end of file From c134af5450909c2440d6a6c5e77df7cc89dcba0d Mon Sep 17 00:00:00 2001 From: Robert Bond Date: Fri, 28 Jun 2024 13:08:17 +0000 Subject: [PATCH 2/4] pwd --- .env.local | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.env.local b/.env.local index c927d73a..8895b89b 100644 --- a/.env.local +++ b/.env.local @@ -118,4 +118,7 @@ NOTIFY_API_KEY = pedwnextauthkey-90f93710-9dae-423e-aea1-11eccd0dc132-0c9469d9-d # [12:24] Thompson, Phil (COOG - Planning & Environment Decisions Wales) # {"pinswg_name":"48181 Planning Appeal E PROOF8.pdf","pinswg_DocumentIds@odata.bind":"/incidents(6CD13EF8-5BC9-ED11-A997-00224800E98C)","pinswg_isharedocumentlocations":"846040009","pinswg_isharedocumentclassification":"846040000","pinswg_uploadurl":"https://pedwinternalprod.blob.core.windows.net/crm-file-upload/6CD13EF8-5BC9-ED11-A997-00224800E98C/48181 Planning Appeal E PROOF8.pdf"} # [12:25] Thompson, Phil (COOG - Planning & Environment Decisions Wales) -# https://crm2016.llc.gov.wales/PEDW/api/data/v8.2/pinswg_documents \ No newline at end of file +# https://crm2016.llc.gov.wales/PEDW/api/data/v8.2/pinswg_documents + + +# DATABASE_URL='sqlserver://pp-pedw-sql.database.windows.net:1433;database=PEDWPreProd;user=pp-pedw-ukw;password=jscw4+896w9YaiXruOA3mtpNkio1oUZxBZcFJ9Awdz4=;encrypt=true;trustservercertificate=false;hostnameincertificate=*.database.windows.net;logintimeout=30;authentication=SqlPassword' \ No newline at end of file From 4091bfa82edd0467055c6755ea8044c809c844ad Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Mon, 1 Jul 2024 09:48:39 +0100 Subject: [PATCH 3/4] updates --- prisma/schema.prisma | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9c18ed49..df34e54c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -8,7 +8,7 @@ datasource db { } model Account { - id String @id(map: "PK__accounts__3213E83F407D3F70") @default(cuid()) @db.VarChar(191) + id String @id(map: "PK__accounts__3213E83FAEBDFC84") @default(cuid()) @db.VarChar(191) userId String @map("user_id") @db.VarChar(191) type String @db.VarChar(191) provider String @db.VarChar(191) @@ -27,7 +27,7 @@ model Account { } model Session { - id String @id(map: "PK__sessions__3213E83F3DEBC794") @default(cuid()) @db.VarChar(191) + id String @id(map: "PK__sessions__3213E83F970AEA7D") @default(cuid()) @db.VarChar(191) sessionToken String @unique @map("session_token") @db.VarChar(191) userId String @map("user_id") @db.VarChar(191) expires DateTime @@ -37,7 +37,7 @@ model Session { } model User { - id String @id(map: "PK__users__3213E83F038A1396") @default(cuid()) @db.VarChar(191) + id String @id(map: "PK__users__3213E83FC774F580") @default(cuid()) @db.VarChar(191) name String? @db.VarChar(191) email String? @unique @db.VarChar(191) emailVerified DateTime? @map("email_verified") From 8b2dc95e847e5c29233b97ae1927e82c99e6ad96 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Mon, 1 Jul 2024 12:31:00 +0100 Subject: [PATCH 4/4] added db storage check debug --- actions/azurestorage.js | 98 ++++++++++++++++++++++++++++++++++++++--- pages/dbcheck.js | 74 +++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 pages/dbcheck.js diff --git a/actions/azurestorage.js b/actions/azurestorage.js index 67dae4d6..06f5593e 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -34,6 +34,8 @@ const accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME; export const createContainerSas = async (containerName) => { // Get environment variables + containerName.length > 0; + // Best practice: create time limits const TEN_MINUTES = 10 * 60 * 1000; const NOW = new Date(); @@ -68,7 +70,7 @@ export const createContainerSas = async (containerName) => { expiresOn: TEN_MINUTES_AFTER_NOW, }; - //conLogJSON.stringify(sasOptions)); + console.log(JSON.stringify(sasOptions)); const sasToken = generateBlobSASQueryParameters( sasOptions, @@ -1116,12 +1118,13 @@ export const getAllProgressBlobs = async (containerName) => { }); } - //console.log( - // "\n////////////////////////////\n", - // "blobObj:", - // blobObj, - // "\n////////////////////////////" - // ); + console.log( + "\n////////////////////////////\n", + sasUrl, + "blobObj:", + blobObj, + "\n////////////////////////////" + ); return blobObj; }; @@ -1332,3 +1335,84 @@ export const createRepCompleteMessage = async ( return sendMessageResponse; }; + +export const listContainers = async ( + blobServiceClient, + containerNamePrefix +) => { + const options = { + includeDeleted: false, + includeMetadata: true, + includeSystem: true, + prefix: containerNamePrefix, + }; + console.log( + "\n\n\n=================================================\n", + "Showing storage account contents:\n\n" + ); + for await (const containerItem of blobServiceClient.listContainers( + options + )) { + // ContainerItem + console.log(`For-await list: ${containerItem.name}`); + + // ContainerClient + const containerClient = blobServiceClient.getContainerClient( + containerItem.name + ); + + await listBlobHierarchical(containerClient).catch((error) => + consoleLogger(error) + ); + // ... do something with container + } + console.log("\n=================================================\n\n\n\n"); +}; + +export const listBlobHierarchical = async ( + containerClient, + virtualHierarchyDelimiter = "/" +) => { + // page size - artificially low as example + const maxPageSize = 2; + + // some options for filtering list + const listOptions = { + includeCopy: false, // include metadata from previous copies + includeDeleted: false, // include deleted blobs + includeDeletedWithVersions: false, // include deleted blobs with versions + includeLegalHold: false, // include legal hold + includeMetadata: true, // include custom metadata + includeSnapshots: false, // include snapshots + includeTags: true, // include indexable tags + includeUncommitedBlobs: false, // include uncommitted blobs + includeVersions: false, // include all blob version + prefix: "", // filter by blob name prefix + }; + + let i = 1; + console.log(`Folder ${virtualHierarchyDelimiter}`); + + for await (const response of containerClient + .listBlobsByHierarchy(virtualHierarchyDelimiter, listOptions) + .byPage({ maxPageSize })) { + console.log(` Blob number ${i++}`); + const segment = response.segment; + + if (segment.blobPrefixes) { + // Do something with each virtual folder + for await (const prefix of segment.blobPrefixes) { + // build new virtualHierarchyDelimiter from current and next + await listBlobHierarchical( + containerClient, + `${virtualHierarchyDelimiter}${prefix.name}` + ); + } + } + + for (const blob of response.segment.blobItems) { + // Do something with each blob + console.log(`\tBlobItem: name - ${blob.name}`); + } + } +}; diff --git a/pages/dbcheck.js b/pages/dbcheck.js new file mode 100644 index 00000000..95f55d34 --- /dev/null +++ b/pages/dbcheck.js @@ -0,0 +1,74 @@ +import { DefaultAzureCredential } from "@azure/identity"; +import { BlobServiceClient, ContainerClient } from "@azure/storage-blob"; +import { v4 as uuidv4 } from "uuid"; +import { + createContainerSas, + listContainers, + listBlobHierarchical, +} from "../actions/azurestorage"; + +import { PrismaClient } from "@prisma/client"; + +import { consoleLogger, getIP } from "../actions"; + +const ShowStorage = (props) => { + const { container } = props; + + return
hello
; +}; + +export const getServerSideProps = async (ctx) => { + const { query, req, res } = ctx; + getIP(req); + + console.log( + "have these?:", + process.env.AZURE_TENANT_ID, + process.env.AZURE_CLIENT_ID, + process.env.AZURE_CLIENT_SECRET + ); + const accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME; + const showDebug = process.env.SHOW_DEBUG || false; + + const creds = new DefaultAzureCredential(); + + const blobServiceClient = new BlobServiceClient( + `https://${accountName}.blob.core.windows.net`, + creds + ); + + console.log( + "\n\n\n=================================================\n", + "Environment name:" + accountName, + "\n=================================================\n" + ); + + const prisma = new PrismaClient(); + + async function checkDB() { + const allUsers = await prisma.user.findMany(); + console.log( + "\n\n\n=================================================\n", + "Show users in Auth DB:\n", + allUsers, + "\n=================================================\n" + ); + } + + showDebug && + (checkDB() + .then(async () => { + await prisma.$disconnect(); + }) + .catch(async (e) => { + consoleLogger(e); + await prisma.$disconnect(); + //process.exit(1); + }), + await listContainers(blobServiceClient).catch((error) => + consoleLogger(error) + )); + return { props: {} }; +}; + +export default ShowStorage;