Policy.cs
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Contentful.Core.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Contentful.Core.Models.Management
{
/// <summary>
/// Represents a policy for actions a <see cref="Role"/> may perform.
/// </summary>
public class Policy
{
/// <summary>
/// The effect of this policy.
/// </summary>
public string Effect { get; set; }
/// <summary>
/// The actions this policy refers to.
/// </summary>
[JsonConverter(typeof(StringAllToListJsonConverter))]
public List<string> Actions { get; set; }
/// <summary>
/// The constraints imposed.
/// </summary>
public IConstraint Constraint { get; set; }
}
/// <summary>
/// Represents a type of constraint that can be imposed by a <see cref="Policy"/>.
/// </summary>
[JsonConverter(typeof(ConstraintJsonConverter))]
public interface IConstraint
{
}
/// <summary>
/// Represents a list of constraints that evaluates if all its conditions are true.
/// </summary>
public class AndConstraint : List<IConstraint>, IConstraint
{
}
/// <summary>
/// Represents a list of constraints that evaluates if one of its conditions are true.
/// </summary>
public class OrConstraint : List<IConstraint>, IConstraint
{
}
/// <summary>
/// Represents a constraint that inverts the value of the constraint it encapsulates.
/// </summary>
public class NotConstraint : IConstraint
{
/// <summary>
/// The constraint to invert.
/// </summary>
public IConstraint ConstraintToInvert { get; set; }
}
/// <summary>
/// Represents a constraint that evaluates a property to equal a certain value.
/// </summary>
public class EqualsConstraint : IConstraint
{
/// <summary>
/// The property to evaluate.
/// </summary>
public string Property { get; set; }
/// <summary>
/// The value to equal.
/// </summary>
public string ValueToEqual { get; set; }
}
/// <summary>
/// Represents a constraint that restricts what fields are allowed to be managed.
/// </summary>
public class PathConstraint : IConstraint
{
/// <summary>
/// The path expression for which fields to be allowed.
/// </summary>
public string Fields { get; set; }
}
}