Skip to content

Commit 5aa1e48

Browse files
authored
Add certificate and managed identity support to packages and eventhub (#309)
* Fix issue in VC versioning * Save * save * Save * save * save * Save * Save * save * Save * save * test * test * Fix test * save * fix console log
1 parent 9679cea commit 5aa1e48

27 files changed

+1140
-831
lines changed

.pipelines/ado-pipeline-linux.yml

Lines changed: 0 additions & 596 deletions
This file was deleted.

.pipelines/ado-pipeline-windows.yml

Lines changed: 0 additions & 92 deletions
This file was deleted.

.pipelines/azure-pipelines-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ stages:
147147
repository: 'microsoft-amazonlinux2-prod-yum'
148148

149149

150-
# Azure Mariner
150+
# AzLinux
151151
- task: PublishLinuxPackagesPMC@0
152152
displayName: 'Mariner 2.0 rpm publish'
153153
inputs:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace VirtualClient.Common.Telemetry
5+
{
6+
using System;
7+
using System.Collections.Generic;
8+
using Azure.Core;
9+
using global::Azure.Messaging.EventHubs;
10+
11+
/// <summary>
12+
/// Represents context to authenticate with Azure Event Hub.
13+
/// </summary>
14+
public class EventHubAuthenticationContext
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="EventHubAuthenticationContext"/> class.
18+
/// </summary>
19+
/// <param name="connectionString">Eventhub connection string</param>
20+
public EventHubAuthenticationContext(string connectionString)
21+
{
22+
this.ConnectionString = connectionString;
23+
}
24+
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="EventHubAuthenticationContext"/> class.
27+
/// </summary>
28+
/// <param name="eventHubNameSpace">Eventhub namespace</param>
29+
/// <param name="tokenCredential">Token credential to authenticate with eventhub</param>
30+
public EventHubAuthenticationContext(string eventHubNameSpace, TokenCredential tokenCredential)
31+
{
32+
this.EventHubNamespace = eventHubNameSpace;
33+
this.TokenCredential = tokenCredential;
34+
}
35+
36+
/// <summary>
37+
/// A connection string to authenticate/authorize with eventhub.
38+
/// </summary>
39+
public string ConnectionString { get; }
40+
41+
/// <summary>
42+
/// Fully qualified eventhub namespace
43+
/// </summary>
44+
public string EventHubNamespace { get; }
45+
46+
/// <summary>
47+
/// TokenCredential for Azure Eventhub
48+
/// </summary>
49+
public TokenCredential TokenCredential { get; }
50+
}
51+
}

src/VirtualClient/VirtualClient.Contracts.UnitTests/Parser/TextParserExtensionsTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace VirtualClient.Contracts.Parser
55
{
66
using NUnit.Framework;
77
using System;
8+
using System.Collections.Generic;
89
using VirtualClient.Common;
910
using VirtualClient.TestExtensions;
1011

@@ -114,5 +115,37 @@ public void TextParserExtensionsTranslateTimeUnitAsExpected(string originalText,
114115
{
115116
Assert.AreEqual(TextParsingExtensions.TranslateTimeByUnit(originalText, metricUnit), expectedOutput);
116117
}
118+
119+
[Test]
120+
public void TextParserExtensionsParseVcDelimeteredParameters()
121+
{
122+
string example = "key1=value1;key2=value2;key3=value3";
123+
var result = TextParsingExtensions.ParseVcDelimiteredParameters(example);
124+
CollectionAssert.AreEqual(new Dictionary<string, string>
125+
{
126+
{ "key1", "value1" },
127+
{ "key2", "value2" },
128+
{ "key3", "value3" }
129+
}, result);
130+
131+
string exampleWithSemiColon = "key1=v1a;v1b,v1c;key2=value2;key3=v3a;v3b";
132+
result = TextParsingExtensions.ParseVcDelimiteredParameters(exampleWithSemiColon);
133+
CollectionAssert.AreEqual(new Dictionary<string, string>
134+
{
135+
{ "key1", "v1a;v1b,v1c" },
136+
{ "key2", "value2" },
137+
{ "key3", "v3a;v3b" }
138+
}, result);
139+
140+
string complexExample = "key1=v1a;v1b,v1 c;key2=value2;key3=v 3 a;;v3b,,,key4=v4a,,,v4b;v4c;;;v4d";
141+
result = TextParsingExtensions.ParseVcDelimiteredParameters(complexExample);
142+
CollectionAssert.AreEqual(new Dictionary<string, string>
143+
{
144+
{ "key1", "v1a;v1b,v1 c" },
145+
{ "key2", "value2" },
146+
{ "key3", "v 3 a;;v3b" },
147+
{ "key4", "v4a,,,v4b;v4c;;;v4d" }
148+
}, result);
149+
}
117150
}
118151
}

