-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from ankushbindlish2/add-graphrbac
Add GraphRbac new library and clone the existing to Version1_6 folder
- Loading branch information
Showing
150 changed files
with
23,329 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/Graph.Rbac/Version1_6.20190326/ActiveDirectory/ADObjectFilterOptions.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,58 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
|
||
namespace Microsoft.Azure.Graph.RBAC.Version1_6_20190326.ActiveDirectory | ||
{ | ||
public class ADObjectFilterOptions | ||
{ | ||
public string SearchString { get; set; } | ||
|
||
public string Mail { get; set; } | ||
|
||
public string UPN { get; set; } | ||
|
||
public string SPN { get; set; } | ||
|
||
public string Id { get; set; } | ||
|
||
public bool Paging { get; set; } | ||
|
||
/// <summary> | ||
/// Used internally to track the paging for the listing, do not change manually. | ||
/// </summary> | ||
public string NextLink { get; set; } | ||
|
||
public bool HasFilter { get { return !string.IsNullOrEmpty(ActiveFilter); } } | ||
|
||
public string ActiveFilter | ||
{ | ||
get | ||
{ | ||
if (!string.IsNullOrEmpty(Id)) | ||
return Id; | ||
else if (!string.IsNullOrEmpty(UPN)) | ||
return UPN; | ||
else if (!string.IsNullOrEmpty(SPN)) | ||
return SPN; | ||
else if (!string.IsNullOrEmpty(Mail)) | ||
return Mail; | ||
else if (!string.IsNullOrEmpty(SearchString)) | ||
return SearchString; | ||
else | ||
return null; | ||
} | ||
} | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/Graph.Rbac/Version1_6.20190326/ActiveDirectory/ActiveDirectoryBaseCmdlet.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,104 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.ResourceManager.Common; | ||
using Microsoft.Azure.Graph.RBAC.Version1_6_20190326.Models; | ||
using System; | ||
using System.Management.Automation; | ||
using System.Net; | ||
using ProjectResources = Microsoft.Azure.Commands.Common.Graph.RBAC.Properties.Resources; | ||
|
||
namespace Microsoft.Azure.Graph.RBAC.Version1_6_20190326.ActiveDirectory | ||
{ | ||
public abstract class ActiveDirectoryBaseCmdlet : AzureRMCmdlet | ||
{ | ||
private ActiveDirectoryClient activeDirectoryClient; | ||
|
||
public ActiveDirectoryClient ActiveDirectoryClient | ||
{ | ||
get | ||
{ | ||
if (activeDirectoryClient == null) | ||
{ | ||
activeDirectoryClient = new ActiveDirectoryClient(DefaultProfile.DefaultContext); | ||
} | ||
|
||
return activeDirectoryClient; | ||
} | ||
|
||
set { activeDirectoryClient = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Handles graph exceptions thrown by client | ||
/// </summary> | ||
/// <param name="exception"></param> | ||
private void HandleException(Exception exception) | ||
{ | ||
Exception targetEx = exception; | ||
string targetErrorId = String.Empty; | ||
ErrorCategory targetErrorCategory = ErrorCategory.NotSpecified; | ||
var graphEx = exception as GraphErrorException; | ||
|
||
if (graphEx != null) | ||
{ | ||
if (graphEx.Body != null && graphEx.Body.Message != null && graphEx.Body.Code != null) { | ||
WriteDebug(String.Format(ProjectResources.GraphException, graphEx.Body.Code, graphEx.Body.Message)); | ||
targetEx = new Exception(graphEx.Body.Message); | ||
targetErrorId = graphEx.Body.Code; | ||
} else { | ||
if (graphEx.Response != null && graphEx.Response.StatusCode == HttpStatusCode.NotFound) { | ||
targetErrorCategory = ErrorCategory.InvalidArgument; | ||
} else { | ||
targetErrorCategory = ErrorCategory.InvalidOperation; | ||
} | ||
Exception parsedException = ParseResponse(graphEx); | ||
targetEx = parsedException != null? parsedException : targetEx; | ||
} | ||
var errorRecord = new ErrorRecord(targetEx, targetErrorId, targetErrorCategory, null); | ||
WriteError(errorRecord); | ||
} | ||
else | ||
{ | ||
throw exception; | ||
} | ||
} | ||
|
||
|
||
private Exception ParseResponse(GraphErrorException graphEx) { | ||
int exceptionMessageIndex = graphEx.Response.Content.IndexOf("\"value\":", StringComparison.CurrentCultureIgnoreCase); | ||
if (exceptionMessageIndex > 0) | ||
{ | ||
string substring = graphEx.Response.Content.Substring(exceptionMessageIndex+9); | ||
// the start index is added 9, so as to remove the delimiter \"value\":\ | ||
string exceptionDetails = substring.Substring(0,substring.IndexOf("\"}")); | ||
return new Exception(exceptionDetails); | ||
} | ||
return null; | ||
} | ||
|
||
protected void ExecutionBlock(Action execAction) | ||
{ | ||
try | ||
{ | ||
execAction(); | ||
} | ||
catch (Exception exception) | ||
{ | ||
WriteDebug(String.Format(ProjectResources.ExceptionInExecution, exception.GetType())); | ||
HandleException(exception); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.