Skip to content

Commit

Permalink
feat: Add GetDomainsForUser API (#161)
Browse files Browse the repository at this point in the history
Signed-off-by: Sagilio <[email protected]>
  • Loading branch information
sagilio committed May 22, 2021
1 parent 1ccfff3 commit e5df0b3
Show file tree
Hide file tree
Showing 21 changed files with 294 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Release
name: Build

on: [push, pull_request]

Expand All @@ -10,7 +10,6 @@ env:
BUILD_RUN_NUMBER: build.${{ GITHUB.RUN_NUMBER }}
GITHUB_TOKEN: ${{ SECRETS.GITHUB_TOKEN }}
MYGET_API_TOKEN: ${{ SECRETS.MYGET_API_TOKEN }}
NUGET_API_TOKEN: ${{ SECRETS.NUGET_API_KEY }}
COVERALLS_REPO_TOKEN: ${{ SECRETS.COVERALLS_REPO_TOKEN }}

jobs:
Expand Down Expand Up @@ -115,7 +114,7 @@ jobs:
name: "drop-ci-benchmark-resuls"
path: './Casbin.Benchmark/BenchmarkDotNet.Artifacts'

run-semantic-release:
dry-run-semantic-release:
runs-on: ubuntu-latest
needs: build
if: github.repository_owner == 'casbin' && github.event_name == 'push'
Expand All @@ -124,15 +123,15 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Run semantic-release
- name: Dry run semantic-release
run: |
export PATH=$PATH:$(yarn global bin)
yarn global add [email protected]
semantic-release
semantic-release --dry-run
release-build-version:
runs-on: windows-latest
needs: run-semantic-release
needs: build
if: github.repository_owner == 'casbin' && github.event_name == 'push'

steps:
Expand Down Expand Up @@ -189,68 +188,3 @@ jobs:

- name: Push develop packages to myget.org
run: dotnet nuget push .\packages\*.nupkg -s myget.org -k $env:MYGET_API_TOKEN --skip-duplicate

release:
runs-on: windows-latest
needs: release-build-version
if: github.repository_owner == 'casbin' && github.event_name == 'push'

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Git fetch tags
run: git fetch --tags

- name: Check tags
run: git tag -l -n

- name: Setup .NET Core 3.1.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Setup .NET 5.0.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Check .NET info
run: dotnet --info

- name: Install dependencies
run: nuget restore

- name: Build solution
run: dotnet build -c Release --no-restore

- name: Pack packages
run: |
$LastTag = git describe --tags (git rev-list --tags --max-count=1);
echo "Last tag is: $LastTag";
$Version = ($LastTag).TrimStart('v');
echo "Publishing version: $Version";
dotnet pack -c Release -o packages /p:PackageVersion=$Version /p:Version=$Version;
- name: Upload packages artefacts
uses: actions/[email protected]
with:
name: "drop-ci-packages"
path: './packages'

- name: Add myget nuget source
run: dotnet nuget add source https://www.myget.org/F/casbin-net/api/v2/package --name myget.org

- name: Push packages to myget.org
run: dotnet nuget push .\packages\*.nupkg -s myget.org -k $env:MYGET_API_TOKEN --skip-duplicate

- name: Add github nuget source
run: dotnet nuget add source https://nuget.pkg.github.com/casbin/index.json --name github.com --username casbin --password $env:GITHUB_TOKEN

- name: Push packages to github.com
run: dotnet nuget push .\packages\*.nupkg -s github.com --skip-duplicate;

- name: Push packages to nuget.org
run: dotnet nuget push .\packages\*.nupkg -s nuget.org -k $env:NUGET_API_TOKEN --skip-duplicate
152 changes: 152 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Release

on: workflow_dispatch

env:
SHA: ${{ GITHUB.SHA }}
REF: ${{ GITHUB.REF }}
RUN_ID: ${{ GITHUB.RUN_ID }}
RUN_NUMBER: ${{ GITHUB.RUN_NUMBER }}
BUILD_RUN_NUMBER: build.${{ GITHUB.RUN_NUMBER }}
GITHUB_TOKEN: ${{ SECRETS.GITHUB_TOKEN }}
MYGET_API_TOKEN: ${{ SECRETS.MYGET_API_TOKEN }}
NUGET_API_TOKEN: ${{ SECRETS.NUGET_API_KEY }}
COVERALLS_REPO_TOKEN: ${{ SECRETS.COVERALLS_REPO_TOKEN }}

jobs:
build:
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup .NET Core 3.1.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Setup .NET 5.0.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Check .NET info
run: dotnet --info

- name: Install dependencies
run: nuget restore

- name: Build solution
run: dotnet build -c Release --no-restore

- name: Test solution
run: dotnet test -c Release --no-build --no-restore --verbosity normal -r test-results --collect:"XPlat Code Coverage" `
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=json,cobertura,lcov,teamcity,opencover

- name: Upload coverage
run: |
dotnet tool install coveralls.net --version 2.0.0-beta0002 --tool-path tools;
$CommitAuthor = git show -s --pretty=format:"%cn";
echo "Coomit author is: $CommitAuthor";
$CommitAuthorEmail = git show -s --pretty=format:"%ce";
echo "Coomit author email is: $CommitAuthorEmail";
$CommitMessage = git show -s --pretty=format:"%s";
echo "Coomit message is: $CommitMessage";
cp test-results/**/*.opencover.xml test-results
tools/csmacnz.Coveralls --opencover -i test-results/coverage.opencover.xml --repoToken $env:COVERALLS_REPO_TOKEN `
--commitId $env:SHA --commitBranch $env:REF --commitAuthor "$CommitAuthor" `
--commitEmail "$CommitAuthorEmail" --commitMessage "$CommitMessage" `
--jobId $env:RUN_NUMBER --serviceName github-actions --useRelativePaths;
if($LastExitCode -ne 0)
{
Write-Warning -Message "Can not upload coverage, laat exit code is ${LastExitCode}."
$LastExitCode = 0;
}
- name: Upload test results artefacts
uses: actions/[email protected]
with:
name: "drop-ci-test-results"
path: './test-results'

run-semantic-release:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run semantic-release
run: |
export PATH=$PATH:$(yarn global bin)
yarn global add [email protected]
semantic-release
release:
runs-on: windows-latest
needs: run-semantic-release

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Git fetch tags
run: git fetch --tags

- name: Check tags
run: git tag -l -n

- name: Setup .NET Core 3.1.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Setup .NET 5.0.x SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Check .NET info
run: dotnet --info

- name: Install dependencies
run: nuget restore

- name: Build solution
run: dotnet build -c Release --no-restore

- name: Pack packages
run: |
$LastTag = git describe --tags (git rev-list --tags --max-count=1);
echo "Last tag is: $LastTag";
$Version = ($LastTag).TrimStart('v');
echo "Publishing version: $Version";
dotnet pack -c Release -o packages /p:PackageVersion=$Version /p:Version=$Version;
- name: Upload packages artefacts
uses: actions/[email protected]
with:
name: "drop-ci-packages"
path: './packages'

- name: Add myget nuget source
run: dotnet nuget add source https://www.myget.org/F/casbin-net/api/v2/package --name myget.org

- name: Push packages to myget.org
run: dotnet nuget push .\packages\*.nupkg -s myget.org -k $env:MYGET_API_TOKEN --skip-duplicate

- name: Add github nuget source
run: dotnet nuget add source https://nuget.pkg.github.com/casbin/index.json --name github.com --username casbin --password $env:GITHUB_TOKEN

- name: Push packages to github.com
run: dotnet nuget push .\packages\*.nupkg -s github.com --skip-duplicate;

- name: Push packages to nuget.org
run: dotnet nuget push .\packages\*.nupkg -s nuget.org -k $env:NUGET_API_TOKEN --skip-duplicate
2 changes: 1 addition & 1 deletion Casbin.Benchmark/BuildInFunctionsBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Casbin.Benchmark
[BenchmarkCategory("Functions")]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.Net48)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.NetCoreApp31, baseline: true)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.NetCoreApp50)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.Net50)]
public class BuildInFunctionsBenchmark
{
public IEnumerable<object[]> KeyMatch4TestData() => new[]
Expand Down
4 changes: 2 additions & 2 deletions Casbin.Benchmark/Casbin.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<ServerGarbageCollection>true</ServerGarbageCollection>
<TargetFrameworks>net48;netcoreapp3.1;net5</TargetFrameworks>
<TargetFrameworks>net5;netcoreapp3.1;net48</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Casbin.Benchmark/EnforcerBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Casbin.Benchmark
[BenchmarkCategory("Enforcer")]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.Net48)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.NetCoreApp31, baseline: true)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.NetCoreApp50)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.Net50)]
public class EnforcerBenchmark
{
private Enforcer NowEnforcer { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Casbin.Benchmark/EnforcerWithCacheBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Casbin.Benchmark
[BenchmarkCategory("EnforcerWithCache")]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.Net48)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.NetCoreApp31, baseline: true)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.NetCoreApp50)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.Net50)]
public class EnforcerWithCacheBenchmark
{
private Enforcer NowEnforcer { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Casbin.Benchmark/ModelBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Casbin.Benchmark
[BenchmarkCategory("Model")]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.Net48)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.NetCoreApp31, baseline: true)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.NetCoreApp50)]
[SimpleJob(RunStrategy.Throughput, targetCount: 10, runtimeMoniker: RuntimeMoniker.Net50)]
public class ModelBenchmark
{
private readonly Enforcer _enforcer;
Expand Down
3 changes: 2 additions & 1 deletion Casbin.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitattributes = .gitattributes
.gitignore = .gitignore
azure-pipelines.yml = azure-pipelines.yml
.github\workflows\build-and-release.yml = .github\workflows\build-and-release.yml
.github\workflows\build.yml = .github\workflows\build.yml
LICENSE = LICENSE
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Casbin.Benchmark", "Casbin.Benchmark\Casbin.Benchmark.csproj", "{1DBC2931-4981-4DB5-A30B-FF6EB8622B04}"
Expand Down
1 change: 1 addition & 0 deletions NetCasbin.UnitTest/Fixtures/TestModelFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class TestModelFixture
internal readonly string _rbacPolicyText = ReadTestFile("rbac_policy.csv");
internal readonly string _rbacWithDenyPolicyText = ReadTestFile("rbac_with_deny_policy.csv");
internal readonly string _rbacWithDomainsPolicyText = ReadTestFile("rbac_with_domains_policy.csv");
internal readonly string _rbacWithDomainsPolicy2Text = ReadTestFile("rbac_with_domains_policy2.csv");
internal readonly string _rbacWithHierarchyPolicyText = ReadTestFile("rbac_with_hierarchy_policy.csv");
internal readonly string _rbacWithHierarchyWithDomainsPolicyText = ReadTestFile("rbac_with_hierarchy_with_domains_policy.csv");
internal readonly string _rbacWithResourceRolePolicyText = ReadTestFile("rbac_with_resource_roles_policy.csv");
Expand Down
9 changes: 7 additions & 2 deletions NetCasbin.UnitTest/Mock/MockRoleManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NetCasbin.Rbac;

namespace NetCasbin.UnitTest.Mock
Expand All @@ -8,11 +9,15 @@ public class MockCustomRoleManager : IRoleManager
{
public Func<string, string, bool> MatchingFunc { get; set; }
public Func<string, string, bool> DomainMatchingFunc { get; set; }
public bool HasPattern { get; } = false;
public bool HasDomainPattern { get; } = false;
public bool HasPattern => false;
public bool HasDomainPattern => false;

public List<string> GetRoles(string name, params string[] domain) => null;
public List<string> GetUsers(string name, params string[] domain) => null;
public IEnumerable<string> GetDomains(string name)
{
return Enumerable.Empty<string>();
}

public bool HasLink(string name1, string name2, params string[] domain)
{
Expand Down
Loading

0 comments on commit e5df0b3

Please sign in to comment.