Skip to content
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# [Choice] .NET version: 6.0, 5.0, 3.1, 6.0-bullseye, 5.0-bullseye, 3.1-bullseye, 6.0-focal, 5.0-focal, 3.1-focal
ARG VARIANT="6.0-bullseye-slim"
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT}
FROM mcr.microsoft.com/devcontainers/dotnet:${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
Expand Down
9 changes: 6 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"args": {
// Update 'VARIANT' to pick a .NET Core version: 3.1, 5.0, 6.0
// Append -bullseye or -focal to pin to an OS version.
"VARIANT": "7.0",
"VARIANT": "8.0-jammy",
// Options
"NODE_VERSION": "lts/*"
}
Expand All @@ -17,7 +17,7 @@
"version": "latest"
},
"ghcr.io/devcontainers/features/dotnet": {
"version": "7.0",
"version": "8.0",
"additionalVersions": "6.0",
"runtimeOnly": false
},
Expand Down Expand Up @@ -47,7 +47,10 @@
"cschleiden.vscode-github-actions",
"ms-azure-devops.azure-pipelines",
"github.vscode-github-actions",
"ms-vscode.powershell"
"ms-vscode.powershell",
"ms-dotnettools.csdevkit",
"ms-dotnettools.vscodeintellicode-csharp",
"chneau.resource-monitor"
]
}
},
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Publish Frontend
run: dotnet publish -c Release ./src/CZ.Azure.FileExchange/ -o temp/frontend
- name: Publish API
run: dotnet publish -c Release ./src/CZ.Azure.FileExchange.Api/ -o temp/api --runtime win-x86 --no-self-contained
run: dotnet publish -c Release ./src/CZ.Azure.FileExchange.Api/ -o temp/api --runtime win-x86 --self-contained
- name: zip outputs
shell: pwsh
run: |
Expand Down Expand Up @@ -110,5 +113,5 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Deploy
run: './build/deploy.ps1 -Token ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_KINDDUNE004C2C103 }} -appBuildOutput ./temp/frontend/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName ${{ github.event.number }} -pullrequestTitle "${{steps.Pr-Title.outputs.pr-title}}" -branchName ${{ github.head_ref }} -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -Verbose -Delete'
shell: pwsh
run: './build/deploy.ps1 -Token ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_KINDDUNE004C2C103 }} -appBuildOutput ./temp/frontend/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName ${{ github.event.number }} -pullrequestTitle "${{steps.Pr-Title.outputs.pr-title}}" -branchName ${{ github.head_ref }} -apiFramework "dotnetisolated" -apiFrameworkVersion "8.0" -Verbose -Delete'
shell: pwsh
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"azureFunctions.projectSubpath": "src/CZ.Azure.FileExchange.Api",
"azureFunctions.deploySubpath": "src/CZ.Azure.FileExchange.Api/bin/Release/net7.0/publish",
"azureFunctions.deploySubpath": "src/CZ.Azure.FileExchange.Api/bin/Release/net8.0/publish",
"azureFunctions.projectLanguage": "C#",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"type": "func",
"dependsOn": "build (functions)",
"options": {
"cwd": "${workspaceFolder}/src/CZ.Azure.FileExchange.Api/bin/Debug/net7.0"
"cwd": "${workspaceFolder}/src/CZ.Azure.FileExchange.Api/bin/Debug/net8.0"
},
"command": "host start",
"isBackground": true,
Expand Down
12 changes: 7 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ $token = Read-Host -MaskInput;
> Important: If you want deploy this, build it on linux!

```powershell
dotnet build
dotnet publish .\src\CZ.Azure.FileExchange\ -o temp/fe
dotnet publish .\src\CZ.Azure.FileExchange.Api\ -o temp/api
dotnet build -c Release
dotnet publish -c Release .\src\CZ.Azure.FileExchange\ -o temp/fe
dotnet publish --runtime win-x86 --no-self-contained -c Release .\src\CZ.Azure.FileExchange.Api\ -o temp/api
```

