├── .azure ├── config.json └── openai-plugin-aspnetcore-dev │ └── config.json ├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .gitattributes ├── .github └── workflows │ └── _build.yaml ├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── LICENSE.txt ├── README.md ├── azure.yaml ├── infra ├── abbreviations.json ├── app │ └── api.bicep ├── core │ ├── host │ │ ├── container-app-upsert.bicep │ │ ├── container-app.bicep │ │ ├── container-apps-environment.bicep │ │ ├── container-apps.bicep │ │ └── container-registry.bicep │ ├── monitor │ │ ├── applicationinsights-dashboard.bicep │ │ ├── applicationinsights.bicep │ │ ├── loganalytics.bicep │ │ └── monitoring.bicep │ └── security │ │ └── registry-access.bicep ├── main.bicep └── main.parameters.json └── src ├── .dockerignore ├── ContosoProductsAPI.csproj ├── ContosoProductsAPI.sln ├── Data └── products.json ├── Dockerfile ├── Model └── Product.cs ├── Program.cs ├── Properties └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json └── wwwroot └── logo.png /.azure/config.json: -------------------------------------------------------------------------------- 1 | {"version":1,"defaultEnvironment":"openai-plugin-aspnetcore-dev"} -------------------------------------------------------------------------------- /.azure/openai-plugin-aspnetcore-dev/config.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/dotnet/.devcontainer/base.Dockerfile 2 | 3 | # [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 4 | ARG VARIANT="7.0-bullseye-slim" 5 | FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} 6 | 7 | # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 8 | ARG NODE_VERSION="none" 9 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 10 | 11 | # [Optional] Uncomment this section to install additional OS packages. 12 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 13 | # && apt-get -y install --no-install-recommends 14 | 15 | # [Optional] Uncomment this line to install global node packages. 16 | # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the 2 | // README at: https://github.com/devcontainers/templates/tree/main/src/dotnet 3 | { 4 | "name": "C# (.NET)", 5 | // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile 6 | "image": "mcr.microsoft.com/devcontainers/dotnet:0-7.0", 7 | "features": { 8 | "ghcr.io/devcontainers/features/powershell:1": {}, 9 | "ghcr.io/devcontainers/features/azure-cli:1": { 10 | "version": "2.48.1" 11 | }, 12 | "ghcr.io/devcontainers/features/docker-from-docker:1": { 13 | "version": "20.10" 14 | }, 15 | "ghcr.io/devcontainers/features/github-cli:1": { 16 | "version": "2" 17 | }, 18 | "ghcr.io/timheuer/devcontainer-azd/azd:1": {} 19 | }, 20 | "customizations": { 21 | "vscode": { 22 | "extensions": [ 23 | "ms-azuretools.azure-dev", 24 | "ms-azuretools.vscode-bicep", 25 | "ms-azuretools.vscode-docker", 26 | "github.vscode-github-actions", 27 | "ms-dotnettools.csharp@prerelease" 28 | ] 29 | }, 30 | "codespaces": { 31 | "openFiles": [ 32 | "src/Program.cs" 33 | ] 34 | } 35 | }, 36 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 37 | "forwardPorts": [7070, 5264], 38 | "portsAttributes": { 39 | "7070": { 40 | "protocol": "https" 41 | } 42 | }, 43 | 44 | // Use 'postCreateCommand' to run commands after the container is created. 45 | "postCreateCommand": "dotnet restore" 46 | } 47 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Ignore files for linguist 2 | *.bicep linguist-detectable=false 3 | 4 | ############################################################################### 5 | # Set default behavior to automatically normalize line endings. 6 | ############################################################################### 7 | * text=auto 8 | 9 | ############################################################################### 10 | # Set default behavior for command prompt diff. 11 | # 12 | # This is need for earlier builds of msysgit that does not have it on by 13 | # default for csharp files. 14 | # Note: This is only used by command line 15 | ############################################################################### 16 | #*.cs diff=csharp 17 | 18 | ############################################################################### 19 | # Set the merge driver for project and solution files 20 | # 21 | # Merging from the command prompt will add diff markers to the files if there 22 | # are conflicts (Merging from VS is not affected by the settings below, in VS 23 | # the diff markers are never inserted). Diff markers may cause the following 24 | # file extensions to fail to load in VS. An alternative would be to treat 25 | # these files as binary and thus will always conflict and require user 26 | # intervention with every merge. To do so, just uncomment the entries below 27 | ############################################################################### 28 | #*.sln merge=binary 29 | #*.csproj merge=binary 30 | #*.vbproj merge=binary 31 | #*.vcxproj merge=binary 32 | #*.vcproj merge=binary 33 | #*.dbproj merge=binary 34 | #*.fsproj merge=binary 35 | #*.lsproj merge=binary 36 | #*.wixproj merge=binary 37 | #*.modelproj merge=binary 38 | #*.sqlproj merge=binary 39 | #*.wwaproj merge=binary 40 | 41 | ############################################################################### 42 | # behavior for image files 43 | # 44 | # image files are treated as binary by default. 45 | ############################################################################### 46 | #*.jpg binary 47 | #*.png binary 48 | #*.gif binary 49 | 50 | ############################################################################### 51 | # diff behavior for common document formats 52 | # 53 | # Convert binary document formats to text before diffing them. This feature 54 | # is only available from the command line. Turn it on by uncommenting the 55 | # entries below. 56 | ############################################################################### 57 | #*.doc diff=astextplain 58 | #*.DOC diff=astextplain 59 | #*.docx diff=astextplain 60 | #*.DOCX diff=astextplain 61 | #*.dot diff=astextplain 62 | #*.DOT diff=astextplain 63 | #*.pdf diff=astextplain 64 | #*.PDF diff=astextplain 65 | #*.rtf diff=astextplain 66 | #*.RTF diff=astextplain 67 | -------------------------------------------------------------------------------- /.github/workflows/_build.yaml: -------------------------------------------------------------------------------- 1 | name: "Base build" 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths-ignore: 8 | - '**/*.md' 9 | - '**/*.gitignore' 10 | - '**/*.gitattributes' 11 | workflow_dispatch: 12 | branches: 13 | - main 14 | paths-ignore: 15 | - '**/*.md' 16 | - '**/*.gitignore' 17 | - '**/*.gitattributes' 18 | 19 | jobs: 20 | build: 21 | name: Build 22 | runs-on: ubuntu-latest 23 | env: 24 | DOTNET_CLI_TELEMETRY_OPTOUT: 1 25 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 26 | DOTNET_NOLOGO: true 27 | DOTNET_GENERATE_ASPNET_CERTIFICATE: false 28 | DOTNET_ADD_GLOBAL_TOOLS_TO_PATH: false 29 | DOTNET_MULTILEVEL_LOOKUP: 0 30 | DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: true 31 | TERM: xterm 32 | PROJECT: src/ContosoProductsAPI.csproj 33 | 34 | steps: 35 | - uses: actions/checkout@v3 36 | 37 | - name: Setup .NET SDK 38 | uses: actions/setup-dotnet@v3 39 | with: 40 | dotnet-version: 7.0.x 41 | 42 | - name: Restore 43 | run: dotnet restore ${{ env.PROJECT }} 44 | 45 | - name: Build 46 | run: dotnet build ${{ env.PROJECT }} --configuration Release --no-restore 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd 364 | .azure/openai-plugin-aspnetcore-dev/.env 365 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "API", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "build", 9 | "program": "${workspaceFolder}/src/bin/Debug/net7.0/ContosoProductsAPI.dll", 10 | "args": [], 11 | "cwd": "${workspaceFolder}/src", 12 | "stopAtEntry": false, 13 | "serverReadyAction": { 14 | "action": "openExternally", 15 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)" 16 | }, 17 | "env": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | }, 20 | "sourceFileMap": { 21 | "/Views": "${workspaceFolder}/Views" 22 | } 23 | }, 24 | { 25 | "name": ".NET Core Attach", 26 | "type": "coreclr", 27 | "request": "attach" 28 | }, 29 | { 30 | "name": "Docker .NET Launch", 31 | "type": "docker", 32 | "request": "launch", 33 | "preLaunchTask": "docker-run: debug", 34 | "netCore": { 35 | "appProject": "${workspaceFolder}/src/ContosoProductsAPI.csproj" 36 | } 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "dotnet.defaultSolution": "src\\ContosoProductsAPI.sln" 3 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/src/ContosoProductsAPI.sln", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/src/ContosoProductsAPI.sln", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "--project", 36 | "${workspaceFolder}/src/ContosoProductsAPI.sln" 37 | ], 38 | "problemMatcher": "$msCompile" 39 | }, 40 | { 41 | "type": "docker-build", 42 | "label": "docker-build: debug", 43 | "dependsOn": [ 44 | "build" 45 | ], 46 | "dockerBuild": { 47 | "tag": "openaipluginaspnetcore:dev", 48 | "target": "base", 49 | "dockerfile": "${workspaceFolder}/src/Dockerfile", 50 | "context": "${workspaceFolder}", 51 | "pull": true 52 | }, 53 | "netCore": { 54 | "appProject": "${workspaceFolder}/src/ContosoProductsAPI.csproj" 55 | } 56 | }, 57 | { 58 | "type": "docker-build", 59 | "label": "docker-build: release", 60 | "dependsOn": [ 61 | "build" 62 | ], 63 | "dockerBuild": { 64 | "tag": "openaipluginaspnetcore:latest", 65 | "dockerfile": "${workspaceFolder}/src/Dockerfile", 66 | "context": "${workspaceFolder}", 67 | "platform": "linux/amd64", 68 | "pull": true 69 | }, 70 | "netCore": { 71 | "appProject": "${workspaceFolder}/src/ContosoProductsAPI.csproj" 72 | } 73 | }, 74 | { 75 | "type": "docker-run", 76 | "label": "docker-run: debug", 77 | "dependsOn": [ 78 | "docker-build: debug" 79 | ], 80 | "dockerRun": {}, 81 | "netCore": { 82 | "appProject": "${workspaceFolder}/src/ContosoProductsAPI.csproj", 83 | "enableDebugging": true 84 | } 85 | }, 86 | { 87 | "type": "docker-run", 88 | "label": "docker-run: release", 89 | "dependsOn": [ 90 | "docker-build: release" 91 | ], 92 | "dockerRun": {}, 93 | "netCore": { 94 | "appProject": "${workspaceFolder}/src/ContosoProductsAPI.csproj" 95 | } 96 | } 97 | ] 98 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChatGPT Plugin Quickstart using C# and ASP.NET Core 2 | 3 | This is a quickstart for sample for creating [ChatGPT Plugin](https://openai.com/blog/chatgpt-plugins) using GitHub Codespaces, Visual Studio or VS Code, and Azure. The sample includes templates to deploy the plugin to [Azure Container Apps](https://learn.microsoft.com/en-us/azure/container-apps/) using the [Azure Developer CLI](https://aka.ms/azd/install). To gain access to ChatGPT plugins, [join waitlist here](https://openai.com/waitlist/plugins)! 4 | 5 | 6 | [![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=lightgrey&logo=github)](https://codespaces.new/timheuer/openai-plugin-aspnetcore) 7 | [![Open in Dev Container](https://img.shields.io/static/v1?style=for-the-badge&label=Dev+Container&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/timheuer/openai-plugin-aspnetcore) 8 | 9 | ## Getting started 10 | 11 | 1. **📤 One-click setup**: [Open a new Codespace](https://codespaces.new/timheuer/openai-plugin-aspnetcore), giving you a fully configured cloud developer environment. 12 | 2. **🪄 Make an API**: Add routes in `Program.cs`, done in a few minutes even without [ASP.NET Core minimal API](https://learn.microsoft.com/aspnet/core/tutorials/min-web-api?view=aspnetcore-7.0&tabs=visual-studio) experience, thanks to [GitHub Copilot](https://github.com/features/copilot/). 13 | 3. **▶️ Run, one-click again**: Use VS or VS Code's built-in *Run* command and open the forwarded port *8000* in your browser. 14 | 4. **💬 Test in ChatGPT**: Copy the URL (make sure its public) and paste it in ChatGPT's [Develop your own plugin](https://platform.openai.com/docs/plugins/getting-started/debugging) flow. 15 | 5. **🔄 Iterate quickly:** Codespaces updates the server on each save, and VS Code's debugger lets you dig into the code execution. 16 | 17 | ## Run 18 | 19 | ### Run in Codespaces 20 | 1. Click here to open in GitHub Codespaces 21 | 22 | [![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=lightgrey&logo=github)](https://codespaces.new/timheuer/openai-plugin-aspnetcore) 23 | 24 | 1. Open Codespaces Ports tab, right click 8000, and make it public. 25 | 1. Copy the Codesapces address for port 8000 26 | 1. Open Chat GPT and add the plugin with the Codespaces address 27 | 1. Run a query for 'hiking boots' 28 | 29 | ### Run in Dev Container 30 | 31 | 1. Click here to open in Dev Container 32 | 33 | [![Open in Dev Container](https://img.shields.io/static/v1?style=for-the-badge&label=Dev+Container&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/timheuer/openai-plugin-aspnetcore) 34 | 35 | 1. Hit F5 to start the API 36 | 1. Open Chat GPT and add the plugin with `localhost:8000` 37 | 1. Run a query for 'hiking boots' 38 | 39 | 40 | ### Run Locally 41 | 42 | 1. Clone the repo to your local machine `git clone https://github.com/timheuer/openai-plugin-aspnetcore` 43 | 1. Open repo in Visual Studio or VS Code 44 | 1. Hit F5 to start the API 45 | 1. Open Chat GPT and add the plugin with `localhost:8000` 46 | 1. Run a query for 'hiking boots' 47 | 48 | ## Deploy to Azure 49 | 50 | > NOTE: If you are running locally, then you first need to [install the Azure Developer CLI](https://aka.ms/azd/install) 51 | 52 | ### Deploy with Azure Developer CLI 53 | 54 | 1. Open a terminal 55 | 1. Run `azd auth login` 56 | 1. Run `azd up` 57 | 1. Copy the endpoint printed to the terminal 58 | 1. Open Chat GPT and add the plugin with that endpoint 59 | 1. Run a query for 'hiking boots' 60 | 61 | ### Deploy with GitHub Actions 62 | 63 | > NOTE: Due to a security restriction Codespaces in the browser may not work for you. If you see an error when running the following commands, then please open the project with VS Code by choosing the Connect to Codespace option. 64 | 65 | 1. Fork this repo to your own account 66 | 1. Open your fork in Codespaces, Dev Container or Local 67 | 1. Open a terminal 68 | 1. Run `azd auth login` 69 | 1. Run `azd pipeline config` 70 | 1. Click on the printed actions link. Scroll to the bottom of the logs to find the endpoint. 71 | 1. Open Chat GPT and add the plugin with that endpoint 72 | 1. Run a query for 'hiking boots' -------------------------------------------------------------------------------- /azure.yaml: -------------------------------------------------------------------------------- 1 | # yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json 2 | 3 | name: openai-plugin-aspnetcore 4 | services: 5 | api: 6 | project: ./src 7 | language: csharp 8 | host: containerapp -------------------------------------------------------------------------------- /infra/abbreviations.json: -------------------------------------------------------------------------------- 1 | { 2 | "analysisServicesServers": "as", 3 | "apiManagementService": "apim-", 4 | "appConfigurationConfigurationStores": "appcs-", 5 | "appManagedEnvironments": "cae-", 6 | "appContainerApps": "ca-", 7 | "authorizationPolicyDefinitions": "policy-", 8 | "automationAutomationAccounts": "aa-", 9 | "blueprintBlueprints": "bp-", 10 | "blueprintBlueprintsArtifacts": "bpa-", 11 | "cacheRedis": "redis-", 12 | "cdnProfiles": "cdnp-", 13 | "cdnProfilesEndpoints": "cdne-", 14 | "cognitiveServicesAccounts": "cog-", 15 | "cognitiveServicesFormRecognizer": "cog-fr-", 16 | "cognitiveServicesTextAnalytics": "cog-ta-", 17 | "computeAvailabilitySets": "avail-", 18 | "computeCloudServices": "cld-", 19 | "computeDiskEncryptionSets": "des", 20 | "computeDisks": "disk", 21 | "computeDisksOs": "osdisk", 22 | "computeGalleries": "gal", 23 | "computeSnapshots": "snap-", 24 | "computeVirtualMachines": "vm", 25 | "computeVirtualMachineScaleSets": "vmss-", 26 | "containerInstanceContainerGroups": "ci", 27 | "containerRegistryRegistries": "cr", 28 | "containerServiceManagedClusters": "aks-", 29 | "databricksWorkspaces": "dbw-", 30 | "dataFactoryFactories": "adf-", 31 | "dataLakeAnalyticsAccounts": "dla", 32 | "dataLakeStoreAccounts": "dls", 33 | "dataMigrationServices": "dms-", 34 | "dBforMySQLServers": "mysql-", 35 | "dBforPostgreSQLServers": "psql-", 36 | "devicesIotHubs": "iot-", 37 | "devicesProvisioningServices": "provs-", 38 | "devicesProvisioningServicesCertificates": "pcert-", 39 | "documentDBDatabaseAccounts": "cosmos-", 40 | "eventGridDomains": "evgd-", 41 | "eventGridDomainsTopics": "evgt-", 42 | "eventGridEventSubscriptions": "evgs-", 43 | "eventHubNamespaces": "evhns-", 44 | "eventHubNamespacesEventHubs": "evh-", 45 | "hdInsightClustersHadoop": "hadoop-", 46 | "hdInsightClustersHbase": "hbase-", 47 | "hdInsightClustersKafka": "kafka-", 48 | "hdInsightClustersMl": "mls-", 49 | "hdInsightClustersSpark": "spark-", 50 | "hdInsightClustersStorm": "storm-", 51 | "hybridComputeMachines": "arcs-", 52 | "insightsActionGroups": "ag-", 53 | "insightsComponents": "appi-", 54 | "keyVaultVaults": "kv-", 55 | "kubernetesConnectedClusters": "arck", 56 | "kustoClusters": "dec", 57 | "kustoClustersDatabases": "dedb", 58 | "logicIntegrationAccounts": "ia-", 59 | "logicWorkflows": "logic-", 60 | "machineLearningServicesWorkspaces": "mlw-", 61 | "managedIdentityUserAssignedIdentities": "id-", 62 | "managementManagementGroups": "mg-", 63 | "migrateAssessmentProjects": "migr-", 64 | "networkApplicationGateways": "agw-", 65 | "networkApplicationSecurityGroups": "asg-", 66 | "networkAzureFirewalls": "afw-", 67 | "networkBastionHosts": "bas-", 68 | "networkConnections": "con-", 69 | "networkDnsZones": "dnsz-", 70 | "networkExpressRouteCircuits": "erc-", 71 | "networkFirewallPolicies": "afwp-", 72 | "networkFirewallPoliciesWebApplication": "waf", 73 | "networkFirewallPoliciesRuleGroups": "wafrg", 74 | "networkFrontDoors": "fd-", 75 | "networkFrontdoorWebApplicationFirewallPolicies": "fdfp-", 76 | "networkLoadBalancersExternal": "lbe-", 77 | "networkLoadBalancersInternal": "lbi-", 78 | "networkLoadBalancersInboundNatRules": "rule-", 79 | "networkLocalNetworkGateways": "lgw-", 80 | "networkNatGateways": "ng-", 81 | "networkNetworkInterfaces": "nic-", 82 | "networkNetworkSecurityGroups": "nsg-", 83 | "networkNetworkSecurityGroupsSecurityRules": "nsgsr-", 84 | "networkNetworkWatchers": "nw-", 85 | "networkPrivateDnsZones": "pdnsz-", 86 | "networkPrivateLinkServices": "pl-", 87 | "networkPublicIPAddresses": "pip-", 88 | "networkPublicIPPrefixes": "ippre-", 89 | "networkRouteFilters": "rf-", 90 | "networkRouteTables": "rt-", 91 | "networkRouteTablesRoutes": "udr-", 92 | "networkTrafficManagerProfiles": "traf-", 93 | "networkVirtualNetworkGateways": "vgw-", 94 | "networkVirtualNetworks": "vnet-", 95 | "networkVirtualNetworksSubnets": "snet-", 96 | "networkVirtualNetworksVirtualNetworkPeerings": "peer-", 97 | "networkVirtualWans": "vwan-", 98 | "networkVpnGateways": "vpng-", 99 | "networkVpnGatewaysVpnConnections": "vcn-", 100 | "networkVpnGatewaysVpnSites": "vst-", 101 | "notificationHubsNamespaces": "ntfns-", 102 | "notificationHubsNamespacesNotificationHubs": "ntf-", 103 | "operationalInsightsWorkspaces": "log-", 104 | "portalDashboards": "dash-", 105 | "powerBIDedicatedCapacities": "pbi-", 106 | "purviewAccounts": "pview-", 107 | "recoveryServicesVaults": "rsv-", 108 | "resourcesResourceGroups": "rg-", 109 | "searchSearchServices": "srch-", 110 | "serviceBusNamespaces": "sb-", 111 | "serviceBusNamespacesQueues": "sbq-", 112 | "serviceBusNamespacesTopics": "sbt-", 113 | "serviceEndPointPolicies": "se-", 114 | "serviceFabricClusters": "sf-", 115 | "signalRServiceSignalR": "sigr", 116 | "sqlManagedInstances": "sqlmi-", 117 | "sqlServers": "sql-", 118 | "sqlServersDataWarehouse": "sqldw-", 119 | "sqlServersDatabases": "sqldb-", 120 | "sqlServersDatabasesStretch": "sqlstrdb-", 121 | "storageStorageAccounts": "st", 122 | "storageStorageAccountsVm": "stvm", 123 | "storSimpleManagers": "ssimp", 124 | "streamAnalyticsCluster": "asa-", 125 | "synapseWorkspaces": "syn", 126 | "synapseWorkspacesAnalyticsWorkspaces": "synw", 127 | "synapseWorkspacesSqlPoolsDedicated": "syndp", 128 | "synapseWorkspacesSqlPoolsSpark": "synsp", 129 | "timeSeriesInsightsEnvironments": "tsi-", 130 | "webServerFarms": "plan-", 131 | "webSitesAppService": "app-", 132 | "webSitesAppServiceEnvironment": "ase-", 133 | "webSitesFunctions": "func-", 134 | "webStaticSites": "stapp-" 135 | } 136 | -------------------------------------------------------------------------------- /infra/app/api.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param location string = resourceGroup().location 3 | param tags object = {} 4 | 5 | param identityName string 6 | param applicationInsightsName string 7 | param containerAppsEnvironmentName string 8 | param containerRegistryName string 9 | param serviceName string = 'api' 10 | param exists bool 11 | 12 | resource apiIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = { 13 | name: identityName 14 | location: location 15 | } 16 | 17 | module app '../core/host/container-app-upsert.bicep' = { 18 | name: '${serviceName}-container-app' 19 | params: { 20 | name: name 21 | location: location 22 | tags: union(tags, { 'azd-service-name': serviceName }) 23 | identityName: identityName 24 | exists: exists 25 | containerAppsEnvironmentName: containerAppsEnvironmentName 26 | containerRegistryName: containerRegistryName 27 | env: [ 28 | { 29 | name: 'AZURE_CLIENT_ID' 30 | value: apiIdentity.properties.clientId 31 | } 32 | { 33 | name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' 34 | value: applicationInsights.properties.ConnectionString 35 | } 36 | ] 37 | targetPort: 80 38 | } 39 | } 40 | 41 | resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = { 42 | name: applicationInsightsName 43 | } 44 | 45 | output SERVICE_API_IDENTITY_PRINCIPAL_ID string = apiIdentity.properties.principalId 46 | output SERVICE_API_NAME string = app.outputs.name 47 | output SERVICE_API_URI string = app.outputs.uri 48 | output SERVICE_API_IMAGE_NAME string = app.outputs.imageName 49 | -------------------------------------------------------------------------------- /infra/core/host/container-app-upsert.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param location string = resourceGroup().location 3 | param tags object = {} 4 | 5 | param containerAppsEnvironmentName string 6 | param containerName string = 'main' 7 | param containerRegistryName string 8 | param secrets array = [] 9 | param env array = [] 10 | param external bool = true 11 | param targetPort int = 80 12 | param exists bool 13 | 14 | @description('User assigned identity name') 15 | param identityName string = '' 16 | 17 | @description('CPU cores allocated to a single container instance, e.g. 0.5') 18 | param containerCpuCoreCount string = '0.5' 19 | 20 | @description('Memory allocated to a single container instance, e.g. 1Gi') 21 | param containerMemory string = '1.0Gi' 22 | 23 | resource existingApp 'Microsoft.App/containerApps@2022-03-01' existing = if (exists) { 24 | name: name 25 | } 26 | 27 | module app 'container-app.bicep' = { 28 | name: '${deployment().name}-update' 29 | params: { 30 | name: name 31 | location: location 32 | tags: tags 33 | identityName: identityName 34 | containerName: containerName 35 | containerAppsEnvironmentName: containerAppsEnvironmentName 36 | containerRegistryName: containerRegistryName 37 | containerCpuCoreCount: containerCpuCoreCount 38 | containerMemory: containerMemory 39 | secrets: secrets 40 | external: external 41 | env: env 42 | imageName: exists ? existingApp.properties.template.containers[0].image : '' 43 | targetPort: targetPort 44 | } 45 | } 46 | 47 | output defaultDomain string = app.outputs.defaultDomain 48 | output imageName string = app.outputs.imageName 49 | output name string = app.outputs.name 50 | output uri string = app.outputs.uri 51 | -------------------------------------------------------------------------------- /infra/core/host/container-app.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param location string = resourceGroup().location 3 | param tags object = {} 4 | 5 | param containerAppsEnvironmentName string 6 | param containerName string = 'main' 7 | param containerRegistryName string 8 | param secrets array = [] 9 | param env array = [] 10 | param external bool = true 11 | param imageName string 12 | param targetPort int = 80 13 | 14 | @description('User assigned identity name') 15 | param identityName string = '' 16 | 17 | @description('CPU cores allocated to a single container instance, e.g. 0.5') 18 | param containerCpuCoreCount string = '0.5' 19 | 20 | @description('Memory allocated to a single container instance, e.g. 1Gi') 21 | param containerMemory string = '1.0Gi' 22 | 23 | resource userIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = { 24 | name: identityName 25 | } 26 | 27 | module containerRegistryAccess '../security/registry-access.bicep' = { 28 | name: '${deployment().name}-registry-access' 29 | params: { 30 | containerRegistryName: containerRegistryName 31 | principalId: userIdentity.properties.principalId 32 | } 33 | } 34 | 35 | resource app 'Microsoft.App/containerApps@2022-03-01' = { 36 | name: name 37 | location: location 38 | tags: tags 39 | // It is critical that the identity is granted ACR pull access before the app is created 40 | // otherwise the container app will throw a provision error 41 | // This also forces us to use an user assigned managed identity since there would no way to 42 | // provide the system assigned identity with the ACR pull access before the app is created 43 | dependsOn: [ containerRegistryAccess ] 44 | identity: { 45 | type: 'UserAssigned' 46 | userAssignedIdentities: { '${userIdentity.id}': {} } 47 | } 48 | properties: { 49 | managedEnvironmentId: containerAppsEnvironment.id 50 | configuration: { 51 | activeRevisionsMode: 'single' 52 | ingress: { 53 | external: external 54 | targetPort: targetPort 55 | transport: 'auto' 56 | } 57 | secrets: secrets 58 | registries: [ 59 | { 60 | server: '${containerRegistry.name}.azurecr.io' 61 | identity: userIdentity.id 62 | } 63 | ] 64 | } 65 | template: { 66 | containers: [ 67 | { 68 | image: !empty(imageName) ? imageName : 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest' 69 | name: containerName 70 | env: env 71 | resources: { 72 | cpu: json(containerCpuCoreCount) 73 | memory: containerMemory 74 | } 75 | } 76 | ] 77 | } 78 | } 79 | } 80 | 81 | resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' existing = { 82 | name: containerAppsEnvironmentName 83 | } 84 | 85 | // 2022-02-01-preview needed for anonymousPullEnabled 86 | resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' existing = { 87 | name: containerRegistryName 88 | } 89 | 90 | output defaultDomain string = containerAppsEnvironment.properties.defaultDomain 91 | output imageName string = imageName 92 | output name string = app.name 93 | output uri string = 'https://${app.properties.configuration.ingress.fqdn}' 94 | -------------------------------------------------------------------------------- /infra/core/host/container-apps-environment.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param location string = resourceGroup().location 3 | param tags object = {} 4 | 5 | param logAnalyticsWorkspaceName string 6 | 7 | resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' = { 8 | name: name 9 | location: location 10 | tags: tags 11 | properties: { 12 | appLogsConfiguration: { 13 | destination: 'log-analytics' 14 | logAnalyticsConfiguration: { 15 | customerId: logAnalyticsWorkspace.properties.customerId 16 | sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey 17 | } 18 | } 19 | } 20 | } 21 | 22 | resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = { 23 | name: logAnalyticsWorkspaceName 24 | } 25 | 26 | output defaultDomain string = containerAppsEnvironment.properties.defaultDomain 27 | output name string = containerAppsEnvironment.name 28 | -------------------------------------------------------------------------------- /infra/core/host/container-apps.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param location string = resourceGroup().location 3 | param tags object = {} 4 | 5 | param containerAppsEnvironmentName string 6 | param containerRegistryName string 7 | param logAnalyticsWorkspaceName string 8 | 9 | module containerAppsEnvironment 'container-apps-environment.bicep' = { 10 | name: '${name}-container-apps-environment' 11 | params: { 12 | name: containerAppsEnvironmentName 13 | location: location 14 | tags: tags 15 | logAnalyticsWorkspaceName: logAnalyticsWorkspaceName 16 | } 17 | } 18 | 19 | module containerRegistry 'container-registry.bicep' = { 20 | name: '${name}-container-registry' 21 | params: { 22 | name: containerRegistryName 23 | location: location 24 | tags: tags 25 | } 26 | } 27 | 28 | output defaultDomain string = containerAppsEnvironment.outputs.defaultDomain 29 | output environmentName string = containerAppsEnvironment.outputs.name 30 | output registryLoginServer string = containerRegistry.outputs.loginServer 31 | output registryName string = containerRegistry.outputs.name 32 | -------------------------------------------------------------------------------- /infra/core/host/container-registry.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param location string = resourceGroup().location 3 | param tags object = {} 4 | 5 | param adminUserEnabled bool = true 6 | param anonymousPullEnabled bool = false 7 | param dataEndpointEnabled bool = false 8 | param encryption object = { 9 | status: 'disabled' 10 | } 11 | param networkRuleBypassOptions string = 'AzureServices' 12 | param publicNetworkAccess string = 'Enabled' 13 | param sku object = { 14 | name: 'Basic' 15 | } 16 | param zoneRedundancy string = 'Disabled' 17 | 18 | @description('The log analytics workspace id used for logging & monitoring') 19 | param workspaceId string = '' 20 | 21 | // 2022-02-01-preview needed for anonymousPullEnabled 22 | resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' = { 23 | name: name 24 | location: location 25 | tags: tags 26 | sku: sku 27 | properties: { 28 | adminUserEnabled: adminUserEnabled 29 | anonymousPullEnabled: anonymousPullEnabled 30 | dataEndpointEnabled: dataEndpointEnabled 31 | encryption: encryption 32 | networkRuleBypassOptions: networkRuleBypassOptions 33 | publicNetworkAccess: publicNetworkAccess 34 | zoneRedundancy: zoneRedundancy 35 | } 36 | } 37 | 38 | // TODO: Update diagnostics to be its own module 39 | // Blocking issue: https://github.com/Azure/bicep/issues/622 40 | // Unable to pass in a `resource` scope or unable to use string interpolation in resource types 41 | resource diagnostics 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = if (!empty(workspaceId)) { 42 | name: 'registry-diagnostics' 43 | scope: containerRegistry 44 | properties: { 45 | workspaceId: workspaceId 46 | logs: [ 47 | { 48 | category: 'ContainerRegistryRepositoryEvents' 49 | enabled: true 50 | } 51 | { 52 | category: 'ContainerRegistryLoginEvents' 53 | enabled: true 54 | } 55 | ] 56 | metrics: [ 57 | { 58 | category: 'AllMetrics' 59 | enabled: true 60 | timeGrain: 'PT1M' 61 | } 62 | ] 63 | } 64 | } 65 | 66 | output loginServer string = containerRegistry.properties.loginServer 67 | output name string = containerRegistry.name 68 | -------------------------------------------------------------------------------- /infra/core/monitor/applicationinsights-dashboard.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param applicationInsightsName string 3 | param location string = resourceGroup().location 4 | param tags object = {} 5 | 6 | // 2020-09-01-preview because that is the latest valid version 7 | resource applicationInsightsDashboard 'Microsoft.Portal/dashboards@2020-09-01-preview' = { 8 | name: name 9 | location: location 10 | tags: tags 11 | properties: { 12 | lenses: [ 13 | { 14 | order: 0 15 | parts: [ 16 | { 17 | position: { 18 | x: 0 19 | y: 0 20 | colSpan: 2 21 | rowSpan: 1 22 | } 23 | metadata: { 24 | inputs: [ 25 | { 26 | name: 'id' 27 | value: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 28 | } 29 | { 30 | name: 'Version' 31 | value: '1.0' 32 | } 33 | ] 34 | #disable-next-line BCP036 35 | type: 'Extension/AppInsightsExtension/PartType/AspNetOverviewPinnedPart' 36 | asset: { 37 | idInputName: 'id' 38 | type: 'ApplicationInsights' 39 | } 40 | defaultMenuItemId: 'overview' 41 | } 42 | } 43 | { 44 | position: { 45 | x: 2 46 | y: 0 47 | colSpan: 1 48 | rowSpan: 1 49 | } 50 | metadata: { 51 | inputs: [ 52 | { 53 | name: 'ComponentId' 54 | value: { 55 | Name: applicationInsights.name 56 | SubscriptionId: subscription().subscriptionId 57 | ResourceGroup: resourceGroup().name 58 | } 59 | } 60 | { 61 | name: 'Version' 62 | value: '1.0' 63 | } 64 | ] 65 | #disable-next-line BCP036 66 | type: 'Extension/AppInsightsExtension/PartType/ProactiveDetectionAsyncPart' 67 | asset: { 68 | idInputName: 'ComponentId' 69 | type: 'ApplicationInsights' 70 | } 71 | defaultMenuItemId: 'ProactiveDetection' 72 | } 73 | } 74 | { 75 | position: { 76 | x: 3 77 | y: 0 78 | colSpan: 1 79 | rowSpan: 1 80 | } 81 | metadata: { 82 | inputs: [ 83 | { 84 | name: 'ComponentId' 85 | value: { 86 | Name: applicationInsights.name 87 | SubscriptionId: subscription().subscriptionId 88 | ResourceGroup: resourceGroup().name 89 | } 90 | } 91 | { 92 | name: 'ResourceId' 93 | value: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 94 | } 95 | ] 96 | #disable-next-line BCP036 97 | type: 'Extension/AppInsightsExtension/PartType/QuickPulseButtonSmallPart' 98 | asset: { 99 | idInputName: 'ComponentId' 100 | type: 'ApplicationInsights' 101 | } 102 | } 103 | } 104 | { 105 | position: { 106 | x: 4 107 | y: 0 108 | colSpan: 1 109 | rowSpan: 1 110 | } 111 | metadata: { 112 | inputs: [ 113 | { 114 | name: 'ComponentId' 115 | value: { 116 | Name: applicationInsights.name 117 | SubscriptionId: subscription().subscriptionId 118 | ResourceGroup: resourceGroup().name 119 | } 120 | } 121 | { 122 | name: 'TimeContext' 123 | value: { 124 | durationMs: 86400000 125 | endTime: null 126 | createdTime: '2018-05-04T01:20:33.345Z' 127 | isInitialTime: true 128 | grain: 1 129 | useDashboardTimeRange: false 130 | } 131 | } 132 | { 133 | name: 'Version' 134 | value: '1.0' 135 | } 136 | ] 137 | #disable-next-line BCP036 138 | type: 'Extension/AppInsightsExtension/PartType/AvailabilityNavButtonPart' 139 | asset: { 140 | idInputName: 'ComponentId' 141 | type: 'ApplicationInsights' 142 | } 143 | } 144 | } 145 | { 146 | position: { 147 | x: 5 148 | y: 0 149 | colSpan: 1 150 | rowSpan: 1 151 | } 152 | metadata: { 153 | inputs: [ 154 | { 155 | name: 'ComponentId' 156 | value: { 157 | Name: applicationInsights.name 158 | SubscriptionId: subscription().subscriptionId 159 | ResourceGroup: resourceGroup().name 160 | } 161 | } 162 | { 163 | name: 'TimeContext' 164 | value: { 165 | durationMs: 86400000 166 | endTime: null 167 | createdTime: '2018-05-08T18:47:35.237Z' 168 | isInitialTime: true 169 | grain: 1 170 | useDashboardTimeRange: false 171 | } 172 | } 173 | { 174 | name: 'ConfigurationId' 175 | value: '78ce933e-e864-4b05-a27b-71fd55a6afad' 176 | } 177 | ] 178 | #disable-next-line BCP036 179 | type: 'Extension/AppInsightsExtension/PartType/AppMapButtonPart' 180 | asset: { 181 | idInputName: 'ComponentId' 182 | type: 'ApplicationInsights' 183 | } 184 | } 185 | } 186 | { 187 | position: { 188 | x: 0 189 | y: 1 190 | colSpan: 3 191 | rowSpan: 1 192 | } 193 | metadata: { 194 | inputs: [] 195 | type: 'Extension/HubsExtension/PartType/MarkdownPart' 196 | settings: { 197 | content: { 198 | settings: { 199 | content: '# Usage' 200 | title: '' 201 | subtitle: '' 202 | } 203 | } 204 | } 205 | } 206 | } 207 | { 208 | position: { 209 | x: 3 210 | y: 1 211 | colSpan: 1 212 | rowSpan: 1 213 | } 214 | metadata: { 215 | inputs: [ 216 | { 217 | name: 'ComponentId' 218 | value: { 219 | Name: applicationInsights.name 220 | SubscriptionId: subscription().subscriptionId 221 | ResourceGroup: resourceGroup().name 222 | } 223 | } 224 | { 225 | name: 'TimeContext' 226 | value: { 227 | durationMs: 86400000 228 | endTime: null 229 | createdTime: '2018-05-04T01:22:35.782Z' 230 | isInitialTime: true 231 | grain: 1 232 | useDashboardTimeRange: false 233 | } 234 | } 235 | ] 236 | #disable-next-line BCP036 237 | type: 'Extension/AppInsightsExtension/PartType/UsageUsersOverviewPart' 238 | asset: { 239 | idInputName: 'ComponentId' 240 | type: 'ApplicationInsights' 241 | } 242 | } 243 | } 244 | { 245 | position: { 246 | x: 4 247 | y: 1 248 | colSpan: 3 249 | rowSpan: 1 250 | } 251 | metadata: { 252 | inputs: [] 253 | type: 'Extension/HubsExtension/PartType/MarkdownPart' 254 | settings: { 255 | content: { 256 | settings: { 257 | content: '# Reliability' 258 | title: '' 259 | subtitle: '' 260 | } 261 | } 262 | } 263 | } 264 | } 265 | { 266 | position: { 267 | x: 7 268 | y: 1 269 | colSpan: 1 270 | rowSpan: 1 271 | } 272 | metadata: { 273 | inputs: [ 274 | { 275 | name: 'ResourceId' 276 | value: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 277 | } 278 | { 279 | name: 'DataModel' 280 | value: { 281 | version: '1.0.0' 282 | timeContext: { 283 | durationMs: 86400000 284 | createdTime: '2018-05-04T23:42:40.072Z' 285 | isInitialTime: false 286 | grain: 1 287 | useDashboardTimeRange: false 288 | } 289 | } 290 | isOptional: true 291 | } 292 | { 293 | name: 'ConfigurationId' 294 | value: '8a02f7bf-ac0f-40e1-afe9-f0e72cfee77f' 295 | isOptional: true 296 | } 297 | ] 298 | #disable-next-line BCP036 299 | type: 'Extension/AppInsightsExtension/PartType/CuratedBladeFailuresPinnedPart' 300 | isAdapter: true 301 | asset: { 302 | idInputName: 'ResourceId' 303 | type: 'ApplicationInsights' 304 | } 305 | defaultMenuItemId: 'failures' 306 | } 307 | } 308 | { 309 | position: { 310 | x: 8 311 | y: 1 312 | colSpan: 3 313 | rowSpan: 1 314 | } 315 | metadata: { 316 | inputs: [] 317 | type: 'Extension/HubsExtension/PartType/MarkdownPart' 318 | settings: { 319 | content: { 320 | settings: { 321 | content: '# Responsiveness\r\n' 322 | title: '' 323 | subtitle: '' 324 | } 325 | } 326 | } 327 | } 328 | } 329 | { 330 | position: { 331 | x: 11 332 | y: 1 333 | colSpan: 1 334 | rowSpan: 1 335 | } 336 | metadata: { 337 | inputs: [ 338 | { 339 | name: 'ResourceId' 340 | value: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 341 | } 342 | { 343 | name: 'DataModel' 344 | value: { 345 | version: '1.0.0' 346 | timeContext: { 347 | durationMs: 86400000 348 | createdTime: '2018-05-04T23:43:37.804Z' 349 | isInitialTime: false 350 | grain: 1 351 | useDashboardTimeRange: false 352 | } 353 | } 354 | isOptional: true 355 | } 356 | { 357 | name: 'ConfigurationId' 358 | value: '2a8ede4f-2bee-4b9c-aed9-2db0e8a01865' 359 | isOptional: true 360 | } 361 | ] 362 | #disable-next-line BCP036 363 | type: 'Extension/AppInsightsExtension/PartType/CuratedBladePerformancePinnedPart' 364 | isAdapter: true 365 | asset: { 366 | idInputName: 'ResourceId' 367 | type: 'ApplicationInsights' 368 | } 369 | defaultMenuItemId: 'performance' 370 | } 371 | } 372 | { 373 | position: { 374 | x: 12 375 | y: 1 376 | colSpan: 3 377 | rowSpan: 1 378 | } 379 | metadata: { 380 | inputs: [] 381 | type: 'Extension/HubsExtension/PartType/MarkdownPart' 382 | settings: { 383 | content: { 384 | settings: { 385 | content: '# Browser' 386 | title: '' 387 | subtitle: '' 388 | } 389 | } 390 | } 391 | } 392 | } 393 | { 394 | position: { 395 | x: 15 396 | y: 1 397 | colSpan: 1 398 | rowSpan: 1 399 | } 400 | metadata: { 401 | inputs: [ 402 | { 403 | name: 'ComponentId' 404 | value: { 405 | Name: applicationInsights.name 406 | SubscriptionId: subscription().subscriptionId 407 | ResourceGroup: resourceGroup().name 408 | } 409 | } 410 | { 411 | name: 'MetricsExplorerJsonDefinitionId' 412 | value: 'BrowserPerformanceTimelineMetrics' 413 | } 414 | { 415 | name: 'TimeContext' 416 | value: { 417 | durationMs: 86400000 418 | createdTime: '2018-05-08T12:16:27.534Z' 419 | isInitialTime: false 420 | grain: 1 421 | useDashboardTimeRange: false 422 | } 423 | } 424 | { 425 | name: 'CurrentFilter' 426 | value: { 427 | eventTypes: [ 428 | 4 429 | 1 430 | 3 431 | 5 432 | 2 433 | 6 434 | 13 435 | ] 436 | typeFacets: {} 437 | isPermissive: false 438 | } 439 | } 440 | { 441 | name: 'id' 442 | value: { 443 | Name: applicationInsights.name 444 | SubscriptionId: subscription().subscriptionId 445 | ResourceGroup: resourceGroup().name 446 | } 447 | } 448 | { 449 | name: 'Version' 450 | value: '1.0' 451 | } 452 | ] 453 | #disable-next-line BCP036 454 | type: 'Extension/AppInsightsExtension/PartType/MetricsExplorerBladePinnedPart' 455 | asset: { 456 | idInputName: 'ComponentId' 457 | type: 'ApplicationInsights' 458 | } 459 | defaultMenuItemId: 'browser' 460 | } 461 | } 462 | { 463 | position: { 464 | x: 0 465 | y: 2 466 | colSpan: 4 467 | rowSpan: 3 468 | } 469 | metadata: { 470 | inputs: [ 471 | { 472 | name: 'options' 473 | value: { 474 | chart: { 475 | metrics: [ 476 | { 477 | resourceMetadata: { 478 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 479 | } 480 | name: 'sessions/count' 481 | aggregationType: 5 482 | namespace: 'microsoft.insights/components/kusto' 483 | metricVisualization: { 484 | displayName: 'Sessions' 485 | color: '#47BDF5' 486 | } 487 | } 488 | { 489 | resourceMetadata: { 490 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 491 | } 492 | name: 'users/count' 493 | aggregationType: 5 494 | namespace: 'microsoft.insights/components/kusto' 495 | metricVisualization: { 496 | displayName: 'Users' 497 | color: '#7E58FF' 498 | } 499 | } 500 | ] 501 | title: 'Unique sessions and users' 502 | visualization: { 503 | chartType: 2 504 | legendVisualization: { 505 | isVisible: true 506 | position: 2 507 | hideSubtitle: false 508 | } 509 | axisVisualization: { 510 | x: { 511 | isVisible: true 512 | axisType: 2 513 | } 514 | y: { 515 | isVisible: true 516 | axisType: 1 517 | } 518 | } 519 | } 520 | openBladeOnClick: { 521 | openBlade: true 522 | destinationBlade: { 523 | extensionName: 'HubsExtension' 524 | bladeName: 'ResourceMenuBlade' 525 | parameters: { 526 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 527 | menuid: 'segmentationUsers' 528 | } 529 | } 530 | } 531 | } 532 | } 533 | } 534 | { 535 | name: 'sharedTimeRange' 536 | isOptional: true 537 | } 538 | ] 539 | #disable-next-line BCP036 540 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 541 | settings: {} 542 | } 543 | } 544 | { 545 | position: { 546 | x: 4 547 | y: 2 548 | colSpan: 4 549 | rowSpan: 3 550 | } 551 | metadata: { 552 | inputs: [ 553 | { 554 | name: 'options' 555 | value: { 556 | chart: { 557 | metrics: [ 558 | { 559 | resourceMetadata: { 560 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 561 | } 562 | name: 'requests/failed' 563 | aggregationType: 7 564 | namespace: 'microsoft.insights/components' 565 | metricVisualization: { 566 | displayName: 'Failed requests' 567 | color: '#EC008C' 568 | } 569 | } 570 | ] 571 | title: 'Failed requests' 572 | visualization: { 573 | chartType: 3 574 | legendVisualization: { 575 | isVisible: true 576 | position: 2 577 | hideSubtitle: false 578 | } 579 | axisVisualization: { 580 | x: { 581 | isVisible: true 582 | axisType: 2 583 | } 584 | y: { 585 | isVisible: true 586 | axisType: 1 587 | } 588 | } 589 | } 590 | openBladeOnClick: { 591 | openBlade: true 592 | destinationBlade: { 593 | extensionName: 'HubsExtension' 594 | bladeName: 'ResourceMenuBlade' 595 | parameters: { 596 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 597 | menuid: 'failures' 598 | } 599 | } 600 | } 601 | } 602 | } 603 | } 604 | { 605 | name: 'sharedTimeRange' 606 | isOptional: true 607 | } 608 | ] 609 | #disable-next-line BCP036 610 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 611 | settings: {} 612 | } 613 | } 614 | { 615 | position: { 616 | x: 8 617 | y: 2 618 | colSpan: 4 619 | rowSpan: 3 620 | } 621 | metadata: { 622 | inputs: [ 623 | { 624 | name: 'options' 625 | value: { 626 | chart: { 627 | metrics: [ 628 | { 629 | resourceMetadata: { 630 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 631 | } 632 | name: 'requests/duration' 633 | aggregationType: 4 634 | namespace: 'microsoft.insights/components' 635 | metricVisualization: { 636 | displayName: 'Server response time' 637 | color: '#00BCF2' 638 | } 639 | } 640 | ] 641 | title: 'Server response time' 642 | visualization: { 643 | chartType: 2 644 | legendVisualization: { 645 | isVisible: true 646 | position: 2 647 | hideSubtitle: false 648 | } 649 | axisVisualization: { 650 | x: { 651 | isVisible: true 652 | axisType: 2 653 | } 654 | y: { 655 | isVisible: true 656 | axisType: 1 657 | } 658 | } 659 | } 660 | openBladeOnClick: { 661 | openBlade: true 662 | destinationBlade: { 663 | extensionName: 'HubsExtension' 664 | bladeName: 'ResourceMenuBlade' 665 | parameters: { 666 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 667 | menuid: 'performance' 668 | } 669 | } 670 | } 671 | } 672 | } 673 | } 674 | { 675 | name: 'sharedTimeRange' 676 | isOptional: true 677 | } 678 | ] 679 | #disable-next-line BCP036 680 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 681 | settings: {} 682 | } 683 | } 684 | { 685 | position: { 686 | x: 12 687 | y: 2 688 | colSpan: 4 689 | rowSpan: 3 690 | } 691 | metadata: { 692 | inputs: [ 693 | { 694 | name: 'options' 695 | value: { 696 | chart: { 697 | metrics: [ 698 | { 699 | resourceMetadata: { 700 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 701 | } 702 | name: 'browserTimings/networkDuration' 703 | aggregationType: 4 704 | namespace: 'microsoft.insights/components' 705 | metricVisualization: { 706 | displayName: 'Page load network connect time' 707 | color: '#7E58FF' 708 | } 709 | } 710 | { 711 | resourceMetadata: { 712 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 713 | } 714 | name: 'browserTimings/processingDuration' 715 | aggregationType: 4 716 | namespace: 'microsoft.insights/components' 717 | metricVisualization: { 718 | displayName: 'Client processing time' 719 | color: '#44F1C8' 720 | } 721 | } 722 | { 723 | resourceMetadata: { 724 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 725 | } 726 | name: 'browserTimings/sendDuration' 727 | aggregationType: 4 728 | namespace: 'microsoft.insights/components' 729 | metricVisualization: { 730 | displayName: 'Send request time' 731 | color: '#EB9371' 732 | } 733 | } 734 | { 735 | resourceMetadata: { 736 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 737 | } 738 | name: 'browserTimings/receiveDuration' 739 | aggregationType: 4 740 | namespace: 'microsoft.insights/components' 741 | metricVisualization: { 742 | displayName: 'Receiving response time' 743 | color: '#0672F1' 744 | } 745 | } 746 | ] 747 | title: 'Average page load time breakdown' 748 | visualization: { 749 | chartType: 3 750 | legendVisualization: { 751 | isVisible: true 752 | position: 2 753 | hideSubtitle: false 754 | } 755 | axisVisualization: { 756 | x: { 757 | isVisible: true 758 | axisType: 2 759 | } 760 | y: { 761 | isVisible: true 762 | axisType: 1 763 | } 764 | } 765 | } 766 | } 767 | } 768 | } 769 | { 770 | name: 'sharedTimeRange' 771 | isOptional: true 772 | } 773 | ] 774 | #disable-next-line BCP036 775 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 776 | settings: {} 777 | } 778 | } 779 | { 780 | position: { 781 | x: 0 782 | y: 5 783 | colSpan: 4 784 | rowSpan: 3 785 | } 786 | metadata: { 787 | inputs: [ 788 | { 789 | name: 'options' 790 | value: { 791 | chart: { 792 | metrics: [ 793 | { 794 | resourceMetadata: { 795 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 796 | } 797 | name: 'availabilityResults/availabilityPercentage' 798 | aggregationType: 4 799 | namespace: 'microsoft.insights/components' 800 | metricVisualization: { 801 | displayName: 'Availability' 802 | color: '#47BDF5' 803 | } 804 | } 805 | ] 806 | title: 'Average availability' 807 | visualization: { 808 | chartType: 3 809 | legendVisualization: { 810 | isVisible: true 811 | position: 2 812 | hideSubtitle: false 813 | } 814 | axisVisualization: { 815 | x: { 816 | isVisible: true 817 | axisType: 2 818 | } 819 | y: { 820 | isVisible: true 821 | axisType: 1 822 | } 823 | } 824 | } 825 | openBladeOnClick: { 826 | openBlade: true 827 | destinationBlade: { 828 | extensionName: 'HubsExtension' 829 | bladeName: 'ResourceMenuBlade' 830 | parameters: { 831 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 832 | menuid: 'availability' 833 | } 834 | } 835 | } 836 | } 837 | } 838 | } 839 | { 840 | name: 'sharedTimeRange' 841 | isOptional: true 842 | } 843 | ] 844 | #disable-next-line BCP036 845 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 846 | settings: {} 847 | } 848 | } 849 | { 850 | position: { 851 | x: 4 852 | y: 5 853 | colSpan: 4 854 | rowSpan: 3 855 | } 856 | metadata: { 857 | inputs: [ 858 | { 859 | name: 'options' 860 | value: { 861 | chart: { 862 | metrics: [ 863 | { 864 | resourceMetadata: { 865 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 866 | } 867 | name: 'exceptions/server' 868 | aggregationType: 7 869 | namespace: 'microsoft.insights/components' 870 | metricVisualization: { 871 | displayName: 'Server exceptions' 872 | color: '#47BDF5' 873 | } 874 | } 875 | { 876 | resourceMetadata: { 877 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 878 | } 879 | name: 'dependencies/failed' 880 | aggregationType: 7 881 | namespace: 'microsoft.insights/components' 882 | metricVisualization: { 883 | displayName: 'Dependency failures' 884 | color: '#7E58FF' 885 | } 886 | } 887 | ] 888 | title: 'Server exceptions and Dependency failures' 889 | visualization: { 890 | chartType: 2 891 | legendVisualization: { 892 | isVisible: true 893 | position: 2 894 | hideSubtitle: false 895 | } 896 | axisVisualization: { 897 | x: { 898 | isVisible: true 899 | axisType: 2 900 | } 901 | y: { 902 | isVisible: true 903 | axisType: 1 904 | } 905 | } 906 | } 907 | } 908 | } 909 | } 910 | { 911 | name: 'sharedTimeRange' 912 | isOptional: true 913 | } 914 | ] 915 | #disable-next-line BCP036 916 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 917 | settings: {} 918 | } 919 | } 920 | { 921 | position: { 922 | x: 8 923 | y: 5 924 | colSpan: 4 925 | rowSpan: 3 926 | } 927 | metadata: { 928 | inputs: [ 929 | { 930 | name: 'options' 931 | value: { 932 | chart: { 933 | metrics: [ 934 | { 935 | resourceMetadata: { 936 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 937 | } 938 | name: 'performanceCounters/processorCpuPercentage' 939 | aggregationType: 4 940 | namespace: 'microsoft.insights/components' 941 | metricVisualization: { 942 | displayName: 'Processor time' 943 | color: '#47BDF5' 944 | } 945 | } 946 | { 947 | resourceMetadata: { 948 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 949 | } 950 | name: 'performanceCounters/processCpuPercentage' 951 | aggregationType: 4 952 | namespace: 'microsoft.insights/components' 953 | metricVisualization: { 954 | displayName: 'Process CPU' 955 | color: '#7E58FF' 956 | } 957 | } 958 | ] 959 | title: 'Average processor and process CPU utilization' 960 | visualization: { 961 | chartType: 2 962 | legendVisualization: { 963 | isVisible: true 964 | position: 2 965 | hideSubtitle: false 966 | } 967 | axisVisualization: { 968 | x: { 969 | isVisible: true 970 | axisType: 2 971 | } 972 | y: { 973 | isVisible: true 974 | axisType: 1 975 | } 976 | } 977 | } 978 | } 979 | } 980 | } 981 | { 982 | name: 'sharedTimeRange' 983 | isOptional: true 984 | } 985 | ] 986 | #disable-next-line BCP036 987 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 988 | settings: {} 989 | } 990 | } 991 | { 992 | position: { 993 | x: 12 994 | y: 5 995 | colSpan: 4 996 | rowSpan: 3 997 | } 998 | metadata: { 999 | inputs: [ 1000 | { 1001 | name: 'options' 1002 | value: { 1003 | chart: { 1004 | metrics: [ 1005 | { 1006 | resourceMetadata: { 1007 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 1008 | } 1009 | name: 'exceptions/browser' 1010 | aggregationType: 7 1011 | namespace: 'microsoft.insights/components' 1012 | metricVisualization: { 1013 | displayName: 'Browser exceptions' 1014 | color: '#47BDF5' 1015 | } 1016 | } 1017 | ] 1018 | title: 'Browser exceptions' 1019 | visualization: { 1020 | chartType: 2 1021 | legendVisualization: { 1022 | isVisible: true 1023 | position: 2 1024 | hideSubtitle: false 1025 | } 1026 | axisVisualization: { 1027 | x: { 1028 | isVisible: true 1029 | axisType: 2 1030 | } 1031 | y: { 1032 | isVisible: true 1033 | axisType: 1 1034 | } 1035 | } 1036 | } 1037 | } 1038 | } 1039 | } 1040 | { 1041 | name: 'sharedTimeRange' 1042 | isOptional: true 1043 | } 1044 | ] 1045 | #disable-next-line BCP036 1046 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 1047 | settings: {} 1048 | } 1049 | } 1050 | { 1051 | position: { 1052 | x: 0 1053 | y: 8 1054 | colSpan: 4 1055 | rowSpan: 3 1056 | } 1057 | metadata: { 1058 | inputs: [ 1059 | { 1060 | name: 'options' 1061 | value: { 1062 | chart: { 1063 | metrics: [ 1064 | { 1065 | resourceMetadata: { 1066 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 1067 | } 1068 | name: 'availabilityResults/count' 1069 | aggregationType: 7 1070 | namespace: 'microsoft.insights/components' 1071 | metricVisualization: { 1072 | displayName: 'Availability test results count' 1073 | color: '#47BDF5' 1074 | } 1075 | } 1076 | ] 1077 | title: 'Availability test results count' 1078 | visualization: { 1079 | chartType: 2 1080 | legendVisualization: { 1081 | isVisible: true 1082 | position: 2 1083 | hideSubtitle: false 1084 | } 1085 | axisVisualization: { 1086 | x: { 1087 | isVisible: true 1088 | axisType: 2 1089 | } 1090 | y: { 1091 | isVisible: true 1092 | axisType: 1 1093 | } 1094 | } 1095 | } 1096 | } 1097 | } 1098 | } 1099 | { 1100 | name: 'sharedTimeRange' 1101 | isOptional: true 1102 | } 1103 | ] 1104 | #disable-next-line BCP036 1105 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 1106 | settings: {} 1107 | } 1108 | } 1109 | { 1110 | position: { 1111 | x: 4 1112 | y: 8 1113 | colSpan: 4 1114 | rowSpan: 3 1115 | } 1116 | metadata: { 1117 | inputs: [ 1118 | { 1119 | name: 'options' 1120 | value: { 1121 | chart: { 1122 | metrics: [ 1123 | { 1124 | resourceMetadata: { 1125 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 1126 | } 1127 | name: 'performanceCounters/processIOBytesPerSecond' 1128 | aggregationType: 4 1129 | namespace: 'microsoft.insights/components' 1130 | metricVisualization: { 1131 | displayName: 'Process IO rate' 1132 | color: '#47BDF5' 1133 | } 1134 | } 1135 | ] 1136 | title: 'Average process I/O rate' 1137 | visualization: { 1138 | chartType: 2 1139 | legendVisualization: { 1140 | isVisible: true 1141 | position: 2 1142 | hideSubtitle: false 1143 | } 1144 | axisVisualization: { 1145 | x: { 1146 | isVisible: true 1147 | axisType: 2 1148 | } 1149 | y: { 1150 | isVisible: true 1151 | axisType: 1 1152 | } 1153 | } 1154 | } 1155 | } 1156 | } 1157 | } 1158 | { 1159 | name: 'sharedTimeRange' 1160 | isOptional: true 1161 | } 1162 | ] 1163 | #disable-next-line BCP036 1164 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 1165 | settings: {} 1166 | } 1167 | } 1168 | { 1169 | position: { 1170 | x: 8 1171 | y: 8 1172 | colSpan: 4 1173 | rowSpan: 3 1174 | } 1175 | metadata: { 1176 | inputs: [ 1177 | { 1178 | name: 'options' 1179 | value: { 1180 | chart: { 1181 | metrics: [ 1182 | { 1183 | resourceMetadata: { 1184 | id: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Insights/components/${applicationInsights.name}' 1185 | } 1186 | name: 'performanceCounters/memoryAvailableBytes' 1187 | aggregationType: 4 1188 | namespace: 'microsoft.insights/components' 1189 | metricVisualization: { 1190 | displayName: 'Available memory' 1191 | color: '#47BDF5' 1192 | } 1193 | } 1194 | ] 1195 | title: 'Average available memory' 1196 | visualization: { 1197 | chartType: 2 1198 | legendVisualization: { 1199 | isVisible: true 1200 | position: 2 1201 | hideSubtitle: false 1202 | } 1203 | axisVisualization: { 1204 | x: { 1205 | isVisible: true 1206 | axisType: 2 1207 | } 1208 | y: { 1209 | isVisible: true 1210 | axisType: 1 1211 | } 1212 | } 1213 | } 1214 | } 1215 | } 1216 | } 1217 | { 1218 | name: 'sharedTimeRange' 1219 | isOptional: true 1220 | } 1221 | ] 1222 | #disable-next-line BCP036 1223 | type: 'Extension/HubsExtension/PartType/MonitorChartPart' 1224 | settings: {} 1225 | } 1226 | } 1227 | ] 1228 | } 1229 | ] 1230 | } 1231 | } 1232 | 1233 | resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = { 1234 | name: applicationInsightsName 1235 | } 1236 | -------------------------------------------------------------------------------- /infra/core/monitor/applicationinsights.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param dashboardName string 3 | param location string = resourceGroup().location 4 | param tags object = {} 5 | 6 | param logAnalyticsWorkspaceId string 7 | 8 | resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = { 9 | name: name 10 | location: location 11 | tags: tags 12 | kind: 'web' 13 | properties: { 14 | Application_Type: 'web' 15 | WorkspaceResourceId: logAnalyticsWorkspaceId 16 | } 17 | } 18 | 19 | module applicationInsightsDashboard 'applicationinsights-dashboard.bicep' = { 20 | name: 'application-insights-dashboard' 21 | params: { 22 | name: dashboardName 23 | location: location 24 | applicationInsightsName: applicationInsights.name 25 | } 26 | } 27 | 28 | output connectionString string = applicationInsights.properties.ConnectionString 29 | output instrumentationKey string = applicationInsights.properties.InstrumentationKey 30 | output name string = applicationInsights.name 31 | -------------------------------------------------------------------------------- /infra/core/monitor/loganalytics.bicep: -------------------------------------------------------------------------------- 1 | param name string 2 | param location string = resourceGroup().location 3 | param tags object = {} 4 | 5 | resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = { 6 | name: name 7 | location: location 8 | tags: tags 9 | properties: any({ 10 | retentionInDays: 30 11 | features: { 12 | searchVersion: 1 13 | } 14 | sku: { 15 | name: 'PerGB2018' 16 | } 17 | }) 18 | } 19 | 20 | output id string = logAnalytics.id 21 | output name string = logAnalytics.name 22 | -------------------------------------------------------------------------------- /infra/core/monitor/monitoring.bicep: -------------------------------------------------------------------------------- 1 | param logAnalyticsName string 2 | param applicationInsightsName string 3 | param applicationInsightsDashboardName string 4 | param location string = resourceGroup().location 5 | param tags object = {} 6 | 7 | module logAnalytics 'loganalytics.bicep' = { 8 | name: 'loganalytics' 9 | params: { 10 | name: logAnalyticsName 11 | location: location 12 | tags: tags 13 | } 14 | } 15 | 16 | module applicationInsights 'applicationinsights.bicep' = { 17 | name: 'applicationinsights' 18 | params: { 19 | name: applicationInsightsName 20 | location: location 21 | tags: tags 22 | dashboardName: applicationInsightsDashboardName 23 | logAnalyticsWorkspaceId: logAnalytics.outputs.id 24 | } 25 | } 26 | 27 | output applicationInsightsConnectionString string = applicationInsights.outputs.connectionString 28 | output applicationInsightsInstrumentationKey string = applicationInsights.outputs.instrumentationKey 29 | output applicationInsightsName string = applicationInsights.outputs.name 30 | output logAnalyticsWorkspaceId string = logAnalytics.outputs.id 31 | output logAnalyticsWorkspaceName string = logAnalytics.outputs.name 32 | -------------------------------------------------------------------------------- /infra/core/security/registry-access.bicep: -------------------------------------------------------------------------------- 1 | param containerRegistryName string 2 | param principalId string 3 | 4 | var acrPullRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') 5 | 6 | resource aksAcrPull 'Microsoft.Authorization/roleAssignments@2022-04-01' = { 7 | scope: containerRegistry // Use when specifying a scope that is different than the deployment scope 8 | name: guid(subscription().id, resourceGroup().id, principalId, acrPullRole) 9 | properties: { 10 | roleDefinitionId: acrPullRole 11 | principalType: 'ServicePrincipal' 12 | principalId: principalId 13 | } 14 | } 15 | 16 | resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' existing = { 17 | name: containerRegistryName 18 | } 19 | -------------------------------------------------------------------------------- /infra/main.bicep: -------------------------------------------------------------------------------- 1 | targetScope = 'subscription' 2 | 3 | @minLength(1) 4 | @maxLength(64) 5 | @description('Name of the the environment which is used to generate a short unique hash used in all resources.') 6 | param environmentName string 7 | 8 | @minLength(1) 9 | @description('Primary location for all resources') 10 | param location string 11 | 12 | param resourceGroupName string = '' 13 | param containerAppsEnvironmentName string = '' 14 | param containerRegistryName string = '' 15 | param apiContainerAppName string = '' 16 | param applicationInsightsDashboardName string = '' 17 | param applicationInsightsName string = '' 18 | param logAnalyticsName string = '' 19 | 20 | param apiAppExists bool = false 21 | 22 | @description('Id of the user or app to assign application roles') 23 | param principalId string = '' 24 | 25 | var abbrs = loadJsonContent('./abbreviations.json') 26 | var resourceToken = toLower(uniqueString(subscription().id, environmentName, location)) 27 | var tags = { 'azd-env-name': environmentName } 28 | 29 | // Organize resources in a resource group 30 | resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = { 31 | name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}' 32 | location: location 33 | tags: tags 34 | } 35 | 36 | // Container apps host (including container registry) 37 | module containerApps './core/host/container-apps.bicep' = { 38 | name: 'container-apps' 39 | scope: resourceGroup 40 | params: { 41 | name: 'app' 42 | containerAppsEnvironmentName: !empty(containerAppsEnvironmentName) ? containerAppsEnvironmentName : '${abbrs.appManagedEnvironments}${resourceToken}' 43 | containerRegistryName: !empty(containerRegistryName) ? containerRegistryName : '${abbrs.containerRegistryRegistries}${resourceToken}' 44 | location: location 45 | logAnalyticsWorkspaceName: monitoring.outputs.logAnalyticsWorkspaceName 46 | } 47 | } 48 | 49 | // API 50 | module api './app/api.bicep' = { 51 | name: 'api' 52 | scope: resourceGroup 53 | params: { 54 | name: !empty(apiContainerAppName) ? apiContainerAppName : '${abbrs.appContainerApps}api-${resourceToken}' 55 | location: location 56 | tags: tags 57 | identityName: '${abbrs.managedIdentityUserAssignedIdentities}api-${resourceToken}' 58 | applicationInsightsName: monitoring.outputs.applicationInsightsName 59 | containerAppsEnvironmentName: containerApps.outputs.environmentName 60 | containerRegistryName: containerApps.outputs.registryName 61 | exists: apiAppExists 62 | } 63 | } 64 | 65 | // Monitor application with Azure Monitor 66 | module monitoring './core/monitor/monitoring.bicep' = { 67 | name: 'monitoring' 68 | scope: resourceGroup 69 | params: { 70 | location: location 71 | tags: tags 72 | logAnalyticsName: !empty(logAnalyticsName) ? logAnalyticsName : '${abbrs.operationalInsightsWorkspaces}${resourceToken}' 73 | applicationInsightsName: !empty(applicationInsightsName) ? applicationInsightsName : '${abbrs.insightsComponents}${resourceToken}' 74 | applicationInsightsDashboardName: !empty(applicationInsightsDashboardName) ? applicationInsightsDashboardName : '${abbrs.portalDashboards}${resourceToken}' 75 | } 76 | } 77 | 78 | output AZURE_LOCATION string = location 79 | output AZURE_TENANT_ID string = tenant().tenantId 80 | output AZURE_RESOURCE_GROUP string = resourceGroup.name 81 | 82 | output APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString 83 | output APPLICATIONINSIGHTS_NAME string = monitoring.outputs.applicationInsightsName 84 | output AZURE_CONTAINER_ENVIRONMENT_NAME string = containerApps.outputs.environmentName 85 | output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerApps.outputs.registryLoginServer 86 | output AZURE_CONTAINER_REGISTRY_NAME string = containerApps.outputs.registryName 87 | output SERVICE_API_NAME string = api.outputs.SERVICE_API_NAME 88 | -------------------------------------------------------------------------------- /infra/main.parameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "environmentName": { 6 | "value": "${AZURE_ENV_NAME}" 7 | }, 8 | "location": { 9 | "value": "${AZURE_LOCATION}" 10 | }, 11 | "principalId": { 12 | "value": "${AZURE_PRINCIPAL_ID}" 13 | }, 14 | "apiAppExists": { 15 | "value": "${SERVICE_API_RESOURCE_EXISTS=true}" 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/bin 15 | **/charts 16 | **/docker-compose* 17 | **/compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | **/infra 25 | LICENSE 26 | README.md 27 | -------------------------------------------------------------------------------- /src/ContosoProductsAPI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | preview 8 | cbae6d3f-49bf-4a7f-8581-0052b3c293d2 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/ContosoProductsAPI.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.33723.381 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContosoProductsAPI", "ContosoProductsAPI.csproj", "{EA2DBEAC-0DC3-45BE-BDB8-F6A9EA2D4EA7}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A6D07A73-E880-455D-8282-8350A5336414}" 9 | ProjectSection(SolutionItems) = preProject 10 | ..\README.md = ..\README.md 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {EA2DBEAC-0DC3-45BE-BDB8-F6A9EA2D4EA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {EA2DBEAC-0DC3-45BE-BDB8-F6A9EA2D4EA7}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {EA2DBEAC-0DC3-45BE-BDB8-F6A9EA2D4EA7}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {EA2DBEAC-0DC3-45BE-BDB8-F6A9EA2D4EA7}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {693203EA-3BF0-4078-8B1D-EAA99BAC5D72} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /src/Data/products.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Contoso Climbing Shoes", 4 | "description": "High-performance climbing shoes for advanced climbers", 5 | "category": "Climbing", 6 | "size": "8", 7 | "price": 149.99 8 | }, 9 | { 10 | "name": "Contoso Hiking Boots", 11 | "description": "Durable hiking boots for all-day comfort on the trails", 12 | "category": "Hiking", 13 | "size": "10", 14 | "price": 129.99 15 | }, 16 | { 17 | "name": "Contoso Climbing Rope", 18 | "description": "Dynamic climbing rope for lead climbing and top roping", 19 | "category": "Climbing", 20 | "size": "60m", 21 | "price": 199.99 22 | }, 23 | { 24 | "name": "Contoso Hiking Backpack", 25 | "description": "Lightweight backpack with ample storage for day hikes", 26 | "category": "Hiking", 27 | "size": "One Size", 28 | "price": 79.99 29 | }, 30 | { 31 | "name": "Contoso Climbing Harness", 32 | "description": "Comfortable and adjustable harness for all types of climbing", 33 | "category": "Climbing", 34 | "size": "Medium", 35 | "price": 89.99 36 | }, 37 | { 38 | "name": "Contoso Hiking Poles", 39 | "description": "Collapsible hiking poles for added stability on the trails", 40 | "category": "Hiking", 41 | "size": "One Size", 42 | "price": 49.99 43 | }, 44 | { 45 | "name": "Contoso Climbing Chalk Bag", 46 | "description": "Durable chalk bag with a drawstring closure for easy access", 47 | "category": "Climbing", 48 | "size": "One Size", 49 | "price": 24.99 50 | }, 51 | { 52 | "name": "Contoso Hiking Hat", 53 | "description": "Breathable and moisture-wicking hat for sunny hikes", 54 | "category": "Hiking", 55 | "size": "One Size", 56 | "price": 19.99 57 | }, 58 | { 59 | "name": "Contoso Climbing Quickdraws", 60 | "description": "Set of 6 quickdraws for sport climbing and trad climbing", 61 | "category": "Climbing", 62 | "size": "One Size", 63 | "price": 119.99 64 | }, 65 | { 66 | "name": "Contoso Hiking Jacket", 67 | "description": "Waterproof and breathable jacket for rainy hikes", 68 | "category": "Hiking", 69 | "size": "Large", 70 | "price": 149.99 71 | }, 72 | { 73 | "name": "Contoso Climbing Helmet", 74 | "description": "Lightweight and durable helmet for rock climbing and mountaineering", 75 | "category": "Climbing", 76 | "size": "Medium", 77 | "price": 99.99 78 | }, 79 | { 80 | "name": "Contoso Hiking Pants", 81 | "description": "Quick-drying and stretchy pants for hiking and backpacking", 82 | "category": "Hiking", 83 | "size": "Small", 84 | "price": 69.99 85 | }, 86 | { 87 | "name": "Contoso Climbing Carabiners", 88 | "description": "Set of 10 carabiners for climbing and rappelling", 89 | "category": "Climbing", 90 | "size": "One Size", 91 | "price": 79.99 92 | }, 93 | { 94 | "name": "Contoso Hiking Socks", 95 | "description": "Moisture-wicking and cushioned socks for long hikes", 96 | "category": "Hiking", 97 | "size": "Medium", 98 | "price": 14.99 99 | }, 100 | { 101 | "name": "Contoso Climbing Pulley", 102 | "description": "Durable and lightweight pulley for hauling gear on big walls", 103 | "category": "Climbing", 104 | "size": "One Size", 105 | "price": 39.99 106 | }, 107 | { 108 | "name": "Contoso Hiking Water Bottle", 109 | "description": "Stainless steel water bottle with a carabiner clip for easy carrying", 110 | "category": "Hiking", 111 | "size": "20 oz", 112 | "price": 24.99 113 | }, 114 | { 115 | "name": "Contoso Climbing Slings", 116 | "description": "Set of 3 slings for building anchors and extending placements", 117 | "category": "Climbing", 118 | "size": "One Size", 119 | "price": 29.99 120 | }, 121 | { 122 | "name": "Contoso Hiking GPS", 123 | "description": "Handheld GPS device with preloaded maps for navigation on the trails", 124 | "category": "Hiking", 125 | "size": "One Size", 126 | "price": 199.99 127 | }, 128 | { 129 | "name": "Contoso Climbing Nut Tool", 130 | "description": "Multi-functional tool for removing stuck nuts and cleaning gear", 131 | "category": "Climbing", 132 | "size": "One Size", 133 | "price": 19.99 134 | }, 135 | { 136 | "name": "Contoso Hiking Headlamp", 137 | "description": "Lightweight and rechargeable headlamp for night hikes and camping", 138 | "category": "Hiking", 139 | "size": "One Size", 140 | "price": 49.99 141 | }, 142 | { 143 | "name": "Contoso Climbing Anchor Kit", 144 | "description": "Complete kit for building anchors on multi-pitch climbs", 145 | "category": "Climbing", 146 | "size": "One Size", 147 | "price": 299.99 148 | }, 149 | { 150 | "name": "Contoso Hiking Sleeping Bag", 151 | "description": "Lightweight and compressible sleeping bag for backpacking", 152 | "category": "Hiking", 153 | "size": "Regular", 154 | "price": 199.99 155 | }, 156 | { 157 | "name": "Contoso Climbing Camalot", 158 | "description": "Durable and versatile camming device for rock climbing", 159 | "category": "Climbing", 160 | "size": "Size 2", 161 | "price": 89.99 162 | }, 163 | { 164 | "name": "Contoso Hiking Tent", 165 | "description": "Lightweight and waterproof tent for backpacking and camping", 166 | "category": "Hiking", 167 | "size": "2-Person", 168 | "price": 299.99 169 | }, 170 | { 171 | "name": "Contoso Climbing Nut", 172 | "description": "Durable and lightweight nut for passive protection on trad climbs", 173 | "category": "Climbing", 174 | "size": "Size 5", 175 | "price": 14.99 176 | }, 177 | { 178 | "name": "Contoso Hiking Stove", 179 | "description": "Compact and efficient stove for cooking meals on the trail", 180 | "category": "Hiking", 181 | "size": "One Size", 182 | "price": 79.99 183 | }, 184 | { 185 | "name": "Contoso Climbing Ascender", 186 | "description": "Mechanical ascender for ascending ropes on big walls and aid climbs", 187 | "category": "Climbing", 188 | "size": "One Size", 189 | "price": 129.99 190 | }, 191 | { 192 | "name": "Contoso Hiking Gaiters", 193 | "description": "Waterproof and breathable gaiters for keeping debris out of your boots", 194 | "category": "Hiking", 195 | "size": "Medium", 196 | "price": 39.99 197 | }, 198 | { 199 | "name": "Contoso Climbing Hex", 200 | "description": "Durable and versatile hex for passive protection on trad climbs", 201 | "category": "Climbing", 202 | "size": "Size 4", 203 | "price": 24.99 204 | }, 205 | { 206 | "name": "Contoso Hiking Compass", 207 | "description": "Compact and accurate compass for navigation on the trails", 208 | "category": "Hiking", 209 | "size": "One Size", 210 | "price": 9.99 211 | }, 212 | { 213 | "name": "Contoso Climbing Cams", 214 | "description": "Set of 3 camming devices for rock climbing and aid climbing", 215 | "category": "Climbing", 216 | "size": "Sizes 1-3", 217 | "price": 299.99 218 | }, 219 | { 220 | "name": "Contoso Hiking First Aid Kit", 221 | "description": "Compact and comprehensive first aid kit for emergencies on the trails", 222 | "category": "Hiking", 223 | "size": "One Size", 224 | "price": 49.99 225 | }, 226 | { 227 | "name": "Contoso Climbing Piton", 228 | "description": "Durable and versatile piton for aid climbing and big wall climbing", 229 | "category": "Climbing", 230 | "size": "Size 2", 231 | "price": 19.99 232 | }, 233 | { 234 | "name": "Contoso Hiking Sunscreen", 235 | "description": "Water-resistant and sweat-resistant sunscreen for sunny hikes", 236 | "category": "Hiking", 237 | "size": "3 oz", 238 | "price": 14.99 239 | }, 240 | { 241 | "name": "Contoso Climbing Pullover", 242 | "description": "Warm and breathable pullover for chilly days at the crag", 243 | "category": "Climbing", 244 | "size": "Large", 245 | "price": 79.99 246 | }, 247 | { 248 | "name": "Contoso Hiking Map", 249 | "description": "Waterproof and tear-resistant map for navigation on the trails", 250 | "category": "Hiking", 251 | "size": "One Size", 252 | "price": 9.99 253 | }, 254 | { 255 | "name": "Contoso Climbing Nut Tool Set", 256 | "description": "Set of 3 multi-functional nut tools for removing stuck nuts and cleaning gear", 257 | "category": "Climbing", 258 | "size": "One Size", 259 | "price": 49.99 260 | }, 261 | { 262 | "name": "Contoso Hiking Insoles", 263 | "description": "Cushioned and supportive insoles for all-day comfort on the trails", 264 | "category": "Hiking", 265 | "size": "Medium", 266 | "price": 29.99 267 | }, 268 | { 269 | "name": "Contoso Climbing Rope Bag", 270 | "description": "Durable and spacious bag for storing and transporting climbing ropes", 271 | "category": "Climbing", 272 | "size": "One Size", 273 | "price": 59.99 274 | }, 275 | { 276 | "name": "Contoso Hiking Rain Poncho", 277 | "description": "Lightweight and waterproof poncho for unexpected rain on the trails", 278 | "category": "Hiking", 279 | "size": "One Size", 280 | "price": 29.99 281 | }, 282 | { 283 | "name": "Contoso Climbing Anchor Cord", 284 | "description": "Durable and static cord for building anchors on multi-pitch climbs", 285 | "category": "Climbing", 286 | "size": "60m", 287 | "price": 99.99 288 | }, 289 | { 290 | "name": "Contoso Hiking Bug Spray", 291 | "description": "DEET-free bug spray for repelling mosquitoes and ticks on the trails", 292 | "category": "Hiking", 293 | "size": "4 oz", 294 | "price": 12.99 295 | }, 296 | { 297 | "name": "Contoso Climbing Nut Set", 298 | "description": "Set of 6 passive nuts for trad climbing and aid climbing", 299 | "category": "Climbing", 300 | "size": "Sizes 1-6", 301 | "price": 99.99 302 | }, 303 | { 304 | "name": "Contoso Hiking Multitool", 305 | "description": "Compact and versatile multitool for repairs and emergencies on the trails", 306 | "category": "Hiking", 307 | "size": "One Size", 308 | "price": 39.99 309 | }, 310 | { 311 | "name": "Contoso Climbing Anchor Webbing", 312 | "description": "Durable and versatile webbing for building anchors on multi-pitch climbs", 313 | "category": "Climbing", 314 | "size": "30ft", 315 | "price": 49.99 316 | }, 317 | { 318 | "name": "Contoso Hiking Sunglasses", 319 | "description": "Polarized and UV-resistant sunglasses for sunny hikes", 320 | "category": "Hiking", 321 | "size": "One Size", 322 | "price": 59.99 323 | }, 324 | { 325 | "name": "Contoso Climbing Nut Tool Holster", 326 | "description": "Durable and adjustable holster for carrying a nut tool on your harness", 327 | "category": "Climbing", 328 | "size": "One Size", 329 | "price": 14.99 330 | }, 331 | { 332 | "name": "Contoso Hiking Camp Stove", 333 | "description": "Compact and efficient camp stove for cooking meals at the campsite", 334 | "category": "Hiking", 335 | "size": "One Size", 336 | "price": 99.99 337 | }, 338 | { 339 | "name": "Contoso Climbing Carabiner Set", 340 | "description": "Set of 10 locking carabiners for building anchors and rappelling", 341 | "category": "Climbing", 342 | "size": "One Size", 343 | "price": 149.99 344 | }, 345 | { 346 | "name": "Contoso Hiking Sleeping Pad", 347 | "description": "Lightweight and inflatable sleeping pad for backpacking", 348 | "category": "Hiking", 349 | "size": "Regular", 350 | "price": 99.99 351 | }, 352 | { 353 | "name": "Contoso Climbing Nut Tool Leash", 354 | "description": "Durable and adjustable leash for securing a nut tool to your harness", 355 | "category": "Climbing", 356 | "size": "One Size", 357 | "price": 9.99 358 | }, 359 | { 360 | "name": "Contoso Hiking Trekking Poles", 361 | "description": "Collapsible and adjustable trekking poles for added stability on the trails", 362 | "category": "Hiking", 363 | "size": "One Size", 364 | "price": 69.99 365 | }, 366 | { 367 | "name": "Contoso Climbing Anchor Hanger", 368 | "description": "Durable and versatile hanger for building anchors on multi-pitch climbs", 369 | "category": "Climbing", 370 | "size": "One Size", 371 | "price": 19.99 372 | }, 373 | { 374 | "name": "Contoso Hiking Water Filter", 375 | "description": "Compact and efficient water filter for purifying water on the trails", 376 | "category": "Hiking", 377 | "size": "One Size", 378 | "price": 79.99 379 | }, 380 | { 381 | "name": "Contoso Climbing Nut Tool Kit", 382 | "description": "Complete kit for removing stuck nuts and cleaning gear on trad climbs", 383 | "category": "Climbing", 384 | "size": "One Size", 385 | "price": 79.99 386 | }, 387 | { 388 | "name": "Contoso Hiking Camp Chair", 389 | "description": "Lightweight and portable camp chair for relaxing at the campsite", 390 | "category": "Hiking", 391 | "size": "One Size", 392 | "price": 49.99 393 | }, 394 | { 395 | "name": "Contoso Climbing Anchor Bolt", 396 | "description": "Durable and versatile bolt for building anchors on multi-pitch climbs", 397 | "category": "Climbing", 398 | "size": "3/8in", 399 | "price": 4.99 400 | }, 401 | { 402 | "name": "Contoso Hiking Camp Table", 403 | "description": "Lightweight and portable camp table for cooking and eating at the campsite", 404 | "category": "Hiking", 405 | "size": "One Size", 406 | "price": 99.99 407 | }, 408 | { 409 | "name": "Contoso Climbing Anchor Nut", 410 | "description": "Durable and versatile nut for building anchors on multi-pitch climbs", 411 | "category": "Climbing", 412 | "size": "Size 3", 413 | "price": 9.99 414 | }, 415 | { 416 | "name": "Contoso Hiking Camp Lantern", 417 | "description": "Compact and rechargeable camp lantern for lighting up the campsite", 418 | "category": "Hiking", 419 | "size": "One Size", 420 | "price": 29.99 421 | }, 422 | { 423 | "name": "Contoso Climbing Anchor Bolt Hanger", 424 | "description": "Durable and versatile hanger for attaching bolts to anchors on multi-pitch climbs", 425 | "category": "Climbing", 426 | "size": "One Size", 427 | "price": 14.99 428 | }, 429 | { 430 | "name": "Contoso Hiking Camp Cookware Set", 431 | "description": "Compact and lightweight cookware set for cooking meals at the campsite", 432 | "category": "Hiking", 433 | "size": "One Size", 434 | "price": 59.99 435 | }, 436 | { 437 | "name": "Contoso Climbing Anchor Bolt Nut", 438 | "description": "Durable and versatile nut for attaching bolts to anchors on multi-pitch climbs", 439 | "category": "Climbing", 440 | "size": "3/8in", 441 | "price": 2.99 442 | } 443 | ] 444 | -------------------------------------------------------------------------------- /src/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base 2 | WORKDIR /app 3 | EXPOSE 80 4 | EXPOSE 443 5 | 6 | FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build 7 | WORKDIR /src 8 | COPY ["ContosoProductsAPI.csproj", "."] 9 | RUN dotnet restore "./ContosoProductsAPI.csproj" 10 | COPY . . 11 | WORKDIR "/src/." 12 | RUN dotnet build "ContosoProductsAPI.csproj" -c Release -o /app/build 13 | 14 | FROM build AS publish 15 | RUN dotnet publish "ContosoProductsAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false /p:PublishIISAssets=false 16 | 17 | FROM base AS final 18 | WORKDIR /app 19 | COPY --from=publish /app/publish . 20 | ENTRYPOINT ["dotnet", "ContosoProductsAPI.dll"] 21 | -------------------------------------------------------------------------------- /src/Model/Product.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | public class Product 4 | { 5 | [JsonPropertyName("name")] 6 | public string? Name { get; set; } 7 | [JsonPropertyName("description")] 8 | public string? Description { get; set; } 9 | [JsonPropertyName("category")] 10 | public string? Category { get; set; } 11 | [JsonPropertyName("size")] 12 | public string? Size { get; set; } 13 | [JsonPropertyName("price")] 14 | public float Price { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | 3 | // get some fake data 4 | var products = JsonSerializer.Deserialize>(File.ReadAllText("./Data/products.json")); 5 | 6 | var builder = WebApplication.CreateBuilder(args); 7 | 8 | builder.Services.AddEndpointsApiExplorer(); 9 | builder.Services.AddSwaggerGen(c => 10 | { 11 | c.SwaggerDoc("v1", new() { Title = "Contoso Product Search", Version = "v1", Description = "Search through Contoso's wide range of outdoor and recreational products." }); 12 | }); 13 | 14 | // For certain scenarios to work with OpenAI, CORS needs to be enabled per documentation here: https://beta.openai.com/docs/developer-quickstart/your-first-api-request 15 | builder.Services.AddCors(options => 16 | { 17 | options.AddPolicy("OpenAI", policy => 18 | { 19 | policy.WithOrigins("https://chat.openai.com"); 20 | policy.AllowAnyHeader(); 21 | policy.AllowAnyMethod(); 22 | }); 23 | }); 24 | 25 | builder.Services.AddAiPluginGen(options => 26 | { 27 | options.NameForHuman = "Contoso Product Search"; 28 | options.NameForModel = "contosoproducts"; 29 | options.LegalInfoUrl = "https://www.microsoft.com/en-us/legal/"; 30 | options.ContactEmail = "noreply@microsoft.com"; 31 | options.RelativeLogoUrl = "/logo.png"; 32 | options.DescriptionForHuman = "Search through Contoso's wide range of outdoor and recreational products."; 33 | options.DescriptionForModel = "Plugin for searching through Contoso's outdoor and recreational products. Use it whenever a user asks about products or activities related to camping, hiking, climbing or camping."; 34 | options.ApiDefinition = new() { RelativeUrl = "/swagger/v1/swagger.yaml" }; 35 | }); 36 | 37 | var app = builder.Build(); 38 | 39 | app.UseCors("OpenAI"); 40 | 41 | // Static files here are being used only to serve the logo.png 42 | // This can be served from anywhere (CDN, blob storage, etc.) and if so, this can be removed. 43 | app.UseStaticFiles(); 44 | 45 | // This ensures the OpenAPI definition is served for the plugin 46 | app.UseSwagger(); 47 | 48 | app.UseAiPluginGen(); 49 | 50 | if (app.Environment.IsDevelopment()) 51 | { 52 | app.UseSwaggerUI(); 53 | } 54 | 55 | app.UseHttpsRedirection(); 56 | 57 | app.MapGet("/products", (string? query = null) => 58 | { 59 | if (query is not null) { 60 | return products?.Where(p => p.Name?.Contains(query, StringComparison.OrdinalIgnoreCase) == true || 61 | p.Description?.Contains(query, StringComparison.OrdinalIgnoreCase) == true || 62 | p.Category?.Contains(query, StringComparison.OrdinalIgnoreCase) == true); 63 | } 64 | 65 | return products; 66 | }) 67 | .WithName("GetProducts") 68 | .WithDescription("Get a list of products") 69 | .WithOpenApi(); 70 | 71 | app.Run(); 72 | -------------------------------------------------------------------------------- /src/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:36257", 8 | "sslPort": 44321 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5264", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7070;http://localhost:5264", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /src/wwwroot/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timheuer/openai-plugin-aspnetcore/d408096cf2ac860591837793d39b0ceba8128597/src/wwwroot/logo.png --------------------------------------------------------------------------------