Extend use of validated string types (#2357)

In the Python code there were more validated string types that haven't been properly ported for use in the C# code (such as Region). Add that type back in and improve some others:

- Use `Region` type to represent regions (implicitly convertible to/from the `AzureLocation` SDK type)
- Improve validation of `Container` type to match Azure specs and use it in more places
- Restore/fix validation of `PoolName` type which was previously removed (#2080) due to being too strict: now allows 1-64 ASCII alphanumeric/hyphen/dash
  - We want to restrict pool names so that we can use them as disambiguating prefixes for scaleset names (see #2189). Note that underscore is not actually permitted in scaleset names so we will probably end up mapping it to hyphen.

Note that once C#7 lands we will be able to simplify the usage of `ValidatedString` a lot (using static abstract methods).

----

Open questions:

For deserializing from "known-good" places such as table storage or from Azure SDK APIs, should we have an `T.UnsafeAssumeValid(string input)` method which does no validation, to protect us from breakage?
This commit is contained in:
George Pollard
2022-09-12 10:06:51 +12:00
committed by GitHub
parent 140638f684
commit 2a2c07ed35
47 changed files with 324 additions and 264 deletions

View File

@ -25,7 +25,9 @@ public class SchedulerTests {
TargetEnv: new Dictionary<string, string>(),
TargetOptions: new List<string>()),
Pool: new TaskPool(1, PoolName.Parse("pool")),
Containers: new List<TaskContainers> { new TaskContainers(ContainerType.Setup, new Container("setup")) },
Containers: new List<TaskContainers> {
new TaskContainers(ContainerType.Setup, Container.Parse("setup"))
},
Colocate: true
),
@ -105,7 +107,7 @@ public class SchedulerTests {
var tasks = BuildTasks(100).Select((task, i) => {
var containers = new List<TaskContainers>(task.Config.Containers!);
if (i % 4 == 0) {
containers[0] = containers[0] with { Name = new Container("setup2") };
containers[0] = containers[0] with { Name = Container.Parse("setup2") };
}
return task with {
JobId = i % 2 == 0 ? jobId : task.JobId,