### Run the App local
Expand Down Expand Up @@ -71,13 +71,14 @@ $body = "<?xml version=`"1.0`" encoding=`"utf-8`"?>
</Cors>
</StorageServiceProperties>"
$lenght = $body.Length;
$bodyMd5 = ([System.BitConverter]::ToString((New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider).ComputeHash((New-Object -TypeName System.Text.UTF8Encoding).GetBytes($body)))).Replace("-","");
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256;
$hmacsha.key = [Convert]::FromBase64String($accountKey);
$date = (Get-Date).ToUniversalTime().ToString("R");
$test = "PUT`n`n`n$lenght`n`n`n`n`n`n`n`n`nx-ms-date:$($date)`nx-ms-version:2018-03-28`n/devstoreaccount1/devstoreaccount1`ncomp:properties`nrestype:service";
$test = "PUT`n`n`n$lenght`n`napplication/x-www-form-urlencoded`n`n`n`n`n`n`nx-ms-date:$($date)`nx-ms-version:2024-02-04`n/devstoreaccount1/devstoreaccount1`ncomp:properties`nrestype:service";
$signature1 = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($test));
$auth = [System.Convert]::ToBase64String($signature1);
Invoke-WebRequest -Method Put "http://127.0.0.1:10000/devstoreaccount1?restype=service&comp=properties" -Headers @{"Authorization" = "SharedKey devstoreaccount1:$($auth)"; "x-ms-version"= "2018-03-28"; "x-ms-date" = $date } -Body $body
Invoke-WebRequest -Method Put "http://127.0.0.1:10000/devstoreaccount1?restype=service&comp=properties" -Headers @{"Authorization" = "SharedKey devstoreaccount1:$($auth)"; "x-ms-version"= "2024-02-04"; "x-ms-date" = $date } -Body $body
```


Expand Down Expand Up @@ -115,3 +116,4 @@ $PrId = "Replace this string with the Id of your PR here";
$PrTitle = "Replace this string with the title of your PR";
./build/deploy.ps1 -Token $token -appBuildOutput ./temp/fe/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName $PrId -pullrequestTitle $PrTitle -branchName $branchName -Delete
```

