12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
+ using Track2 = Azure . ResourceManager . Storage ;
16
+ using Track2Models = Azure . ResourceManager . Storage . Models ;
15
17
using Microsoft . Azure . Management . Storage . Models ;
16
18
using Microsoft . WindowsAzure . Commands . Common . Attributes ;
17
19
using System ;
@@ -27,23 +29,22 @@ public class PSBlobInventoryPolicy
27
29
public PSBlobInventoryPolicy ( )
28
30
{ }
29
31
30
- public PSBlobInventoryPolicy ( BlobInventoryPolicy policy , string ResourceGroupName , string StorageAccountName )
32
+ public PSBlobInventoryPolicy ( Track2 . BlobInventoryPolicyResource policy , string resourceGroupName , string storageAccountName )
31
33
{
32
- this . ResourceGroupName = ResourceGroupName ;
33
- this . StorageAccountName = StorageAccountName ;
34
+ this . ResourceGroupName = resourceGroupName ;
35
+ this . StorageAccountName = storageAccountName ;
34
36
this . Id = policy . Id ;
35
- this . Name = policy . Name ;
36
- this . Type = policy . Type ;
37
- this . LastModifiedTime = policy . LastModifiedTime ;
38
- this . SystemData = policy . SystemData is null ? null : new PSSystemData ( policy . SystemData ) ;
39
-
40
- this . Enabled = policy . Policy . Enabled ;
41
- this . Destination = policy . Policy . Destination ;
42
-
43
- if ( policy . Policy . Rules != null )
37
+ this . Name = policy . Data . Name ;
38
+ this . Type = policy . Data . ResourceType ;
39
+ this . LastModifiedTime = policy . Data . LastModifiedOn ;
40
+ this . SystemData = policy . Data . SystemData is null ? null : new PSSystemData ( policy . Data . SystemData ) ;
41
+ this . Enabled = policy . Data . Policy . Enabled ;
42
+ // TODO: Destination is currently not supported yet. Will add later.
43
+
44
+ if ( policy . Data . Policy . Rules != null )
44
45
{
45
46
List < PSBlobInventoryPolicyRule > psRules = new List < PSBlobInventoryPolicyRule > ( ) ;
46
- foreach ( BlobInventoryPolicyRule rule in policy . Policy . Rules )
47
+ foreach ( Track2Models . BlobInventoryPolicyRule rule in policy . Data . Policy . Rules )
47
48
{
48
49
psRules . Add ( new PSBlobInventoryPolicyRule ( rule ) ) ;
49
50
}
@@ -55,32 +56,29 @@ public PSBlobInventoryPolicy(BlobInventoryPolicy policy, string ResourceGroupNam
55
56
}
56
57
}
57
58
58
- public BlobInventoryPolicy ParseBlobInventoryPolicy ( )
59
+
60
+ public Track2 . BlobInventoryPolicyData ParseBlobInventoryPolicy ( )
59
61
{
60
- List < BlobInventoryPolicyRule > invRules = ParseBlobInventoryPolicyRules ( this . Rules ) ;
62
+ List < Track2Models . BlobInventoryPolicyRule > invRules = ParseBlobInventoryPolicyRules ( this . Rules ) ;
61
63
62
- BlobInventoryPolicySchema policySchema = new BlobInventoryPolicySchema ( )
64
+ Track2Models . BlobInventoryPolicySchema policySchema = new Track2Models . BlobInventoryPolicySchema (
65
+ this . Enabled ,
66
+ Track2Models . InventoryRuleType . Inventory ,
67
+ invRules ) ;
68
+
69
+ Track2 . BlobInventoryPolicyData data = new Track2 . BlobInventoryPolicyData
63
70
{
64
- Enabled = this . Enabled ,
65
- //Destination = this.Destination,
66
- Rules = invRules
71
+ Policy = policySchema ,
67
72
} ;
68
- return new BlobInventoryPolicy (
69
- policySchema ,
70
- this . Id ,
71
- this . Name ,
72
- this . Type ,
73
- this . LastModifiedTime ,
74
- this . SystemData is null ? null : this . SystemData . ParseSystemData ( )
75
- ) ;
73
+ return data ;
76
74
}
77
75
78
- public static List < BlobInventoryPolicyRule > ParseBlobInventoryPolicyRules ( PSBlobInventoryPolicyRule [ ] rules )
76
+ public static List < Track2Models . BlobInventoryPolicyRule > ParseBlobInventoryPolicyRules ( PSBlobInventoryPolicyRule [ ] rules )
79
77
{
80
- List < BlobInventoryPolicyRule > invRules = null ;
78
+ List < Track2Models . BlobInventoryPolicyRule > invRules = null ;
81
79
if ( rules != null )
82
80
{
83
- invRules = new List < BlobInventoryPolicyRule > ( ) ;
81
+ invRules = new List < Track2Models . BlobInventoryPolicyRule > ( ) ;
84
82
foreach ( PSBlobInventoryPolicyRule rule in rules )
85
83
{
86
84
invRules . Add ( rule . ParseBlobInventoryPolicyRule ( ) ) ;
@@ -99,7 +97,7 @@ public static List<BlobInventoryPolicyRule> ParseBlobInventoryPolicyRules(PSBlob
99
97
[ Ps1Xml ( Label = "Type" , Target = ViewControl . List , Position = 2 ) ]
100
98
public string Type { get ; set ; }
101
99
[ Ps1Xml ( Label = "LastModifiedTime" , Target = ViewControl . List , Position = 4 ) ]
102
- public DateTime ? LastModifiedTime { get ; set ; }
100
+ public DateTimeOffset ? LastModifiedTime { get ; set ; }
103
101
104
102
//public PSBlobInventoryPolicySchema Policy { get; set; }
105
103
@@ -108,7 +106,6 @@ public static List<BlobInventoryPolicyRule> ParseBlobInventoryPolicyRules(PSBlob
108
106
[ Ps1Xml ( Label = "Rules" , Target = ViewControl . List , Position = 7 ) ]
109
107
public PSBlobInventoryPolicyRule [ ] Rules { get ; set ; }
110
108
public PSSystemData SystemData { get ; set ; }
111
- public string Destination { get ; private set ; }
112
109
}
113
110
114
111
/// <summary>
@@ -117,23 +114,25 @@ public static List<BlobInventoryPolicyRule> ParseBlobInventoryPolicyRules(PSBlob
117
114
public class PSBlobInventoryPolicyRule
118
115
{
119
116
public PSBlobInventoryPolicyRule ( ) { }
120
- public PSBlobInventoryPolicyRule ( BlobInventoryPolicyRule rule )
117
+ public PSBlobInventoryPolicyRule ( Track2Models . BlobInventoryPolicyRule rule )
121
118
{
122
119
this . Enabled = rule . Enabled ;
123
120
this . Name = rule . Name ;
124
121
this . Destination = rule . Destination ;
125
122
this . Definition = rule . Definition is null ? null : new PSBlobInventoryPolicyDefinition ( rule . Definition ) ;
126
123
}
127
124
128
- public BlobInventoryPolicyRule ParseBlobInventoryPolicyRule ( )
125
+ public Track2Models . BlobInventoryPolicyRule ParseBlobInventoryPolicyRule ( )
129
126
{
130
- return new BlobInventoryPolicyRule ( )
131
- {
132
- Enabled = this . Enabled ,
133
- Name = this . Name ,
134
- Destination = this . Destination ,
135
- Definition = this . Definition is null ? null : this . Definition . parseBlobInventoryPolicyDefinition ( )
136
- } ;
127
+ Track2Models . BlobInventoryPolicyDefinition policyDefinition = this . Definition ? . parseBlobInventoryPolicyDefinition ( ) ;
128
+
129
+ Track2Models . BlobInventoryPolicyRule policyRule = new Track2Models . BlobInventoryPolicyRule (
130
+ this . Enabled ,
131
+ this . Name ,
132
+ this . Destination ,
133
+ policyDefinition ) ;
134
+
135
+ return policyRule ;
137
136
}
138
137
139
138
public bool Enabled { get ; set ; }
@@ -152,20 +151,29 @@ public class PSBlobInventoryPolicyDefinition
152
151
{
153
152
public PSBlobInventoryPolicyDefinition ( ) { }
154
153
155
- public PSBlobInventoryPolicyDefinition ( BlobInventoryPolicyDefinition Definition )
154
+ public PSBlobInventoryPolicyDefinition ( Track2Models . BlobInventoryPolicyDefinition Definition )
156
155
{
157
156
this . Filters = Definition . Filters is null ? null : new PSBlobInventoryPolicyFilter ( Definition . Filters ) ;
158
- this . Format = Definition . Format ;
159
- this . Schedule = Definition . Schedule ;
160
- this . ObjectType = Definition . ObjectType ;
157
+ this . Format = Definition . Format . ToString ( ) ;
158
+ this . Schedule = Definition . Schedule . ToString ( ) ;
159
+ this . ObjectType = Definition . ObjectType . ToString ( ) ;
161
160
this . SchemaFields = Definition . SchemaFields is null ? null : ( ( List < string > ) Definition . SchemaFields ) . ToArray ( ) ;
162
161
}
163
162
164
- public BlobInventoryPolicyDefinition parseBlobInventoryPolicyDefinition ( )
163
+ public Track2Models . BlobInventoryPolicyDefinition parseBlobInventoryPolicyDefinition ( )
165
164
{
166
- return new BlobInventoryPolicyDefinition ( this . Format , this . Schedule , this . ObjectType ,
167
- this . SchemaFields is null ? null : new List < string > ( this . SchemaFields ) ,
168
- this . Filters is null ? null : this . Filters . ParseBlobInventoryPolicyFilter ( ) ) ;
165
+ Track2Models . BlobInventoryPolicyDefinition policyDefinition = new Track2Models . BlobInventoryPolicyDefinition (
166
+ new Track2Models . Format ( this . Format ) ,
167
+ new Track2Models . Schedule ( this . Schedule ) ,
168
+ new Track2Models . ObjectType ( this . ObjectType ) ,
169
+ this . SchemaFields is null ? null : new List < string > ( this . SchemaFields )
170
+ ) ;
171
+
172
+ if ( this . Filters != null )
173
+ {
174
+ policyDefinition . Filters = this . Filters . ParseBlobInventoryPolicyFilter ( ) ;
175
+ }
176
+ return policyDefinition ;
169
177
}
170
178
171
179
public PSBlobInventoryPolicyFilter Filters { get ; set ; }
@@ -213,23 +221,37 @@ public class PSBlobInventoryPolicyFilter
213
221
{
214
222
public PSBlobInventoryPolicyFilter ( ) { }
215
223
216
- public PSBlobInventoryPolicyFilter ( BlobInventoryPolicyFilter filters )
224
+ public PSBlobInventoryPolicyFilter ( Track2Models . BlobInventoryPolicyFilter filters )
217
225
{
218
226
this . PrefixMatch = PSManagementPolicyRuleFilter . StringListToArray ( filters . PrefixMatch ) ;
219
227
this . BlobTypes = PSManagementPolicyRuleFilter . StringListToArray ( filters . BlobTypes ) ;
220
228
this . IncludeBlobVersions = filters . IncludeBlobVersions ;
221
229
this . IncludeSnapshots = filters . IncludeSnapshots ;
222
230
}
223
231
224
- public BlobInventoryPolicyFilter ParseBlobInventoryPolicyFilter ( )
232
+ public Track2Models . BlobInventoryPolicyFilter ParseBlobInventoryPolicyFilter ( )
225
233
{
226
- return new BlobInventoryPolicyFilter ( )
234
+ Track2Models . BlobInventoryPolicyFilter policyFilter = new Track2Models . BlobInventoryPolicyFilter ( )
227
235
{
228
- PrefixMatch = PSManagementPolicyRuleFilter . StringArrayToList ( this . PrefixMatch ) ,
229
- BlobTypes = PSManagementPolicyRuleFilter . StringArrayToList ( this . BlobTypes ) ,
230
236
IncludeSnapshots = this . IncludeSnapshots ,
231
237
IncludeBlobVersions = this . IncludeBlobVersions
232
238
} ;
239
+
240
+ if ( this . PrefixMatch != null )
241
+ {
242
+ foreach ( string prefixMatch in this . PrefixMatch )
243
+ {
244
+ policyFilter . PrefixMatch . Add ( prefixMatch ) ;
245
+ }
246
+ }
247
+ if ( this . BlobTypes != null )
248
+ {
249
+ foreach ( string blobType in this . BlobTypes )
250
+ {
251
+ policyFilter . BlobTypes . Add ( blobType ) ;
252
+ }
253
+ }
254
+ return policyFilter ;
233
255
}
234
256
235
257
public string [ ] PrefixMatch { get ; set ; }
@@ -245,26 +267,21 @@ public class PSSystemData
245
267
{
246
268
public PSSystemData ( ) { }
247
269
248
- public PSSystemData ( SystemData SystemData )
270
+ public PSSystemData ( global :: Azure . ResourceManager . Models . SystemData SystemData )
249
271
{
250
272
this . CreatedBy = SystemData . CreatedBy ;
251
- this . CreatedByType = SystemData . CreatedByType ;
252
- this . CreatedAt = SystemData . CreatedAt ;
273
+ this . CreatedByType = SystemData . CreatedByType . ToString ( ) ;
274
+ this . CreatedAt = SystemData . CreatedOn ;
253
275
this . LastModifiedBy = SystemData . LastModifiedBy ;
254
- this . LastModifiedByType = SystemData . LastModifiedByType ;
255
- this . LastModifiedAt = SystemData . LastModifiedAt ;
256
- }
257
-
258
- public SystemData ParseSystemData ( )
259
- {
260
- return new SystemData ( this . CreatedBy , this . CreatedByType , this . CreatedAt , this . LastModifiedBy , this . LastModifiedByType , this . LastModifiedAt ) ;
276
+ this . LastModifiedByType = SystemData . LastModifiedByType . ToString ( ) ;
277
+ this . LastModifiedAt = SystemData . LastModifiedOn ;
261
278
}
262
279
263
280
public string CreatedBy { get ; set ; }
264
281
public string CreatedByType { get ; set ; }
265
- public DateTime ? CreatedAt { get ; set ; }
282
+ public DateTimeOffset ? CreatedAt { get ; set ; }
266
283
public string LastModifiedBy { get ; set ; }
267
284
public string LastModifiedByType { get ; set ; }
268
- public DateTime ? LastModifiedAt { get ; set ; }
285
+ public DateTimeOffset ? LastModifiedAt { get ; set ; }
269
286
}
270
287
}
0 commit comments