-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathContainerRegistryResponseUtil.cs
More file actions
76 lines (59 loc) · 2.89 KB
/
ContainerRegistryResponseUtil.cs
File metadata and controls
76 lines (59 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.Json;
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
{
internal class ContainerRegistryResponseUtil : ResponseUtil
{
#region Members
internal override PSRepositoryInfo Repository { get; set; }
#endregion
#region Constructor
public ContainerRegistryResponseUtil(PSRepositoryInfo repository) : base(repository)
{
Repository = repository;
}
#endregion
#region Overridden Methods
public override IEnumerable<PSResourceResult> ConvertToPSResourceResult(FindResults responseResults, bool isResourceRequestedWithWildcard = false)
{
Hashtable[] responses = responseResults.HashtableResponse;
foreach (Hashtable response in responses)
{
string responseConversionError = String.Empty;
PSResourceInfo pkg = null;
// Hashtable should have keys for Name, Metadata, ResourceType
if (!response.ContainsKey("Name") && string.IsNullOrWhiteSpace(response["Name"].ToString()))
{
yield return new PSResourceResult(returnedObject: pkg, exception: new ConvertToPSResourceException("Error retrieving package name from response."), isTerminatingError: true);
}
if (!response.ContainsKey("Metadata"))
{
yield return new PSResourceResult(returnedObject: pkg, exception: new ConvertToPSResourceException("Error retrieving package metadata from response."), isTerminatingError: true);
}
ResourceType? resourceType = response.ContainsKey("ResourceType") ? response["ResourceType"] as ResourceType? : ResourceType.None;
try
{
using (JsonDocument pkgVersionEntry = JsonDocument.Parse(response["Metadata"].ToString()))
{
PSResourceInfo.TryConvertFromContainerRegistryJson(response["Name"].ToString(), pkgVersionEntry, resourceType, out pkg, Repository, out responseConversionError);
}
}
catch (Exception e)
{
responseConversionError = e.Message;
}
if (!String.IsNullOrEmpty(responseConversionError))
{
yield return new PSResourceResult(returnedObject: null, new ConvertToPSResourceException(responseConversionError), isTerminatingError: false);
}
yield return new PSResourceResult(returnedObject: pkg, exception: null, isTerminatingError: false);
}
}
#endregion
}
}