2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ stages:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '7.x'
version: '8.x'
- task: UseDotNet@2
inputs:
packageType: 'sdk'
Expand Down
8 changes: 6 additions & 2 deletions deploayWebApp.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ resource deployPrWebApp 'Microsoft.Resources/deploymentScripts@2020-10-01' = if
[string] $branch,
[string] $prNumber
)
# this makes it easier for us to read the log output
$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;
try{
# download artifact from pipeline run
$workflowArtifactUrl = "$($githubRuntimeApiUrl)_apis/pipelines/workflows/$githubRunId/artifacts";
Expand All @@ -77,7 +79,7 @@ resource deployPrWebApp 'Microsoft.Resources/deploymentScripts@2020-10-01' = if
Set-Location ./artifact/
$secretProperties = Get-AzStaticWebAppSecret -Name $staticWebAppName -ResourceGroupName $resourceGroupName
$token = $secretProperties.Property.Item("apiKey")
./deploy.ps1 -Token $token -appBuildOutput ./frontend.zip -apiBuildOutput ./api.zip -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -workingDir $pwd -branchName $branch -envrionmentName $prNumber -Verbose
./deploy.ps1 -Token $token -appBuildOutput ./frontend.zip -apiBuildOutput ./api.zip -apiFramework "dotnetisolated" -apiFrameworkVersion "8.0" -workingDir $pwd -branchName $branch -envrionmentName $prNumber -Verbose
# for azure Deployment Script output
$DeploymentScriptOutputs = @{}
$DeploymentScriptOutputs['staticWebUrl'] = "https://$((Get-AzStaticWebAppBuild -Name $staticWebAppName -ResourceGroupName $resourceGroupName -EnvironmentName $prNumber).Hostname)"
Expand Down Expand Up @@ -112,6 +114,8 @@ resource deployWebApp 'Microsoft.Resources/deploymentScripts@2020-10-01' = if (e
[string] $staticWebAppName,
[string] $resourceGroupName
)
# this makes it easier for us to read the log output
$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;
# take stable releases here
$result = Invoke-RestMethod https://api.github.com/repos/codez-one/CZ.Azure.FileExchange/releases/latest -Headers @{"X-GitHub-Api-Version" = "2022-11-28" }
$frontendDownloadUrl = ($result.assets | ? {$_.name -like 'Frontend.zip'}).browser_download_url;
Expand All @@ -127,7 +131,7 @@ resource deployWebApp 'Microsoft.Resources/deploymentScripts@2020-10-01' = if (e
$secretProperties = Get-AzStaticWebAppSecret -Name $staticWebAppName -ResourceGroupName $resourceGroupName
$token = $secretProperties.Property.Item("apiKey")
$token.Substring(0,5)
./deploy.ps1 -Token $token -appBuildOutput ./frontend.zip -apiBuildOutput ./api.zip -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -workingDir $pwd -Verbose
./deploy.ps1 -Token $token -appBuildOutput ./frontend.zip -apiBuildOutput ./api.zip -apiFramework "dotnetisolated" -apiFrameworkVersion "8.0" -workingDir $pwd -Verbose
$DeploymentScriptOutputs = @{}
$DeploymentScriptOutputs['staticWebUrl'] = "https://$((Get-AzStaticWebApp -Name $staticWebAppName -ResourceGroupName $resourceGroupName).DefaultHostname)"
'''
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.100",
"version": "8.0.101",
"rollForward": "latestMajor"
}
}
9 changes: 3 additions & 6 deletions src/CZ.Azure.FileExchange.Api/AddMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ namespace CZ.Azure.FileExchange.Api;
using System;
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using global::Azure.Messaging.EventGrid;
using Microsoft.Azure.Functions.Worker.Http;
using global::Azure.Messaging.EventGrid.SystemEvents;
using global::Azure.Storage.Blobs;
using System.Globalization;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;

public class AddMetadata
public class AddMetadata(ILoggerFactory loggerFactory)
{
private readonly ILogger logger;
private readonly ILogger logger = loggerFactory.CreateLogger<AddMetadata>();
private const string BlobChanged = "Microsoft.Storage.BlobTierChanged";
private const string SetBlobTier = "SetBlobTier";
private const string AzureValidation = "Microsoft.EventGrid.SubscriptionValidationEvent";


public AddMetadata(ILoggerFactory loggerFactory) => this.logger = loggerFactory.CreateLogger<AddMetadata>();

[Function("AddMetadata")]
[OpenApiOperation(operationId: "Run")]
[OpenApiRequestBody("application/json", typeof(IEnumerable<EventGridEvent>))]
Expand Down
26 changes: 15 additions & 11 deletions src/CZ.Azure.FileExchange.Api/CZ.Azure.FileExchange.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>84a717a7-ef76-47be-9101-2a62e74fd7d3</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.EventGrid" Version="4.14.1" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.15.1" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.13.1" />
<PackageReference Include="Azure.Storage.Queues" Version="12.13.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.13.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.EventGrid" Version="4.21.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.17.1" />
<PackageReference Include="Azure.Storage.Queues" Version="12.17.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="5.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.9.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.2.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
6 changes: 3 additions & 3 deletions src/CZ.Azure.FileExchange.Api/GenerateSas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace CZ.Azure.FileExchange.Api;
using global::Azure.Storage.Blobs;
using global::Azure.Storage.Sas;
using System.Net.Http;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
using Microsoft.Azure.Functions.Worker.Http;

public class GenerateSas
{
Expand Down Expand Up @@ -52,13 +52,13 @@ public async Task<HttpResponseData> Run(
var badResponse = req.CreateResponse(HttpStatusCode.BadRequest);
var badContent = new StringContent("Failed to greate SaS token to upload your files. Please try again.");
badResponse.Headers.Add("Content-Type", badContent.Headers.ContentType?.ToString());
badResponse.WriteString(await badContent.ReadAsStringAsync());
await badResponse.WriteStringAsync(await badContent.ReadAsStringAsync());
return badResponse;
}
var okResponse = req.CreateResponse(HttpStatusCode.OK);
var content = new StringContent(uri.ToString());
okResponse.Headers.Add("Content-Type", content.Headers.ContentType?.ToString());
okResponse.WriteString(await content.ReadAsStringAsync());
await okResponse.WriteStringAsync(await content.ReadAsStringAsync());
return okResponse;
}

Expand Down
2 changes: 1 addition & 1 deletion src/CZ.Azure.FileExchange.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
services.AddHttpClient();
})
.ConfigureFunctionsWorkerDefaults(worker => worker.UseNewtonsoftJson())
.ConfigureFunctionsWebApplication(worker => worker.UseNewtonsoftJson())
.ConfigureOpenApi()
.Build();

Expand Down
15 changes: 5 additions & 10 deletions src/CZ.Azure.FileExchange/CZ.Azure.FileExchange.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DartSassBuilder" Version="0.3.0-beta" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.1" PrivateAssets="all" />
<PackageReference Include="DartSassBuilder" Version="1.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" />
</ItemGroup>

<!-- SASS options -->
<PropertyGroup>
<!-- outputstyle option -->
Expand All @@ -27,9 +24,7 @@
<!-- add files manually -->
<SassFile Include="Client/**/*.scss" />
</ItemGroup>

<Target Name="copy_sass_to_the_right_place" AfterTargets="DartSass_Build">
<Copy SourceFiles="Client/styles/main.css" DestinationFolder="wwwroot/client/" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion src/CZ.Azure.FileExchange/staticwebapp.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"platform": {
"apiRuntime": "dotnet-isolated:7.0"
"apiRuntime": "dotnet-isolated:8.0"
}
}
3 changes: 3 additions & 0 deletions src/CZ.Azure.FileExchange/wwwroot/staticwebapp.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"platform": {
"apiRuntime": "dotnet-isolated:8.0"
},
"navigationFallback": {
"rewrite": "/index.html",
"exclude": [
Expand Down