Skip to content

Commit 25eccaa

Browse files
authored
Merge pull request Azure#140 from ankushbindlish2/add-graphrbac
Add GraphRbac new library and clone the existing to Version1_6 folder
2 parents 299bf24 + e88d579 commit 25eccaa

File tree

150 files changed

+23329
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+23329
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
16+
namespace Microsoft.Azure.Graph.RBAC.Version1_6_20190326.ActiveDirectory
17+
{
18+
public class ADObjectFilterOptions
19+
{
20+
public string SearchString { get; set; }
21+
22+
public string Mail { get; set; }
23+
24+
public string UPN { get; set; }
25+
26+
public string SPN { get; set; }
27+
28+
public string Id { get; set; }
29+
30+
public bool Paging { get; set; }
31+
32+
/// <summary>
33+
/// Used internally to track the paging for the listing, do not change manually.
34+
/// </summary>
35+
public string NextLink { get; set; }
36+
37+
public bool HasFilter { get { return !string.IsNullOrEmpty(ActiveFilter); } }
38+
39+
public string ActiveFilter
40+
{
41+
get
42+
{
43+
if (!string.IsNullOrEmpty(Id))
44+
return Id;
45+
else if (!string.IsNullOrEmpty(UPN))
46+
return UPN;
47+
else if (!string.IsNullOrEmpty(SPN))
48+
return SPN;
49+
else if (!string.IsNullOrEmpty(Mail))
50+
return Mail;
51+
else if (!string.IsNullOrEmpty(SearchString))
52+
return SearchString;
53+
else
54+
return null;
55+
}
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.ResourceManager.Common;
16+
using Microsoft.Azure.Graph.RBAC.Version1_6_20190326.Models;
17+
using System;
18+
using System.Management.Automation;
19+
using System.Net;
20+
using ProjectResources = Microsoft.Azure.Commands.Common.Graph.RBAC.Properties.Resources;
21+
22+
namespace Microsoft.Azure.Graph.RBAC.Version1_6_20190326.ActiveDirectory
23+
{
24+
public abstract class ActiveDirectoryBaseCmdlet : AzureRMCmdlet
25+
{
26+
private ActiveDirectoryClient activeDirectoryClient;
27+
28+
public ActiveDirectoryClient ActiveDirectoryClient
29+
{
30+
get
31+
{
32+
if (activeDirectoryClient == null)
33+
{
34+
activeDirectoryClient = new ActiveDirectoryClient(DefaultProfile.DefaultContext);
35+
}
36+
37+
return activeDirectoryClient;
38+
}
39+
40+
set { activeDirectoryClient = value; }
41+
}
42+
43+
/// <summary>
44+
/// Handles graph exceptions thrown by client
45+
/// </summary>
46+
/// <param name="exception"></param>
47+
private void HandleException(Exception exception)
48+
{
49+
Exception targetEx = exception;
50+
string targetErrorId = String.Empty;
51+
ErrorCategory targetErrorCategory = ErrorCategory.NotSpecified;
52+
var graphEx = exception as GraphErrorException;
53+
54+
if (graphEx != null)
55+
{
56+
if (graphEx.Body != null && graphEx.Body.Message != null && graphEx.Body.Code != null) {
57+
WriteDebug(String.Format(ProjectResources.GraphException, graphEx.Body.Code, graphEx.Body.Message));
58+
targetEx = new Exception(graphEx.Body.Message);
59+
targetErrorId = graphEx.Body.Code;
60+
} else {
61+
if (graphEx.Response != null && graphEx.Response.StatusCode == HttpStatusCode.NotFound) {
62+
targetErrorCategory = ErrorCategory.InvalidArgument;
63+
} else {
64+
targetErrorCategory = ErrorCategory.InvalidOperation;
65+
}
66+
Exception parsedException = ParseResponse(graphEx);
67+
targetEx = parsedException != null? parsedException : targetEx;
68+
}
69+
var errorRecord = new ErrorRecord(targetEx, targetErrorId, targetErrorCategory, null);
70+
WriteError(errorRecord);
71+
}
72+
else
73+
{
74+
throw exception;
75+
}
76+
}
77+
78+
79+
private Exception ParseResponse(GraphErrorException graphEx) {
80+
int exceptionMessageIndex = graphEx.Response.Content.IndexOf("\"value\":", StringComparison.CurrentCultureIgnoreCase);
81+
if (exceptionMessageIndex > 0)
82+
{
83+
string substring = graphEx.Response.Content.Substring(exceptionMessageIndex+9);
84+
// the start index is added 9, so as to remove the delimiter \"value\":\
85+
string exceptionDetails = substring.Substring(0,substring.IndexOf("\"}"));
86+
return new Exception(exceptionDetails);
87+
}
88+
return null;
89+
}
90+
91+
protected void ExecutionBlock(Action execAction)
92+
{
93+
try
94+
{
95+
execAction();
96+
}
97+
catch (Exception exception)
98+
{
99+
WriteDebug(String.Format(ProjectResources.ExceptionInExecution, exception.GetType()));
100+
HandleException(exception);
101+
}
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)