Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 5 #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions fa-import-service/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.js.map
*.ts
.git*
.vscode
local.settings.json
test
getting_started.md
node_modules/@types/
node_modules/azure-functions-core-tools/
node_modules/typescript/
48 changes: 48 additions & 0 deletions fa-import-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
bin
obj
csx
.vs
edge
Publish

*.user
*.suo
*.cscfg
*.Cache
project.lock.json

/packages
/TestResults

/tools/NuGet.exe
/App_Data
/secrets
/data
.secrets
appsettings.json
local.settings.json

node_modules
dist

# Local python packages
.python_packages/

# Python Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json
5 changes: 5 additions & 0 deletions fa-import-service/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}
13 changes: 13 additions & 0 deletions fa-import-service/blob-import-products-from-file/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"bindings": [
{
"authLevel": "function",
"name": "blob",
"type": "blobTrigger",
"direction": "in",
"path": "uploaded",
"connection": "AZURE_STORAGE_CONNECTION_STRING"
}
],
"scriptFile": "../dist/blob-import-products-from-file/index.js"
}
17 changes: 17 additions & 0 deletions fa-import-service/blob-import-products-from-file/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AzureFunction, Context } from "@azure/functions";
import { parse } from 'csv-parse';

const blobTrigger: AzureFunction = async function (context: Context, myBlob: any): Promise<void> {
const records = parse(context.bindings.blob, {
columns: true,
skip_empty_lines: true,
});

context.log(context.bindings);

records.forEach((record) => {
context.log(`Record: ${JSON.stringify(record)}`);
});
};

export default blobTrigger;
11 changes: 11 additions & 0 deletions fa-import-service/blob-import-products-from-file/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# BlobTrigger - TypeScript

The `BlobTrigger` makes it incredibly easy to react to new Blobs inside of Azure Blob Storage. This sample demonstrates a simple use case of processing data from a given Blob using TypeScript.

## How it works

For a `BlobTrigger` to work, you provide a path which dictates where the blobs are located inside your container, and can also help restrict the types of blobs you wish to return. For instance, you can set the path to `samples/{name}.png` to restrict the trigger to only the samples path and only blobs with ".png" at the end of their name.

## Learn more

<TODO> Documentation
15 changes: 15 additions & 0 deletions fa-import-service/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
22 changes: 22 additions & 0 deletions fa-import-service/http-get-import-products-file/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post",
"put"
],
"route": "import"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/http-get-import-products-file/index.js"
}
51 changes: 51 additions & 0 deletions fa-import-service/http-get-import-products-file/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'dotenv/config'
import { AzureFunction, Context, HttpRequest } from "@azure/functions"
import { BlobSASPermissions, BlobServiceClient, StorageSharedKeyCredential, generateBlobSASQueryParameters } from "@azure/storage-blob";

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
try {
const fileName = req.query.name;
const account = process.env.AZURE_STORAGE_ACCOUNT_NAME;
const accountKey = process.env.AZURE_STORAGE_ACCOUNT_KEY;
const containerName = 'container';
const sharedKeyCredential = new StorageSharedKeyCredential(
account,
accountKey,
);
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
sharedKeyCredential,
);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(fileName);
const sasToken = generateBlobSASQueryParameters(
{
containerName,
blobName: fileName,
permissions: BlobSASPermissions.parse('rwc'), // read, write
startsOn: new Date(),
expiresOn: new Date(new Date().valueOf() + 86400),
},
sharedKeyCredential,
).toString();
const sasUrl = blobClient.url + '?' + sasToken;
context.res = {
status: 200,
body: {
sasToken,
sasUrl,
url: blobClient.url,
},
};
} catch (e) {
context.log(e);
context.res = {
status: 500,
body: {
error: e.message,
},
};
}
};

export default httpTrigger;
2 changes: 2 additions & 0 deletions fa-import-service/import-blob
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Title,Description
Product title,Product description
Loading