src/VirtualClient/VirtualClient.Contracts/DependencyBlobStore.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Azure.Core;
12
using VirtualClient.Common.Extensions;
23

34
// Copyright (c) Microsoft Corporation.
@@ -22,9 +23,32 @@ public DependencyBlobStore(string storeName, string connectionToken)
2223
this.ConnectionToken = connectionToken;
2324
}
2425

26+
/// <summary>
27+
/// Initializes an instance of the <see cref="DependencyBlobStore"/> class.
28+
/// </summary>
29+
/// <param name="storeName">The name of the content store (e.g. Content, Packages).</param>
30+
/// <param name="endpointUrl"></param>
31+
/// <param name="tokenCredential"></param>
32+
public DependencyBlobStore(string storeName, string endpointUrl, TokenCredential tokenCredential)
33+
: base(storeName, DependencyStore.StoreTypeAzureStorageBlob)
34+
{
35+
this.EndpointUrl = endpointUrl;
36+
this.TokenCredential = tokenCredential;
37+
}
38+
2539
/// <summary>
2640
/// A connection string or SAS token used to authenticate/authorize with the blob store.
2741
/// </summary>
2842
public string ConnectionToken { get; }
43+
44+
/// <summary>
45+
/// Endpoint for Azure Storage url
46+
/// </summary>
47+
public string EndpointUrl { get; }
48+
49+
/// <summary>
50+
/// TokenCredential for Azure Storage
51+
/// </summary>
52+
public TokenCredential TokenCredential { get; }
2953
}
3054
}

src/VirtualClient/VirtualClient.Contracts/Parser/TextParsingExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace VirtualClient.Contracts
88
using System.Data;
99
using System.Linq;
1010
using System.Text.RegularExpressions;
11+
using YamlDotNet.Core.Tokens;
1112

1213
/// <summary>
1314
/// Extensions for parsing test documents.
@@ -103,6 +104,34 @@ public static IDictionary<string, string> Sectionize(string text, Regex delimite
103104
return result;
104105
}
105106

107+
/// <summary>
108+
/// Sectionize raw text into sections based on regex. First line of each section will become section key!
109+
/// </summary>
110+
/// <param name="text">Raw text.</param>
111+
public static IDictionary<string, IConvertible> ParseVcDelimiteredParameters(string text)
112+
{
113+
IDictionary<string, IConvertible> delimitedValues = new Dictionary<string, IConvertible>(StringComparer.OrdinalIgnoreCase);
114+
string[] segments = text.Split('=', StringSplitOptions.TrimEntries);
115+
// Only start at second segment and end at second to last segment
116+
// Because first segment is the key for first pair, and last segment is the value for last pair.
117+
string key = segments[0];
118+
for (int i = 1; i < segments.Length - 1; i++)
119+
{
120+
// This is just to
121+
int lastCommaIndex = segments[i].LastIndexOf(",,,");
122+
int lastSemicolonIndex = segments[i].LastIndexOf(';');
123+
int splitIndex = Math.Max(lastCommaIndex, lastSemicolonIndex);
124+
125+
string value = segments[i].Substring(0, splitIndex);
126+
delimitedValues.Add(key, value);
127+
key = segments[i].Substring(splitIndex).Trim(';').Trim(',');
128+
}
129+
130+
delimitedValues.Add(key, segments[segments.Length - 1]);
131+
132+
return delimitedValues;
133+
}
134+
106135
/// <summary>
107136
/// Translate the unit of time to second. Example: 1m->60 and 1h->3,600
108137
/// </summary>

src/VirtualClient/VirtualClient.Core.UnitTests/BackwardsCompatibilityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,4 @@ public void TryMapProfileHandlesOriginalProfileNamesNotContainingDashLinuxPostfi
205205
Assert.IsNull(otherProfile);
206206
}
207207
}
208-
}
208+
}

0 commit comments

Comments
 (0)