コード例 #1
0
 public ImplicitRegistration(Type policyInterface, object policy)
     : base(typeof(LifetimeManager))
 {
     Key  = typeof(LifetimeManager);
     Next = new PolicyEntry
     {
         Key   = policyInterface,
         Value = policy,
         Next  = Next
     };
 }
コード例 #2
0
ファイル: TokenTest.cs プロジェクト: valmac/consuldotnet-1
        public async Task Token_CreateWithPoliciesDelete()
        {
            Skip.If(string.IsNullOrEmpty(TestHelper.MasterToken));

            var policyOneEntry = new PolicyEntry
            {
                Name        = "TokenTestPolicyOne",
                Description = "ACL API Test Policy One",
                Rules       = "key \"\" { policy = \"deny\" }",
                Datacenters = new string[] { }
            };

            var policyTwoEntry = new PolicyEntry
            {
                Name        = "TokenTestPolicyTwo",
                Description = "ACL API Test Policy Two",
                Rules       = "key_prefix \"test\" { policy = \"deny\" }",
                Datacenters = new [] { "DC1", "DC2" }
            };

            var policyOne = await _client.Policy.Create(policyOneEntry);

            var policyTwo = await _client.Policy.Create(policyTwoEntry);

            Assert.NotNull(policyOne.Response);
            Assert.NotNull(policyTwo.Response);

            var tokenEntry = new TokenEntry
            {
                Description = "API Testing Token",
                SecretID    = "2BF4CA45-5C67-471C-8391-E5D54C76A08B",
                Policies    = new PolicyLink[] { policyOne.Response, policyTwo.Response },
                Local       = true
            };

            var newToken = await _client.Token.Create(tokenEntry);

            Assert.NotEqual(TimeSpan.Zero, newToken.RequestTime);
            Assert.NotNull(newToken.Response);
            Assert.False(string.IsNullOrEmpty(newToken.Response.AccessorID));
            Assert.Equal(tokenEntry.Description, newToken.Response.Description);
            Assert.Equal(tokenEntry.SecretID, newToken.Response.SecretID);
            Assert.Equal(tokenEntry.Local, newToken.Response.Local);

            var deleteResponse = await _client.Token.Delete(newToken.Response.AccessorID);

            Assert.True(deleteResponse.Response);
            deleteResponse = await _client.Policy.Delete(policyOne.Response.ID);

            Assert.True(deleteResponse.Response);
            deleteResponse = await _client.Policy.Delete(policyTwo.Response.ID);

            Assert.True(deleteResponse.Response);
        }
コード例 #3
0
        private LinkedList <PurchasePolicy> parseTwoComplex(IEnumerable <PolicyEntry> policyEntries)
        {
            LinkedList <PurchasePolicy> policyList = new LinkedList <PurchasePolicy>();
            ComplexPurchasePolicy       compParent = null;
            ComplexPurchasePolicy       compChild  = null;
            int compParentPos  = -1;
            int compChildPos   = -1;
            int idRegularChild = -1;
            int id1Child       = -1;
            int id2Child       = -1;

            for (int i = 0; i < policyEntries.Count(); i++)
            {
                if (policyEntries.ElementAt(i).getType() == "complex" && policyEntries.ElementAt(i).getIsPartOfComp())
                {
                    compChildPos = i;
                    id1Child     = policyEntries.ElementAt(i).getSubID1();
                    id2Child     = policyEntries.ElementAt(i).getSubID2();
                }
                else if (policyEntries.ElementAt(i).getType() == "complex" && !policyEntries.ElementAt(i).getIsPartOfComp())
                {
                    compParentPos = i;
                }
            }
            PurchasePolicy child1 = null;
            PurchasePolicy child2 = null;

            for (int i = 0; i < policyEntries.Count(); i++)
            {
                PolicyEntry p = policyEntries.ElementAt(i);
                if (p.getPolicyID() == id1Child)
                {
                    child1 = parseRegular(p);
                }
                else if (p.getPolicyID() == id2Child)
                {
                    child2 = parseRegular(p);
                }
                else if (p.getPolicyID() != id1Child & p.getPolicyID() != id2Child && p.getPolicyID() != compChildPos)
                {
                    idRegularChild = i;
                }
            }

            compChild = new ComplexPurchasePolicy(policyEntries.ElementAt(compChildPos).getCompType(), child1, child2, policyEntries.ElementAt(compChildPos).getPolicyID());
            PurchasePolicy regularChild = parseRegular(policyEntries.ElementAt(idRegularChild));

            compParent = new ComplexPurchasePolicy(policyEntries.ElementAt(compParentPos).getCompType(), compChild, regularChild, policyEntries.ElementAt(compParentPos).getPolicyID());

            policyList.AddLast(compParent);
            return(policyList);
        }
