-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pooja Adhikari
committed
Dec 20, 2018
1 parent
17bffda
commit abd7fb0
Showing
14 changed files
with
251 additions
and
4 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/Microsoft.Health.ControlPlane.Core/Features/Exceptions/RoleNotFoundException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Diagnostics; | ||
|
||
namespace Microsoft.Health.ControlPlane.Core.Features.Exceptions | ||
{ | ||
public class RoleNotFoundException : ControlPlaneException | ||
{ | ||
public RoleNotFoundException(string name) | ||
: base(string.Format(Resources.RoleNotFound, name)) | ||
{ | ||
Debug.Assert(!string.IsNullOrEmpty(name), "Role identifier should not be empty"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Microsoft.Health.ControlPlane.Core/Features/Rbac/Roles/ResourceAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles | ||
{ | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum ResourceAction | ||
{ | ||
/// <summary> | ||
/// Read | ||
/// </summary> | ||
[EnumMember(Value = "read")] | ||
Read, | ||
|
||
/// <summary> | ||
/// Write | ||
/// </summary> | ||
[EnumMember(Value = "write")] | ||
Write, | ||
|
||
/// <summary> | ||
/// HardDelete | ||
/// </summary> | ||
[EnumMember(Value = "hardDelete")] | ||
HardDelete, | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Microsoft.Health.ControlPlane.Core/Features/Rbac/Roles/ResourcePermission.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles | ||
{ | ||
public class ResourcePermission | ||
{ | ||
public ResourcePermission() | ||
{ | ||
Actions = new List<ResourceAction>(); | ||
} | ||
|
||
public ResourcePermission(IList<ResourceAction> resourceActions) | ||
{ | ||
Actions = resourceActions; | ||
} | ||
|
||
public IList<ResourceAction> Actions { get; } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Microsoft.Health.ControlPlane.Core/Features/Rbac/Roles/Role.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles | ||
{ | ||
public class Role | ||
{ | ||
[JsonConstructor] | ||
protected Role() | ||
{ | ||
} | ||
|
||
public Role(string name, IList<ResourcePermission> resourcePermissions, string version) | ||
{ | ||
Name = name; | ||
ResourcePermissions = resourcePermissions; | ||
Version = version; | ||
} | ||
|
||
public string Name { get; set; } | ||
|
||
public virtual string Version { get; set; } | ||
|
||
public IList<ResourcePermission> ResourcePermissions { get; internal set; } = new List<ResourcePermission>(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Microsoft.Health.ControlPlane.CosmosDb/Features/Storage/Rbac/CosmosRole.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles; | ||
using Microsoft.Health.CosmosDb.Features.Storage; | ||
using Newtonsoft.Json; | ||
|
||
namespace Microsoft.Health.ControlPlane.CosmosDb.Features.Storage.Rbac | ||
{ | ||
public class CosmosRole : Role | ||
{ | ||
internal const string RolePartition = "Role_"; | ||
|
||
public CosmosRole(Role role) | ||
: base(role.Name, role.ResourcePermissions, role.Version) | ||
{ | ||
ETag = $"\"{role.Version}\""; | ||
} | ||
|
||
[JsonConstructor] | ||
protected CosmosRole() | ||
{ | ||
} | ||
|
||
[JsonProperty("id")] | ||
public string Id => Name; | ||
|
||
[JsonProperty("partitionKey")] | ||
public string PartitionKey { get; } = RolePartition; | ||
|
||
[JsonProperty("_etag")] | ||
public string ETag { get; protected set; } | ||
|
||
[JsonProperty(KnownDocumentProperties.IsSystem)] | ||
public bool IsSystem { get; } = true; | ||
|
||
public override string Version => ETag; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Microsoft.Health.ControlPlane.CosmosDb/Features/Storage/Rbac/CosmosRoleExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Health.ControlPlane.Core.Features.Rbac.Roles; | ||
|
||
namespace Microsoft.Health.ControlPlane.CosmosDb.Features.Storage.Rbac | ||
{ | ||
public static class CosmosRoleExtensions | ||
{ | ||
public static Role ToRole(this CosmosRole cosmosRole) | ||
{ | ||
return new Role( | ||
cosmosRole.Name, | ||
cosmosRole.ResourcePermissions, | ||
cosmosRole.ETag.Trim('"')); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters