Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main() {
// Enter your storage account name and SAS
const account = process.env.ACCOUNT_NAME || "";
const accountSas = process.env.ACCOUNT_SAS || "";
// Use AnonymousCredential when url already includes a SAS signature
const anonymousCredential = new AnonymousCredential();
// List containers
const blobServiceClient = new BlobServiceClient(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net${accountSas}`,
anonymousCredential
);
let i = 1;
for await (const container of blobServiceClient.listContainers()) {
console.log(`Container ${i++}: ${container.name}`);
}
// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerClient = blobServiceClient.getContainerClient(containerName);
export async function main() {
// Enter your storage account name and SAS
const account = process.env.ACCOUNT_NAME || "";
const accountSas = process.env.ACCOUNT_SAS || "";
// Use AnonymousCredential when url already includes a SAS signature
const anonymousCredential = new AnonymousCredential();
// List containers
const blobServiceClient = new BlobServiceClient(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net${accountSas}`,
anonymousCredential
);
let i = 1;
for await (const container of blobServiceClient.listContainers()) {
console.log(`Container ${i++}: ${container.name}`);
}
// Create a container
const containerName = `newcontainer${new Date().getTime()}`;
const containerClient = blobServiceClient.getContainerClient(containerName);
import dynamico from '@dynamico/express-middleware';
import { AzureBlobStorage } from '@dynamico/azure-blob-storage';
import { ContainerURL, StorageURL, AnonymousCredential } from '@azure/storage-blob';
import cors from 'cors';
import nconf from 'nconf';
const secretsFilePath = process.env.SECRET_FILE_PATH ? process.env.SECRET_FILE_PATH : '/run/secrets/azure-uri';
nconf.file(secretsFilePath).env({ lowerCase: true });
const app = express();
if (!nconf.get('container_sas')) {
throw new Error(`Can't start server, missing SAS key`);
}
const container = new ContainerURL(nconf.get('container_sas'), StorageURL.newPipeline(new AnonymousCredential()));
const storageProvider = new AzureBlobStorage({
container,
indexBlobName: nconf.get('index_blob_name'),
timeout: Number(nconf.get('blob_download_timeout')),
concurrentConnections: Number(nconf.get('blob_download_concurrent_connections'))
});
const serverTimeout = Number(nconf.get('server_timeout') || 3 * 60 * 1000);
app.use(cors());
app.use(dynamico(storageProvider, { readOnly: nconf.get('dynamico_readonly') === 'true' }));
app.use(jsonErrorHandler({ log: console.log }));
app.get('/monitoring/healthz', (req, res) => res.sendStatus(200));
const port = Number(nconf.get('port') || 1234);
app
.listen(port, () => {
console.log(`Dynamico Azure Blob Storage registry listening on ${port}`);
})
.argv()
.file('azure', azureSecretsFilePath)
.file('redis', redisSecretsFilePath)
.file('config', filePath)
.env({ lowerCase: true });
const app = express();
if (!nconf.get('container_sas')) {
throw new Error(`Can't start server, missing SAS key`);
}
if (!nconf.get('redis_config')) {
throw new Error(`Can't start server, missing redis configuration`);
}
const container = new ContainerURL(nconf.get('container_sas'), StorageURL.newPipeline(new AnonymousCredential()));
const componentsStorageProvider = new AzureBlobStorage({
container,
indexBlobName: nconf.get('index_blob_name'),
timeout: Number(nconf.get('blob_download_timeout')),
concurrentConnections: Number(nconf.get('blob_download_concurrent_connections'))
});
const redisClient = redis.createClient(nconf.get('redis_config'));
const indexStorageProvider = new RedisIndexStorage(redisClient, nconf.get('index_key_name'));
const serverTimeout = Number(nconf.get('server_timeout') || 3 * 60 * 1000);
const dynamicoMiddleware = dynamico(new CompositionStorage(indexStorageProvider, componentsStorageProvider), {
readOnly: nconf.get('dynamico_readonly') === 'true'
});
app.use(cors());
app.use(dynamicoMiddleware);
private getCredential(): Credential {
if (this.options.oauthToken) {
return new TokenCredential(this.options.oauthToken);
} else {
return new AnonymousCredential();
}
}