コード例 #4
0
        public bool Policy_rsp(IPAddress src, IPAddress dst, int cap) //Zezwala lub nie na zestawienie polaczenia
        {
            PolicyEntry result = policies.Find(x => (x.src.ToString().Contains(src.ToString()) && x.dst.ToString().Contains(dst.ToString())));

            if (result.max_cap > cap)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
        private int howManyComplex(IEnumerable <PolicyEntry> policyEntries)
        {
            int count = 0;

            for (int i = 0; i < policyEntries.Count(); i++)
            {
                PolicyEntry p = policyEntries.ElementAt(i);
                if (p.getType() == "complex")
                {
                    count++;
                }
            }
            return(count);
        }
コード例 #6
0
 public PurchasePolicy parseRegular(PolicyEntry p)
 {
     if (p.getType() == "min")
     {
         MinAmountPurchase policy = new MinAmountPurchase(p.getAmount(), p.getPolicyID());
         return(policy);
     }
     else if (p.getType() == "max")
     {
         MaxAmountPurchase policy = new MaxAmountPurchase(p.getAmount(), p.getPolicyID());
         return(policy);
     }
     else
     {
         TotalPricePolicy policy = new TotalPricePolicy(p.getAmount(), p.getPolicyID());
         return(policy);
     }
 }
コード例 #7
0
        public async Task Policy_CreateDelete()
        {
            Skip.If(string.IsNullOrEmpty(TestHelper.MasterToken));

            var policyEntry = new PolicyEntry()
            {
                Name        = "UnitTestPolicy",
                Description = "Policy for API Unit Testing",
                Rules       = "key \"\" { policy = \"deny\" }"
            };

            var newPolicyResult = await _client.Policy.Create(policyEntry);

            Assert.NotNull(newPolicyResult.Response);
            Assert.NotEqual(TimeSpan.Zero, newPolicyResult.RequestTime);
            Assert.False(string.IsNullOrEmpty(newPolicyResult.Response.ID));
            Assert.Equal(policyEntry.Description, newPolicyResult.Response.Description);
            Assert.Equal(policyEntry.Name, newPolicyResult.Response.Name);
            Assert.Equal(policyEntry.Rules, newPolicyResult.Response.Rules);

            var deleteResponse = await _client.Policy.Delete(newPolicyResult.Response.ID);

            Assert.True(deleteResponse.Response);
        }
コード例 #8
0
 /// <summary>
 /// There are no comments for PolicyEntries in the schema.
 /// </summary>
 public void AddToPolicyEntries(PolicyEntry policyEntry)
 {
     base.AddObject("PolicyEntries", policyEntry);
 }
コード例 #9
0
 /// <summary>
 /// Create a new PolicyEntry object.
 /// </summary>
 /// <param name="groupID">Initial value of GroupID.</param>
 public static PolicyEntry CreatePolicyEntry(int groupID)
 {
     PolicyEntry policyEntry = new PolicyEntry();
     policyEntry.GroupID = groupID;
     return policyEntry;
 }
コード例 #10
0
 public void addEntry(PolicyEntry new_entry)
 {
     _policy_entries.Add(new_entry);
 }
コード例 #11
0
        public async Task Role_Create_WithPoliciesReadDelete()
        {
            Skip.If(string.IsNullOrEmpty(TestHelper.MasterToken));

            var policyOneEntry = new PolicyEntry
            {
                Name        = "RoleTestPolicyOne",
                Description = "ACL API Test Policy One",
                Rules       = "key \"\" { policy = \"deny\" }",
                Datacenters = new string[] { }
            };

            var policyOne = await _client.Policy.Create(policyOneEntry);

            Assert.NotNull(policyOne.Response);

            var policyTwoEntry = new PolicyEntry
            {
                Name        = "RoleTestPolicyTwo",
                Description = "ACL API Test Policy Two",
                Rules       = "key_prefix \"test\" { policy = \"deny\" }",
                Datacenters = new [] { "DC1", "DC2" }
            };

            var policyTwo = await _client.Policy.Create(policyTwoEntry);

            Assert.NotNull(policyTwo.Response);

            var roleEntry = new RoleEntry
            {
                Name        = "APITestingRole",
                Description = "Role for API Testing (Role_CreateWithPoliciesReadDelete)",
                Policies    = new PolicyLink[] { policyOne.Response, policyTwo.Response }
            };

            var newRoleResult = await _client.Role.Create(roleEntry);

            Assert.NotNull(newRoleResult.Response);
            Assert.NotEqual(TimeSpan.Zero, newRoleResult.RequestTime);
            Assert.False(string.IsNullOrEmpty(newRoleResult.Response.ID));
            Assert.Equal(roleEntry.Description, newRoleResult.Response.Description);
            Assert.Equal(roleEntry.Name, newRoleResult.Response.Name);

            var readRole = await _client.Role.Read(newRoleResult.Response.ID);

            Assert.NotNull(readRole.Response);
            Assert.NotEqual(TimeSpan.Zero, readRole.RequestTime);
            Assert.Equal(newRoleResult.Response.ID, readRole.Response.ID);
            Assert.Equal(newRoleResult.Response.Name, readRole.Response.Name);
            Assert.Equal(newRoleResult.Response.Description, readRole.Response.Description);

            var deleteResponse = await _client.Role.Delete(newRoleResult.Response.ID);

            Assert.True(deleteResponse.Response);
            deleteResponse = await _client.Policy.Delete(policyOne.Response.ID);

            Assert.True(deleteResponse.Response);
            deleteResponse = await _client.Policy.Delete(policyTwo.Response.ID);

            Assert.True(deleteResponse.Response);
        }