kalai-attach 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+
2
+ const xsenv = require('@sap/xsenv');
3
+ const axios = require('axios');
4
+ const jose = require('node-jose');
5
+ const { MongoClient } = require('mongodb');
6
+ const https = require('https');
7
+ const { log } = require('@sap/cds');
8
+ const fetch = require('node-fetch').default;
9
+ xsenv.loadEnv();
10
+ const dest_service = xsenv.getServices({ dest: { tag: 'destination' } }).dest;
11
+
12
+ async function getAccessToken() {
13
+ try {
14
+ const response = await axios({
15
+ method: 'post',
16
+ url: `${dest_service.url}/oauth/token`,
17
+ headers: {
18
+ 'Content-Type': 'application/x-www-form-urlencoded',
19
+ 'Authorization': `Basic ${Buffer.from(`${dest_service.clientid}:${dest_service.clientsecret}`).toString('base64')}`
20
+ },
21
+ data: 'grant_type=client_credentials'
22
+ });
23
+
24
+ return response.data.access_token;
25
+ } catch (error) {
26
+ console.error('Error fetching access token:', error.response.data);
27
+ //throw error;
28
+ return error.response.data;
29
+ }
30
+ }
31
+
32
+ module.exports = {
33
+ async fetchfromDestination(destinationName) {
34
+ const destService = xsenv.getServices({ dest: { tag: 'destination' } }).dest;
35
+ try {
36
+
37
+ const headers = {
38
+ 'Content-Type': 'application/json',
39
+ };
40
+ const token = await getAccessToken();
41
+ headers.Authorization = `Bearer ${token}`;
42
+
43
+ const response = await axios.get(`${destService.uri}/destination-configuration/v1/destinations/${destinationName}`, {
44
+ headers,
45
+ });
46
+ console.log("responsessss"+response.data.destinationConfiguration);
47
+
48
+ const config = response.data.destinationConfiguration;;
49
+
50
+ if (!config) {
51
+ throw new Error(`Destination ${destinationName} not found in BTP Cockpit`);
52
+ }
53
+
54
+ const { container_name, connection_string, sas_token,container_uri } = config;
55
+
56
+ if (!container_name || !sas_token || !connection_string) {
57
+ throw new Error(`Azure configuration fields are missing in destination: ${destinationName}`);
58
+ }
59
+ return { container_name, connection_string, sas_token,container_uri }
60
+ } catch (err) {
61
+ throw new Error("Configuration of Azure Container is Missing")
62
+ }
63
+ }
64
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kalai-attach",
3
3
  "description": "CAP cds-plugin providing image and attachment storing out-of-the-box.",
4
- "version": "1.0.10",
4
+ "version": "1.0.12",
5
5
  "repository": "capjsattachments-kalai",
6
6
  "author": "Kalai",
7
7
  "homepage": "https://github.com/Kalaikovan-airdit",
@@ -40,6 +40,11 @@
40
40
  },
41
41
  "cds": {
42
42
  "requires": {
43
+ "malwareScanner": {
44
+ "vcap": {
45
+ "label": "malware-scanner"
46
+ }
47
+ },
43
48
  "kinds": {
44
49
  "attachments-azure": {
45
50
  "impl": "kalai-attach/srv/azure-blob-storage"
@@ -2,6 +2,7 @@ const { BlobServiceClient } = require('@azure/storage-blob')
2
2
  const cds = require("@sap/cds")
3
3
  const LOG = cds.log('attachments')
4
4
  const utils = require('../lib/helper')
5
+ const { fetchfromDestination } = require('../lib/destinations')
5
6
 
6
7
  module.exports = class AzureAttachmentsService extends require("./object-store") {
7
8
 
@@ -10,10 +11,10 @@ module.exports = class AzureAttachmentsService extends require("./object-store")
10
11
  * @returns {Promise<{blobServiceClient: import('@azure/storage-blob').BlobServiceClient, containerClient: import('@azure/storage-blob').ContainerClient}>}
11
12
  */
12
13
  async retrieveClient() {
13
- try{
14
- const container_name="aisp"
15
- const sas_token="sp=rcwdl&st=2025-12-26T10:41:33Z&se=2030-12-25T18:56:33Z&spr=https&sv=2024-11-04&sr=c&sig=i5ENp1nzh0GrnNd%2FCAnkBBK3vCrHI8vCnHS9og%2F8P8I%3D"
16
- const container_uri="https://aairdoc9262.blob.core.windows.net"
14
+ try {
15
+ const { container_name, connection_string, sas_token, } = await fetchfromDestination('AISP-ATTACHMENTS')
16
+
17
+ const container_uri = "https://aairdoc9262.blob.core.windows.net"
17
18
 
18
19
  const blobServiceClient = new BlobServiceClient(container_uri + "?" + sas_token)
19
20
  const containerClient = blobServiceClient.getContainerClient(container_name)
@@ -25,7 +26,7 @@ module.exports = class AzureAttachmentsService extends require("./object-store")
25
26
  this.clientsCache.set(newAzureCredentials)
26
27
 
27
28
  LOG.debug('Azure Blob Storage client has been created successful', {
28
-
29
+
29
30
  containerName: containerClient.containerName
30
31
  })
31
32
  return newAzureCredentials;