added azure related code
[it/otf.git] / otf-frontend / server / src / lib / azure-storage.js
diff --git a/otf-frontend/server/src/lib/azure-storage.js b/otf-frontend/server/src/lib/azure-storage.js
new file mode 100644 (file)
index 0000000..29102b6
--- /dev/null
@@ -0,0 +1,51 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+const {\r
+    ServiceURL,\r
+    StorageURL,\r
+    SharedKeyCredential,\r
+    TokenCredential,\r
+    ContainerURL\r
+  } = require("@azure/storage-blob");\r
+\r
+module.exports = function(app) {\r
+    // Enter your storage account name and shared key\r
+    const account = app.get('azure').storage.account;\r
+    const accountKey = app.get('azure').storage.key;\r
+    const container = app.get('azure').storage.container;\r
+  \r
+    // Use SharedKeyCredential with storage account and account key\r
+    const sharedKeyCredential = new SharedKeyCredential(account, accountKey);\r
+  \r
+    // Use TokenCredential with OAuth token\r
+    const tokenCredential = new TokenCredential("token");\r
+    tokenCredential.token = "renewedToken"; // Renew the token by updating token field of token credential\r
+  \r
+    // Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline\r
+    const pipeline = StorageURL.newPipeline(sharedKeyCredential);\r
+  \r
+    // List containers\r
+    const serviceURL = new ServiceURL(\r
+      // When using AnonymousCredential, following url should include a valid SAS or support public access\r
+      `https://${account}.blob.core.windows.net`,\r
+      pipeline\r
+    );\r
+\r
+    const containerURL = ContainerURL.fromServiceURL(serviceURL, container);\r
+\r
+    app.set('azureStorageContainerUrl', containerURL);\r
+}
\ No newline at end of file