-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate BlobInventoryPolicy related cmdelts and Invoke-AzStorageAccountFailover to Track2 SDK #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Track2 = Azure.ResourceManager.Storage; | ||
using Track2Models = Azure.ResourceManager.Storage.Models; | ||
using Microsoft.Azure.Management.Storage.Models; | ||
using Microsoft.WindowsAzure.Commands.Common.Attributes; | ||
using System; | ||
|
@@ -27,23 +29,22 @@ public class PSBlobInventoryPolicy | |
public PSBlobInventoryPolicy() | ||
{ } | ||
|
||
public PSBlobInventoryPolicy(BlobInventoryPolicy policy, string ResourceGroupName, string StorageAccountName) | ||
public PSBlobInventoryPolicy(Track2.BlobInventoryPolicyResource policy, string resourceGroupName, string storageAccountName) | ||
{ | ||
this.ResourceGroupName = ResourceGroupName; | ||
this.StorageAccountName = StorageAccountName; | ||
this.ResourceGroupName = resourceGroupName; | ||
this.StorageAccountName = storageAccountName; | ||
this.Id = policy.Id; | ||
this.Name = policy.Name; | ||
this.Type = policy.Type; | ||
this.LastModifiedTime = policy.LastModifiedTime; | ||
this.SystemData = policy.SystemData is null ? null : new PSSystemData(policy.SystemData); | ||
|
||
this.Enabled = policy.Policy.Enabled; | ||
this.Destination = policy.Policy.Destination; | ||
|
||
if (policy.Policy.Rules != null) | ||
this.Name = policy.Data.Name; | ||
this.Type = policy.Data.ResourceType; | ||
this.LastModifiedTime = policy.Data.LastModifiedOn; | ||
this.SystemData = policy.Data.SystemData is null ? null : new PSSystemData(policy.Data.SystemData); | ||
this.Enabled = policy.Data.Policy.Enabled; | ||
// TODO: Destination is currently not supported yet. Will add later. | ||
|
||
if (policy.Data.Policy.Rules != null) | ||
{ | ||
List<PSBlobInventoryPolicyRule> psRules = new List<PSBlobInventoryPolicyRule>(); | ||
foreach (BlobInventoryPolicyRule rule in policy.Policy.Rules) | ||
foreach (Track2Models.BlobInventoryPolicyRule rule in policy.Data.Policy.Rules) | ||
{ | ||
psRules.Add(new PSBlobInventoryPolicyRule(rule)); | ||
} | ||
|
@@ -55,32 +56,29 @@ public PSBlobInventoryPolicy(BlobInventoryPolicy policy, string ResourceGroupNam | |
} | ||
} | ||
|
||
public BlobInventoryPolicy ParseBlobInventoryPolicy() | ||
|
||
public Track2.BlobInventoryPolicyData ParseBlobInventoryPolicy() | ||
{ | ||
List<BlobInventoryPolicyRule> invRules = ParseBlobInventoryPolicyRules(this.Rules); | ||
List<Track2Models.BlobInventoryPolicyRule> invRules = ParseBlobInventoryPolicyRules(this.Rules); | ||
|
||
BlobInventoryPolicySchema policySchema = new BlobInventoryPolicySchema() | ||
Track2Models.BlobInventoryPolicySchema policySchema = new Track2Models.BlobInventoryPolicySchema( | ||
this.Enabled, | ||
Track2Models.InventoryRuleType.Inventory, | ||
invRules); | ||
|
||
Track2.BlobInventoryPolicyData data = new Track2.BlobInventoryPolicyData | ||
{ | ||
Enabled = this.Enabled, | ||
//Destination = this.Destination, | ||
Rules = invRules | ||
Policy = policySchema, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks still still missing ID, Name, LastModified... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might not be an issue, since this function is only used in set-AzstorageStorageBlobInventoryPolicy, to parse the input the policy (PSH object) to the policy (SDK object) to set. And I can understand SDK not allow to set them, since they should only be read from server, but not set by customer. In a word, if PSH code works with it, I believe this will not be an issue. |
||
}; | ||
return new BlobInventoryPolicy( | ||
policySchema, | ||
this.Id, | ||
this.Name, | ||
this.Type, | ||
this.LastModifiedTime, | ||
this.SystemData is null ? null : this.SystemData.ParseSystemData() | ||
); | ||
return data; | ||
} | ||
|
||
public static List<BlobInventoryPolicyRule> ParseBlobInventoryPolicyRules(PSBlobInventoryPolicyRule[] rules) | ||
public static List<Track2Models.BlobInventoryPolicyRule> ParseBlobInventoryPolicyRules(PSBlobInventoryPolicyRule[] rules) | ||
{ | ||
List<BlobInventoryPolicyRule> invRules = null; | ||
List<Track2Models.BlobInventoryPolicyRule> invRules = null; | ||
if (rules != null) | ||
{ | ||
invRules = new List<BlobInventoryPolicyRule>(); | ||
invRules = new List<Track2Models.BlobInventoryPolicyRule>(); | ||
foreach (PSBlobInventoryPolicyRule rule in rules) | ||
{ | ||
invRules.Add(rule.ParseBlobInventoryPolicyRule()); | ||
|
@@ -99,7 +97,7 @@ public static List<BlobInventoryPolicyRule> ParseBlobInventoryPolicyRules(PSBlob | |
[Ps1Xml(Label = "Type", Target = ViewControl.List, Position = 2)] | ||
public string Type { get; set; } | ||
[Ps1Xml(Label = "LastModifiedTime", Target = ViewControl.List, Position = 4)] | ||
public DateTime? LastModifiedTime { get; set; } | ||
public DateTimeOffset? LastModifiedTime { get; set; } | ||
|
||
//public PSBlobInventoryPolicySchema Policy { get; set; } | ||
|
||
|
@@ -108,7 +106,6 @@ public static List<BlobInventoryPolicyRule> ParseBlobInventoryPolicyRules(PSBlob | |
[Ps1Xml(Label = "Rules", Target = ViewControl.List, Position = 7)] | ||
public PSBlobInventoryPolicyRule[] Rules { get; set; } | ||
public PSSystemData SystemData { get; set; } | ||
public string Destination { get; private set; } | ||
} | ||
|
||
/// <summary> | ||
|
@@ -117,23 +114,25 @@ public static List<BlobInventoryPolicyRule> ParseBlobInventoryPolicyRules(PSBlob | |
public class PSBlobInventoryPolicyRule | ||
{ | ||
public PSBlobInventoryPolicyRule() { } | ||
public PSBlobInventoryPolicyRule(BlobInventoryPolicyRule rule) | ||
public PSBlobInventoryPolicyRule(Track2Models.BlobInventoryPolicyRule rule) | ||
{ | ||
this.Enabled = rule.Enabled; | ||
this.Name = rule.Name; | ||
this.Destination = rule.Destination; | ||
this.Definition = rule.Definition is null ? null : new PSBlobInventoryPolicyDefinition(rule.Definition); | ||
} | ||
|
||
public BlobInventoryPolicyRule ParseBlobInventoryPolicyRule() | ||
public Track2Models.BlobInventoryPolicyRule ParseBlobInventoryPolicyRule() | ||
{ | ||
return new BlobInventoryPolicyRule() | ||
{ | ||
Enabled = this.Enabled, | ||
Name = this.Name, | ||
Destination = this.Destination, | ||
Definition = this.Definition is null ? null : this.Definition.parseBlobInventoryPolicyDefinition() | ||
}; | ||
Track2Models.BlobInventoryPolicyDefinition policyDefinition = this.Definition?.parseBlobInventoryPolicyDefinition(); | ||
|
||
Track2Models.BlobInventoryPolicyRule policyRule = new Track2Models.BlobInventoryPolicyRule( | ||
this.Enabled, | ||
this.Name, | ||
this.Destination, | ||
policyDefinition); | ||
|
||
return policyRule; | ||
} | ||
|
||
public bool Enabled { get; set; } | ||
|
@@ -152,20 +151,29 @@ public class PSBlobInventoryPolicyDefinition | |
{ | ||
public PSBlobInventoryPolicyDefinition() { } | ||
|
||
public PSBlobInventoryPolicyDefinition(BlobInventoryPolicyDefinition Definition) | ||
public PSBlobInventoryPolicyDefinition(Track2Models.BlobInventoryPolicyDefinition Definition) | ||
{ | ||
this.Filters = Definition.Filters is null ? null : new PSBlobInventoryPolicyFilter(Definition.Filters); | ||
this.Format = Definition.Format; | ||
this.Schedule = Definition.Schedule; | ||
this.ObjectType = Definition.ObjectType; | ||
this.Format = Definition.Format.ToString(); | ||
this.Schedule = Definition.Schedule.ToString(); | ||
this.ObjectType = Definition.ObjectType.ToString(); | ||
this.SchemaFields = Definition.SchemaFields is null ? null : ((List<string>)Definition.SchemaFields).ToArray(); | ||
} | ||
|
||
public BlobInventoryPolicyDefinition parseBlobInventoryPolicyDefinition() | ||
public Track2Models.BlobInventoryPolicyDefinition parseBlobInventoryPolicyDefinition() | ||
{ | ||
return new BlobInventoryPolicyDefinition(this.Format, this.Schedule, this.ObjectType, | ||
this.SchemaFields is null? null: new List<string>(this.SchemaFields), | ||
this.Filters is null? null : this.Filters.ParseBlobInventoryPolicyFilter()); | ||
Track2Models.BlobInventoryPolicyDefinition policyDefinition = new Track2Models.BlobInventoryPolicyDefinition( | ||
new Track2Models.Format(this.Format), | ||
new Track2Models.Schedule(this.Schedule), | ||
new Track2Models.ObjectType(this.ObjectType), | ||
this.SchemaFields is null ? null : new List<string>(this.SchemaFields) | ||
); | ||
|
||
if (this.Filters != null) | ||
{ | ||
policyDefinition.Filters = this.Filters.ParseBlobInventoryPolicyFilter(); | ||
} | ||
return policyDefinition; | ||
} | ||
|
||
public PSBlobInventoryPolicyFilter Filters { get; set; } | ||
|
@@ -213,23 +221,37 @@ public class PSBlobInventoryPolicyFilter | |
{ | ||
public PSBlobInventoryPolicyFilter() { } | ||
|
||
public PSBlobInventoryPolicyFilter(BlobInventoryPolicyFilter filters) | ||
public PSBlobInventoryPolicyFilter(Track2Models.BlobInventoryPolicyFilter filters) | ||
{ | ||
this.PrefixMatch = PSManagementPolicyRuleFilter.StringListToArray(filters.PrefixMatch); | ||
this.BlobTypes = PSManagementPolicyRuleFilter.StringListToArray(filters.BlobTypes); | ||
this.IncludeBlobVersions = filters.IncludeBlobVersions; | ||
this.IncludeSnapshots = filters.IncludeSnapshots; | ||
} | ||
|
||
public BlobInventoryPolicyFilter ParseBlobInventoryPolicyFilter() | ||
public Track2Models.BlobInventoryPolicyFilter ParseBlobInventoryPolicyFilter() | ||
{ | ||
return new BlobInventoryPolicyFilter() | ||
Track2Models.BlobInventoryPolicyFilter policyFilter = new Track2Models.BlobInventoryPolicyFilter() | ||
{ | ||
PrefixMatch = PSManagementPolicyRuleFilter.StringArrayToList(this.PrefixMatch), | ||
BlobTypes = PSManagementPolicyRuleFilter.StringArrayToList(this.BlobTypes), | ||
IncludeSnapshots = this.IncludeSnapshots, | ||
IncludeBlobVersions = this.IncludeBlobVersions | ||
}; | ||
|
||
if (this.PrefixMatch != null) | ||
{ | ||
foreach (string prefixMatch in this.PrefixMatch) | ||
{ | ||
policyFilter.PrefixMatch.Add(prefixMatch); | ||
} | ||
} | ||
if (this.BlobTypes != null) | ||
{ | ||
foreach (string blobType in this.BlobTypes) | ||
{ | ||
policyFilter.BlobTypes.Add(blobType); | ||
} | ||
} | ||
return policyFilter; | ||
} | ||
|
||
public string[] PrefixMatch { get; set; } | ||
|
@@ -245,26 +267,21 @@ public class PSSystemData | |
{ | ||
public PSSystemData() { } | ||
|
||
public PSSystemData(SystemData SystemData) | ||
public PSSystemData(global::Azure.ResourceManager.Models.SystemData SystemData) | ||
{ | ||
this.CreatedBy = SystemData.CreatedBy; | ||
this.CreatedByType = SystemData.CreatedByType; | ||
this.CreatedAt = SystemData.CreatedAt; | ||
this.CreatedByType = SystemData.CreatedByType.ToString(); | ||
this.CreatedAt = SystemData.CreatedOn; | ||
this.LastModifiedBy = SystemData.LastModifiedBy; | ||
this.LastModifiedByType = SystemData.LastModifiedByType; | ||
this.LastModifiedAt = SystemData.LastModifiedAt; | ||
} | ||
|
||
public SystemData ParseSystemData() | ||
{ | ||
return new SystemData(this.CreatedBy, this.CreatedByType, this.CreatedAt, this.LastModifiedBy, this.LastModifiedByType, this.LastModifiedAt); | ||
this.LastModifiedByType = SystemData.LastModifiedByType.ToString(); | ||
this.LastModifiedAt = SystemData.LastModifiedOn; | ||
} | ||
|
||
public string CreatedBy { get; set; } | ||
public string CreatedByType { get; set; } | ||
public DateTime? CreatedAt { get; set; } | ||
public DateTimeOffset? CreatedAt { get; set; } | ||
public string LastModifiedBy { get; set; } | ||
public string LastModifiedByType { get; set; } | ||
public DateTime? LastModifiedAt { get; set; } | ||
public DateTimeOffset? LastModifiedAt { get; set; } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to add a comments to add the destination which is on a later API version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done