diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..616e7cc388c98ba204be7b9fecd5ab05ada034b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,270 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# 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 +Resharper + +# 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 + +#cake +tools/* +!tools/packages.config +dist/ + +# Dotnet Tool Manifest +.config/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 79f102986f5aff458c71f376926004e5fd9e4e23..67b710564e36a7ea38f392ef761ef182dcf55123 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,13 +1,27 @@ stages: - - test_live + - test_ip + - test_ecs -test_live: - stage: test_live +test_ip: + stage: test_ip variables: ErrorActionPreference: stop tags: - live script: - - PowerShell .\ipconnectivitychecker.ps1 + - PowerShell .\ipconnectivitychecker.ps1 when: always - \ No newline at end of file + rules: + - if: $CI_COMMIT_BRANCH == "main" + +test_ecs: + stage: test_ecs + variables: + ErrorActionPreference: stop + tags: + - live + script: + - dotnet run .\src\IPConnectivityChecker.sln --project .\src\IPConnectivityChecker\IPConnectivityChecker.csproj + when: always + rules: + - if: $CI_COMMIT_BRANCH == "main" \ No newline at end of file diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000000000000000000000000000000000000..1bdc0fe219f5f35d8a024a66d9fd715f44539640 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,7 @@ +mode: ContinuousDeployment +next-version: 1.0.0 +major-version-bump-message: 'Breaking:' +minor-version-bump-message: '(Update|New):' +patch-version-bump-message: 'Fix:' +no-bump-message: '.*' +commit-message-incrementing: Enabled \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..5b003aafe714db12a871d215d7223fb657f391e5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 RWTH Aachen University + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/nunit3-junit.xslt b/nunit3-junit.xslt new file mode 100644 index 0000000000000000000000000000000000000000..bf69bdb1d2cd6fc2fdbeb915b4eb6732f720848e --- /dev/null +++ b/nunit3-junit.xslt @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Taken from: https://github.com/nunit/nunit-transforms/tree/master/nunit3-junit +--> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:output method="xml" indent="yes"/> + + <xsl:template match="/test-run"> + <testsuites tests="{@testcasecount}" failures="{@failed}" disabled="{@skipped}" time="{@duration}"> + <xsl:apply-templates/> + </testsuites> + </xsl:template> + + <xsl:template match="test-suite"> + <xsl:if test="test-case"> + <testsuite tests="{@testcasecount}" time="{@duration}" errors="{@testcasecount - @passed - @skipped - @failed}" failures="{@failed}" skipped="{@skipped}" timestamp="{@start-time}"> + <xsl:attribute name="name"> + <xsl:for-each select="ancestor-or-self::test-suite/@name"> + <xsl:value-of select="concat(., '.')"/> + </xsl:for-each> + </xsl:attribute> + <xsl:apply-templates select="test-case"/> + </testsuite> + <xsl:apply-templates select="test-suite"/> + </xsl:if> + <xsl:if test="not(test-case)"> + <xsl:apply-templates/> + </xsl:if> + </xsl:template> + + <xsl:template match="test-case"> + <testcase name="{@name}" assertions="{@asserts}" time="{@duration}" status="{@result}" classname="{@classname}"> + <xsl:if test="@runstate = 'Skipped' or @runstate = 'Ignored'"> + <skipped/> + </xsl:if> + + <xsl:apply-templates/> + </testcase> + </xsl:template> + + <xsl:template match="command-line"/> + <xsl:template match="settings"/> + + <xsl:template match="output"> + <system-out> + <xsl:value-of select="."/> + </system-out> + </xsl:template> + + <xsl:template match="stack-trace"> + </xsl:template> + + <xsl:template match="test-case/failure"> + <failure message="{./message}"> + <xsl:value-of select="./stack-trace"/> + </failure> + </xsl:template> + + <xsl:template match="test-suite/failure"/> + + <xsl:template match="test-case/reason"> + <skipped message="{./message}"/> + </xsl:template> + + <xsl:template match="test-case/assertions"> + </xsl:template> + + <xsl:template match="test-suite/reason"/> + + <xsl:template match="properties"/> +</xsl:stylesheet> \ No newline at end of file diff --git a/src/IPConnectivityChecker.sln b/src/IPConnectivityChecker.sln new file mode 100644 index 0000000000000000000000000000000000000000..7f888a06180cd8ae9be32a2fe100bc76c38127c7 --- /dev/null +++ b/src/IPConnectivityChecker.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IPConnectivityChecker", "IPConnectivityChecker\IPConnectivityChecker.csproj", "{F5208FD7-C6B4-4906-8433-1CD3DC37C46C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F5208FD7-C6B4-4906-8433-1CD3DC37C46C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5208FD7-C6B4-4906-8433-1CD3DC37C46C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5208FD7-C6B4-4906-8433-1CD3DC37C46C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5208FD7-C6B4-4906-8433-1CD3DC37C46C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A5EB9DEA-FE3B-404A-9C69-6C24885EAFA1} + EndGlobalSection +EndGlobal diff --git a/src/IPConnectivityChecker/IPConnectivityChecker.csproj b/src/IPConnectivityChecker/IPConnectivityChecker.csproj new file mode 100644 index 0000000000000000000000000000000000000000..009079cd8ce15c119a9c051e1c0df818d8ffaf38 --- /dev/null +++ b/src/IPConnectivityChecker/IPConnectivityChecker.csproj @@ -0,0 +1,17 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <RootNamespace>IPConnectivityChecker</RootNamespace> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Coscine.Configuration" Version="2.1.0" /> + <PackageReference Include="Coscine.Database" Version="2.11.1" /> + <PackageReference Include="Coscine.ResourceTypes" Version="1.1.4" /> + </ItemGroup> + +</Project> diff --git a/src/IPConnectivityChecker/Implementations/ECSChecker.cs b/src/IPConnectivityChecker/Implementations/ECSChecker.cs new file mode 100644 index 0000000000000000000000000000000000000000..35ddc2cccfa76d981c58ee7e98f2aaf0b33259da --- /dev/null +++ b/src/IPConnectivityChecker/Implementations/ECSChecker.cs @@ -0,0 +1,141 @@ +using Amazon.S3; +using Coscine.Database.DataModel; +using Coscine.Database.Models; +using Coscine.ECSManager; +using Coscine.ResourceTypes; +using Coscine.ResourceTypes.Base; +using Coscine.ResourceTypes.RdsS3; +using Coscine.ResourceTypes.RdsWorm; +using ResourceTypes.Rds; + +namespace IPConnectivityChecker.Implementations +{ + public class ECSChecker + { + public async Task<bool> CheckECS() + { + var resourceTypeModel = new ResourceTypeModel(); + var resourceTypes = resourceTypeModel.GetAll(); + + var working = true; + + foreach (var resourceType in resourceTypes) + { + if (resourceType.Type.Contains("rds")) + { + Console.WriteLine("Checking resourcetype with type '" + resourceType.Type + "' and specific type '" + resourceType.SpecificType + "'!"); + BaseResourceType resourceTypeDefinition; + try + { + resourceTypeDefinition = ResourceTypeFactory.Instance.GetResourceType(resourceType.Type, resourceType.SpecificType); + } + catch (Exception e) + { + Console.WriteLine("Error on resourcetype with type '" + resourceType.Type + "' and specific type '" + resourceType.SpecificType + "'!"); + Console.WriteLine(e); + working = false; + continue; + } + if (resourceType.Type == "rds") + { + var rdsResourceTypeDefinition = (RdsResourceType)resourceTypeDefinition; + var rdsResourceTypeConfiguration = rdsResourceTypeDefinition.RdsResourceTypeConfiguration; + + working = working && await S3ClientCheck(rdsResourceTypeConfiguration.Endpoint, rdsResourceTypeConfiguration.AccessKey, rdsResourceTypeConfiguration.SecretKey, resourceType); + + var ecsManager = new EcsManager + { + EcsManagerConfiguration = rdsResourceTypeConfiguration.EcsManagerConfiguration + }; + working = working && await LoginToECS(ecsManager.EcsManagerConfiguration, resourceType); + } + else if (resourceType.Type == "rdss3") + { + var rdss3ResourceTypeDefinition = (RdsS3ResourceType)resourceTypeDefinition; + var rdsS3ResourceTypeConfiguration = rdss3ResourceTypeDefinition.RdsS3ResourceTypeConfiguration; + + working = working && await S3ClientCheck(rdsS3ResourceTypeConfiguration.Endpoint, rdsS3ResourceTypeConfiguration.AccessKey, rdsS3ResourceTypeConfiguration.SecretKey, resourceType); + + var rdsS3EcsManager = new EcsManager + { + EcsManagerConfiguration = rdsS3ResourceTypeConfiguration.RdsS3EcsManagerConfiguration + }; + working = working && await LoginToECS(rdsS3EcsManager.EcsManagerConfiguration, resourceType); + + var userEcsManager = new EcsManager + { + EcsManagerConfiguration = rdsS3ResourceTypeConfiguration.UserEcsManagerConfiguration + }; + working = working && await LoginToECS(userEcsManager.EcsManagerConfiguration, resourceType); + } + else if (resourceType.Type == "rdss3worm") + { + var rdss3wormResourceTypeDefinition = (RdsS3WormResourceType)resourceTypeDefinition; + var rdsS3WormResourceTypeConfiguration = rdss3wormResourceTypeDefinition.RdsS3WormResourceTypeConfiguration; + + working = working && await S3ClientCheck(rdsS3WormResourceTypeConfiguration.Endpoint, rdsS3WormResourceTypeConfiguration.AccessKey, rdsS3WormResourceTypeConfiguration.SecretKey, resourceType); + + var rdsS3EcsManager = new EcsManager + { + EcsManagerConfiguration = rdsS3WormResourceTypeConfiguration.RdsS3EcsManagerConfiguration + }; + working = working && await LoginToECS(rdsS3EcsManager.EcsManagerConfiguration, resourceType); + + var userEcsManager = new EcsManager + { + EcsManagerConfiguration = rdsS3WormResourceTypeConfiguration.UserEcsManagerConfiguration + }; + working = working && await LoginToECS(userEcsManager.EcsManagerConfiguration, resourceType); + + } + Console.WriteLine(); + } + } + + return working; + + } + + private async Task<bool> S3ClientCheck(string endpoint, string accessKey, string secretKey, ResourceType resourceType) + { + try + { + var amazonS3Config = new AmazonS3Config + { + ServiceURL = endpoint, + ForcePathStyle = true + }; + using var _s3client = new AmazonS3Client(accessKey, secretKey, amazonS3Config); + await _s3client.ListBucketsAsync(); + } + catch (Exception e) + { + Console.WriteLine("S3 Client Check: FAILED for resourcetype with type '" + resourceType.Type + "' and specific type '" + resourceType.SpecificType + "'!"); + Console.WriteLine(e); + return false; + } + return true; + } + + private async Task<bool> LoginToECS(EcsManagerConfiguration EcsManagerConfiguration, ResourceType resourceType) + { + try + { + // create new management client USING NAMESPACE ADMINISTRATOR to obtain token + using var client = new CoscineECSManagementClient(EcsManagerConfiguration.NamespaceAdminName, EcsManagerConfiguration.NamespaceAdminPassword, EcsManagerConfiguration.ManagerApiEndpoint); + // authenticate + await client.Authenticate(); + // log out + await client.LogOut(); + } + catch (Exception e) + { + Console.WriteLine("Login Check: FAILED for resourcetype with type '" + resourceType.Type + "' and specific type '" + resourceType.SpecificType + "'!"); + Console.WriteLine(e); + return false; + } + return true; + } + + } +} diff --git a/src/IPConnectivityChecker/Program.cs b/src/IPConnectivityChecker/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..8cfe805967c19dabcddefab76a141757885d2b44 --- /dev/null +++ b/src/IPConnectivityChecker/Program.cs @@ -0,0 +1,11 @@ +using IPConnectivityChecker.Implementations; + +var allWorking = true; + +var ecsChecker = new ECSChecker(); +allWorking = allWorking && await ecsChecker.CheckECS(); + +if (!allWorking) +{ + throw new ArgumentException("Some checks are returning an error state!"); +}