Skip to content

Commit

Permalink
Merge pull request #29 from NatVanG/AsAzureFunction
Browse files Browse the repository at this point in the history
Azure function
  • Loading branch information
NatVanG authored Feb 25, 2024
2 parents baead10 + 5f1bdac commit 963a829
Show file tree
Hide file tree
Showing 26 changed files with 1,163 additions and 177 deletions.
6 changes: 6 additions & 0 deletions PBIXInspector.sln
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BaseThemes", "BaseThemes",
DocsExamples\ReportExample\PBI Inspector Reporting.Report\StaticResources\SharedResources\BaseThemes\CY23SU11.json = DocsExamples\ReportExample\PBI Inspector Reporting.Report\StaticResources\SharedResources\BaseThemes\CY23SU11.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PBIXInspectorAzureFunctions", "PBIXInspectorAzureFunctions\PBIXInspectorAzureFunctions.csproj", "{B6F334C7-0E39-487E-83D9-76430CCA80B4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -111,6 +113,10 @@ Global
{2EFEF6B8-E017-4D14-9F30-DCD093CB85CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EFEF6B8-E017-4D14-9F30-DCD093CB85CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EFEF6B8-E017-4D14-9F30-DCD093CB85CD}.Release|Any CPU.Build.0 = Release|Any CPU
{B6F334C7-0E39-487E-83D9-76430CCA80B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6F334C7-0E39-487E-83D9-76430CCA80B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6F334C7-0E39-487E-83D9-76430CCA80B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6F334C7-0E39-487E-83D9-76430CCA80B4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
264 changes: 264 additions & 0 deletions PBIXInspectorAzureFunctions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# Azure Functions localsettings file
local.settings.json

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
project.fragment.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe
paket-files/

# FAKE - F# Make
.fake/

# JetBrains Rider
.idea/
*.sln.iml

# CodeRush
.cr/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
24 changes: 24 additions & 0 deletions PBIXInspectorAzureFunctions/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["PBIXInspectorAzureFunctions/PBIXInspectorAzureFunctions.csproj", "PBIXInspectorAzureFunctions/"]
RUN dotnet restore "./PBIXInspectorAzureFunctions/./PBIXInspectorAzureFunctions.csproj"
COPY . .
WORKDIR "/src/PBIXInspectorAzureFunctions"
RUN dotnet build "./PBIXInspectorAzureFunctions.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./PBIXInspectorAzureFunctions.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
69 changes: 69 additions & 0 deletions PBIXInspectorAzureFunctions/Inspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Azure.Storage.Blobs;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PBIXInspectorLibrary;
using PBIXInspectorLibrary.Output;
using System.Reflection.Metadata;
using System.Text.Json;
using System.Threading.Tasks;

namespace PBIXInspectorAzureFunctions
{
public static class Inspect
{
/// <summary>
/// Azure function that inspect a report layout json files for compliance with the rules defined in the supplied Rules.json file
/// </summary>
/// <param name="reportDefinitionTrigger">The Azure function blob trigger</param>
/// <param name="rulesInput">The rules file</param>
/// <param name="context">The Azure Function context e.g. to retrieve the logger instance</param>
/// <returns>A json string with the test results</returns>
/// TODO: Add support for multiple rules files
[Function(nameof(Inspect))]
[BlobOutput("pbi-inspector-output/{name}")]
public static string Run(
[BlobTrigger("pbi-report-definitions/{name}")] BlobClient reportDefinitionTriggerClient,
[BlobInput("pbi-inspector-rules/Rules.json")] Stream rulesInputStream,
FunctionContext context)
{
var logger = context.GetLogger("Inspect");

var inspector = new Inspector();
inspector.MessageIssued += (sender, e) => logger.LogInformation(e.Message);

try
{
var inspectionResults = inspector.Inspect(reportDefinitionTriggerClient.OpenRead(), rulesInputStream);

var testRun = new TestRun() { CompletionTime = DateTime.Now, TestedFilePath = reportDefinitionTriggerClient.Uri.ToString(), RulesFilePath = "pbi-inspector-rules/Rules.json", Verbose = true, Results = inspectionResults };

var jsonTestRun = System.Text.Json.JsonSerializer.Serialize(testRun);

// Blob Output
return jsonTestRun;
}
catch (ArgumentNullException ex)
{
logger.LogError(ex, "An error occurred during inspection");
return string.Empty;
}
catch (FileNotFoundException ex)
{
logger.LogError(ex, "An error occurred during inspection");
return string.Empty;
}
catch (PBIXInspectorException ex)
{
logger.LogError(ex, "An error occurred during inspection");
return string.Empty;
}
finally
{
logger.LogInformation("Inspection completed");
inspector.MessageIssued -= (sender, e) => logger.LogInformation(e.Message);
}
}
}
}
Loading

0 comments on commit 963a829

Please sign in to comment.