From f2db563c89424785e4c7c8cc7b0c495142c55ffc Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Wed, 11 Dec 2019 14:52:24 -0500 Subject: [PATCH] delete un-used code. --- src/Runner.Common/Constants.cs | 1 - .../Configuration/CredentialManager.cs | 1 - .../Configuration/CredentialProvider.cs | 38 - src/Runner.Listener/JobDispatcher.cs | 6 - src/Runner.Worker/ExecutionContext.cs | 6 - src/Runner.Worker/Worker.cs | 9 - src/Sdk/DTExpressions/Expressions/AndNode.cs | 22 - .../DTExpressions/Expressions/CoalesceNode.cs | 31 - .../CollectionAccessors/JArrayAccessor.cs | 31 - .../CollectionAccessors/JObjectAccessor.cs | 56 - .../JsonDictionaryContractAccessor.cs | 106 - .../JsonObjectContractAccessor.cs | 89 - .../ListOfObjectAccessor.cs | 30 - ...eadOnlyDictionaryOfStringObjectAccessor.cs | 37 - ...eadOnlyDictionaryOfStringStringAccessor.cs | 54 - .../ReadOnlyListOfObjectAccessor.cs | 24 - .../Expressions/ContainerNode.cs | 49 - .../DTExpressions/Expressions/ContainsNode.cs | 16 - .../Expressions/ContainsValueNode.cs | 46 - .../Expressions/ConversionResult.cs | 19 - .../DTExpressions/Expressions/EndsWithNode.cs | 16 - .../DTExpressions/Expressions/EqualNode.cs | 14 - .../Expressions/EvaluationContext.cs | 78 - .../Expressions/EvaluationMemory.cs | 111 - .../Expressions/EvaluationOptions.cs | 43 - .../Expressions/EvaluationResult.cs | 828 -- .../Expressions/EvaluationTraceWriter.cs | 37 - .../Expressions/ExpressionConstants.cs | 52 - .../Expressions/ExpressionException.cs | 22 - .../Expressions/ExpressionNode.cs | 494 - .../Expressions/ExpressionParser.cs | 547 -- .../Expressions/ExpressionParserOptions.cs | 13 - .../Expressions/ExpressionUtil.cs | 211 - .../DTExpressions/Expressions/FormatNode.cs | 394 - .../DTExpressions/Expressions/FunctionInfo.cs | 26 - .../DTExpressions/Expressions/FunctionNode.cs | 45 - .../Expressions/GreaterThanNode.cs | 14 - .../Expressions/GreaterThanOrEqualNode.cs | 14 - src/Sdk/DTExpressions/Expressions/IBoolean.cs | 12 - .../Expressions/IExpressionNode.cs | 70 - .../Expressions/IFunctionInfo.cs | 12 - .../Expressions/INamedValueInfo.cs | 10 - src/Sdk/DTExpressions/Expressions/INumber.cs | 12 - .../Expressions/IReadOnlyArray.cs | 11 - .../Expressions/IReadOnlyObject.cs | 11 - src/Sdk/DTExpressions/Expressions/IString.cs | 12 - .../DTExpressions/Expressions/ITraceWriter.cs | 10 - src/Sdk/DTExpressions/Expressions/InNode.cs | 24 - .../DTExpressions/Expressions/IndexerNode.cs | 452 - src/Sdk/DTExpressions/Expressions/JoinNode.cs | 69 - .../DTExpressions/Expressions/LessThanNode.cs | 14 - .../Expressions/LessThanOrEqualNode.cs | 14 - .../Expressions/LexicalAnalyzer.cs | 293 - .../Expressions/LiteralValueNode.cs | 47 - .../Expressions/MemoryCounter.cs | 166 - .../Expressions/NamedValueInfo.cs | 20 - .../Expressions/NamedValueNode.cs | 24 - .../DTExpressions/Expressions/NotEqualNode.cs | 14 - .../DTExpressions/Expressions/NotInNode.cs | 24 - src/Sdk/DTExpressions/Expressions/NotNode.cs | 14 - src/Sdk/DTExpressions/Expressions/OrNode.cs | 22 - .../Expressions/ParseException.cs | 65 - .../Expressions/ParseExceptionKind.cs | 14 - .../DTExpressions/Expressions/ResultMemory.cs | 58 - .../Expressions/StartsWithNode.cs | 16 - src/Sdk/DTExpressions/Expressions/Token.cs | 28 - .../DTExpressions/Expressions/TokenKind.cs | 29 - .../Expressions/TypeCastException.cs | 67 - .../Expressions/UnknownFunctionNode.cs | 13 - .../Expressions/UnknownNamedValueNode.cs | 13 - .../DTExpressions/Expressions/ValueKind.cs | 17 - src/Sdk/DTExpressions/Expressions/XOrNode.cs | 14 - .../Generated/TaskAgentHttpClientBase.cs | 7998 ----------------- .../Generated/TaskHttpClientBase.cs | 479 - src/Sdk/DTLogging/Logging/ValueEncoders.cs | 2 +- .../Pipelines/AgentJobRequestMessageUtil.cs | 769 -- .../Pipelines/AgentPoolReference.cs | 38 - .../DTPipelines/Pipelines/AgentPoolStore.cs | 116 - .../DTPipelines/Pipelines/AgentPoolTarget.cs | 169 - .../Pipelines/AgentQueueReference.cs | 38 - .../DTPipelines/Pipelines/AgentQueueStore.cs | 161 - .../DTPipelines/Pipelines/AgentQueueTarget.cs | 647 -- .../Pipelines/Artifacts/ArtifactConstants.cs | 15 - .../Artifacts/DownloadStepExtensions.cs | 150 - .../Pipelines/Artifacts/IArtifactResolver.cs | 49 - .../Artifacts/PipelineArtifactConstants.cs | 113 - .../Artifacts/YamlArtifactConstants.cs | 16 - src/Sdk/DTPipelines/Pipelines/BuildOptions.cs | 119 - .../DTPipelines/Pipelines/BuildResource.cs | 68 - .../Checkpoints/CheckpointContext.cs | 63 - .../Checkpoints/CheckpointDecision.cs | 36 - .../Pipelines/Checkpoints/CheckpointScope.cs | 56 - .../Pipelines/Checkpoints/ResourceInfo.cs | 22 - .../Pipelines/ContinuousIntegrationTrigger.cs | 89 - src/Sdk/DTPipelines/Pipelines/CounterStore.cs | 61 - .../DTPipelines/Pipelines/CreateJobResult.cs | 50 - .../Pipelines/DeploymentExecutionOptions.cs | 74 - .../Pipelines/DeploymentGroupTarget.cs | 158 - .../Environment/EnvironmentReference.cs | 38 - .../Pipelines/EnvironmentDeploymentTarget.cs | 21 - .../DTPipelines/Pipelines/EnvironmentStore.cs | 97 - .../DTPipelines/Pipelines/ExecutionOptions.cs | 107 - .../Pipelines/ExpandPhaseResult.cs | 66 - .../Pipelines/Expressions/CounterNode.cs | 28 - .../Expressions/ExpressionConstants.cs | 30 - .../Expressions/InputValidationConstants.cs | 32 - .../Pipelines/Expressions/InputValueNode.cs | 15 - .../Pipelines/Expressions/IsEmailNode.cs | 22 - .../Expressions/IsIPv4AddressNode.cs | 22 - .../Pipelines/Expressions/IsInRangeNode.cs | 24 - .../Pipelines/Expressions/IsMatchNode.cs | 30 - .../Pipelines/Expressions/IsSHA1Node.cs | 22 - .../Pipelines/Expressions/IsUrlNode.cs | 22 - .../Pipelines/Expressions/LengthNode.cs | 63 - .../Expressions/PipelineContextNode.cs | 32 - .../Expressions/VariablesContextNode.cs | 16 - .../DTPipelines/Pipelines/GraphCondition.cs | 247 - src/Sdk/DTPipelines/Pipelines/GroupStep.cs | 86 - .../Pipelines/IAgentPoolResolver.cs | 37 - .../DTPipelines/Pipelines/IAgentPoolStore.cs | 27 - .../Pipelines/IAgentQueueResolver.cs | 37 - .../DTPipelines/Pipelines/IAgentQueueStore.cs | 27 - .../DTPipelines/Pipelines/ICounterResolver.cs | 11 - .../DTPipelines/Pipelines/ICounterStore.cs | 24 - .../Pipelines/IEnvironmentResolver.cs | 14 - .../Pipelines/IEnvironmentStore.cs | 22 - src/Sdk/DTPipelines/Pipelines/IGraphNode.cs | 51 - src/Sdk/DTPipelines/Pipelines/IJobFactory.cs | 20 - .../DTPipelines/Pipelines/IPackageStore.cs | 12 - .../DTPipelines/Pipelines/IPhaseProvider.cs | 20 - .../DTPipelines/Pipelines/IPipelineContext.cs | 14 - .../Pipelines/IPipelineContextExtensions.cs | 81 - .../Pipelines/IPipelineIdGenerator.cs | 35 - .../DTPipelines/Pipelines/IResourceStore.cs | 87 - .../Pipelines/IResourceStoreExtensions.cs | 198 - .../Pipelines/ISecureFileResolver.cs | 37 - .../DTPipelines/Pipelines/ISecureFileStore.cs | 19 - .../Pipelines/IServiceEndpointResolver.cs | 46 - .../Pipelines/IServiceEndpointStore.cs | 39 - .../DTPipelines/Pipelines/IStepProvider.cs | 21 - .../DTPipelines/Pipelines/ITaskResolver.cs | 12 - src/Sdk/DTPipelines/Pipelines/ITaskStore.cs | 30 - .../Pipelines/ITaskTemplateResolver.cs | 14 - .../Pipelines/ITaskTemplateStore.cs | 16 - src/Sdk/DTPipelines/Pipelines/IVariable.cs | 88 - .../Pipelines/IVariableGroupResolver.cs | 32 - .../Pipelines/IVariableGroupStore.cs | 21 - .../Pipelines/IVariableValueProvider.cs | 22 - src/Sdk/DTPipelines/Pipelines/Job.cs | 291 - .../Pipelines/JobExpansionOptions.cs | 106 - src/Sdk/DTPipelines/Pipelines/JobFactory.cs | 480 - src/Sdk/DTPipelines/Pipelines/JobResources.cs | 23 - .../GraphConditionNamedValue.cs | 24 - .../ObjectTemplating/MatrixBuilder.cs | 445 - .../PipelineTemplateConverter.cs | 783 -- .../PipelineTemplateEvaluator.cs | 85 - .../PipelineTemplateParser.cs | 239 - .../ObjectTemplating/ReferenceNameBuilder.cs | 121 - .../ObjectTemplating/YamlTemplateLoader.cs | 251 - src/Sdk/DTPipelines/Pipelines/PackageStore.cs | 51 - .../Pipelines/ParallelExecutionOptions.cs | 315 - src/Sdk/DTPipelines/Pipelines/Phase.cs | 1677 ---- .../DTPipelines/Pipelines/PhaseCondition.cs | 22 - .../DTPipelines/Pipelines/PhaseDependency.cs | 56 - src/Sdk/DTPipelines/Pipelines/PhaseNode.cs | 421 - src/Sdk/DTPipelines/Pipelines/PhaseTarget.cs | 260 - .../DTPipelines/Pipelines/PhaseTargetType.cs | 24 - .../Pipelines/PipelineBuildContext.cs | 182 - .../Pipelines/PipelineBuildResult.cs | 73 - .../DTPipelines/Pipelines/PipelineBuilder.cs | 411 - .../Pipelines/PipelineConstants.cs | 82 - .../Pipelines/PipelineContextBase.cs | 439 - .../Pipelines/PipelineContextBuilder.cs | 562 -- .../Pipelines/PipelineEnvironment.cs | 212 - .../Pipelines/PipelineException.cs | 297 - .../Pipelines/PipelineIdGenerator.cs | 114 - .../DTPipelines/Pipelines/PipelineProcess.cs | 115 - .../DTPipelines/Pipelines/PipelineResource.cs | 57 - .../Pipelines/PipelineResources.cs | 570 -- .../DTPipelines/Pipelines/PipelineState.cs | 22 - .../Pipelines/PipelineStepsTemplate.cs | 55 - .../DTPipelines/Pipelines/PipelineTemplate.cs | 147 - .../DTPipelines/Pipelines/PipelineTrigger.cs | 22 - .../Pipelines/PipelineTriggerType.cs | 18 - .../Pipelines/PipelineUtilities.cs | 407 - .../Pipelines/PipelineValidationError.cs | 60 - .../Pipelines/PipelineValidationErrors.cs | 99 - .../DTPipelines/Pipelines/ProviderPhase.cs | 227 - .../Pipelines/PullRequestTrigger.cs | 83 - .../DTPipelines/Pipelines/ResourceComparer.cs | 20 - .../DTPipelines/Pipelines/ResourceStore.cs | 666 -- .../Pipelines/Runtime/AgentJobStartedData.cs | 17 - .../Runtime/GraphExecutionContext.cs | 46 - .../Pipelines/Runtime/GraphNodeInstance.cs | 144 - .../Pipelines/Runtime/JobAttempt.cs | 14 - .../Pipelines/Runtime/JobExecutionContext.cs | 113 - .../Pipelines/Runtime/JobInstance.cs | 124 - .../Pipelines/Runtime/JobStartedEventData.cs | 30 - .../Pipelines/Runtime/PhaseAttempt.cs | 30 - .../Runtime/PhaseExecutionContext.cs | 116 - .../Pipelines/Runtime/PhaseInstance.cs | 61 - .../Runtime/PipelineAttemptBuilder.cs | 632 -- .../Runtime/PipelineExecutionContext.cs | 68 - .../Pipelines/Runtime/StageAttempt.cs | 40 - .../Runtime/StageExecutionContext.cs | 63 - .../Pipelines/Runtime/StageInstance.cs | 61 - .../Pipelines/SecretStoreConfiguration.cs | 91 - .../Pipelines/SecureFileReference.cs | 38 - .../DTPipelines/Pipelines/SecureFileStore.cs | 105 - src/Sdk/DTPipelines/Pipelines/ServerTarget.cs | 92 - .../Pipelines/ServiceEndpointStore.cs | 118 - src/Sdk/DTPipelines/Pipelines/Stage.cs | 208 - .../DTPipelines/Pipelines/StageCondition.cs | 22 - src/Sdk/DTPipelines/Pipelines/Step.cs | 16 - .../DTPipelines/Pipelines/StepConverter.cs | 43 +- .../DTPipelines/Pipelines/TaskCondition.cs | 166 - .../Pipelines/TaskDefinitionExtensions.cs | 70 - src/Sdk/DTPipelines/Pipelines/TaskStep.cs | 177 - .../Pipelines/TaskStepDefinitionReference.cs | 51 - src/Sdk/DTPipelines/Pipelines/TaskStore.cs | 214 - .../Pipelines/TaskTemplateReference.cs | 47 - .../DTPipelines/Pipelines/TaskTemplateStep.cs | 65 - .../Pipelines/TaskTemplateStore.cs | 36 - .../Pipelines/TimelineRecordIdGenerator.cs | 189 - .../Pipelines/Validation/GraphValidator.cs | 186 - .../Pipelines/Validation/IInputValidator.cs | 18 - .../Validation/InputValidationContext.cs | 73 - .../Validation/InputValidationResult.cs | 43 - .../Pipelines/Validation/InputValidator.cs | 44 - .../Validation/ScriptTaskValidator.cs | 198 - .../Pipelines/Validation/ValidationResult.cs | 110 - src/Sdk/DTPipelines/Pipelines/Variable.cs | 50 - .../Pipelines/VariableGroupReference.cs | 63 - .../Pipelines/VariableGroupStore.cs | 187 - .../DTPipelines/Pipelines/WorkspaceMapping.cs | 71 - .../DTWebApi/WebApi/AgentJobRequestMessage.cs | 79 - src/Sdk/DTWebApi/WebApi/AuditAction.cs | 19 - .../AzureKeyVaultVariableGroupProviderData.cs | 30 - .../WebApi/AzureKeyVaultVariableValue.cs | 47 - src/Sdk/DTWebApi/WebApi/DeploymentGroup.cs | 83 - .../WebApi/DeploymentGroupActionFilter.cs | 31 - .../WebApi/DeploymentGroupCreateParameter.cs | 72 - .../DTWebApi/WebApi/DeploymentGroupExpands.cs | 31 - .../DTWebApi/WebApi/DeploymentGroupMetrics.cs | 62 - .../WebApi/DeploymentGroupReference.cs | 90 - .../WebApi/DeploymentGroupUpdateParameter.cs | 32 - src/Sdk/DTWebApi/WebApi/DeploymentMachine.cs | 99 - .../WebApi/DeploymentMachineExpands.cs | 19 - .../DTWebApi/WebApi/DeploymentMachineGroup.cs | 38 - .../WebApi/DeploymentMachineGroupReference.cs | 37 - .../DTWebApi/WebApi/DeploymentPoolSummary.cs | 78 - .../WebApi/DeploymentPoolSummaryExpands.cs | 31 - .../WebApi/DeploymentTargetExpands.cs | 37 - .../WebApi/DeploymentTargetUpdateParameter.cs | 41 - .../Environment/EnvironmentCreateParameter.cs | 35 - .../EnvironmentDeploymentExecutionRecord.cs | 192 - .../WebApi/Environment/EnvironmentExpands.cs | 25 - .../WebApi/Environment/EnvironmentInstance.cs | 116 - .../EnvironmentLinkedResourceReference.cs | 34 - .../Environment/EnvironmentReference.cs | 18 - .../WebApi/Environment/EnvironmentResource.cs | 51 - .../EnvironmentResourceReference.cs | 63 - .../Environment/EnvironmentResourceType.cs | 31 - .../Environment/EnvironmentUpdateParameter.cs | 34 - .../WebApi/Environment/KubernetesResource.cs | 20 - .../KubernetesResourceCreateParameters.cs | 23 - .../WebApi/Environment/VirtualMachine.cs | 41 - .../WebApi/Environment/VirtualMachineGroup.cs | 14 - .../VirtualMachineGroupCreateParameters.cs | 14 - .../DTWebApi/WebApi/IOrchestrationProcess.cs | 172 - src/Sdk/DTWebApi/WebApi/JobEnvironment.cs | 294 - src/Sdk/DTWebApi/WebApi/JobEvent.cs | 105 - src/Sdk/DTWebApi/WebApi/JobRequestMessage.cs | 86 - .../WebApi/JobRequestMessageJsonConverter.cs | 89 - .../WebApi/MachineGroupActionFilter.cs | 19 - .../WebApi/MarketplacePurchasedLicense.cs | 35 - src/Sdk/DTWebApi/WebApi/PlanEnvironment.cs | 156 - .../WebApi/PublishTaskGroupMetadata.cs | 20 - src/Sdk/DTWebApi/WebApi/ResourceLimit.cs | 96 - src/Sdk/DTWebApi/WebApi/ResourceUsage.cs | 58 - src/Sdk/DTWebApi/WebApi/SecureFile.cs | 109 - .../DTWebApi/WebApi/SecureFileActionFilter.cs | 19 - .../WebApi/ServerTaskRequestMessage.cs | 43 - .../ServerTaskSectionExecutionOutput.cs | 14 - .../AadLoginPromptOption.cs | 46 - .../AadOauthTokenRequest.cs | 21 - .../AadOauthTokenResult.cs | 15 - .../AzureKeyVaultPermission.cs | 16 - .../AzureManagementGroup.cs | 40 - .../AzureManagementGroupQueryResult.cs | 26 - .../ServiceEndpointLegacy/AzurePermission.cs | 130 - .../AzurePermissionResourceProviders.cs | 12 - .../AzureResourcePermission.cs | 16 - .../AzureRoleAssignmentPermission.cs | 17 - .../AzureSubscription.cs | 24 - .../AzureSubscriptionQueryResult.cs | 17 - .../DataSourceBinding.cs | 29 - .../DTWebApi/WebApi/TaskAgentHttpClient.cs | 540 -- .../WebApi/TaskAgentHttpClientCompatBase.cs | 316 - .../TaskAgentPoolMaintenanceDefinition.cs | 168 - .../WebApi/TaskAgentPoolMaintenanceJob.cs | 169 - .../TaskAgentPoolMaintenanceJobResult.cs | 18 - .../TaskAgentPoolMaintenanceJobStatus.cs | 21 - .../TaskAgentPoolMaintenanceJobTargetAgent.cs | 41 - .../WebApi/TaskAgentPoolMaintenanceOptions.cs | 33 - ...TaskAgentPoolMaintenanceRetentionPolicy.cs | 47 - .../TaskAgentPoolMaintenanceSchedule.cs | 58 - .../TaskAgentPoolMaintenanceScheduleDays.cs | 62 - src/Sdk/DTWebApi/WebApi/TaskAgentQueue.cs | 97 - .../WebApi/TaskAgentQueueActionFilter.cs | 22 - src/Sdk/DTWebApi/WebApi/TaskDefinition.cs | 552 -- .../DTWebApi/WebApi/TaskDefinitionEndpoint.cs | 87 - .../WebApi/TaskDefinitionReference.cs | 78 - src/Sdk/DTWebApi/WebApi/TaskDefinitionType.cs | 12 - src/Sdk/DTWebApi/WebApi/TaskExecution.cs | 68 - src/Sdk/DTWebApi/WebApi/TaskGroup.cs | 173 - .../WebApi/TaskGroupCreateParameter.cs | 140 - .../DTWebApi/WebApi/TaskGroupDefinition.cs | 96 - src/Sdk/DTWebApi/WebApi/TaskGroupExpands.cs | 11 - .../DTWebApi/WebApi/TaskGroupQueryOrder.cs | 30 - src/Sdk/DTWebApi/WebApi/TaskGroupRevision.cs | 34 - src/Sdk/DTWebApi/WebApi/TaskGroupStep.cs | 156 - .../WebApi/TaskGroupUpdateParameter.cs | 158 - src/Sdk/DTWebApi/WebApi/TaskHttpClient.cs | 14 - .../DTWebApi/WebApi/TaskHubLicenseDetails.cs | 78 - .../DTWebApi/WebApi/TaskInputDefinition.cs | 35 - src/Sdk/DTWebApi/WebApi/TaskInputType.cs | 15 - src/Sdk/DTWebApi/WebApi/TaskInstance.cs | 130 - .../WebApi/TaskOrchestrationContainer.cs | 116 - .../DTWebApi/WebApi/TaskOrchestrationItem.cs | 24 - .../TaskOrchestrationItemJsonConverter.cs | 100 - .../WebApi/TaskOrchestrationItemType.cs | 14 - .../DTWebApi/WebApi/TaskOrchestrationJob.cs | 166 - .../DTWebApi/WebApi/TaskOrchestrationPlan.cs | 145 - ...TaskOrchestrationPlanGroupsQueueMetrics.cs | 23 - .../WebApi/TaskOrchestrationPlanReference.cs | 7 - .../WebApi/TaskOrchestrationQueuedPlan.cs | 72 - .../TaskOrchestrationQueuedPlanGroup.cs | 61 - .../DTWebApi/WebApi/TaskRunsOnConstants.cs | 23 - .../DTWebApi/WebApi/TaskSourceDefinition.cs | 35 - src/Sdk/DTWebApi/WebApi/TaskVersion.cs | 182 - src/Sdk/DTWebApi/WebApi/TaskVersionSpec.cs | 239 - src/Sdk/DTWebApi/WebApi/VariableGroup.cs | 244 - .../WebApi/VariableGroupActionFilter.cs | 19 - .../WebApi/VariableGroupParameters.cs | 159 - .../WebApi/VariableGroupProviderData.cs | 13 - .../WebApi/VariableGroupQueryOrder.cs | 29 - src/Sdk/DTWebApi/WebApi/VariableGroupType.cs | 12 - .../DTWebApi/WebApi/VariableGroupUtility.cs | 300 - src/Sdk/DTWebApi/WebApi/VariableValue.cs | 1 - src/Sdk/Resources/ContentResources.g.cs | 20 - .../Configuration/ArgumentValidatorTestsL0.cs | 2 +- .../Configuration/ConfigurationManagerL0.cs | 2 - src/Test/L0/Listener/JobDispatcherL0.cs | 7 +- src/Test/L0/Listener/RunnerL0.cs | 9 +- src/Test/L0/ProcessInvokerL0.cs | 2 +- src/Test/L0/Worker/ActionCommandManagerL0.cs | 7 +- src/Test/L0/Worker/ExecutionContextL0.cs | 21 +- src/Test/L0/Worker/JobRunnerL0.cs | 19 +- src/Test/L0/Worker/WorkerL0.cs | 14 +- 360 files changed, 41 insertions(+), 42871 deletions(-) delete mode 100644 src/Sdk/DTExpressions/Expressions/AndNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CoalesceNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CollectionAccessors/JArrayAccessor.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CollectionAccessors/JObjectAccessor.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CollectionAccessors/JsonDictionaryContractAccessor.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CollectionAccessors/JsonObjectContractAccessor.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CollectionAccessors/ListOfObjectAccessor.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyDictionaryOfStringObjectAccessor.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyDictionaryOfStringStringAccessor.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyListOfObjectAccessor.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ContainerNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ContainsNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ContainsValueNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ConversionResult.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/EndsWithNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/EqualNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/EvaluationContext.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/EvaluationMemory.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/EvaluationOptions.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/EvaluationResult.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/EvaluationTraceWriter.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ExpressionConstants.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ExpressionException.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ExpressionNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ExpressionParser.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ExpressionParserOptions.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ExpressionUtil.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/FormatNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/FunctionInfo.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/FunctionNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/GreaterThanNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/GreaterThanOrEqualNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/IBoolean.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/IExpressionNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/IFunctionInfo.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/INamedValueInfo.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/INumber.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/IReadOnlyArray.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/IReadOnlyObject.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/IString.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ITraceWriter.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/InNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/IndexerNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/JoinNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/LessThanNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/LessThanOrEqualNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/LexicalAnalyzer.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/LiteralValueNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/MemoryCounter.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/NamedValueInfo.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/NamedValueNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/NotEqualNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/NotInNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/NotNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/OrNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ParseException.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ParseExceptionKind.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ResultMemory.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/StartsWithNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/Token.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/TokenKind.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/TypeCastException.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/UnknownFunctionNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/UnknownNamedValueNode.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/ValueKind.cs delete mode 100644 src/Sdk/DTExpressions/Expressions/XOrNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/AgentJobRequestMessageUtil.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/AgentPoolReference.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/AgentPoolStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/AgentPoolTarget.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/AgentQueueReference.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/AgentQueueStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/AgentQueueTarget.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Artifacts/ArtifactConstants.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Artifacts/DownloadStepExtensions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Artifacts/IArtifactResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Artifacts/PipelineArtifactConstants.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Artifacts/YamlArtifactConstants.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/BuildOptions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/BuildResource.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointContext.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointDecision.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointScope.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Checkpoints/ResourceInfo.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ContinuousIntegrationTrigger.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/CounterStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/CreateJobResult.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/DeploymentExecutionOptions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/DeploymentGroupTarget.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Environment/EnvironmentReference.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/EnvironmentDeploymentTarget.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/EnvironmentStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ExecutionOptions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ExpandPhaseResult.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/CounterNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/ExpressionConstants.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/InputValidationConstants.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/InputValueNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/IsEmailNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/IsIPv4AddressNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/IsInRangeNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/IsMatchNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/IsSHA1Node.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/IsUrlNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/LengthNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/PipelineContextNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Expressions/VariablesContextNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/GraphCondition.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/GroupStep.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IAgentPoolResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IAgentPoolStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IAgentQueueResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IAgentQueueStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ICounterResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ICounterStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IEnvironmentResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IEnvironmentStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IGraphNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IJobFactory.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IPackageStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IPhaseProvider.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IPipelineContextExtensions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IPipelineIdGenerator.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IResourceStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IResourceStoreExtensions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ISecureFileResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ISecureFileStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IServiceEndpointResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IServiceEndpointStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IStepProvider.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ITaskResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ITaskStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ITaskTemplateResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ITaskTemplateStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IVariable.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IVariableGroupResolver.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IVariableGroupStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/IVariableValueProvider.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Job.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/JobExpansionOptions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/JobFactory.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ObjectTemplating/GraphConditionNamedValue.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ObjectTemplating/MatrixBuilder.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateParser.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ObjectTemplating/ReferenceNameBuilder.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ObjectTemplating/YamlTemplateLoader.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PackageStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ParallelExecutionOptions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Phase.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PhaseCondition.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PhaseDependency.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PhaseNode.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PhaseTarget.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PhaseTargetType.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineBuildContext.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineBuildResult.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineBuilder.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineContextBase.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineContextBuilder.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineEnvironment.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineException.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineIdGenerator.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineProcess.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineResource.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineResources.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineState.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineStepsTemplate.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineTemplate.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineTrigger.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineTriggerType.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineUtilities.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineValidationError.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PipelineValidationErrors.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ProviderPhase.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/PullRequestTrigger.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ResourceComparer.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ResourceStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/AgentJobStartedData.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/GraphExecutionContext.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/GraphNodeInstance.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/JobAttempt.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/JobExecutionContext.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/JobInstance.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/JobStartedEventData.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/PhaseAttempt.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/PhaseExecutionContext.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/PhaseInstance.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/PipelineAttemptBuilder.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/PipelineExecutionContext.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/StageAttempt.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/StageExecutionContext.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Runtime/StageInstance.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/SecretStoreConfiguration.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/SecureFileReference.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/SecureFileStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ServerTarget.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/ServiceEndpointStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Stage.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/StageCondition.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TaskCondition.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TaskDefinitionExtensions.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TaskStep.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TaskStepDefinitionReference.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TaskStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TaskTemplateReference.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TaskTemplateStep.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TaskTemplateStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/TimelineRecordIdGenerator.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Validation/GraphValidator.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Validation/IInputValidator.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Validation/InputValidationContext.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Validation/InputValidationResult.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Validation/InputValidator.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Validation/ScriptTaskValidator.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Validation/ValidationResult.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/Variable.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/VariableGroupReference.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/VariableGroupStore.cs delete mode 100644 src/Sdk/DTPipelines/Pipelines/WorkspaceMapping.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/AgentJobRequestMessage.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/AuditAction.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/AzureKeyVaultVariableGroupProviderData.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/AzureKeyVaultVariableValue.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentGroup.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentGroupActionFilter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentGroupCreateParameter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentGroupExpands.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentGroupMetrics.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentGroupReference.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentGroupUpdateParameter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentMachine.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentMachineExpands.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentMachineGroup.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentMachineGroupReference.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentPoolSummary.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentPoolSummaryExpands.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentTargetExpands.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/DeploymentTargetUpdateParameter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentCreateParameter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentDeploymentExecutionRecord.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentExpands.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentInstance.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentLinkedResourceReference.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentReference.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResource.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResourceReference.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResourceType.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/EnvironmentUpdateParameter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/KubernetesResource.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/KubernetesResourceCreateParameters.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/VirtualMachine.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/VirtualMachineGroup.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/Environment/VirtualMachineGroupCreateParameters.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/IOrchestrationProcess.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/JobEnvironment.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/JobRequestMessage.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/JobRequestMessageJsonConverter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/MachineGroupActionFilter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/MarketplacePurchasedLicense.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/PlanEnvironment.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/PublishTaskGroupMetadata.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ResourceLimit.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ResourceUsage.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/SecureFile.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/SecureFileActionFilter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServerTaskRequestMessage.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServerTaskSectionExecutionOutput.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadLoginPromptOption.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadOauthTokenRequest.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadOauthTokenResult.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureKeyVaultPermission.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureManagementGroup.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureManagementGroupQueryResult.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermission.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermissionResourceProviders.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureResourcePermission.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureRoleAssignmentPermission.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureSubscription.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureSubscriptionQueryResult.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/DataSourceBinding.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceDefinition.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJob.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobResult.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobStatus.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobTargetAgent.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceOptions.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceRetentionPolicy.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceSchedule.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceScheduleDays.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentQueue.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskAgentQueueActionFilter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskDefinition.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskDefinitionEndpoint.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskDefinitionReference.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskDefinitionType.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskExecution.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskGroup.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskGroupCreateParameter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskGroupDefinition.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskGroupExpands.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskGroupQueryOrder.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskGroupRevision.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskGroupStep.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskGroupUpdateParameter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskHubLicenseDetails.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskInputDefinition.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskInputType.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskInstance.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationContainer.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationItem.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationItemJsonConverter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationItemType.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationJob.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlan.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlanGroupsQueueMetrics.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationQueuedPlan.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskOrchestrationQueuedPlanGroup.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskRunsOnConstants.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskSourceDefinition.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskVersion.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/TaskVersionSpec.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/VariableGroup.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/VariableGroupActionFilter.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/VariableGroupParameters.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/VariableGroupProviderData.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/VariableGroupQueryOrder.cs delete mode 100644 src/Sdk/DTWebApi/WebApi/VariableGroupType.cs delete mode 100644 src/Sdk/Resources/ContentResources.g.cs diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index f4211ce91..c7c0b7a0e 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -166,7 +166,6 @@ namespace GitHub.Runner.Common { public static readonly string AAD = "AAD"; public static readonly string OAuthAccessToken = "OAuthAccessToken"; - public static readonly string PAT = "PAT"; public static readonly string OAuth = "OAuth"; } diff --git a/src/Runner.Listener/Configuration/CredentialManager.cs b/src/Runner.Listener/Configuration/CredentialManager.cs index 34e540fe6..a56f865a6 100644 --- a/src/Runner.Listener/Configuration/CredentialManager.cs +++ b/src/Runner.Listener/Configuration/CredentialManager.cs @@ -21,7 +21,6 @@ namespace GitHub.Runner.Listener.Configuration public static readonly Dictionary CredentialTypes = new Dictionary(StringComparer.OrdinalIgnoreCase) { { Constants.Configuration.AAD, typeof(AadDeviceCodeAccessToken)}, - { Constants.Configuration.PAT, typeof(PersonalAccessToken)}, { Constants.Configuration.OAuth, typeof(OAuthCredential)}, { Constants.Configuration.OAuthAccessToken, typeof(OAuthAccessTokenCredential)}, }; diff --git a/src/Runner.Listener/Configuration/CredentialProvider.cs b/src/Runner.Listener/Configuration/CredentialProvider.cs index 5223c0803..7af741b2a 100644 --- a/src/Runner.Listener/Configuration/CredentialProvider.cs +++ b/src/Runner.Listener/Configuration/CredentialProvider.cs @@ -190,42 +190,4 @@ namespace GitHub.Runner.Listener.Configuration CredentialData.Data[Constants.Runner.CommandLine.Args.Token] = command.GetToken(); } } - - public sealed class PersonalAccessToken : CredentialProvider - { - public PersonalAccessToken() : base(Constants.Configuration.PAT) { } - - public override VssCredentials GetVssCredentials(IHostContext context) - { - ArgUtil.NotNull(context, nameof(context)); - Tracing trace = context.GetTrace(nameof(PersonalAccessToken)); - trace.Info(nameof(GetVssCredentials)); - ArgUtil.NotNull(CredentialData, nameof(CredentialData)); - string token; - if (!CredentialData.Data.TryGetValue(Constants.Runner.CommandLine.Args.Token, out token)) - { - token = null; - } - - ArgUtil.NotNullOrEmpty(token, nameof(token)); - - trace.Info("token retrieved: {0} chars", token.Length); - - // PAT uses a basic credential - VssBasicCredential basicCred = new VssBasicCredential("ActionsRunner", token); - VssCredentials creds = new VssCredentials(null, basicCred, CredentialPromptType.DoNotPrompt); - trace.Info("cred created"); - - return creds; - } - - public override void EnsureCredential(IHostContext context, CommandSettings command, string serverUrl) - { - ArgUtil.NotNull(context, nameof(context)); - Tracing trace = context.GetTrace(nameof(PersonalAccessToken)); - trace.Info(nameof(EnsureCredential)); - ArgUtil.NotNull(command, nameof(command)); - CredentialData.Data[Constants.Runner.CommandLine.Args.Token] = command.GetToken(); - } - } } diff --git a/src/Runner.Listener/JobDispatcher.cs b/src/Runner.Listener/JobDispatcher.cs index 4fa3af7fd..d48f2f6ce 100644 --- a/src/Runner.Listener/JobDispatcher.cs +++ b/src/Runner.Listener/JobDispatcher.cs @@ -22,7 +22,6 @@ namespace GitHub.Runner.Listener void Run(Pipelines.AgentJobRequestMessage message, bool runOnce = false); bool Cancel(JobCancelMessage message); Task WaitAsync(CancellationToken token); - TaskResult GetLocalRunJobResult(AgentJobRequestMessage message); Task ShutdownAsync(); } @@ -165,11 +164,6 @@ namespace GitHub.Runner.Listener } } - public TaskResult GetLocalRunJobResult(AgentJobRequestMessage message) - { - return _localRunJobResult.Value[message.RequestId]; - } - public async Task ShutdownAsync() { Trace.Info($"Shutting down JobDispatcher. Make sure all WorkerDispatcher has finished."); diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index 23e6ad8fa..c8692fe3c 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -41,7 +41,6 @@ namespace GitHub.Runner.Worker TaskResult? CommandResult { get; set; } CancellationToken CancellationToken { get; } List Endpoints { get; } - List SecureFiles { get; } PlanFeatures Features { get; } Variables Variables { get; } @@ -136,7 +135,6 @@ namespace GitHub.Runner.Worker public Task ForceCompleted => _forceCompleted.Task; public CancellationToken CancellationToken => _cancellationTokenSource.Token; public List Endpoints { get; private set; } - public List SecureFiles { get; private set; } public Variables Variables { get; private set; } public Dictionary IntraActionState { get; private set; } public HashSet OutputVariables => _outputvariables; @@ -257,7 +255,6 @@ namespace GitHub.Runner.Worker child.Features = Features; child.Variables = Variables; child.Endpoints = Endpoints; - child.SecureFiles = SecureFiles; if (intraActionState == null) { child.IntraActionState = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -549,9 +546,6 @@ namespace GitHub.Runner.Worker // Endpoints Endpoints = message.Resources.Endpoints; - // SecureFiles - SecureFiles = message.Resources.SecureFiles; - // Variables Variables = new Variables(HostContext, message.Variables); diff --git a/src/Runner.Worker/Worker.cs b/src/Runner.Worker/Worker.cs index de22c444e..97141d42e 100644 --- a/src/Runner.Worker/Worker.cs +++ b/src/Runner.Worker/Worker.cs @@ -178,15 +178,6 @@ namespace GitHub.Runner.Worker } } } - - // Add masks for secure file download tickets - foreach (SecureFile file in message.Resources.SecureFiles ?? new List()) - { - if (!string.IsNullOrEmpty(file.Ticket)) - { - HostContext.SecretMasker.AddValue(file.Ticket); - } - } } private void SetCulture(Pipelines.AgentJobRequestMessage message) diff --git a/src/Sdk/DTExpressions/Expressions/AndNode.cs b/src/Sdk/DTExpressions/Expressions/AndNode.cs deleted file mode 100644 index 47411f8c7..000000000 --- a/src/Sdk/DTExpressions/Expressions/AndNode.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class AndNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - foreach (ExpressionNode parameter in Parameters) - { - if (!parameter.EvaluateBoolean(context)) - { - return false; - } - } - - return true; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CoalesceNode.cs b/src/Sdk/DTExpressions/Expressions/CoalesceNode.cs deleted file mode 100644 index 87ff6ff6b..000000000 --- a/src/Sdk/DTExpressions/Expressions/CoalesceNode.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class CoalesceNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - EvaluationResult result = null; - foreach (ExpressionNode parameter in Parameters) - { - result = parameter.Evaluate(context); - if (result.Kind == ValueKind.Null) - { - continue; - } - - if (result.Kind == ValueKind.String && String.IsNullOrEmpty(result.Value as String)) - { - continue; - } - - break; - } - - return result?.Value; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JArrayAccessor.cs b/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JArrayAccessor.cs deleted file mode 100644 index 3ee25afa9..000000000 --- a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JArrayAccessor.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Expressions.CollectionAccessors -{ - internal sealed class JArrayAccessor : IReadOnlyArray - { - public JArrayAccessor(JArray jarray) - { - m_jarray = jarray; - } - - public Int32 Count => m_jarray.Count; - - public Object this[Int32 index] => m_jarray[index]; - - public IEnumerator GetEnumerator() - { - return m_jarray.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return m_jarray.GetEnumerator(); - } - - private readonly JArray m_jarray; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JObjectAccessor.cs b/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JObjectAccessor.cs deleted file mode 100644 index 4484812fa..000000000 --- a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JObjectAccessor.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Expressions.CollectionAccessors -{ - internal sealed class JObjectAccessor : IReadOnlyObject - { - public JObjectAccessor(JObject jobject) - { - m_jobject = jobject; - } - - public Int32 Count => m_jobject.Count; - - public IEnumerable Keys => (m_jobject as IDictionary).Keys; - - // This uses Select. Calling .Values directly throws an exception. - public IEnumerable Values => (m_jobject as IDictionary).Select(x => x.Value); - - public Object this[String key] => m_jobject[key]; - - public Boolean ContainsKey(String key) - { - return (m_jobject as IDictionary).ContainsKey(key); - } - - public IEnumerator> GetEnumerator() - { - return (m_jobject as IDictionary).Select(x => new KeyValuePair(x.Key, x.Value)).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return (m_jobject as IDictionary).Select(x => new KeyValuePair(x.Key, x.Value)).GetEnumerator(); - } - - public Boolean TryGetValue( - String key, - out Object value) - { - if ((m_jobject as IDictionary).TryGetValue(key, out JToken val)) - { - value = val; - return true; - } - - value = null; - return false; - } - - private readonly JObject m_jobject; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JsonDictionaryContractAccessor.cs b/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JsonDictionaryContractAccessor.cs deleted file mode 100644 index 9b1821985..000000000 --- a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JsonDictionaryContractAccessor.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Newtonsoft.Json.Serialization; - -namespace GitHub.DistributedTask.Expressions.CollectionAccessors -{ - internal sealed class JsonDictionaryContractAccessor : IReadOnlyObject - { - public JsonDictionaryContractAccessor( - JsonDictionaryContract contract, - Object obj) - { - m_contract = contract; - m_obj = obj; - } - - public Int32 Count - { - get - { - var genericMethod = s_getCountTemplate.Value.MakeGenericMethod(m_contract.DictionaryValueType); - return (Int32)genericMethod.Invoke(null, new[] { m_obj }); - } - } - - public IEnumerable Keys - { - get - { - var genericMethod = s_getKeysTemplate.Value.MakeGenericMethod(m_contract.DictionaryValueType); - return genericMethod.Invoke(null, new[] { m_obj }) as IEnumerable; - } - } - - public IEnumerable Values => Keys.Select(x => this[x]); - - public Object this[String key] - { - get - { - if (TryGetValue(key, out Object value)) - { - return value; - } - - throw new KeyNotFoundException(ExpressionResources.KeyNotFound(key)); - } - } - - public Boolean ContainsKey(String key) - { - return TryGetValue(key, out _); - } - - public IEnumerator> GetEnumerator() - { - return Keys.Select(x => new KeyValuePair(x, this[x])).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return Keys.Select(x => new KeyValuePair(x, this[x])).GetEnumerator(); - } - - public Boolean TryGetValue( - String key, - out Object value) - { - var genericMethod = s_tryGetValueTemplate.Value.MakeGenericMethod(m_contract.DictionaryValueType); - var tuple = genericMethod.Invoke(null, new[] { m_obj, key }) as Tuple; - value = tuple.Item2; - return tuple.Item1; - } - - private static Int32 GetCount(IDictionary dictionary) - { - return dictionary.Count; - } - - private static IEnumerable GetKeys(IDictionary dictionary) - { - return dictionary.Keys; - } - - private static Tuple TryGetValue( - IDictionary dictionary, - String key) - { - if (dictionary.TryGetValue(key, out TValue value)) - { - return new Tuple(true, value); - } - - return new Tuple(false, null); - } - - private static Lazy s_getCountTemplate = new Lazy(() => typeof(JsonDictionaryContractAccessor).GetTypeInfo().GetMethod(nameof(GetCount), BindingFlags.NonPublic | BindingFlags.Static)); - private static Lazy s_getKeysTemplate = new Lazy(() => typeof(JsonDictionaryContractAccessor).GetTypeInfo().GetMethod(nameof(GetKeys), BindingFlags.NonPublic | BindingFlags.Static)); - private static Lazy s_tryGetValueTemplate = new Lazy(() => typeof(JsonDictionaryContractAccessor).GetTypeInfo().GetMethod(nameof(TryGetValue), BindingFlags.NonPublic | BindingFlags.Static)); - private readonly JsonDictionaryContract m_contract; - private readonly Object m_obj; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JsonObjectContractAccessor.cs b/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JsonObjectContractAccessor.cs deleted file mode 100644 index 56928166f..000000000 --- a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/JsonObjectContractAccessor.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json.Serialization; - -namespace GitHub.DistributedTask.Expressions.CollectionAccessors -{ - internal sealed class JsonObjectContractAccessor : IReadOnlyObject - { - public JsonObjectContractAccessor( - JsonObjectContract contract, - Object obj) - { - m_contract = contract; - m_obj = obj; - } - - public Int32 Count => GetProperties().Count(); - - public IEnumerable Keys => GetProperties().Select(x => x.PropertyName); - - public IEnumerable Values => GetProperties().Select(x => x.ValueProvider.GetValue(m_obj)); - - public Object this[String key] - { - get - { - if (TryGetValue(key, out Object value)) - { - return value; - } - - throw new KeyNotFoundException(ExpressionResources.KeyNotFound(key)); - } - } - - public Boolean ContainsKey(String key) - { - return TryGetProperty(key, out _); - } - - public IEnumerator> GetEnumerator() - { - return Keys.Select(x => new KeyValuePair(x, this[x])).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return Keys.Select(x => new KeyValuePair(x, this[x])).GetEnumerator(); - } - - public Boolean TryGetValue( - String key, - out Object value) - { - if (TryGetProperty(key, out JsonProperty property)) - { - value = property.ValueProvider.GetValue(m_obj); - return true; - } - - value = null; - return false; - } - - private IEnumerable GetProperties() - { - return m_contract.Properties.Where(x => !x.Ignored); - } - - private Boolean TryGetProperty( - String key, - out JsonProperty property) - { - property = m_contract.Properties.GetClosestMatchProperty(key); - if (property != null && !property.Ignored) - { - return true; - } - - property = null; - return false; - } - - private readonly JsonObjectContract m_contract; - private readonly Object m_obj; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ListOfObjectAccessor.cs b/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ListOfObjectAccessor.cs deleted file mode 100644 index 2bf375d12..000000000 --- a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ListOfObjectAccessor.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.Expressions.CollectionAccessors -{ - internal sealed class ListOfObjectAccessor : IReadOnlyArray - { - public ListOfObjectAccessor(IList list) - { - m_list = list; - } - - public Int32 Count => m_list.Count; - - public Object this[Int32 index] => m_list[index]; - - public IEnumerator GetEnumerator() - { - return m_list.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return m_list.GetEnumerator(); - } - - private readonly IList m_list; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyDictionaryOfStringObjectAccessor.cs b/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyDictionaryOfStringObjectAccessor.cs deleted file mode 100644 index c1a1bf0bf..000000000 --- a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyDictionaryOfStringObjectAccessor.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.Expressions.CollectionAccessors -{ - internal sealed class ReadOnlyDictionaryOfStringObjectAccessor : IReadOnlyObject - { - public ReadOnlyDictionaryOfStringObjectAccessor(IReadOnlyDictionary dictionary) - { - m_dictionary = dictionary; - } - - public Int32 Count => m_dictionary.Count; - - public IEnumerable Keys => m_dictionary.Keys; - - public IEnumerable Values => m_dictionary.Values; - - public Object this[String key] => m_dictionary[key]; - - public Boolean ContainsKey(String key) => m_dictionary.ContainsKey(key); - - public IEnumerator> GetEnumerator() => m_dictionary.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => m_dictionary.GetEnumerator(); - - public Boolean TryGetValue( - String key, - out Object value) - { - return m_dictionary.TryGetValue(key, out value); - } - - private readonly IReadOnlyDictionary m_dictionary; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyDictionaryOfStringStringAccessor.cs b/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyDictionaryOfStringStringAccessor.cs deleted file mode 100644 index 5421608cb..000000000 --- a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyDictionaryOfStringStringAccessor.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -namespace GitHub.DistributedTask.Expressions.CollectionAccessors -{ - internal sealed class ReadOnlyDictionaryOfStringStringAccessor : IReadOnlyObject - { - public ReadOnlyDictionaryOfStringStringAccessor(IReadOnlyDictionary dictionary) - { - m_dictionary = dictionary; - } - - public Int32 Count => m_dictionary.Count; - - public IEnumerable Keys => m_dictionary.Keys; - - public IEnumerable Values => m_dictionary.Values.OfType(); - - public Object this[String key] => m_dictionary[key]; - - public Boolean ContainsKey(String key) - { - return m_dictionary.ContainsKey(key); - } - - public IEnumerator> GetEnumerator() - { - return m_dictionary.Select(x => new KeyValuePair(x.Key, x.Value)).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return m_dictionary.Select(x => new KeyValuePair(x.Key, x.Value)).GetEnumerator(); - } - - public Boolean TryGetValue( - String key, - out Object value) - { - if (m_dictionary.TryGetValue(key, out String val)) - { - value = val; - return true; - } - - value = default; - return false; - } - - private readonly IReadOnlyDictionary m_dictionary; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyListOfObjectAccessor.cs b/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyListOfObjectAccessor.cs deleted file mode 100644 index 74b56bd79..000000000 --- a/src/Sdk/DTExpressions/Expressions/CollectionAccessors/ReadOnlyListOfObjectAccessor.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.Expressions.CollectionAccessors -{ - internal sealed class ReadOnlyListOfObjectAccessor : IReadOnlyArray - { - public ReadOnlyListOfObjectAccessor(IReadOnlyList list) - { - m_list = list; - } - - public Int32 Count => m_list.Count; - - public Object this[Int32 index] => m_list[index]; - - public IEnumerator GetEnumerator() => m_list.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => m_list.GetEnumerator(); - - private readonly IReadOnlyList m_list; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ContainerNode.cs b/src/Sdk/DTExpressions/Expressions/ContainerNode.cs deleted file mode 100644 index 372304d0f..000000000 --- a/src/Sdk/DTExpressions/Expressions/ContainerNode.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class ContainerNode : ExpressionNode - { - public IReadOnlyList Parameters => m_parameters.AsReadOnly(); - - public void AddParameter(ExpressionNode node) - { - m_parameters.Add(node); - node.Container = this; - } - - public void ReplaceParameter(Int32 index, ExpressionNode node) - { - m_parameters[index] = node; - node.Container = this; - } - - public override IEnumerable GetParameters() - { - List matched = new List(); - Queue parameters = new Queue(this.Parameters); - - while (parameters.Count > 0) - { - var parameter = parameters.Dequeue(); - if (typeof(T).GetTypeInfo().IsAssignableFrom(parameter.GetType().GetTypeInfo())) - { - matched.Add((T)parameter); - } - - foreach (var childParameter in parameter.GetParameters()) - { - parameters.Enqueue(childParameter); - } - } - - return matched; - } - - private readonly List m_parameters = new List(); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ContainsNode.cs b/src/Sdk/DTExpressions/Expressions/ContainsNode.cs deleted file mode 100644 index eca9e2c85..000000000 --- a/src/Sdk/DTExpressions/Expressions/ContainsNode.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class ContainsNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - String left = Parameters[0].EvaluateString(context) as String ?? String.Empty; - String right = Parameters[1].EvaluateString(context) as String ?? String.Empty; - return left.IndexOf(right, StringComparison.OrdinalIgnoreCase) >= 0; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ContainsValueNode.cs b/src/Sdk/DTExpressions/Expressions/ContainsValueNode.cs deleted file mode 100644 index d86de2e14..000000000 --- a/src/Sdk/DTExpressions/Expressions/ContainsValueNode.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class ContainsValueNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override object EvaluateCore(EvaluationContext context) - { - EvaluationResult left = Parameters[0].Evaluate(context); - - if (left.TryGetCollectionInterface(out Object collection)) - { - EvaluationResult right = Parameters[1].Evaluate(context); - - if (collection is IReadOnlyArray array) - { - foreach (var item in array) - { - var itemResult = EvaluationResult.CreateIntermediateResult(context, item, out _); - - if (right.Equals(context, itemResult)) - { - return true; - } - } - } - else if (collection is IReadOnlyObject obj) - { - foreach (var value in obj.Values) - { - var valueResult = EvaluationResult.CreateIntermediateResult(context, value, out _); - - if (right.Equals(context, valueResult)) - { - return true; - } - } - } - } - - return false; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ConversionResult.cs b/src/Sdk/DTExpressions/Expressions/ConversionResult.cs deleted file mode 100644 index 018f65d02..000000000 --- a/src/Sdk/DTExpressions/Expressions/ConversionResult.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public struct ConversionResult - { - /// - /// Result object after the conversion - /// - public Object Result; - - /// - /// Memory overhead for the result object - /// - public ResultMemory ResultMemory; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/EndsWithNode.cs b/src/Sdk/DTExpressions/Expressions/EndsWithNode.cs deleted file mode 100644 index b09a561af..000000000 --- a/src/Sdk/DTExpressions/Expressions/EndsWithNode.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class EndsWithNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - String left = Parameters[0].EvaluateString(context) ?? String.Empty; - String right = Parameters[1].EvaluateString(context) ?? String.Empty; - return left.EndsWith(right, StringComparison.OrdinalIgnoreCase); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/EqualNode.cs b/src/Sdk/DTExpressions/Expressions/EqualNode.cs deleted file mode 100644 index 2361c5c3d..000000000 --- a/src/Sdk/DTExpressions/Expressions/EqualNode.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class EqualNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return Parameters[0].Evaluate(context).Equals(context, Parameters[1].Evaluate(context)); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/EvaluationContext.cs b/src/Sdk/DTExpressions/Expressions/EvaluationContext.cs deleted file mode 100644 index 1d339c928..000000000 --- a/src/Sdk/DTExpressions/Expressions/EvaluationContext.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Logging; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class EvaluationContext - { - internal EvaluationContext( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state, - EvaluationOptions options, - ExpressionNode node) - { - ArgumentUtility.CheckForNull(trace, nameof(trace)); - ArgumentUtility.CheckForNull(secretMasker, nameof(secretMasker)); - Trace = trace; - SecretMasker = secretMasker; - State = state; - - // Copy the options - options = new EvaluationOptions(copy: options); - if (options.MaxMemory == 0) - { - // Set a reasonable default max memory - options.MaxMemory = 1048576; // 1 mb - } - Options = options; - Memory = new EvaluationMemory(options.MaxMemory, node); - - m_traceResults = new Dictionary(); - m_traceMemory = new MemoryCounter(null, options.MaxMemory); - } - - public ITraceWriter Trace { get; } - - public ISecretMasker SecretMasker { get; } - - public Object State { get; } - - internal EvaluationMemory Memory { get; } - - internal EvaluationOptions Options { get; } - - internal void SetTraceResult( - ExpressionNode node, - EvaluationResult result) - { - // Remove if previously added. This typically should not happen. This could happen - // due to a badly authored function. So we'll handle it and track memory correctly. - if (m_traceResults.TryGetValue(node, out String oldValue)) - { - m_traceMemory.Remove(oldValue); - m_traceResults.Remove(node); - } - - // Check max memory - String value = ExpressionUtil.FormatValue(SecretMasker, result); - if (m_traceMemory.TryAdd(value)) - { - // Store the result - m_traceResults[node] = value; - } - } - - internal Boolean TryGetTraceResult(ExpressionNode node, out String value) - { - return m_traceResults.TryGetValue(node, out value); - } - - private readonly Dictionary m_traceResults = new Dictionary(); - private readonly MemoryCounter m_traceMemory; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/EvaluationMemory.cs b/src/Sdk/DTExpressions/Expressions/EvaluationMemory.cs deleted file mode 100644 index e35985197..000000000 --- a/src/Sdk/DTExpressions/Expressions/EvaluationMemory.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.Expressions -{ - /// - /// This is an internal class only. - /// - /// This class is used to track current memory consumption - /// across the entire expression evaluation. - /// - internal sealed class EvaluationMemory - { - internal EvaluationMemory( - Int32 maxBytes, - ExpressionNode node) - { - m_maxAmount = maxBytes; - m_node = node; - } - - internal void AddAmount( - Int32 depth, - Int32 bytes, - Boolean trimDepth = false) - { - // Trim deeper depths - if (trimDepth) - { - while (m_maxActiveDepth > depth) - { - var amount = m_depths[m_maxActiveDepth]; - - if (amount > 0) - { - // Sanity check - if (amount > m_totalAmount) - { - throw new InvalidOperationException("Bytes to subtract exceeds total bytes"); - } - - // Subtract from the total - checked - { - m_totalAmount -= amount; - } - - // Reset the amount - m_depths[m_maxActiveDepth] = 0; - } - - m_maxActiveDepth--; - } - } - - // Grow the depths - if (depth > m_maxActiveDepth) - { - // Grow the list - while (m_depths.Count <= depth) - { - m_depths.Add(0); - } - - // Adjust the max active depth - m_maxActiveDepth = depth; - } - - checked - { - // Add to the depth - m_depths[depth] += bytes; - - // Add to the total - m_totalAmount += bytes; - } - - // Check max - if (m_totalAmount > m_maxAmount) - { - throw new InvalidOperationException(ExpressionResources.ExceededAllowedMemory(m_node?.ConvertToExpression())); - } - } - - internal static Int32 CalculateBytes(Object obj) - { - if (obj is String str) - { - // This measurement doesn't have to be perfect - // https://codeblog.jonskeet.uk/2011/04/05/of-memory-and-strings/ - - checked - { - return c_stringBaseOverhead + ((str?.Length ?? 0) * sizeof(Char)); - } - } - else - { - return c_minObjectSize; - } - } - - private const Int32 c_minObjectSize = 24; - private const Int32 c_stringBaseOverhead = 26; - private readonly List m_depths = new List(); - private readonly Int32 m_maxAmount; - private readonly ExpressionNode m_node; - private Int32 m_maxActiveDepth = -1; - private Int32 m_totalAmount; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/EvaluationOptions.cs b/src/Sdk/DTExpressions/Expressions/EvaluationOptions.cs deleted file mode 100644 index e42260056..000000000 --- a/src/Sdk/DTExpressions/Expressions/EvaluationOptions.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class EvaluationOptions - { - public EvaluationOptions() - { - } - - public EvaluationOptions(EvaluationOptions copy) - { - if (copy != null) - { - Converters = copy.Converters; - MaxMemory = copy.MaxMemory; - TimeZone = copy.TimeZone; - UseCollectionInterfaces = copy.UseCollectionInterfaces; - } - } - - /// - /// Converters allow types to be coerced into data that is friendly - /// for expression functions to operate on it. - /// - /// As each node in the expression tree is evaluated, converters are applied. - /// When a node's result matches a converter type, the result is intercepted - /// by the converter, and converter result is used instead. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public IDictionary> Converters { get; set; } - - public Int32 MaxMemory { get; set; } - - public TimeZoneInfo TimeZone { get; set; } - - [EditorBrowsable(EditorBrowsableState.Never)] - public Boolean UseCollectionInterfaces { get; set; } // Feature flag for now behavior - } -} diff --git a/src/Sdk/DTExpressions/Expressions/EvaluationResult.cs b/src/Sdk/DTExpressions/Expressions/EvaluationResult.cs deleted file mode 100644 index cb1d1cb3e..000000000 --- a/src/Sdk/DTExpressions/Expressions/EvaluationResult.cs +++ /dev/null @@ -1,828 +0,0 @@ -using GitHub.DistributedTask.Expressions.CollectionAccessors; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Globalization; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class EvaluationResult - { - internal EvaluationResult( - EvaluationContext context, - Int32 level, - Object val, - ValueKind kind, - Object raw) - : this(context, level, val, kind, raw, false) - { - } - - internal EvaluationResult( - EvaluationContext context, - Int32 level, - Object val, - ValueKind kind, - Object raw, - Boolean omitTracing) - { - m_level = level; - Value = val; - Kind = kind; - Raw = raw; - m_omitTracing = omitTracing; - - if (!omitTracing) - { - TraceValue(context); - } - } - - public ValueKind Kind { get; } - - /// - /// When a custom converter is applied to the node result, raw contains the original value - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public Object Raw { get; } - - public Object Value { get; } - - public int CompareTo( - EvaluationContext context, - EvaluationResult right) - { - Object leftValue; - ValueKind leftKind; - switch (Kind) - { - case ValueKind.Boolean: - case ValueKind.DateTime: - case ValueKind.Number: - case ValueKind.String: - case ValueKind.Version: - leftValue = Value; - leftKind = Kind; - break; - default: - leftValue = ConvertToNumber(context); // Will throw or succeed - leftKind = ValueKind.Number; - break; - } - - if (leftKind == ValueKind.Boolean) - { - Boolean b = right.ConvertToBoolean(context); - return ((Boolean)leftValue).CompareTo(b); - } - else if (leftKind == ValueKind.DateTime) - { - DateTimeOffset d = right.ConvertToDateTime(context); - return ((DateTimeOffset)leftValue).CompareTo(d); - } - else if (leftKind == ValueKind.Number) - { - Decimal d = right.ConvertToNumber(context); - return ((Decimal)leftValue).CompareTo(d); - } - else if (leftKind == ValueKind.String) - { - String s = right.ConvertToString(context); - return String.Compare(leftValue as String ?? String.Empty, s ?? String.Empty, StringComparison.OrdinalIgnoreCase); - } - else //if (leftKind == ValueKind.Version) - { - Version v = right.ConvertToVersion(context); - return (leftValue as Version).CompareTo(v); - } - } - - public Boolean ConvertToBoolean(EvaluationContext context) - { - Boolean result; - switch (Kind) - { - case ValueKind.Boolean: - return (Boolean)Value; // Not converted. Don't trace. - - case ValueKind.Number: - result = (Decimal)Value != 0m; // 0 converts to false, otherwise true. - TraceValue(context, result, ValueKind.Boolean); - return result; - - case ValueKind.String: - result = !String.IsNullOrEmpty(Value as String); - TraceValue(context, result, ValueKind.Boolean); - return result; - - case ValueKind.Array: - case ValueKind.DateTime: - case ValueKind.Object: - case ValueKind.Version: - result = true; - TraceValue(context, result, ValueKind.Boolean); - return result; - - case ValueKind.Null: - result = false; - TraceValue(context, result, ValueKind.Boolean); - return result; - - default: // Should never reach here. - throw new NotSupportedException($"Unable to convert value to Boolean. Unexpected value kind '{Kind}'."); - } - } - - public DateTimeOffset ConvertToDateTime(EvaluationContext context) - { - DateTimeOffset result; - if (TryConvertToDateTime(context, out result)) - { - return result; - } - - throw new TypeCastException(context?.SecretMasker, Value, fromKind: Kind, toKind: ValueKind.DateTime); - } - - public Object ConvertToNull(EvaluationContext context) - { - Object result; - if (TryConvertToNull(context, out result)) - { - return result; - } - - throw new TypeCastException(context?.SecretMasker, Value, fromKind: Kind, toKind: ValueKind.Null); - } - - public Decimal ConvertToNumber(EvaluationContext context) - { - Decimal result; - if (TryConvertToNumber(context, out result)) - { - return result; - } - - throw new TypeCastException(context?.SecretMasker, Value, fromKind: Kind, toKind: ValueKind.Number); - } - - public String ConvertToString(EvaluationContext context) - { - String result; - if (TryConvertToString(context, out result)) - { - return result; - } - - throw new TypeCastException(context?.SecretMasker, Value, fromKind: Kind, toKind: ValueKind.String); - } - - public Version ConvertToVersion(EvaluationContext context) - { - Version result; - if (TryConvertToVersion(context, out result)) - { - return result; - } - - throw new TypeCastException(context?.SecretMasker, Value, fromKind: Kind, toKind: ValueKind.Version); - } - - public Boolean Equals( - EvaluationContext context, - EvaluationResult right) - { - if (Kind == ValueKind.Boolean) - { - Boolean b = right.ConvertToBoolean(context); - return (Boolean)Value == b; - } - else if (Kind == ValueKind.DateTime) - { - DateTimeOffset d; - if (right.TryConvertToDateTime(context, out d)) - { - return (DateTimeOffset)Value == d; - } - } - else if (Kind == ValueKind.Number) - { - Decimal d; - if (right.TryConvertToNumber(context, out d)) - { - return (Decimal)Value == d; - } - } - else if (Kind == ValueKind.Version) - { - Version v; - if (right.TryConvertToVersion(context, out v)) - { - return (Version)Value == v; - } - } - else if (Kind == ValueKind.String) - { - String s; - if (right.TryConvertToString(context, out s)) - { - return String.Equals( - Value as String ?? String.Empty, - s ?? String.Empty, - StringComparison.OrdinalIgnoreCase); - } - } - else if (Kind == ValueKind.Array || Kind == ValueKind.Object) - { - return Kind == right.Kind && Object.ReferenceEquals(Value, right.Value); - } - else if (Kind == ValueKind.Null) - { - Object n; - if (right.TryConvertToNull(context, out n)) - { - return true; - } - } - - return false; - } - - public Boolean TryConvertToDateTime( - EvaluationContext context, - out DateTimeOffset result) - { - switch (Kind) - { - case ValueKind.DateTime: - result = (DateTimeOffset)Value; // Not converted. Don't trace again. - return true; - - case ValueKind.String: - if (TryParseDateTime(context?.Options, Value as String, out result)) - { - TraceValue(context, result, ValueKind.DateTime); - return true; - } - - TraceCoercionFailed(context, toKind: ValueKind.DateTime); - return false; - - case ValueKind.Array: - case ValueKind.Boolean: - case ValueKind.Null: - case ValueKind.Number: - case ValueKind.Object: - case ValueKind.Version: - result = default; - TraceCoercionFailed(context, toKind: ValueKind.DateTime); - return false; - - default: // Should never reach here. - throw new NotSupportedException($"Unable to determine whether value can be converted to Number. Unexpected value kind '{Kind}'."); - } - } - - public Boolean TryConvertToNull( - EvaluationContext context, - out Object result) - { - switch (Kind) - { - case ValueKind.Null: - result = null; // Not converted. Don't trace again. - return true; - - case ValueKind.String: - if (String.IsNullOrEmpty(Value as String)) - { - result = null; - TraceValue(context, result, ValueKind.Null); - return true; - } - - break; - } - - result = null; - TraceCoercionFailed(context, toKind: ValueKind.Null); - return false; - } - - public Boolean TryConvertToNumber( - EvaluationContext context, - out Decimal result) - { - switch (Kind) - { - case ValueKind.Boolean: - result = (Boolean)Value ? 1m : 0m; - TraceValue(context, result, ValueKind.Number); - return true; - - case ValueKind.Number: - result = (Decimal)Value; // Not converted. Don't trace again. - return true; - - case ValueKind.String: - String s = Value as String ?? String.Empty; - if (String.IsNullOrEmpty(s)) - { - result = 0m; - TraceValue(context, result, ValueKind.Number); - return true; - } - - if (Decimal.TryParse(s, s_numberStyles, CultureInfo.InvariantCulture, out result)) - { - TraceValue(context, result, ValueKind.Number); - return true; - } - - TraceCoercionFailed(context, toKind: ValueKind.Number); - return false; - - case ValueKind.Array: - case ValueKind.DateTime: - case ValueKind.Object: - case ValueKind.Version: - result = default(Decimal); - TraceCoercionFailed(context, toKind: ValueKind.Number); - return false; - - case ValueKind.Null: - result = 0m; - TraceValue(context, result, ValueKind.Number); - return true; - - default: // Should never reach here. - throw new NotSupportedException($"Unable to determine whether value can be converted to Number. Unexpected value kind '{Kind}'."); - } - } - - public Boolean TryConvertToString( - EvaluationContext context, - out String result) - { - switch (Kind) - { - case ValueKind.Boolean: - result = String.Format(CultureInfo.InvariantCulture, "{0}", Value); - TraceValue(context, result, ValueKind.String); - return true; - - case ValueKind.DateTime: - result = ((DateTimeOffset)Value).ToString(ExpressionConstants.DateTimeFormat, CultureInfo.InvariantCulture); - TraceValue(context, result, ValueKind.String); - return true; - - case ValueKind.Number: - result = ((Decimal)Value).ToString(ExpressionConstants.NumberFormat, CultureInfo.InvariantCulture); - TraceValue(context, result, ValueKind.String); - return true; - - case ValueKind.String: - result = Value as String; // Not converted. Don't trace. - return true; - - case ValueKind.Version: - result = (Value as Version).ToString(); - TraceValue(context, result, ValueKind.String); - return true; - - case ValueKind.Null: - result = String.Empty; - TraceValue(context, result, ValueKind.Null); - return true; - - case ValueKind.Array: - case ValueKind.Object: - result = null; - TraceCoercionFailed(context, toKind: ValueKind.String); - return false; - - default: // Should never reach here. - throw new NotSupportedException($"Unable to convert to String. Unexpected value kind '{Kind}'."); - } - } - - public Boolean TryConvertToVersion( - EvaluationContext context, - out Version result) - { - switch (Kind) - { - case ValueKind.Boolean: - result = null; - TraceCoercionFailed(context, toKind: ValueKind.Version); - return false; - - case ValueKind.Number: - if (Version.TryParse(ConvertToString(context), out result)) - { - TraceValue(context, result, ValueKind.Version); - return true; - } - - TraceCoercionFailed(context, toKind: ValueKind.Version); - return false; - - case ValueKind.String: - String s = Value as String ?? String.Empty; - if (Version.TryParse(s, out result)) - { - TraceValue(context, result, ValueKind.Version); - return true; - } - - TraceCoercionFailed(context, toKind: ValueKind.Version); - return false; - - case ValueKind.Version: - result = Value as Version; // Not converted. Don't trace again. - return true; - - case ValueKind.Array: - case ValueKind.DateTime: - case ValueKind.Object: - case ValueKind.Null: - result = null; - TraceCoercionFailed(context, toKind: ValueKind.Version); - return false; - - default: // Should never reach here. - throw new NotSupportedException($"Unable to convert to Version. Unexpected value kind '{Kind}'."); - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public Boolean TryGetCollectionInterface(out Object collection) - { - if ((Kind == ValueKind.Object || Kind == ValueKind.Array)) - { - var obj = Value; - if (obj is IReadOnlyObject) - { - collection = obj; - return true; - } - else if (obj is IDictionary dictionary1) - { - collection = new ReadOnlyDictionaryOfStringStringAccessor(new ReadOnlyDictionary(dictionary1)); - return true; - } - else if (obj is IDictionary dictionary2) - { - collection = new ReadOnlyDictionaryOfStringObjectAccessor(new ReadOnlyDictionary(dictionary2)); - return true; - } - else if (obj is IReadOnlyDictionary dictionary3) - { - collection = new ReadOnlyDictionaryOfStringStringAccessor(dictionary3); - return true; - } - else if (obj is IReadOnlyDictionary dictionary4) - { - collection = new ReadOnlyDictionaryOfStringObjectAccessor(dictionary4); - return true; - } - else if (obj is JObject jobject) - { - collection = new JObjectAccessor(jobject); - return true; - } - else if (obj is IReadOnlyArray) - { - collection = obj; - return true; - } - else if (obj is IList list1) - { - collection = new ListOfObjectAccessor(list1); - return true; - } - else if (obj is IReadOnlyList list2) - { - collection = new ReadOnlyListOfObjectAccessor(list2); - return true; - } - else if (obj is JArray jarray) - { - collection = new JArrayAccessor(jarray); - return true; - } - - var contract = s_serializer.Value.ContractResolver.ResolveContract(obj.GetType()); - if (contract is JsonObjectContract objectContract) - { - collection = new JsonObjectContractAccessor(objectContract, obj); - return true; - } - else if (contract is JsonDictionaryContract dictionaryContract && dictionaryContract.DictionaryKeyType == typeof(String)) - { - collection = new JsonDictionaryContractAccessor(dictionaryContract, obj); - return true; - } - } - - collection = null; - return false; - } - - /// - /// Useful for working with values that are not the direct evaluation result of a parameter. - /// This allows ExpressionNode authors to leverage the coercion and comparision functions - /// for any values. - /// - /// Also note, the value will be canonicalized (for example numeric types converted to decimal) and any - /// matching converters applied. - /// - public static EvaluationResult CreateIntermediateResult( - EvaluationContext context, - Object obj, - out ResultMemory conversionResultMemory) - { - var val = ExpressionUtil.ConvertToCanonicalValue(context?.Options, obj, out ValueKind kind, out Object raw, out conversionResultMemory); - return new EvaluationResult(context, 0, val, kind, raw, omitTracing: true); - } - - private void TraceCoercionFailed( - EvaluationContext context, - ValueKind toKind) - { - if (!m_omitTracing) - { - TraceVerbose(context, String.Format(CultureInfo.InvariantCulture, "=> Unable to coerce {0} to {1}.", Kind, toKind)); - } - } - - private void TraceValue(EvaluationContext context) - { - if (!m_omitTracing) - { - TraceValue(context, Value, Kind); - } - } - - private void TraceValue( - EvaluationContext context, - Object val, - ValueKind kind) - { - if (!m_omitTracing) - { - TraceVerbose(context, String.Concat("=> ", ExpressionUtil.FormatValue(context?.SecretMasker, val, kind))); - } - } - - private void TraceVerbose( - EvaluationContext context, - String message) - { - if (!m_omitTracing) - { - context?.Trace.Verbose(String.Empty.PadLeft(m_level * 2, '.') + (message ?? String.Empty)); - } - } - - private static Boolean TryParseDateTime( - EvaluationOptions options, - String s, - out DateTimeOffset result) - { - if (String.IsNullOrEmpty(s)) - { - result = default; - return false; - } - - s = s.Trim(); - var i = 0; - - // Year, month, day, hour, min, sec - if (!ReadInt32(s, 4, 4, ref i, out Int32 year) || - !ReadSeparator(s, ref i, new[] { '-', '/' }, out Char dateSeparator) || - !ReadInt32(s, 1, 2, ref i, out Int32 month) || - !ReadSeparator(s, ref i, dateSeparator) || - !ReadInt32(s, 1, 2, ref i, out Int32 day) || - !ReadSeparator(s, ref i, ' ', 'T') || - !ReadInt32(s, 1, 2, ref i, out Int32 hour) || - !ReadSeparator(s, ref i, ':') || - !ReadInt32(s, 1, 2, ref i, out Int32 minute) || - !ReadSeparator(s, ref i, ':') || - !ReadInt32(s, 1, 2, ref i, out Int32 second)) - { - result = default; - return false; - } - - // Fraction of second - Int32 ticks; - if (ExpressionUtil.SafeCharAt(s, i) == '.') - { - i++; - if (!ReadDigits(s, 1, 7, ref i, out String digits)) - { - result = default; - return false; - } - - if (digits.Length < 7) - { - digits = digits.PadRight(7, '0'); - } - - ticks = Int32.Parse(digits, NumberStyles.None, CultureInfo.InvariantCulture); - } - else - { - ticks = 0; - } - - TimeSpan offset; - - // End of string indicates local time zone - if (i >= s.Length) - { - // Determine the offset - var timeZone = options?.TimeZone ?? TimeZoneInfo.Local; - try - { - var dateTime = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified); - offset = timeZone.GetUtcOffset(dateTime); - } - catch - { - result = default; - return false; - } - } - // Offset, then end of string - else if (!ReadOffset(s, ref i, out offset) || - i < s.Length) - { - result = default; - return false; - } - - // Construct the DateTimeOffset - try - { - result = new DateTimeOffset(year, month, day, hour, minute, second, offset); - } - catch - { - result = default; - return false; - } - - // Add fraction of second - if (ticks > 0) - { - result = result.AddTicks(ticks); - } - - return true; - } - - private static Boolean ReadDigits( - String str, - Int32 minLength, - Int32 maxLength, - ref Int32 index, - out String result) - { - var startIndex = index; - while (Char.IsDigit(ExpressionUtil.SafeCharAt(str, index))) - { - index++; - } - - var length = index - startIndex; - if (length < minLength || length > maxLength) - { - result = default; - return false; - } - - result = str.Substring(startIndex, length); - return true; - } - - private static Boolean ReadInt32( - String str, - Int32 minLength, - Int32 maxLength, - ref Int32 index, - out Int32 result) - { - if (!ReadDigits(str, minLength, maxLength, ref index, out String digits)) - { - result = default; - return false; - } - - result = Int32.Parse(digits, NumberStyles.None, CultureInfo.InvariantCulture); - return true; - } - - private static Boolean ReadSeparator( - String str, - ref Int32 index, - params Char[] allowed) - { - return ReadSeparator(str, ref index, allowed, out _); - } - - private static Boolean ReadSeparator( - String str, - ref Int32 index, - Char[] allowed, - out Char separator) - { - separator = ExpressionUtil.SafeCharAt(str, index++); - foreach (var a in allowed) - { - if (separator == a) - { - return true; - } - } - - separator = default; - return false; - } - - private static Boolean ReadOffset( - String str, - ref Int32 index, - out TimeSpan offset) - { - // Z indicates UTC - if (ExpressionUtil.SafeCharAt(str, index) == 'Z') - { - index++; - offset = TimeSpan.Zero; - return true; - } - - Boolean subtract; - - // Negative - if (ExpressionUtil.SafeCharAt(str, index) == '-') - { - index++; - subtract = true; - } - // Positive - else if (ExpressionUtil.SafeCharAt(str, index) == '+') - { - index++; - subtract = false; - } - // Invalid - else - { - offset = default; - return false; - } - - // Hour and minute - if (!ReadInt32(str, 1, 2, ref index, out Int32 hour) || - !ReadSeparator(str, ref index, ':') || - !ReadInt32(str, 1, 2, ref index, out Int32 minute)) - { - offset = default; - return false; - } - - // Construct the offset - if (subtract) - { - offset = TimeSpan.Zero.Subtract(new TimeSpan(hour, minute, 0)); - } - else - { - offset = new TimeSpan(hour, minute, 0); - } - - return true; - } - - private static readonly NumberStyles s_numberStyles = - NumberStyles.AllowDecimalPoint | - NumberStyles.AllowLeadingSign | - NumberStyles.AllowLeadingWhite | - NumberStyles.AllowThousands | - NumberStyles.AllowTrailingWhite; - private static readonly Lazy s_serializer = new Lazy(() => JsonUtility.CreateJsonSerializer()); - private readonly Int32 m_level; - private readonly Boolean m_omitTracing; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/EvaluationTraceWriter.cs b/src/Sdk/DTExpressions/Expressions/EvaluationTraceWriter.cs deleted file mode 100644 index 071317165..000000000 --- a/src/Sdk/DTExpressions/Expressions/EvaluationTraceWriter.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using GitHub.DistributedTask.Logging; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class EvaluationTraceWriter : ITraceWriter - { - public EvaluationTraceWriter(ITraceWriter trace, ISecretMasker secretMasker) - { - ArgumentUtility.CheckForNull(secretMasker, nameof(secretMasker)); - m_trace = trace; - m_secretMasker = secretMasker; - } - - public void Info(String message) - { - if (m_trace != null) - { - message = m_secretMasker.MaskSecrets(message); - m_trace.Info(message); - } - } - - public void Verbose(String message) - { - if (m_trace != null) - { - message = m_secretMasker.MaskSecrets(message); - m_trace.Verbose(message); - } - } - - private readonly ISecretMasker m_secretMasker; - private readonly ITraceWriter m_trace; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ExpressionConstants.cs b/src/Sdk/DTExpressions/Expressions/ExpressionConstants.cs deleted file mode 100644 index 54f7b7d3e..000000000 --- a/src/Sdk/DTExpressions/Expressions/ExpressionConstants.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.Expressions -{ - internal static class ExpressionConstants - { - static ExpressionConstants() - { - AddFunction("and", 2, Int32.MaxValue); - AddFunction("coalesce", 2, Int32.MaxValue); - AddFunction("contains", 2, 2); - AddFunction("containsValue", 2, 2); - AddFunction("endsWith", 2, 2); - AddFunction("eq", 2, 2); - AddFunction("format", 1, Byte.MaxValue); - AddFunction("gt", 2, 2); - AddFunction("ge", 2, 2); - AddFunction("lt", 2, 2); - AddFunction("join", 2, 2); - AddFunction("le", 2, 2); - AddFunction("in", 2, Int32.MaxValue); - AddFunction("not", 1, 1); - AddFunction("ne", 2, 2); - AddFunction("notIn", 2, Int32.MaxValue); - AddFunction("or", 2, Int32.MaxValue); - AddFunction("startsWith", 2, 2); - AddFunction("xor", 2, 2); - } - - private static void AddFunction(String name, Int32 minParameters, Int32 maxParameters) - where T : FunctionNode, new() - { - WellKnownFunctions.Add(name, new FunctionInfo(name, minParameters, maxParameters)); - } - - internal static readonly String DateTimeFormat = @"yyyy\-MM\-dd\ HH\:mm\:sszzz"; - internal static readonly Int32 MaxDepth = 50; - internal static readonly Int32 MaxLength = 21000; // Under 85,000 large object heap threshold, even if .NET switches to UTF-32 - internal static readonly String NumberFormat = "0.#######"; - internal static readonly Dictionary WellKnownFunctions = new Dictionary(StringComparer.OrdinalIgnoreCase); - - // Punctuation - internal const Char StartIndex = '['; - internal const Char StartParameter = '('; - internal const Char EndIndex = ']'; - internal const Char EndParameter = ')'; - internal const Char Separator = ','; - internal const Char Dereference = '.'; - internal const Char Wildcard = '*'; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ExpressionException.cs b/src/Sdk/DTExpressions/Expressions/ExpressionException.cs deleted file mode 100644 index ef2623cd6..000000000 --- a/src/Sdk/DTExpressions/Expressions/ExpressionException.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using GitHub.DistributedTask.Logging; - -namespace GitHub.DistributedTask.Expressions -{ - public class ExpressionException : Exception - { - internal ExpressionException(ISecretMasker secretMasker, String message) - { - if (secretMasker != null) - { - message = secretMasker.MaskSecrets(message); - } - - m_message = message; - } - - public override String Message => m_message; - - private readonly String m_message; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ExpressionNode.cs b/src/Sdk/DTExpressions/Expressions/ExpressionNode.cs deleted file mode 100644 index e08b8d90e..000000000 --- a/src/Sdk/DTExpressions/Expressions/ExpressionNode.cs +++ /dev/null @@ -1,494 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using GitHub.DistributedTask.Logging; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class ExpressionNode : IExpressionNode - { - internal ContainerNode Container { get; set; } - - internal Int32 Level { get; private set; } - - /// - /// The name is used for tracing. Normally the parser will set the name. However if a node - /// is added manually, then the name may not be set and will fallback to the type name. - /// - protected internal String Name - { - get - { - return !String.IsNullOrEmpty(m_name) ? m_name : this.GetType().Name; - } - - set - { - m_name = value; - } - } - - /// - /// Indicates whether the evalation result should be stored on the context and used - /// when the realized result is traced. - /// - protected abstract Boolean TraceFullyRealized { get; } - - internal abstract String ConvertToExpression(); - - internal abstract String ConvertToRealizedExpression(EvaluationContext context); - - /// - /// Evaluates the node - /// - protected virtual Object EvaluateCore(EvaluationContext context) - { - throw new InvalidOperationException($"Method {nameof(EvaluateCore)} not implemented"); - } - - /// - /// Evaluates the node - /// - /// The current expression context - /// - /// Helps determine how much memory is being consumed across the evaluation of the expression. - /// - protected virtual Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - return EvaluateCore(context); - } - - /// - /// INode entry point. - /// - public T Evaluate( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state, - EvaluationOptions options = null) - { - if (Container != null) - { - // Do not localize. This is an SDK consumer error. - throw new NotSupportedException($"Expected {nameof(IExpressionNode)}.{nameof(Evaluate)} to be called on root node only."); - } - - ISecretMasker originalSecretMasker = secretMasker; - try - { - secretMasker = secretMasker?.Clone() ?? new SecretMasker(); - trace = new EvaluationTraceWriter(trace, secretMasker); - var context = new EvaluationContext(trace, secretMasker, state, options, this); - trace.Info($"Evaluating: {ConvertToExpression()}"); - - // String - if (typeof(T).Equals(typeof(String))) - { - String stringResult = EvaluateString(context); - TraceTreeResult(context, stringResult, ValueKind.String); - return (T)(Object)stringResult; - } - // Boolean - else if (typeof(T).Equals(typeof(Boolean))) - { - Boolean booleanResult = EvaluateBoolean(context); - TraceTreeResult(context, booleanResult, ValueKind.Boolean); - return (T)(Object)booleanResult; - } - // Version - else if (typeof(T).Equals(typeof(Version))) - { - Version versionResult = EvaluateVersion(context); - TraceTreeResult(context, versionResult, ValueKind.Version); - return (T)(Object)versionResult; - } - // DateTime types - else if (typeof(T).Equals(typeof(DateTimeOffset))) - { - DateTimeOffset dateTimeResult = EvaluateDateTime(context); - TraceTreeResult(context, dateTimeResult, ValueKind.DateTime); - return (T)(Object)dateTimeResult; - } - else if (typeof(T).Equals(typeof(DateTime))) - { - DateTimeOffset dateTimeResult = EvaluateDateTime(context); - TraceTreeResult(context, dateTimeResult, ValueKind.DateTime); - return (T)(Object)dateTimeResult.UtcDateTime; - } - - TypeInfo typeInfo = typeof(T).GetTypeInfo(); - if (typeInfo.IsPrimitive) - { - // Decimal - if (typeof(T).Equals(typeof(Decimal))) - { - Decimal decimalResult = EvaluateNumber(context); - TraceTreeResult(context, decimalResult, ValueKind.Number); - return (T)(Object)decimalResult; - } - // Other numeric types - else if (typeof(T).Equals(typeof(Byte)) || - typeof(T).Equals(typeof(SByte)) || - typeof(T).Equals(typeof(Int16)) || - typeof(T).Equals(typeof(UInt16)) || - typeof(T).Equals(typeof(Int32)) || - typeof(T).Equals(typeof(UInt32)) || - typeof(T).Equals(typeof(Int64)) || - typeof(T).Equals(typeof(UInt64)) || - typeof(T).Equals(typeof(Single)) || - typeof(T).Equals(typeof(Double))) - { - Decimal decimalResult = EvaluateNumber(context); - trace.Verbose($"Converting expression result to type {typeof(T).Name}"); - try - { - T numericResult = (T)Convert.ChangeType(decimalResult, typeof(T)); - - // Note, the value is converted back to decimal before tracing, in order to leverage the same - // util-formatting method used in other places. - TraceTreeResult(context, Convert.ToDecimal((Object)numericResult), ValueKind.Number); - - return numericResult; - } - catch (Exception exception) - { - context.Trace.Verbose($"Failed to convert the result number into the type {typeof(T).Name}. {exception.Message}"); - throw new TypeCastException( - secretMasker, - value: decimalResult, - fromKind: ValueKind.Number, - toType: typeof(T), - error: exception.Message); - } - } - } - - // Generic evaluate - EvaluationResult result = Evaluate(context); - TraceTreeResult(context, result.Value, result.Kind); - - // JToken - if (typeof(T).Equals(typeof(JToken))) - { - if (result.Value is null) - { - return default; - } - else if (result.Value is JToken) - { - return (T)result.Value; - } - else - { - return (T)(Object)JToken.FromObject(result.Value, JsonUtility.CreateJsonSerializer()); - } - } - // Object or Array - else if (result.Kind == ValueKind.Object || result.Kind == ValueKind.Array) - { - Type resultType = result.Value.GetType(); - context.Trace.Verbose($"Result type: {resultType.Name}"); - if (typeInfo.IsAssignableFrom(resultType.GetTypeInfo())) - { - return (T)result.Value; - } - else - { - context.Trace.Verbose($"Unable to assign result to the type {typeof(T).Name}"); - throw new TypeCastException(fromType: resultType, toType: typeof(T)); - } - } - // Null - else if (result.Kind == ValueKind.Null) - { - return default; - } - // String - else if (result.Kind == ValueKind.String) - { - // Treat empty string as null - String stringResult = result.Value as String; - if (String.IsNullOrEmpty(stringResult)) - { - return default; - } - - // Otherwise deserialize - try - { - return JsonUtility.FromString(stringResult); - } - catch (Exception exception) when (exception is JsonReaderException || exception is JsonSerializationException) - { - context.Trace.Verbose($"Failed to json-deserialize the result string into the type {typeof(T).Name}. {exception.Message}"); - throw new TypeCastException( - context.SecretMasker, - value: stringResult, - fromKind: ValueKind.String, - toType: typeof(T), - error: exception.Message); - } - } - else - { - context.Trace.Verbose($"Unable to convert from kind {result.Kind} to the type {typeof(T).Name}"); - throw new TypeCastException( - context.SecretMasker, - value: result.Value, - fromKind: result.Kind, - toType: typeof(T)); - } - } - finally - { - if (secretMasker != null && secretMasker != originalSecretMasker) - { - (secretMasker as IDisposable)?.Dispose(); - secretMasker = null; - } - } - } - - /// - /// INode entry point. - /// - public Object Evaluate( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state, - EvaluationOptions options = null) - { - return Evaluate(trace, secretMasker, state, options, out _, out _); - } - - /// - /// INode entry point. - /// - public Boolean EvaluateBoolean( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state) - { - return Evaluate(trace, secretMasker, state); - } - - /// - /// INode entry point. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public EvaluationResult EvaluateResult( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state, - EvaluationOptions options) - { - var val = Evaluate(trace, secretMasker, state, options, out ValueKind kind, out Object raw); - return new EvaluationResult(null, 0, val, kind, raw, omitTracing: true); - } - - /// - /// This function is intended only for ExpressionNode authors to call. The EvaluationContext - /// caches result-state specific to the evaluation instance. - /// - public EvaluationResult Evaluate(EvaluationContext context) - { - // Evaluate - Level = Container == null ? 0 : Container.Level + 1; - TraceVerbose(context, Level, $"Evaluating {Name}:"); - var coreResult = EvaluateCore(context, out ResultMemory coreMemory); - - if (coreMemory == null) - { - coreMemory = new ResultMemory(); - } - - // Convert to canonical value - var val = ExpressionUtil.ConvertToCanonicalValue(context.Options, coreResult, out ValueKind kind, out Object raw, out ResultMemory conversionMemory); - - // The depth can be safely trimmed when the total size of the core result is known, - // or when the total size of the core result can easily be determined. - var trimDepth = coreMemory.IsTotal || (Object.ReferenceEquals(raw, null) && s_simpleKinds.Contains(kind)); - - // Account for the memory overhead of the core result - var coreBytes = coreMemory.Bytes ?? EvaluationMemory.CalculateBytes(raw ?? val); - context.Memory.AddAmount(Level, coreBytes, trimDepth); - - // Account for the memory overhead of the conversion result - if (!Object.ReferenceEquals(raw, null)) - { - if (conversionMemory == null) - { - conversionMemory = new ResultMemory(); - } - - var conversionBytes = conversionMemory.Bytes ?? EvaluationMemory.CalculateBytes(val); - context.Memory.AddAmount(Level, conversionBytes); - } - - var result = new EvaluationResult(context, Level, val, kind, raw); - - // Store the trace result - if (this.TraceFullyRealized) - { - context.SetTraceResult(this, result); - } - - return result; - } - - /// - /// This function is intended only for ExpressionNode authors to call during evaluation. - /// The EvaluationContext caches result-state specific to the evaluation instance. - /// - public Boolean EvaluateBoolean(EvaluationContext context) - { - return Evaluate(context).ConvertToBoolean(context); - } - - /// - /// This function is intended only for ExpressionNode authors to call during evaluation. - /// The EvaluationContext caches result-state specific to the evaluation instance. - /// - public DateTimeOffset EvaluateDateTime(EvaluationContext context) - { - return Evaluate(context).ConvertToDateTime(context); - } - - /// - /// This function is intended only for ExpressionNode authors to call during evaluation. - /// The EvaluationContext caches result-state specific to the evaluation instance. - /// - public Decimal EvaluateNumber(EvaluationContext context) - { - return Evaluate(context).ConvertToNumber(context); - } - - /// - /// This function is intended only for ExpressionNode authors to call during evaluation. - /// The EvaluationContext caches result-state specific to the evaluation instance. - /// - public String EvaluateString(EvaluationContext context) - { - return Evaluate(context).ConvertToString(context); - } - - /// - /// This function is intended only for ExpressionNode authors to call during evaluation. - /// The EvaluationContext caches result-state specific to the evaluation instance. - /// - public Version EvaluateVersion(EvaluationContext context) - { - return Evaluate(context).ConvertToVersion(context); - } - - public virtual IEnumerable GetParameters() where T : IExpressionNode - { - return new T[0]; - } - - protected MemoryCounter CreateMemoryCounter(EvaluationContext context) - { - return new MemoryCounter(this, context.Options.MaxMemory); - } - - private Object Evaluate( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state, - EvaluationOptions options, - out ValueKind kind, - out Object raw) - { - if (Container != null) - { - // Do not localize. This is an SDK consumer error. - throw new NotSupportedException($"Expected {nameof(IExpressionNode)}.{nameof(Evaluate)} to be called on root node only."); - } - - ISecretMasker originalSecretMasker = secretMasker; - try - { - // Evaluate - secretMasker = secretMasker?.Clone() ?? new SecretMasker(); - trace = new EvaluationTraceWriter(trace, secretMasker); - var context = new EvaluationContext(trace, secretMasker, state, options, this); - trace.Info($"Evaluating: {ConvertToExpression()}"); - EvaluationResult result = Evaluate(context); - - // Trace the result - TraceTreeResult(context, result.Value, result.Kind); - - kind = result.Kind; - raw = result.Raw; - return result.Value; - } - finally - { - if (secretMasker != null && secretMasker != originalSecretMasker) - { - (secretMasker as IDisposable)?.Dispose(); - secretMasker = null; - } - } - } - - private void TraceTreeResult( - EvaluationContext context, - Object result, - ValueKind kind) - { - // Get the realized expression - String realizedExpression = ConvertToRealizedExpression(context); - - // Format the result - String traceValue = ExpressionUtil.FormatValue(context.SecretMasker, result, kind); - - // Only trace the realized expression if it is meaningfully different - if (!String.Equals(realizedExpression, traceValue, StringComparison.Ordinal)) - { - if (kind == ValueKind.Number && - String.Equals(realizedExpression, $"'{traceValue}'", StringComparison.Ordinal)) - { - // Don't bother tracing the realized expression when the result is a number and the - // realized expresion is a precisely matching string. - } - else - { - context.Trace.Info($"Expanded: {realizedExpression}"); - } - } - - // Always trace the result - context.Trace.Info($"Result: {traceValue}"); - } - - private static void TraceVerbose( - EvaluationContext context, - Int32 level, - String message) - { - context.Trace.Verbose(String.Empty.PadLeft(level * 2, '.') + (message ?? String.Empty)); - } - - private static readonly ValueKind[] s_simpleKinds = new[] - { - ValueKind.Boolean, - ValueKind.DateTime, - ValueKind.Null, - ValueKind.Number, - ValueKind.String, - ValueKind.Version, - }; - - private String m_name; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ExpressionParser.cs b/src/Sdk/DTExpressions/Expressions/ExpressionParser.cs deleted file mode 100644 index 9e562f388..000000000 --- a/src/Sdk/DTExpressions/Expressions/ExpressionParser.cs +++ /dev/null @@ -1,547 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class ExpressionParser - { - public ExpressionParser(): this(null) - { - } - - public ExpressionParser(ExpressionParserOptions options) - { - m_parserOptions = options ?? new ExpressionParserOptions(); - } - - public IExpressionNode CreateTree( - String expression, - ITraceWriter trace, - IEnumerable namedValues, - IEnumerable functions) - { - var context = new ParseContext(expression, trace, namedValues, functions, allowUnknownKeywords: false, allowKeywordHyphens: m_parserOptions.AllowHyphens); - context.Trace.Info($"Parsing expression: <{expression}>"); - return CreateTree(context); - } - - public void ValidateSyntax( - String expression, - ITraceWriter trace) - { - var context = new ParseContext(expression, trace, namedValues: null, functions: null, allowUnknownKeywords: true, allowKeywordHyphens: m_parserOptions.AllowHyphens); - context.Trace.Info($"Validating expression syntax: <{expression}>"); - CreateTree(context); - } - - private static IExpressionNode CreateTree(ParseContext context) - { - while (TryGetNextToken(context)) - { - switch (context.Token.Kind) - { - // Punctuation - case TokenKind.StartIndex: - HandleStartIndex(context); - break; - case TokenKind.EndIndex: - HandleEndIndex(context); - break; - case TokenKind.EndParameter: - HandleEndParameter(context); - break; - case TokenKind.Separator: - HandleSeparator(context); - break; - case TokenKind.Dereference: - HandleDereference(context); - break; - case TokenKind.Wildcard: - HandleWildcard(context); - break; - - // Functions - case TokenKind.WellKnownFunction: - case TokenKind.ExtensionFunction: - HandleFunction(context); - break; - - // Leaf values - case TokenKind.Boolean: - case TokenKind.Number: - case TokenKind.Version: - case TokenKind.String: - case TokenKind.ExtensionNamedValue: - HandleValue(context); - break; - - // Unknown keyword - case TokenKind.UnknownKeyword: - HandleUnknownKeyword(context); - break; - - // Malformed - case TokenKind.Unrecognized: - throw new ParseException(ParseExceptionKind.UnrecognizedValue, context.Token, context.Expression); - - // Unexpected - case TokenKind.PropertyName: // PropertyName should never reach here (HandleDereference reads next token). - case TokenKind.StartParameter: // StartParameter is only expected by HandleFunction. - default: - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - - // Validate depth. - if (context.Containers.Count >= ExpressionConstants.MaxDepth) - { - throw new ParseException(ParseExceptionKind.ExceededMaxDepth, token: null, expression: context.Expression); - } - } - - // Validate all containers were closed. - if (context.Containers.Count > 0) - { - ContainerInfo container = context.Containers.Peek(); - if (container.Node is FunctionNode) - { - throw new ParseException(ParseExceptionKind.UnclosedFunction, container.Token, context.Expression); - } - else - { - throw new ParseException(ParseExceptionKind.UnclosedIndexer, container.Token, context.Expression); - } - } - - return context.Root; - } - - private static bool TryGetNextToken(ParseContext context) - { - context.LastToken = context.Token; - if (context.Lexer.TryGetNextToken(ref context.Token)) - { - // Adjust indent level. - int indentLevel = context.Containers.Count; - if (indentLevel > 0) - { - switch (context.Token.Kind) - { - case TokenKind.StartParameter: - case TokenKind.EndParameter: - case TokenKind.EndIndex: - indentLevel--; - break; - } - } - - String indent = String.Empty.PadRight(indentLevel * 2, '.'); - switch (context.Token.Kind) - { - // Literal values - case TokenKind.Boolean: - context.Trace.Verbose($"{indent}{ExpressionUtil.FormatValue(null, context.Token.ParsedValue, ValueKind.Boolean)}"); - break; - case TokenKind.Number: - context.Trace.Verbose($"{indent}{ExpressionUtil.FormatValue(null, context.Token.ParsedValue, ValueKind.Number)}"); - break; - case TokenKind.Version: - context.Trace.Verbose($"{indent}{ExpressionUtil.FormatValue(null, context.Token.ParsedValue, ValueKind.Version)}"); - break; - case TokenKind.String: - context.Trace.Verbose($"{indent}{ExpressionUtil.FormatValue(null, context.Token.ParsedValue, ValueKind.String)}"); - break; - // Property or unrecognized - case TokenKind.PropertyName: - case TokenKind.Unrecognized: - context.Trace.Verbose($"{indent}{context.Token.Kind} {ExpressionUtil.FormatValue(null, context.Token.RawValue, ValueKind.String)}"); - break; - // Function or punctuation - case TokenKind.WellKnownFunction: - case TokenKind.ExtensionFunction: - case TokenKind.ExtensionNamedValue: - case TokenKind.Wildcard: - case TokenKind.UnknownKeyword: - case TokenKind.StartIndex: - case TokenKind.StartParameter: - case TokenKind.EndIndex: - case TokenKind.EndParameter: - case TokenKind.Separator: - case TokenKind.Dereference: - context.Trace.Verbose($"{indent}{context.Token.RawValue}"); - break; - default: // Should never reach here. - throw new NotSupportedException($"Unexpected token kind: {context.Token.Kind}"); - } - - return true; - } - - return false; - } - - private static void HandleStartIndex(ParseContext context) - { - // Validate follows ")", "]", "*", or a property name. - if (context.LastToken == null || - (context.LastToken.Kind != TokenKind.EndParameter && context.LastToken.Kind != TokenKind.EndIndex && context.LastToken.Kind != TokenKind.PropertyName && context.LastToken.Kind != TokenKind.ExtensionNamedValue && context.LastToken.Kind != TokenKind.UnknownKeyword && context.LastToken.Kind != TokenKind.Wildcard)) - { - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - - // Wrap the object being indexed into. - var indexer = new IndexerNode(); - ExpressionNode obj = null; - if (context.Containers.Count > 0) - { - ContainerNode container = context.Containers.Peek().Node; - Int32 objIndex = container.Parameters.Count - 1; - obj = container.Parameters[objIndex]; - container.ReplaceParameter(objIndex, indexer); - } - else - { - obj = context.Root; - context.Root = indexer; - } - - indexer.AddParameter(obj); - - // Update the container stack. - context.Containers.Push(new ContainerInfo() { Node = indexer, Token = context.Token }); - } - - private static void HandleDereference(ParseContext context) - { - // Validate follows ")", "]", "*", or a property name. - if (context.LastToken == null || - (context.LastToken.Kind != TokenKind.EndParameter && context.LastToken.Kind != TokenKind.EndIndex && context.LastToken.Kind != TokenKind.PropertyName && context.LastToken.Kind != TokenKind.ExtensionNamedValue && context.LastToken.Kind != TokenKind.UnknownKeyword && context.LastToken.Kind != TokenKind.Wildcard)) - { - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - - // Wrap the object being indexed into. - var indexer = new IndexerNode(); - ExpressionNode obj = null; - if (context.Containers.Count > 0) - { - ContainerNode container = context.Containers.Peek().Node; - Int32 objIndex = container.Parameters.Count - 1; - obj = container.Parameters[objIndex]; - container.ReplaceParameter(objIndex, indexer); - } - else - { - obj = context.Root; - context.Root = indexer; - } - - indexer.AddParameter(obj); - - // Validate a token follows. - if (!TryGetNextToken(context)) - { - throw new ParseException(ParseExceptionKind.ExpectedPropertyName, context.LastToken, context.Expression); - } - - if (context.Token.Kind == TokenKind.PropertyName) - { - indexer.AddParameter(new LiteralValueNode(context.Token.RawValue)); - } - else if (context.Token.Kind == TokenKind.Wildcard) - { - // For a wildcard we add a third parameter, a boolean set to true, so that we know it's a wildcard. - indexer.AddParameter(new LiteralValueNode(context.Token.RawValue)); - indexer.AddParameter(new LiteralValueNode(true)); - } - else - { - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - } - - private static void HandleWildcard(ParseContext context) - { - // Validate follows "[". - if (context.LastToken == null || - context.LastToken.Kind != TokenKind.StartIndex) - { - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - - // When we have a wildcard, we add the wildcard and also third boolean parameter set to true. - // This lets us differentiate downstream from '*'. - context.Containers.Peek().Node.AddParameter(new LiteralValueNode(context.Token.RawValue)); - context.Containers.Peek().Node.AddParameter(new LiteralValueNode(true)); - } - - private static void HandleEndParameter(ParseContext context) - { - ContainerInfo container = context.Containers.Count > 0 ? context.Containers.Peek() : null; // Validate: - if (container == null || // 1) Container is not null - !(container.Node is FunctionNode) || // 2) Container is a function - container.Node.Parameters.Count < GetMinParamCount(context, container.Token) || // 3) Not below min param threshold - container.Node.Parameters.Count > GetMaxParamCount(context, container.Token) || // 4) Not above max param threshold - context.LastToken.Kind == TokenKind.Separator) // 5) Last token is not a separator - { - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - - context.Containers.Pop(); - } - - private static void HandleEndIndex(ParseContext context) - { - IndexerNode indexer = context.Containers.Count > 0 ? context.Containers.Peek().Node as IndexerNode : null; - // // Validate: - if (indexer == null || // 1) Container is an indexer - !(indexer.Parameters.Count == 2 || indexer.Parameters.Count == 3)) // 2) Can be 2 or 3 parameters. It's 3 parameters when we are using a filtered array since we - // set a boolean along with the wildcard. - { - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - - context.Containers.Pop(); - } - - private static void HandleUnknownKeyword(ParseContext context) - { - // Validate. - if (!context.AllowUnknownKeywords) - { - throw new ParseException(ParseExceptionKind.UnrecognizedValue, context.Token, context.Expression); - } - - // Try handle function. - if (HandleFunction(context, bestEffort: true)) - { - return; - } - - // Handle named value. - HandleValue(context); - } - - private static void HandleValue(ParseContext context) - { - // Validate either A) is the first token OR B) follows "[" "(" or ",". - if (context.LastToken != null && - context.LastToken.Kind != TokenKind.StartIndex && - context.LastToken.Kind != TokenKind.StartParameter && - context.LastToken.Kind != TokenKind.Separator) - { - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - - // Create the node. - ExpressionNode node; - switch (context.Token.Kind) - { - case TokenKind.ExtensionNamedValue: - String name = context.Token.RawValue; - node = context.ExtensionNamedValues[name].CreateNode(); - node.Name = name; - break; - case TokenKind.UnknownKeyword: - node = new UnknownNamedValueNode(); - node.Name = context.Token.RawValue; - break; - default: - node = new LiteralValueNode(context.Token.ParsedValue); - break; - } - - // Update the tree. - if (context.Root == null) - { - context.Root = node; - } - else - { - context.Containers.Peek().Node.AddParameter(node); - } - } - - private static void HandleSeparator(ParseContext context) - { - ContainerInfo container = context.Containers.Count > 0 ? context.Containers.Peek() : null; // Validate: - if (container == null || // 1) Container is not null - !(container.Node is FunctionNode) || // 2) Container is a function - container.Node.Parameters.Count < 1 || // 3) At least one parameter - container.Node.Parameters.Count >= GetMaxParamCount(context, container.Token) ||// 4) Under max parameters threshold - context.LastToken.Kind == TokenKind.Separator) // 5) Last token is not a separator - { - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - } - - private static Boolean HandleFunction( - ParseContext context, - Boolean bestEffort = false) - { - // Validate either A) is first token OR B) follows "," or "[" or "(". - if (context.LastToken != null && - (context.LastToken.Kind != TokenKind.Separator && - context.LastToken.Kind != TokenKind.StartIndex && - context.LastToken.Kind != TokenKind.StartParameter)) - { - if (bestEffort) - { - return false; - } - - throw new ParseException(ParseExceptionKind.UnexpectedSymbol, context.Token, context.Expression); - } - - // Validate '(' follows. - if (bestEffort) - { - Token nextToken = null; - if (!context.Lexer.TryPeekNextToken(ref nextToken) || nextToken.Kind != TokenKind.StartParameter) - { - return false; - } - - TryGetNextToken(context); - } - else if (!TryGetNextToken(context) || context.Token.Kind != TokenKind.StartParameter) - { - throw new ParseException(ParseExceptionKind.ExpectedStartParameter, context.LastToken, context.Expression); - } - - // Create the node. - FunctionNode node; - String name = context.LastToken.RawValue; - switch (context.LastToken.Kind) - { - case TokenKind.WellKnownFunction: - node = ExpressionConstants.WellKnownFunctions[name].CreateNode(); - node.Name = name; - break; - case TokenKind.ExtensionFunction: - node = context.ExtensionFunctions[name].CreateNode(); - node.Name = name; - break; - case TokenKind.UnknownKeyword: - node = new UnknownFunctionNode(); - node.Name = name; - break; - default: - // Should never reach here. - throw new NotSupportedException($"Unexpected function token name: '{context.LastToken.Kind}'"); - } - - // Update the tree. - if (context.Root == null) - { - context.Root = node; - } - else - { - context.Containers.Peek().Node.AddParameter(node); - } - - // Update the container stack. - context.Containers.Push(new ContainerInfo() { Node = node, Token = context.LastToken }); - return true; - } - - private static int GetMinParamCount( - ParseContext context, - Token token) - { - switch (token.Kind) - { - case TokenKind.WellKnownFunction: - return ExpressionConstants.WellKnownFunctions[token.RawValue].MinParameters; - case TokenKind.ExtensionFunction: - return context.ExtensionFunctions[token.RawValue].MinParameters; - case TokenKind.UnknownKeyword: - return 0; - default: // Should never reach here. - throw new NotSupportedException($"Unexpected token kind '{token.Kind}'. Unable to determine min param count."); - } - } - - private static Int32 GetMaxParamCount( - ParseContext context, - Token token) - { - switch (token.Kind) - { - case TokenKind.WellKnownFunction: - return ExpressionConstants.WellKnownFunctions[token.RawValue].MaxParameters; - case TokenKind.ExtensionFunction: - return context.ExtensionFunctions[token.RawValue].MaxParameters; - case TokenKind.UnknownKeyword: - return Int32.MaxValue; - default: // Should never reach here. - throw new NotSupportedException($"Unexpected token kind '{token.Kind}'. Unable to determine max param count."); - } - } - - private ExpressionParserOptions m_parserOptions; - - private sealed class ContainerInfo - { - public ContainerNode Node { get; set; } - - public Token Token { get; set; } - } - - private sealed class ParseContext - { - public readonly Boolean AllowUnknownKeywords; - public readonly Stack Containers = new Stack(); - public readonly String Expression; - public readonly Dictionary ExtensionFunctions = new Dictionary(StringComparer.OrdinalIgnoreCase); - public readonly Dictionary ExtensionNamedValues = new Dictionary(StringComparer.OrdinalIgnoreCase); - public readonly LexicalAnalyzer Lexer; - public readonly ITraceWriter Trace; - public Token Token; - public Token LastToken; - public ExpressionNode Root; - - public ParseContext( - String expression, - ITraceWriter trace, - IEnumerable namedValues, - IEnumerable functions, - Boolean allowUnknownKeywords = false, - Boolean allowKeywordHyphens = false) - { - Expression = expression ?? String.Empty; - if (Expression.Length > ExpressionConstants.MaxLength) - { - throw new ParseException(ParseExceptionKind.ExceededMaxLength, token: null, expression: Expression); - } - - Trace = trace ?? new NoOperationTraceWriter(); - foreach (INamedValueInfo namedValueInfo in (namedValues ?? new INamedValueInfo[0])) - { - ExtensionNamedValues.Add(namedValueInfo.Name, namedValueInfo); - } - - foreach (IFunctionInfo functionInfo in (functions ?? new IFunctionInfo[0])) - { - ExtensionFunctions.Add(functionInfo.Name, functionInfo); - } - - AllowUnknownKeywords = allowUnknownKeywords; - Lexer = new LexicalAnalyzer(Expression, namedValues: ExtensionNamedValues.Keys, functions: ExtensionFunctions.Keys, allowKeywordHyphens); - } - - private class NoOperationTraceWriter : ITraceWriter - { - public void Info(String message) - { - } - - public void Verbose(String message) - { - } - } - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ExpressionParserOptions.cs b/src/Sdk/DTExpressions/Expressions/ExpressionParserOptions.cs deleted file mode 100644 index 49e267e82..000000000 --- a/src/Sdk/DTExpressions/Expressions/ExpressionParserOptions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - public sealed class ExpressionParserOptions - { - public Boolean AllowHyphens - { - get; - set; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ExpressionUtil.cs b/src/Sdk/DTExpressions/Expressions/ExpressionUtil.cs deleted file mode 100644 index ffb8219d5..000000000 --- a/src/Sdk/DTExpressions/Expressions/ExpressionUtil.cs +++ /dev/null @@ -1,211 +0,0 @@ -using System; -using System.ComponentModel; -using System.Globalization; -using System.Reflection; -using GitHub.DistributedTask.Logging; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - internal static class ExpressionUtil - { - internal static Object ConvertToCanonicalValue( - EvaluationOptions options, - Object val, - out ValueKind kind, - out Object raw, - out ResultMemory conversionResultMemory) - { - // Apply converter - if (options?.Converters?.Count > 0 && - !Object.ReferenceEquals(val, null) && - options.Converters.TryGetValue(val.GetType(), out Converter convert)) - { - raw = val; - var conversionResult = convert(val); - val = conversionResult.Result; - conversionResultMemory = conversionResult.ResultMemory; - } - else - { - raw = null; - conversionResultMemory = null; - } - - if (Object.ReferenceEquals(val, null)) - { - kind = ValueKind.Null; - return null; - } - else if (val is IString str) - { - kind = ValueKind.String; - return str.GetString(); - } - else if (val is IBoolean booleanValue) - { - kind = ValueKind.Boolean; - return booleanValue.GetBoolean(); - } - else if (val is INumber num) - { - kind = ValueKind.Number; - return num.GetNumber(); - } - else if (val is JToken) - { - var jtoken = val as JToken; - switch (jtoken.Type) - { - case JTokenType.Array: - kind = ValueKind.Array; - return jtoken; - case JTokenType.Boolean: - kind = ValueKind.Boolean; - return jtoken.ToObject(); - case JTokenType.Float: - case JTokenType.Integer: - kind = ValueKind.Number; - // todo: test the extents of the conversion - return jtoken.ToObject(); - case JTokenType.Null: - kind = ValueKind.Null; - return null; - case JTokenType.Object: - kind = ValueKind.Object; - return jtoken; - case JTokenType.String: - kind = ValueKind.String; - return jtoken.ToObject(); - } - } - else if (val is String) - { - kind = ValueKind.String; - return val; - } - else if (val is Version) - { - kind = ValueKind.Version; - return val; - } - else if (!val.GetType().GetTypeInfo().IsClass) - { - if (val is Boolean) - { - kind = ValueKind.Boolean; - return val; - } - else if (val is DateTimeOffset) - { - kind = ValueKind.DateTime; - return val; - } - else if (val is DateTime dateTime) - { - kind = ValueKind.DateTime; - switch (dateTime.Kind) - { - // When Local: convert to preferred time zone - case DateTimeKind.Local: - var targetTimeZone = options?.TimeZone ?? TimeZoneInfo.Local; - var localDateTimeOffset = new DateTimeOffset(dateTime); - return TimeZoneInfo.ConvertTime(localDateTimeOffset, targetTimeZone); - // When Unspecified: assume preferred time zone - case DateTimeKind.Unspecified: - var timeZone = options?.TimeZone ?? TimeZoneInfo.Local; - var offset = timeZone.GetUtcOffset(dateTime); - return new DateTimeOffset(dateTime, offset); - // When UTC: keep UTC - case DateTimeKind.Utc: - return new DateTimeOffset(dateTime); - default: - throw new NotSupportedException($"Unexpected DateTimeKind '{dateTime.Kind}'"); // Should never happen - } - } - else if (val is Decimal || val is Byte || val is SByte || val is Int16 || val is UInt16 || val is Int32 || val is UInt32 || val is Int64 || val is UInt64 || val is Single || val is Double) - { - kind = ValueKind.Number; - return Convert.ToDecimal(val); - } - else if (val is Enum) - { - var strVal = String.Format(CultureInfo.InvariantCulture, "{0:G}", val); - if (Decimal.TryParse(strVal, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out Decimal decVal)) - { - kind = ValueKind.Number; - return decVal; - } - - kind = ValueKind.String; - return strVal; - } - } - - kind = ValueKind.Object; - return val; - } - - internal static String FormatValue( - ISecretMasker secretMasker, - EvaluationResult evaluationResult) - { - return FormatValue(secretMasker, evaluationResult.Value, evaluationResult.Kind); - } - - internal static String FormatValue( - ISecretMasker secretMasker, - Object value, - ValueKind kind) - { - switch (kind) - { - case ValueKind.Boolean: - return ((Boolean)value).ToString(); - - case ValueKind.DateTime: - var strDateTime = "(DateTime)" + ((DateTimeOffset)value).ToString(ExpressionConstants.DateTimeFormat, CultureInfo.InvariantCulture); - return secretMasker != null ? secretMasker.MaskSecrets(strDateTime) : strDateTime; - - case ValueKind.Number: - var strNumber = ((Decimal)value).ToString(ExpressionConstants.NumberFormat, CultureInfo.InvariantCulture); - return secretMasker != null ? secretMasker.MaskSecrets(strNumber) : strNumber; - - case ValueKind.String: - // Mask secrets before string-escaping. - var strValue = secretMasker != null ? secretMasker.MaskSecrets(value as String) : value as String; - return $"'{StringEscape(strValue)}'"; - - case ValueKind.Version: - String strVersion = secretMasker != null ? secretMasker.MaskSecrets(value.ToString()) : value.ToString(); - return $"v{strVersion}"; - - case ValueKind.Array: - case ValueKind.Null: - case ValueKind.Object: - return kind.ToString(); - - default: // Should never reach here. - throw new NotSupportedException($"Unable to convert to realized expression. Unexpected value kind: {kind}"); - } - } - - internal static Char SafeCharAt( - String str, - Int32 index) - { - if (str.Length > index) - { - return str[index]; - } - - return '\0'; - } - - internal static String StringEscape(String value) - { - return String.IsNullOrEmpty(value) ? String.Empty : value.Replace("'", "''"); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/FormatNode.cs b/src/Sdk/DTExpressions/Expressions/FormatNode.cs deleted file mode 100644 index 19325f4ae..000000000 --- a/src/Sdk/DTExpressions/Expressions/FormatNode.cs +++ /dev/null @@ -1,394 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class FormatNode : FunctionNode - { - protected sealed override Object EvaluateCore(EvaluationContext context) - { - var format = Parameters[0].EvaluateString(context); - var index = 0; - var result = new FormatResultBuilder(this, context, CreateMemoryCounter(context)); - while (index < format.Length) - { - var lbrace = format.IndexOf('{', index); - var rbrace = format.IndexOf('}', index); - - // Left brace - if (lbrace >= 0 && (rbrace < 0 || rbrace > lbrace)) - { - // Escaped left brace - if (ExpressionUtil.SafeCharAt(format, lbrace + 1) == '{') - { - result.Append(format.Substring(index, lbrace - index + 1)); - index = lbrace + 2; - } - // Left brace, number, optional format specifiers, right brace - else if (rbrace > lbrace + 1 && - ReadArgIndex(format, lbrace + 1, out Byte argIndex, out Int32 endArgIndex) && - ReadFormatSpecifiers(format, endArgIndex + 1, out String formatSpecifiers, out rbrace)) - { - // Check parameter count - if (argIndex > Parameters.Count - 2) - { - throw new FormatException(ExpressionResources.InvalidFormatArgIndex(format)); - } - - // Append the portion before the left brace - if (lbrace > index) - { - result.Append(format.Substring(index, lbrace - index)); - } - - // Append the arg - result.Append(argIndex, formatSpecifiers); - index = rbrace + 1; - } - else - { - throw new FormatException(ExpressionResources.InvalidFormatString(format)); - } - } - // Right brace - else if (rbrace >= 0) - { - // Escaped right brace - if (ExpressionUtil.SafeCharAt(format, rbrace + 1) == '}') - { - result.Append(format.Substring(index, rbrace - index + 1)); - index = rbrace + 2; - } - else - { - throw new FormatException(ExpressionResources.InvalidFormatString(format)); - } - } - // Last segment - else - { - result.Append(format.Substring(index)); - break; - } - } - - return result.ToString(); - } - - private Boolean ReadArgIndex( - String str, - Int32 startIndex, - out Byte result, - out Int32 endIndex) - { - // Count the number of digits - var length = 0; - while (Char.IsDigit(ExpressionUtil.SafeCharAt(str, startIndex + length))) - { - length++; - } - - // Validate at least one digit - if (length < 1) - { - result = default; - endIndex = default; - return false; - } - - // Parse the number - endIndex = startIndex + length - 1; - return Byte.TryParse(str.Substring(startIndex, length), NumberStyles.None, CultureInfo.InvariantCulture, out result); - } - - private Boolean ReadFormatSpecifiers( - String str, - Int32 startIndex, - out String result, - out Int32 rbrace) - { - // No format specifiers - var c = ExpressionUtil.SafeCharAt(str, startIndex); - if (c == '}') - { - result = String.Empty; - rbrace = startIndex; - return true; - } - - // Validate starts with ":" - if (c != ':') - { - result = default; - rbrace = default; - return false; - } - - // Read the specifiers - var specifiers = new StringBuilder(); - var index = startIndex + 1; - while (true) - { - // Validate not the end of the string - if (index >= str.Length) - { - result = default; - rbrace = default; - return false; - } - - c = str[index]; - - // Not right-brace - if (c != '}') - { - specifiers.Append(c); - index++; - } - // Escaped right-brace - else if (ExpressionUtil.SafeCharAt(str, index + 1) == '}') - { - specifiers.Append('}'); - index += 2; - } - // Closing right-brace - else - { - result = specifiers.ToString(); - rbrace = index; - return true; - } - } - } - - private sealed class FormatResultBuilder - { - internal FormatResultBuilder( - FormatNode node, - EvaluationContext context, - MemoryCounter counter) - { - m_node = node; - m_context = context; - m_counter = counter; - m_cache = new ArgValue[node.Parameters.Count - 1]; - } - - // Build the final string. This is when lazy segments are evaluated. - public override String ToString() - { - return String.Join( - String.Empty, - m_segments.Select(obj => - { - if (obj is Lazy lazy) - { - return lazy.Value; - } - else - { - return obj as String; - } - })); - } - - // Append a static value - internal void Append(String value) - { - if (value?.Length > 0) - { - // Track memory - m_counter.Add(value); - - // Append the segment - m_segments.Add(value); - } - } - - // Append an argument - internal void Append( - Int32 argIndex, - String formatSpecifiers) - { - // Delay execution until the final ToString - m_segments.Add(new Lazy(() => - { - String result; - - // Get the arg from the cache - var argValue = m_cache[argIndex]; - - // Evaluate the arg and cache the result - if (argValue == null) - { - // The evaluation result is required when format specifiers are used. Otherwise the string - // result is required. Go ahead and store both values. Since ConvertToString produces tracing, - // we need to run that now so the tracing appears in order in the log. - var evaluationResult = m_node.Parameters[argIndex + 1].Evaluate(m_context); - var stringResult = evaluationResult.ConvertToString(m_context); - argValue = new ArgValue(evaluationResult, stringResult); - m_cache[argIndex] = argValue; - } - - // No format specifiers - if (String.IsNullOrEmpty(formatSpecifiers)) - { - result = argValue.StringResult; - } - // DateTime - else if (argValue.EvaluationResult.Kind == ValueKind.DateTime) - { - result = FormatDateTime((DateTimeOffset)argValue.EvaluationResult.Value, formatSpecifiers); - } - // Invalid - else - { - throw new FormatException(ExpressionResources.InvalidFormatSpecifiers(formatSpecifiers, argValue.EvaluationResult.Kind)); - } - - // Track memory - if (!String.IsNullOrEmpty(result)) - { - m_counter.Add(result); - } - - return result; - })); - } - - private String FormatDateTime( - DateTimeOffset dateTime, - String specifiers) - { - var result = new StringBuilder(); - var i = 0; - while (true) - { - // Get the next specifier - var specifier = GetNextSpecifier(specifiers, ref i); - - // Check end of string - if (String.IsNullOrEmpty(specifier)) - { - break; - } - - // Append the value - switch (specifier) - { - case "yyyy": - case "yy": - case "MM": - case "dd": - case "HH": - case "mm": - case "ss": - case "ff": - case "fff": - case "ffff": - case "fffff": - case "ffffff": - case "fffffff": - case "zzz": - result.Append(dateTime.ToString(specifier)); - break; - - // .Net requires a leading % for some specifiers - case "M": - case "d": - case "H": - case "m": - case "s": - case "f": - case "K": - result.Append(dateTime.ToString("%" + specifier)); - break; - - default: - // Escaped character - if (specifier[0] == '\\') - { - result.Append(specifier[1]); - } - else if (specifier[0] == ' ') - { - result.Append(specifier); - } - // Unexpected - else - { - throw new FormatException(ExpressionResources.InvalidFormatSpecifiers(specifiers, ValueKind.DateTime)); - } - break; - } - } - - return result.ToString(); - } - - private String GetNextSpecifier( - String specifiers, - ref Int32 index) - { - // End of string - if (index >= specifiers.Length) - { - return String.Empty; - } - - // Get the first char - var startIndex = index; - var c = specifiers[index++]; - - // Escaped - if (c == '\\') - { - // End of string - if (index >= specifiers.Length) - { - throw new FormatException(ExpressionResources.InvalidFormatSpecifiers(specifiers, ValueKind.DateTime)); - } - - index++; - } - // Find consecutive matches - else - { - while (index < specifiers.Length && specifiers[index] == c) - { - index++; - } - } - - return specifiers.Substring(startIndex, index - startIndex); - } - - private readonly ArgValue[] m_cache; - private readonly EvaluationContext m_context; - private readonly MemoryCounter m_counter; - private readonly FormatNode m_node; - private readonly List m_segments = new List(); - } - - /// - /// Stores an EvaluateResult and the value converted to a String. - /// - private sealed class ArgValue - { - public ArgValue( - EvaluationResult evaluationResult, - String stringResult) - { - EvaluationResult = evaluationResult; - StringResult = stringResult; - } - - public EvaluationResult EvaluationResult { get; } - - public String StringResult { get; } - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/FunctionInfo.cs b/src/Sdk/DTExpressions/Expressions/FunctionInfo.cs deleted file mode 100644 index 6852ea977..000000000 --- a/src/Sdk/DTExpressions/Expressions/FunctionInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - public class FunctionInfo : IFunctionInfo - where T : FunctionNode, new() - { - public FunctionInfo(String name, Int32 minParameters, Int32 maxParameters) - { - Name = name; - MinParameters = minParameters; - MaxParameters = maxParameters; - } - - public String Name { get; } - - public Int32 MinParameters { get; } - - public Int32 MaxParameters { get; } - - public FunctionNode CreateNode() - { - return new T(); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/FunctionNode.cs b/src/Sdk/DTExpressions/Expressions/FunctionNode.cs deleted file mode 100644 index 6722f36a3..000000000 --- a/src/Sdk/DTExpressions/Expressions/FunctionNode.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.ComponentModel; -using System.Globalization; -using System.Linq; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class FunctionNode : ContainerNode - { - /// - /// Generally this should not be overridden. True indicates the result of the node is traced as part of the "expanded" - /// (i.e. "realized") trace information. Otherwise the node expression is printed, and parameters to the node may or - /// may not be fully realized - depending on each respective parameter's trace-fully-realized setting. - /// - /// The purpose is so the end user can understand how their expression expanded at run time. For example, consider - /// the expression: eq(variables.publish, 'true'). The runtime-expanded expression may be: eq('true', 'true') - /// - protected override Boolean TraceFullyRealized => true; - - internal sealed override String ConvertToExpression() - { - return String.Format( - CultureInfo.InvariantCulture, - "{0}({1})", - Name, - String.Join(", ", Parameters.Select(x => x.ConvertToExpression()))); - } - - internal sealed override String ConvertToRealizedExpression(EvaluationContext context) - { - // Check if the result was stored - if (context.TryGetTraceResult(this, out String result)) - { - return result; - } - - return String.Format( - CultureInfo.InvariantCulture, - "{0}({1})", - Name, - String.Join(", ", Parameters.Select(x => x.ConvertToRealizedExpression(context)))); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/GreaterThanNode.cs b/src/Sdk/DTExpressions/Expressions/GreaterThanNode.cs deleted file mode 100644 index 2c101b766..000000000 --- a/src/Sdk/DTExpressions/Expressions/GreaterThanNode.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class GreaterThanNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return Parameters[0].Evaluate(context).CompareTo(context, Parameters[1].Evaluate(context)) > 0; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/GreaterThanOrEqualNode.cs b/src/Sdk/DTExpressions/Expressions/GreaterThanOrEqualNode.cs deleted file mode 100644 index 85116ed67..000000000 --- a/src/Sdk/DTExpressions/Expressions/GreaterThanOrEqualNode.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class GreaterThanOrEqualNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return Parameters[0].Evaluate(context).CompareTo(context, Parameters[1].Evaluate(context)) >= 0; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/IBoolean.cs b/src/Sdk/DTExpressions/Expressions/IBoolean.cs deleted file mode 100644 index b5a1fec8b..000000000 --- a/src/Sdk/DTExpressions/Expressions/IBoolean.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IBoolean - { - Boolean GetBoolean(); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/IExpressionNode.cs b/src/Sdk/DTExpressions/Expressions/IExpressionNode.cs deleted file mode 100644 index 52c0d9a9a..000000000 --- a/src/Sdk/DTExpressions/Expressions/IExpressionNode.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Logging; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IExpressionNode - { - /// - /// Evaluates the expression and attempts to cast or deserialize the result to the specified - /// type. The specified type can either be simple type or a JSON-serializable class. Allowed - /// simple types are: Boolean, String, Version, Byte, SByte, Int16, UInt16, Int32, UInt32, - /// Int64, UInt64, Single, Double, or Decimal. When a JSON-serializable class is specified, the - /// following rules are applied: If the type of the evaluation result object, is assignable to - /// the specified type, then the result will be cast and returned. If the evaluation result - /// object is a String, it will be deserialized as the specified type. If the evaluation result - /// object is null, null will be returned. - /// - /// Optional trace writer - /// Optional secret masker - /// State object for custom evaluation function nodes and custom named-value nodes - T Evaluate( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state, - EvaluationOptions options = null); - - /// - /// Evaluates the expression and returns the result. - /// - /// Optional trace writer - /// Optional secret masker - /// State object for custom evaluation function nodes and custom named-value nodes - Object Evaluate( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state, - EvaluationOptions options = null); - - /// - /// Evaluates the expression and casts the result to a Boolean. - /// - /// Optional trace writer - /// Optional secret masker - /// State object for custom evaluation function nodes and custom named-value nodes - Boolean EvaluateBoolean( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state); - - IEnumerable GetParameters() where T : IExpressionNode; - - /// - /// Evaluates the expression and returns the result, wrapped in the SDK helper - /// for converting, comparing, and traversing objects. - /// - /// Optional trace writer - /// Optional secret masker - /// State object for custom evaluation function nodes and custom named-value nodes - /// Evaluation options - [EditorBrowsable(EditorBrowsableState.Never)] - EvaluationResult EvaluateResult( - ITraceWriter trace, - ISecretMasker secretMasker, - Object state, - EvaluationOptions options); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/IFunctionInfo.cs b/src/Sdk/DTExpressions/Expressions/IFunctionInfo.cs deleted file mode 100644 index 0aad42a8c..000000000 --- a/src/Sdk/DTExpressions/Expressions/IFunctionInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - public interface IFunctionInfo - { - String Name { get; } - Int32 MinParameters { get; } - Int32 MaxParameters { get; } - FunctionNode CreateNode(); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/INamedValueInfo.cs b/src/Sdk/DTExpressions/Expressions/INamedValueInfo.cs deleted file mode 100644 index 94dfcd3c6..000000000 --- a/src/Sdk/DTExpressions/Expressions/INamedValueInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - public interface INamedValueInfo - { - String Name { get; } - NamedValueNode CreateNode(); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/INumber.cs b/src/Sdk/DTExpressions/Expressions/INumber.cs deleted file mode 100644 index 7baa37529..000000000 --- a/src/Sdk/DTExpressions/Expressions/INumber.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface INumber - { - Decimal GetNumber(); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/IReadOnlyArray.cs b/src/Sdk/DTExpressions/Expressions/IReadOnlyArray.cs deleted file mode 100644 index 686e8bc26..000000000 --- a/src/Sdk/DTExpressions/Expressions/IReadOnlyArray.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IReadOnlyArray : IReadOnlyList - { - } -} diff --git a/src/Sdk/DTExpressions/Expressions/IReadOnlyObject.cs b/src/Sdk/DTExpressions/Expressions/IReadOnlyObject.cs deleted file mode 100644 index 757a17c12..000000000 --- a/src/Sdk/DTExpressions/Expressions/IReadOnlyObject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IReadOnlyObject : IReadOnlyDictionary - { - } -} diff --git a/src/Sdk/DTExpressions/Expressions/IString.cs b/src/Sdk/DTExpressions/Expressions/IString.cs deleted file mode 100644 index c7d677ce6..000000000 --- a/src/Sdk/DTExpressions/Expressions/IString.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IString - { - String GetString(); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ITraceWriter.cs b/src/Sdk/DTExpressions/Expressions/ITraceWriter.cs deleted file mode 100644 index c1b7fa1f7..000000000 --- a/src/Sdk/DTExpressions/Expressions/ITraceWriter.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - public interface ITraceWriter - { - void Info(String message); - void Verbose(String message); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/InNode.cs b/src/Sdk/DTExpressions/Expressions/InNode.cs deleted file mode 100644 index 7807e1942..000000000 --- a/src/Sdk/DTExpressions/Expressions/InNode.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class InNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - EvaluationResult left = Parameters[0].Evaluate(context); - for (Int32 i = 1; i < Parameters.Count; i++) - { - EvaluationResult right = Parameters[i].Evaluate(context); - if (left.Equals(context, right)) - { - return true; - } - } - - return false; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/IndexerNode.cs b/src/Sdk/DTExpressions/Expressions/IndexerNode.cs deleted file mode 100644 index 37d818104..000000000 --- a/src/Sdk/DTExpressions/Expressions/IndexerNode.cs +++ /dev/null @@ -1,452 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.Reflection; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class IndexerNode : ContainerNode - { - internal IndexerNode() - { - Name = "indexer"; - } - - protected sealed override Boolean TraceFullyRealized => true; - - internal sealed override String ConvertToExpression() - { - return String.Format( - CultureInfo.InvariantCulture, - "{0}[{1}]", - Parameters[0].ConvertToExpression(), - Parameters[1].ConvertToExpression()); - } - - internal sealed override String ConvertToRealizedExpression(EvaluationContext context) - { - // Check if the result was stored - if (context.TryGetTraceResult(this, out String result)) - { - return result; - } - - return ConvertToExpression(); - } - - protected sealed override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - EvaluationResult firstParameter = Parameters[0].Evaluate(context); - - if (context.Options.UseCollectionInterfaces) - { - if (!firstParameter.TryGetCollectionInterface(out Object collection)) - { - // Even if we can't get the collection interface, return empty filtered array if it is a wildcard. - if (Parameters.Count > 2) - { - resultMemory = null; - return new FilteredArray(); - } - - resultMemory = null; - return null; - } - - // Handle operating on a filtered array - if (collection is FilteredArray filteredArray) - { - return HandleFilteredArray(context, filteredArray, out resultMemory); - } - // Handle operating on an object - else if (collection is IReadOnlyObject obj) - { - return HandleObject(context, obj, out resultMemory); - } - // Handle operating on an array - else if (collection is IReadOnlyArray array) - { - return HandleArray(context, array, out resultMemory); - } - - resultMemory = null; - return null; - } - else - { - Object result = null; - - if (firstParameter.Kind == ValueKind.Array && firstParameter.Value is JArray) - { - var jarray = firstParameter.Value as JArray; - EvaluationResult index = Parameters[1].Evaluate(context); - if (index.Kind == ValueKind.Number) - { - Decimal d = (Decimal)index.Value; - if (d >= 0m && d < (Decimal)jarray.Count && d == Math.Floor(d)) - { - result = jarray[(Int32)d]; - } - } - else if (index.Kind == ValueKind.String && !String.IsNullOrEmpty(index.Value as String)) - { - Decimal d; - if (index.TryConvertToNumber(context, out d)) - { - if (d >= 0m && d < (Decimal)jarray.Count && d == Math.Floor(d)) - { - result = jarray[(Int32)d]; - } - } - } - } - else if (firstParameter.Kind == ValueKind.Object) - { - if (firstParameter.Value is JObject) - { - var jobject = firstParameter.Value as JObject; - EvaluationResult index = Parameters[1].Evaluate(context); - String s; - if (index.TryConvertToString(context, out s)) - { - result = jobject[s]; - } - } - else if (firstParameter.Value is IDictionary) - { - var dictionary = firstParameter.Value as IDictionary; - EvaluationResult index = Parameters[1].Evaluate(context); - if (index.TryConvertToString(context, out String key)) - { - if (!dictionary.TryGetValue(key, out String resultString)) - { - result = null; - } - else - { - result = resultString; - } - } - } - else if (firstParameter.Value is IDictionary) - { - var dictionary = firstParameter.Value as IDictionary; - EvaluationResult index = Parameters[1].Evaluate(context); - String s; - if (index.TryConvertToString(context, out s)) - { - if (!dictionary.TryGetValue(s, out result)) - { - result = null; - } - } - } - else if (firstParameter.Value is IReadOnlyDictionary) - { - var dictionary = firstParameter.Value as IReadOnlyDictionary; - EvaluationResult index = Parameters[1].Evaluate(context); - if (index.TryConvertToString(context, out String key)) - { - if (!dictionary.TryGetValue(key, out String resultString)) - { - result = null; - } - else - { - result = resultString; - } - } - } - else if (firstParameter.Value is IReadOnlyDictionary) - { - var dictionary = firstParameter.Value as IReadOnlyDictionary; - EvaluationResult index = Parameters[1].Evaluate(context); - String s; - if (index.TryConvertToString(context, out s)) - { - if (!dictionary.TryGetValue(s, out result)) - { - result = null; - } - } - } - else - { - var contract = s_serializer.Value.ContractResolver.ResolveContract(firstParameter.Value.GetType()); - var objectContract = contract as JsonObjectContract; - if (objectContract != null) - { - EvaluationResult index = Parameters[1].Evaluate(context); - if (index.TryConvertToString(context, out String key)) - { - var property = objectContract.Properties.GetClosestMatchProperty(key); - if (property != null) - { - result = objectContract.Properties[property.PropertyName].ValueProvider.GetValue(firstParameter.Value); - } - } - } - else - { - var dictionaryContract = contract as JsonDictionaryContract; - if (dictionaryContract != null && dictionaryContract.DictionaryKeyType == typeof(String)) - { - EvaluationResult index = Parameters[1].Evaluate(context); - if (index.TryConvertToString(context, out String key)) - { - var genericMethod = s_tryGetValueTemplate.Value.MakeGenericMethod(dictionaryContract.DictionaryValueType); - resultMemory = null; - return genericMethod.Invoke(null, new[] { firstParameter.Value, key }); - } - } - } - } - } - - resultMemory = null; - return result; - } - } - - private Object HandleFilteredArray( - EvaluationContext context, - FilteredArray filteredArray, - out ResultMemory resultMemory) - { - EvaluationResult indexResult = Parameters[1].Evaluate(context); - var indexHelper = new IndexHelper(indexResult, context); - - Boolean isFilter; - if (Parameters.Count > 2) - { - isFilter = true; - - if (!String.Equals(indexHelper.StringIndex, ExpressionConstants.Wildcard.ToString(), StringComparison.Ordinal)) - { - throw new InvalidOperationException($"Unexpected filter '{indexHelper.StringIndex}'"); - } - } - else - { - isFilter = false; - } - - var result = new FilteredArray(); - var counter = new MemoryCounter(this, context.Options.MaxMemory); - - foreach (var item in filteredArray) - { - // Leverage the expression SDK to traverse the object - var itemResult = EvaluationResult.CreateIntermediateResult(context, item, out _); - if (itemResult.TryGetCollectionInterface(out Object nestedCollection)) - { - // Apply the index to a child object - if (nestedCollection is IReadOnlyObject nestedObject) - { - if (isFilter) - { - foreach (var val in nestedObject.Values) - { - result.Add(val); - counter.Add(IntPtr.Size); - } - } - else if (indexHelper.HasStringIndex) - { - if (nestedObject.TryGetValue(indexHelper.StringIndex, out Object nestedObjectValue)) - { - result.Add(nestedObjectValue); - counter.Add(IntPtr.Size); - } - } - } - // Apply the index to a child array - else if (nestedCollection is IReadOnlyArray nestedArray) - { - if (isFilter) - { - foreach (var val in nestedArray) - { - result.Add(val); - counter.Add(IntPtr.Size); - } - } - else if (indexHelper.HasIntegerIndex && - indexHelper.IntegerIndex < nestedArray.Count) - { - result.Add(nestedArray[indexHelper.IntegerIndex]); - counter.Add(IntPtr.Size); - } - } - } - } - - resultMemory = new ResultMemory { Bytes = counter.CurrentBytes }; - return result; - } - - private Object HandleObject( - EvaluationContext context, - IReadOnlyObject obj, - out ResultMemory resultMemory) - { - EvaluationResult indexResult = Parameters[1].Evaluate(context); - var indexHelper = new IndexHelper(indexResult, context); - - if (indexHelper.HasStringIndex) - { - Boolean isFilter = Parameters.Count > 2; - - if (isFilter) - { - var filteredArray = new FilteredArray(); - var counter = new MemoryCounter(this, context.Options.MaxMemory); - - foreach (var val in obj.Values) - { - filteredArray.Add(val); - counter.Add(IntPtr.Size); - } - - resultMemory = new ResultMemory { Bytes = counter.CurrentBytes }; - return filteredArray; - } - else if (obj.TryGetValue(indexHelper.StringIndex, out Object result)) - { - resultMemory = null; - return result; - } - } - - resultMemory = null; - return null; - } - - private Object HandleArray( - EvaluationContext context, - IReadOnlyArray array, - out ResultMemory resultMemory) - { - // Similar to as above but for an array - EvaluationResult indexResult = Parameters[1].Evaluate(context); - var indexHelper = new IndexHelper(indexResult, context); - - // When we are operating on a array and it has three parameters, with the second being a string * and the third being a true boolean, it's a filtered array. - if (Parameters.Count > 2) - { - var filtered = new FilteredArray(); - var counter = new MemoryCounter(this, context.Options.MaxMemory); - - foreach (var x in array) - { - filtered.Add(x); - counter.Add(IntPtr.Size); - } - - resultMemory = new ResultMemory { Bytes = counter.CurrentBytes }; - return filtered; - } - - if (indexHelper.HasIntegerIndex && indexHelper.IntegerIndex < array.Count) - { - resultMemory = null; - return array[indexHelper.IntegerIndex]; - } - - resultMemory = null; - return null; - } - - // todo: remove with feature flag cleanup for "UseCollectionInterfaces" - private static Object TryGetValue( - IDictionary dictionary, - String key) - { - TValue value; - if (!dictionary.TryGetValue(key, out value)) - { - return null; - } - - return value; - } - - private class FilteredArray : IReadOnlyArray - { - public FilteredArray() - { - m_list = new List(); - } - - public void Add(Object o) - { - m_list.Add(o); - } - - public Int32 Count => m_list.Count; - - public Object this[Int32 index] => m_list[index]; - - public IEnumerator GetEnumerator() => m_list.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => m_list.GetEnumerator(); - - private readonly IList m_list; - } - - private class IndexHelper - { - public Boolean HasIntegerIndex => m_integerIndex.Value.Item1; - public Int32 IntegerIndex => m_integerIndex.Value.Item2; - - public Boolean HasStringIndex => m_stringIndex.Value.Item1; - public String StringIndex => m_stringIndex.Value.Item2; - - public IndexHelper( - EvaluationResult result, - EvaluationContext context) - { - m_result = result; - m_context = context; - - m_integerIndex = new Lazy>(() => - { - if (m_result.TryConvertToNumber(m_context, out Decimal decimalIndex) && - decimalIndex >= 0m) - { - return new Tuple(true, (Int32)Math.Floor(decimalIndex)); - } - - return new Tuple(false, default(Int32)); - }); - - m_stringIndex = new Lazy>(() => - { - if (m_result.TryConvertToString(m_context, out String stringIndex)) - { - return new Tuple(true, stringIndex); - } - - return new Tuple(false, null); - }); - } - - private Lazy> m_integerIndex; - private Lazy> m_stringIndex; - - private readonly EvaluationResult m_result; - private readonly EvaluationContext m_context; - } - - // todo: remove these properties with feature flag cleanup for "UseCollectionInterfaces" - private static Lazy s_serializer = new Lazy(() => JsonUtility.CreateJsonSerializer()); - private static Lazy s_tryGetValueTemplate = new Lazy(() => typeof(IndexerNode).GetTypeInfo().GetMethod(nameof(TryGetValue), BindingFlags.NonPublic | BindingFlags.Static)); - } -} diff --git a/src/Sdk/DTExpressions/Expressions/JoinNode.cs b/src/Sdk/DTExpressions/Expressions/JoinNode.cs deleted file mode 100644 index cdef727d7..000000000 --- a/src/Sdk/DTExpressions/Expressions/JoinNode.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Text; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class JoinNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => true; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - var items = Parameters[1].Evaluate(context); - - if (items.TryGetCollectionInterface(out var collection) && collection is IReadOnlyArray array) - { - if (array.Count > 0) - { - var result = new StringBuilder(); - var memory = new MemoryCounter(this, context.Options.MaxMemory); - - // Append the first item - var item = array[0]; - var itemResult = EvaluationResult.CreateIntermediateResult(context, item, out _); - if (itemResult.TryConvertToString(context, out String itemString)) - { - memory.Add(itemString); - result.Append(itemString); - } - - // More items? - if (array.Count > 1) - { - var separator = Parameters[0].EvaluateString(context); - - for (var i = 1; i < array.Count; i++) - { - // Append the separator - memory.Add(separator); - result.Append(separator); - - // Append the next item - var nextItem = array[i]; - var nextItemResult = EvaluationResult.CreateIntermediateResult(context, nextItem, out _); - if (nextItemResult.TryConvertToString(context, out String nextItemString)) - { - memory.Add(nextItemString); - result.Append(nextItemString); - } - } - } - - return result.ToString(); - } - else - { - return String.Empty; - } - } - else if (items.TryConvertToString(context, out String str)) - { - return str; - } - else - { - return String.Empty; - } - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/LessThanNode.cs b/src/Sdk/DTExpressions/Expressions/LessThanNode.cs deleted file mode 100644 index 08018719e..000000000 --- a/src/Sdk/DTExpressions/Expressions/LessThanNode.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class LessThanNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return Parameters[0].Evaluate(context).CompareTo(context, Parameters[1].Evaluate(context)) < 0; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/LessThanOrEqualNode.cs b/src/Sdk/DTExpressions/Expressions/LessThanOrEqualNode.cs deleted file mode 100644 index 39367fc22..000000000 --- a/src/Sdk/DTExpressions/Expressions/LessThanOrEqualNode.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class LessThanOrEqualNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return Parameters[0].Evaluate(context).CompareTo(context, Parameters[1].Evaluate(context)) <= 0; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/LexicalAnalyzer.cs b/src/Sdk/DTExpressions/Expressions/LexicalAnalyzer.cs deleted file mode 100644 index a688aac49..000000000 --- a/src/Sdk/DTExpressions/Expressions/LexicalAnalyzer.cs +++ /dev/null @@ -1,293 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class LexicalAnalyzer - { - public LexicalAnalyzer(String expression, IEnumerable namedValues, IEnumerable functions, Boolean allowKeywordHyphens) - { - m_expression = expression; - m_extensionNamedValues = new HashSet(namedValues ?? new String[0], StringComparer.OrdinalIgnoreCase); - m_extensionFunctions = new HashSet(functions ?? new String[0], StringComparer.OrdinalIgnoreCase); - m_allowKeyHyphens = allowKeywordHyphens; - } - - public Boolean TryGetNextToken(ref Token token) - { - // Skip whitespace. - while (m_index < m_expression.Length && Char.IsWhiteSpace(m_expression[m_index])) - { - m_index++; - } - - // Test end of string. - if (m_index >= m_expression.Length) - { - token = null; - return false; - } - - // Read the first character to determine the type of token. - Char c = m_expression[m_index]; - switch (c) - { - case ExpressionConstants.StartIndex: - token = new Token(TokenKind.StartIndex, c, m_index++); - break; - case ExpressionConstants.StartParameter: - token = new Token(TokenKind.StartParameter, c, m_index++); - break; - case ExpressionConstants.EndIndex: - token = new Token(TokenKind.EndIndex, c, m_index++); - break; - case ExpressionConstants.EndParameter: - token = new Token(TokenKind.EndParameter, c, m_index++); - break; - case ExpressionConstants.Separator: - token = new Token(TokenKind.Separator, c, m_index++); - break; - case ExpressionConstants.Wildcard: - token = new Token(TokenKind.Wildcard, c, m_index++); - break; - case '\'': - token = ReadStringToken(); - break; - default: - if (c == '.') - { - if (m_lastToken == null || - m_lastToken.Kind == TokenKind.Separator || - m_lastToken.Kind == TokenKind.StartIndex || - m_lastToken.Kind == TokenKind.StartParameter) - { - token = ReadNumberOrVersionToken(); - } - else - { - token = new Token(TokenKind.Dereference, c, m_index++); - } - } - else if (c == '-' || (c >= '0' && c <= '9')) - { - token = ReadNumberOrVersionToken(); - } - else - { - token = ReadKeywordToken(m_allowKeyHyphens); - } - - break; - } - - m_lastToken = token; - return true; - } - - public Boolean TryPeekNextToken(ref Token token) - { - // Record the state. - Int32 index = m_index; - Token lastToken = m_lastToken; - - // Get next token. - Boolean result = TryGetNextToken(ref token); - - // Restore the state. - m_index = index; - m_lastToken = lastToken; - - return result; - } - - private Token ReadNumberOrVersionToken() - { - Int32 startIndex = m_index; - Int32 periods = 0; - do - { - if (m_expression[m_index] == '.') - { - periods++; - } - - m_index++; - } - while (m_index < m_expression.Length && (!TestWhitespaceOrPunctuation(m_expression[m_index]) || m_expression[m_index] == '.')); - - Int32 length = m_index - startIndex; - String str = m_expression.Substring(startIndex, length); - if (periods >= 2) - { - Version version; - if (Version.TryParse(str, out version)) - { - return new Token(TokenKind.Version, str, startIndex, version); - } - } - else - { - // Note, NumberStyles.AllowThousands cannot be allowed since comma has special meaning as a token separator. - Decimal d; - if (Decimal.TryParse( - str, - NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, - CultureInfo.InvariantCulture, - out d)) - { - return new Token(TokenKind.Number, str, startIndex, d); - } - } - - return new Token(TokenKind.Unrecognized, str, startIndex); - } - - private Token ReadKeywordToken(bool allowHyphen) - { - // Read to the end of the keyword. - Int32 startIndex = m_index; - m_index++; // Skip the first char. It is already known to be the start of the keyword. - while (m_index < m_expression.Length && !TestWhitespaceOrPunctuation(m_expression[m_index])) - { - m_index++; - } - - // Test if valid keyword character sequence. - Int32 length = m_index - startIndex; - String str = m_expression.Substring(startIndex, length); - if (TestKeyword(str, allowHyphen)) - { - // Test if follows property dereference operator. - if (m_lastToken != null && m_lastToken.Kind == TokenKind.Dereference) - { - return new Token(TokenKind.PropertyName, str, startIndex); - } - - // Boolean - if (str.Equals(Boolean.TrueString, StringComparison.OrdinalIgnoreCase)) - { - return new Token(TokenKind.Boolean, str, startIndex, true); - } - else if (str.Equals(Boolean.FalseString, StringComparison.OrdinalIgnoreCase)) - { - return new Token(TokenKind.Boolean, str, startIndex, false); - } - // Well-known function - else if (ExpressionConstants.WellKnownFunctions.ContainsKey(str)) - { - return new Token(TokenKind.WellKnownFunction, str, startIndex); - } - // Extension value - else if (m_extensionNamedValues.Contains(str)) - { - return new Token(TokenKind.ExtensionNamedValue, str, startIndex); - } - // Extension function - else if (m_extensionFunctions.Contains(str)) - { - return new Token(TokenKind.ExtensionFunction, str, startIndex); - } - } - - // Unknown keyword - return new Token(TokenKind.UnknownKeyword, str, startIndex); - } - - private Token ReadStringToken() - { - Int32 startIndex = m_index; - Char c; - Boolean closed = false; - var str = new StringBuilder(); - m_index++; // Skip the leading single-quote. - while (m_index < m_expression.Length) - { - c = m_expression[m_index++]; - if (c == '\'') - { - // End of string. - if (m_index >= m_expression.Length || m_expression[m_index] != '\'') - { - closed = true; - break; - } - - // Escaped single quote. - m_index++; - } - - str.Append(c); - } - - Int32 length = m_index - startIndex; - String rawValue = m_expression.Substring(startIndex, length); - if (closed) - { - return new Token(TokenKind.String, rawValue, startIndex, str.ToString()); - } - - return new Token(TokenKind.Unrecognized, rawValue, startIndex); - } - - private static Boolean TestKeyword(String str, bool allowHyphen) - { - if (String.IsNullOrEmpty(str)) - { - return false; - } - - Char first = str[0]; - if ((first >= 'a' && first <= 'z') || - (first >= 'A' && first <= 'Z') || - first == '_') - { - for (Int32 i = 1 ; i < str.Length ; i++) - { - Char c = str[i]; - if ((c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || - c == '_' || (allowHyphen && c == '-')) - { - // OK - } - else - { - return false; - } - } - - return true; - } - else - { - return false; - } - } - - private static Boolean TestWhitespaceOrPunctuation(Char c) - { - switch (c) - { - case ExpressionConstants.StartIndex: - case ExpressionConstants.StartParameter: - case ExpressionConstants.EndIndex: - case ExpressionConstants.EndParameter: - case ExpressionConstants.Separator: - case ExpressionConstants.Dereference: - return true; - default: - return char.IsWhiteSpace(c); - } - } - - private readonly String m_expression; // Raw expression string. - private readonly HashSet m_extensionFunctions; - private readonly HashSet m_extensionNamedValues; - private Int32 m_index; // Index of raw condition string. - private Token m_lastToken; - private readonly Boolean m_allowKeyHyphens; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/LiteralValueNode.cs b/src/Sdk/DTExpressions/Expressions/LiteralValueNode.cs deleted file mode 100644 index 2639cdbcc..000000000 --- a/src/Sdk/DTExpressions/Expressions/LiteralValueNode.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class LiteralValueNode : ExpressionNode - { - public LiteralValueNode(Object val) - { - ValueKind kind; - - // Note, it is OK to pass null EvaluationOptions here since the parser does not support - // localized values. For example, if parsing local date-times were supported, then we - // would need to know the account's time zone at parse time. This is an OK limitation, - // since we can defer this type of problem to runtime, for example by adding a parseDate function. - Value = ExpressionUtil.ConvertToCanonicalValue(null, val, out kind, out _, out _); - - Kind = kind; - Name = kind.ToString(); - } - - public ValueKind Kind { get; } - - public Object Value { get; } - - // Prevent the value from being stored on the evaluation context. - // This avoids unneccessarily duplicating the value in memory. - protected sealed override Boolean TraceFullyRealized => false; - - internal sealed override String ConvertToExpression() - { - return ExpressionUtil.FormatValue(null, Value, Kind); - } - - internal sealed override String ConvertToRealizedExpression(EvaluationContext context) - { - return ExpressionUtil.FormatValue(null, Value, Kind); - } - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return Value; - } - } - -} diff --git a/src/Sdk/DTExpressions/Expressions/MemoryCounter.cs b/src/Sdk/DTExpressions/Expressions/MemoryCounter.cs deleted file mode 100644 index 305b8b856..000000000 --- a/src/Sdk/DTExpressions/Expressions/MemoryCounter.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System; -using System.ComponentModel; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Expressions -{ - /// - /// Helper class for ExpressionNode authors. This class helps calculate memory overhead for a result object. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class MemoryCounter - { - internal MemoryCounter( - ExpressionNode node, - Int32? maxBytes) - { - m_node = node; - m_maxBytes = (maxBytes ?? 0) > 0 ? maxBytes.Value : Int32.MaxValue; - } - - public Int32 CurrentBytes => m_currentBytes; - - public void Add(Int32 amount) - { - if (!TryAdd(amount)) - { - throw new InvalidOperationException(ExpressionResources.ExceededAllowedMemory(m_node?.ConvertToExpression())); - } - } - - public void Add(String value) - { - Add(CalculateSize(value)); - } - - public void Add( - JToken value, - Boolean traverse) - { - // This measurement doesn't have to be perfect - // https://codeblog.jonskeet.uk/2011/04/05/of-memory-and-strings/ - - if (value is null) - { - Add(MinObjectSize); - } - - if (!traverse) - { - switch (value.Type) - { - case JTokenType.Bytes: - case JTokenType.String: - case JTokenType.Uri: - Add(value.ToObject()); - return; - - case JTokenType.Property: - var property = value as JProperty; - Add(property.Name); - return; - - default: - Add(MinObjectSize); - return; - } - } - - do - { - // Descend as much as possible - while (true) - { - // Add bytes - Add(value, false); - - // Descend - if (value.HasValues) - { - value = value.First; - } - // No more descendants - else - { - break; - } - } - - // Next sibling or ancestor sibling - do - { - var sibling = value.Next; - - // Sibling found - if (sibling != null) - { - value = sibling; - break; - } - - // Ascend - value = value.Parent; - - } while (value != null); - - } while (value != null); - } - - public void AddMinObjectSize() - { - Add(MinObjectSize); - } - - public void Remove(String value) - { - m_currentBytes -= CalculateSize(value); - } - - public static Int32 CalculateSize(String value) - { - // This measurement doesn't have to be perfect. - // https://codeblog.jonskeet.uk/2011/04/05/of-memory-and-strings/ - - Int32 bytes; - checked - { - bytes = StringBaseOverhead + ((value?.Length ?? 0) * 2); - } - return bytes; - } - - internal Boolean TryAdd(Int32 amount) - { - try - { - checked - { - amount += m_currentBytes; - } - - if (amount > m_maxBytes) - { - return false; - } - - m_currentBytes = amount; - return true; - } - catch (OverflowException) - { - return false; - } - } - - internal Boolean TryAdd(String value) - { - return TryAdd(CalculateSize(value)); - } - - internal const Int32 MinObjectSize = 24; - internal const Int32 StringBaseOverhead = 26; - private readonly Int32 m_maxBytes; - private readonly ExpressionNode m_node; - private Int32 m_currentBytes; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/NamedValueInfo.cs b/src/Sdk/DTExpressions/Expressions/NamedValueInfo.cs deleted file mode 100644 index 1c7484438..000000000 --- a/src/Sdk/DTExpressions/Expressions/NamedValueInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - public class NamedValueInfo : INamedValueInfo - where T : NamedValueNode, new() - { - public NamedValueInfo(String name) - { - Name = name; - } - - public String Name { get; } - - public NamedValueNode CreateNode() - { - return new T(); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/NamedValueNode.cs b/src/Sdk/DTExpressions/Expressions/NamedValueNode.cs deleted file mode 100644 index 9dfab2a88..000000000 --- a/src/Sdk/DTExpressions/Expressions/NamedValueNode.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class NamedValueNode : ExpressionNode - { - internal sealed override string ConvertToExpression() => Name; - - protected sealed override Boolean TraceFullyRealized => true; - - internal sealed override String ConvertToRealizedExpression(EvaluationContext context) - { - // Check if the result was stored - if (context.TryGetTraceResult(this, out String result)) - { - return result; - } - - return Name; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/NotEqualNode.cs b/src/Sdk/DTExpressions/Expressions/NotEqualNode.cs deleted file mode 100644 index 4a54e6215..000000000 --- a/src/Sdk/DTExpressions/Expressions/NotEqualNode.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class NotEqualNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return !Parameters[0].Evaluate(context).Equals(context, Parameters[1].Evaluate(context)); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/NotInNode.cs b/src/Sdk/DTExpressions/Expressions/NotInNode.cs deleted file mode 100644 index c7b1a5a08..000000000 --- a/src/Sdk/DTExpressions/Expressions/NotInNode.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class NotInNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - EvaluationResult left = Parameters[0].Evaluate(context); - for (Int32 i = 1; i < Parameters.Count; i++) - { - EvaluationResult right = Parameters[i].Evaluate(context); - if (left.Equals(context, right)) - { - return false; - } - } - - return true; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/NotNode.cs b/src/Sdk/DTExpressions/Expressions/NotNode.cs deleted file mode 100644 index b27ef2fc4..000000000 --- a/src/Sdk/DTExpressions/Expressions/NotNode.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class NotNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return !Parameters[0].EvaluateBoolean(context); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/OrNode.cs b/src/Sdk/DTExpressions/Expressions/OrNode.cs deleted file mode 100644 index 513a2e5e5..000000000 --- a/src/Sdk/DTExpressions/Expressions/OrNode.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class OrNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - foreach (ExpressionNode parameter in Parameters) - { - if (parameter.EvaluateBoolean(context)) - { - return true; - } - } - - return false; - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ParseException.cs b/src/Sdk/DTExpressions/Expressions/ParseException.cs deleted file mode 100644 index 489c0d873..000000000 --- a/src/Sdk/DTExpressions/Expressions/ParseException.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - public sealed class ParseException : ExpressionException - { - internal ParseException(ParseExceptionKind kind, Token token, String expression) - : base(secretMasker: null, message: String.Empty) - { - Expression = expression; - Kind = kind; - RawToken = token?.RawValue; - TokenIndex = token?.Index ?? 0; - String description; - switch (kind) - { - case ParseExceptionKind.ExceededMaxDepth: - description = ExpressionResources.ExceededMaxExpressionDepth(ExpressionConstants.MaxDepth); - break; - case ParseExceptionKind.ExceededMaxLength: - description = ExpressionResources.ExceededMaxExpressionLength(ExpressionConstants.MaxLength); - break; - case ParseExceptionKind.ExpectedPropertyName: - description = ExpressionResources.ExpectedPropertyName(); - break; - case ParseExceptionKind.ExpectedStartParameter: - description = ExpressionResources.ExpectedStartParameter(); - break; - case ParseExceptionKind.UnclosedFunction: - description = ExpressionResources.UnclosedFunction(); - break; - case ParseExceptionKind.UnclosedIndexer: - description = ExpressionResources.UnclosedIndexer(); - break; - case ParseExceptionKind.UnexpectedSymbol: - description = ExpressionResources.UnexpectedSymbol(); - break; - case ParseExceptionKind.UnrecognizedValue: - description = ExpressionResources.UnrecognizedValue(); - break; - default: // Should never reach here. - throw new Exception($"Unexpected parse exception kind '{kind}'."); - } - - if (token == null) - { - Message = ExpressionResources.ParseErrorWithFwlink(description); - } - else - { - Message = ExpressionResources.ParseErrorWithTokenInfo(description, RawToken, TokenIndex + 1, Expression); - } - } - - internal String Expression { get; } - - internal ParseExceptionKind Kind { get; } - - internal String RawToken { get; } - - internal Int32 TokenIndex { get; } - - public sealed override String Message { get; } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ParseExceptionKind.cs b/src/Sdk/DTExpressions/Expressions/ParseExceptionKind.cs deleted file mode 100644 index cddebfed2..000000000 --- a/src/Sdk/DTExpressions/Expressions/ParseExceptionKind.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace GitHub.DistributedTask.Expressions -{ - internal enum ParseExceptionKind - { - ExceededMaxDepth, - ExceededMaxLength, - ExpectedPropertyName, - ExpectedStartParameter, - UnclosedFunction, - UnclosedIndexer, - UnexpectedSymbol, - UnrecognizedValue, - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ResultMemory.cs b/src/Sdk/DTExpressions/Expressions/ResultMemory.cs deleted file mode 100644 index 762980b11..000000000 --- a/src/Sdk/DTExpressions/Expressions/ResultMemory.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class ResultMemory - { - /// - /// Only set a non-null value when both of the following conditions are met: - /// 1) The result is a complex object. In other words, the result is - /// not a simple type: string, boolean, number, version, datetime, or null. - /// 2) The result is a newly created object. - /// - /// - /// For example, consider a function jsonParse() which takes a string parameter, - /// and returns a JToken object. The JToken object is newly created and a rough - /// measurement should be returned for the number of bytes it consumes in memory. - /// - /// - /// - /// For another example, consider a function which returns a sub-object from a - /// complex parameter value. From the perspective of an individual function, - /// the size of the complex parameter value is unknown. In this situation, set the - /// value to IntPtr.Size. - /// - /// - /// - /// When you are unsure, set the value to null. Null indicates the overhead of a - /// new pointer should be accounted for. - /// - /// - public Int32? Bytes { get; set; } - - /// - /// Indicates whether represents the total size of the result. - /// True indicates the accounting-overhead of downstream parameters can be discarded. - /// - /// For , this value is currently ignored. - /// - /// - /// For example, consider a funciton jsonParse() which takes a string paramter, - /// and returns a JToken object. The JToken object is newly created and a rough - /// measurement should be returned for the amount of bytes it consumes in memory. - /// Set the to true, since new object contains no references - /// to previously allocated memory. - /// - /// - /// - /// For another example, consider a function which wraps a complex parameter result. - /// should be set to the amount of newly allocated memory. - /// However since the object references previously allocated memory, set - /// to false. - /// - /// - public Boolean IsTotal { get; set; } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/StartsWithNode.cs b/src/Sdk/DTExpressions/Expressions/StartsWithNode.cs deleted file mode 100644 index 9c5e04bb2..000000000 --- a/src/Sdk/DTExpressions/Expressions/StartsWithNode.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class StartsWithNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - String left = Parameters[0].EvaluateString(context) ?? String.Empty; - String right = Parameters[1].EvaluateString(context) ?? String.Empty; - return left.StartsWith(right, StringComparison.OrdinalIgnoreCase); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/Token.cs b/src/Sdk/DTExpressions/Expressions/Token.cs deleted file mode 100644 index c1788a04d..000000000 --- a/src/Sdk/DTExpressions/Expressions/Token.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class Token - { - public Token(TokenKind kind, Char rawValue, Int32 index, Object parsedValue = null) - : this(kind, rawValue.ToString(), index, parsedValue) - { - } - - public Token(TokenKind kind, String rawValue, Int32 index, Object parsedValue = null) - { - Kind = kind; - RawValue = rawValue; - Index = index; - ParsedValue = parsedValue; - } - - public TokenKind Kind { get; } - - public String RawValue { get; } - - public Int32 Index { get; } - - public Object ParsedValue { get; } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/TokenKind.cs b/src/Sdk/DTExpressions/Expressions/TokenKind.cs deleted file mode 100644 index 97cbf20d4..000000000 --- a/src/Sdk/DTExpressions/Expressions/TokenKind.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace GitHub.DistributedTask.Expressions -{ - internal enum TokenKind - { - // Punctuation - StartIndex, - StartParameter, - EndIndex, - EndParameter, - Separator, - Dereference, - Wildcard, - - // Values - Boolean, - Number, - Version, - String, - PropertyName, - - // Functions and named-values - WellKnownFunction, - ExtensionFunction, - ExtensionNamedValue, - UnknownKeyword, - - Unrecognized, - } -} diff --git a/src/Sdk/DTExpressions/Expressions/TypeCastException.cs b/src/Sdk/DTExpressions/Expressions/TypeCastException.cs deleted file mode 100644 index 59ad6afaa..000000000 --- a/src/Sdk/DTExpressions/Expressions/TypeCastException.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using GitHub.DistributedTask.Logging; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class TypeCastException : ExpressionException - { - internal TypeCastException(Type fromType, Type toType) - : base(null, String.Empty) - { - FromType = fromType; - ToType = toType; - m_message = ExpressionResources.TypeCastErrorNoValue(fromType.Name, toType.Name); - } - - internal TypeCastException(ISecretMasker secretMasker, Object value, ValueKind fromKind, ValueKind toKind) - : base(null, String.Empty) - { - Value = value; - FromKind = fromKind; - ToKind = toKind; - m_message = ExpressionResources.TypeCastError( - fromKind, // from kind - toKind, // to kind - ExpressionUtil.FormatValue(secretMasker, value, fromKind)); // value - } - - internal TypeCastException(ISecretMasker secretMasker, Object value, ValueKind fromKind, Type toType) - : base(null, String.Empty) - { - Value = value; - FromKind = fromKind; - ToType = toType; - m_message = ExpressionResources.TypeCastError( - fromKind, // from kind - toType, // to type - ExpressionUtil.FormatValue(secretMasker, value, fromKind)); // value - } - - internal TypeCastException(ISecretMasker secretMasker, Object value, ValueKind fromKind, Type toType, String error) - : base(null, String.Empty) - { - Value = value; - FromKind = fromKind; - ToType = toType; - m_message = ExpressionResources.TypeCastErrorWithError( - fromKind, // from kind - toType, // to type - ExpressionUtil.FormatValue(secretMasker, value, fromKind), // value - secretMasker != null ? secretMasker.MaskSecrets(error) : error); // error - } - - public override String Message => m_message; - - internal Object Value { get; } - - internal ValueKind? FromKind { get; } - - internal Type FromType { get; } - - internal ValueKind? ToKind { get; } - - internal Type ToType { get; } - - private readonly String m_message; - } -} diff --git a/src/Sdk/DTExpressions/Expressions/UnknownFunctionNode.cs b/src/Sdk/DTExpressions/Expressions/UnknownFunctionNode.cs deleted file mode 100644 index 6f22f1874..000000000 --- a/src/Sdk/DTExpressions/Expressions/UnknownFunctionNode.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class UnknownFunctionNode : FunctionNode - { - protected sealed override Object EvaluateCore(EvaluationContext context) - { - // Should never reach here. - throw new NotSupportedException("Unknown function node is not supported during evaluation."); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/UnknownNamedValueNode.cs b/src/Sdk/DTExpressions/Expressions/UnknownNamedValueNode.cs deleted file mode 100644 index a6dedc643..000000000 --- a/src/Sdk/DTExpressions/Expressions/UnknownNamedValueNode.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class UnknownNamedValueNode : NamedValueNode - { - protected sealed override object EvaluateCore(EvaluationContext evaluationContext) - { - // Should never reach here. - throw new NotSupportedException("Unknown function node is not supported during evaluation."); - } - } -} diff --git a/src/Sdk/DTExpressions/Expressions/ValueKind.cs b/src/Sdk/DTExpressions/Expressions/ValueKind.cs deleted file mode 100644 index ea3dc8477..000000000 --- a/src/Sdk/DTExpressions/Expressions/ValueKind.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel; - -namespace GitHub.DistributedTask.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public enum ValueKind - { - Array, - Boolean, - DateTime, - Null, - Number, - Object, - String, - Version, - } -} diff --git a/src/Sdk/DTExpressions/Expressions/XOrNode.cs b/src/Sdk/DTExpressions/Expressions/XOrNode.cs deleted file mode 100644 index e00837482..000000000 --- a/src/Sdk/DTExpressions/Expressions/XOrNode.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Expressions -{ - internal sealed class XorNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - return Parameters[0].EvaluateBoolean(context) ^ Parameters[1].EvaluateBoolean(context); - } - } -} diff --git a/src/Sdk/DTGenerated/Generated/TaskAgentHttpClientBase.cs b/src/Sdk/DTGenerated/Generated/TaskAgentHttpClientBase.cs index 408b407a3..c2d321c31 100644 --- a/src/Sdk/DTGenerated/Generated/TaskAgentHttpClientBase.cs +++ b/src/Sdk/DTGenerated/Generated/TaskAgentHttpClientBase.cs @@ -60,184 +60,6 @@ namespace GitHub.DistributedTask.WebApi { } - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task AddAgentCloudAsync( - TaskAgentCloud agentCloud, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("bfa72b3d-0fc6-43fb-932b-a7f6559f93b9"); - HttpContent content = new ObjectContent(agentCloud, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task DeleteAgentCloudAsync( - int agentCloudId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("bfa72b3d-0fc6-43fb-932b-a7f6559f93b9"); - object routeValues = new { agentCloudId = agentCloudId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task GetAgentCloudAsync( - int agentCloudId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("bfa72b3d-0fc6-43fb-932b-a7f6559f93b9"); - object routeValues = new { agentCloudId = agentCloudId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentCloudsAsync( - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("bfa72b3d-0fc6-43fb-932b-a7f6559f93b9"); - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get agent cloud types. - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentCloudTypesAsync( - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("5932e193-f376-469d-9c3e-e5588ce12cb5"); - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForQueueAsync( - int queueId, - int top, - string continuationToken = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("f5f81ffb-f396-498d-85b1-5ada145e648a"); - object routeValues = new { queueId = queueId }; - - List> queryParams = new List>(); - queryParams.Add("$top", top.ToString(CultureInfo.InvariantCulture)); - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task QueueAgentRequestAsync( - int queueId, - TaskAgentJobRequest request, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("f5f81ffb-f396-498d-85b1-5ada145e648a"); - object routeValues = new { queueId = queueId }; - HttpContent content = new ObjectContent(request, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - /// /// [Preview API] Adds an agent to a pool. You probably don't want to call this endpoint directly. Instead, [configure an agent](https://docs.microsoft.com/azure/devops/pipelines/agents/agents) using the agent download package. /// @@ -471,1685 +293,6 @@ namespace GitHub.DistributedTask.WebApi content: content); } - /// - /// [Preview API] Returns list of azure subscriptions - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetAzureManagementGroupsAsync( - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("39fe3bf2-7ee0-4198-a469-4a29929afa9c"); - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Returns list of azure subscriptions - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetAzureSubscriptionsAsync( - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("bcd6189c-0303-471f-a8e1-acb22b74d700"); - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] GET a PAT token for managing (configuring, removing, tagging) deployment targets in a deployment group. - /// - /// Project ID or project name - /// ID of the deployment group in which deployment targets are managed. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GenerateDeploymentGroupAccessTokenAsync( - string project, - int deploymentGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("3d197ba2-c3e9-4253-882f-0ee2440f8174"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] GET a PAT token for managing (configuring, removing, tagging) deployment targets in a deployment group. - /// - /// Project ID - /// ID of the deployment group in which deployment targets are managed. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GenerateDeploymentGroupAccessTokenAsync( - Guid project, - int deploymentGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("3d197ba2-c3e9-4253-882f-0ee2440f8174"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Create a deployment group. - /// - /// Project ID or project name - /// Deployment group to create. - /// - /// The cancellation token to cancel operation. - public virtual Task AddDeploymentGroupAsync( - string project, - DeploymentGroupCreateParameter deploymentGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(deploymentGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Create a deployment group. - /// - /// Project ID - /// Deployment group to create. - /// - /// The cancellation token to cancel operation. - public virtual Task AddDeploymentGroupAsync( - Guid project, - DeploymentGroupCreateParameter deploymentGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(deploymentGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Delete a deployment group. - /// - /// Project ID or project name - /// ID of the deployment group to be deleted. - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteDeploymentGroupAsync( - string project, - int deploymentGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Delete a deployment group. - /// - /// Project ID - /// ID of the deployment group to be deleted. - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteDeploymentGroupAsync( - Guid project, - int deploymentGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Get a deployment group by its ID. - /// - /// Project ID or project name - /// ID of the deployment group. - /// Get the deployment group only if this action can be performed on it. - /// Include these additional details in the returned object. - /// - /// The cancellation token to cancel operation. - public virtual Task GetDeploymentGroupAsync( - string project, - int deploymentGroupId, - DeploymentGroupActionFilter? actionFilter = null, - DeploymentGroupExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a deployment group by its ID. - /// - /// Project ID - /// ID of the deployment group. - /// Get the deployment group only if this action can be performed on it. - /// Include these additional details in the returned object. - /// - /// The cancellation token to cancel operation. - public virtual Task GetDeploymentGroupAsync( - Guid project, - int deploymentGroupId, - DeploymentGroupActionFilter? actionFilter = null, - DeploymentGroupExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of deployment groups by name or IDs. - /// - /// Project ID or project name - /// Name of the deployment group. - /// Get only deployment groups on which this action can be performed. - /// Include these additional details in the returned objects. - /// Get deployment groups with names greater than this continuationToken lexicographically. - /// Maximum number of deployment groups to return. Default is **1000**. - /// Comma separated list of IDs of the deployment groups. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetDeploymentGroupsAsync( - string project, - string name = null, - DeploymentGroupActionFilter? actionFilter = null, - DeploymentGroupExpands? expand = null, - string continuationToken = null, - int? top = null, - IEnumerable ids = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (name != null) - { - queryParams.Add("name", name); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (ids != null && ids.Any()) - { - queryParams.Add("ids", string.Join(",", ids)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of deployment groups by name or IDs. - /// - /// Project ID - /// Name of the deployment group. - /// Get only deployment groups on which this action can be performed. - /// Include these additional details in the returned objects. - /// Get deployment groups with names greater than this continuationToken lexicographically. - /// Maximum number of deployment groups to return. Default is **1000**. - /// Comma separated list of IDs of the deployment groups. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetDeploymentGroupsAsync( - Guid project, - string name = null, - DeploymentGroupActionFilter? actionFilter = null, - DeploymentGroupExpands? expand = null, - string continuationToken = null, - int? top = null, - IEnumerable ids = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (name != null) - { - queryParams.Add("name", name); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (ids != null && ids.Any()) - { - queryParams.Add("ids", string.Join(",", ids)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Update a deployment group. - /// - /// Project ID or project name - /// ID of the deployment group. - /// Deployment group to update. - /// - /// The cancellation token to cancel operation. - public virtual Task UpdateDeploymentGroupAsync( - string project, - int deploymentGroupId, - DeploymentGroupUpdateParameter deploymentGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent(deploymentGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update a deployment group. - /// - /// Project ID - /// ID of the deployment group. - /// Deployment group to update. - /// - /// The cancellation token to cancel operation. - public virtual Task UpdateDeploymentGroupAsync( - Guid project, - int deploymentGroupId, - DeploymentGroupUpdateParameter deploymentGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("083c4d89-ab35-45af-aa11-7cf66895c53e"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent(deploymentGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Get a list of deployment group metrics. - /// - /// Project ID or project name - /// Name of the deployment group. - /// Get metrics for deployment groups with names greater than this continuationToken lexicographically. - /// Maximum number of deployment group metrics to return. Default is **50**. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentGroupsMetricsAsync( - string project, - string deploymentGroupName = null, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("281c6308-427a-49e1-b83a-dac0f4862189"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (deploymentGroupName != null) - { - queryParams.Add("deploymentGroupName", deploymentGroupName); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of deployment group metrics. - /// - /// Project ID - /// Name of the deployment group. - /// Get metrics for deployment groups with names greater than this continuationToken lexicographically. - /// Maximum number of deployment group metrics to return. Default is **50**. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentGroupsMetricsAsync( - Guid project, - string deploymentGroupName = null, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("281c6308-427a-49e1-b83a-dac0f4862189"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (deploymentGroupName != null) - { - queryParams.Add("deploymentGroupName", deploymentGroupName); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForDeploymentMachineAsync( - string project, - int deploymentGroupId, - int machineId, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("a3540e5b-f0dc-4668-963b-b752459be545"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - queryParams.Add("machineId", machineId.ToString(CultureInfo.InvariantCulture)); - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForDeploymentMachineAsync( - Guid project, - int deploymentGroupId, - int machineId, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("a3540e5b-f0dc-4668-963b-b752459be545"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - queryParams.Add("machineId", machineId.ToString(CultureInfo.InvariantCulture)); - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForDeploymentMachinesAsync( - string project, - int deploymentGroupId, - IEnumerable machineIds = null, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("a3540e5b-f0dc-4668-963b-b752459be545"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (machineIds != null && machineIds.Any()) - { - queryParams.Add("machineIds", string.Join(",", machineIds)); - } - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForDeploymentMachinesAsync( - Guid project, - int deploymentGroupId, - IEnumerable machineIds = null, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("a3540e5b-f0dc-4668-963b-b752459be545"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (machineIds != null && machineIds.Any()) - { - queryParams.Add("machineIds", string.Join(",", machineIds)); - } - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task RefreshDeploymentMachinesAsync( - string project, - int deploymentGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("91006ac4-0f68-4d82-a2bc-540676bd73ce"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task RefreshDeploymentMachinesAsync( - Guid project, - int deploymentGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("91006ac4-0f68-4d82-a2bc-540676bd73ce"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] GET a PAT token for managing (configuring, removing, tagging) deployment agents in a deployment pool. - /// - /// ID of the deployment pool in which deployment agents are managed. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GenerateDeploymentPoolAccessTokenAsync( - int poolId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("e077ee4a-399b-420b-841f-c43fbc058e0b"); - object routeValues = new { poolId = poolId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of deployment pool summaries. - /// - /// Name of the deployment pool. - /// Include these additional details in the returned objects. - /// List of deployment pool ids. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentPoolsSummaryAsync( - string poolName = null, - DeploymentPoolSummaryExpands? expands = null, - IEnumerable poolIds = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6525d6c6-258f-40e0-a1a9-8a24a3957625"); - - List> queryParams = new List>(); - if (poolName != null) - { - queryParams.Add("poolName", poolName); - } - if (expands != null) - { - queryParams.Add("expands", expands.Value.ToString()); - } - if (poolIds != null && poolIds.Any()) - { - queryParams.Add("poolIds", string.Join(",", poolIds)); - } - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get agent requests for a deployment target. - /// - /// Project ID or project name - /// ID of the deployment group to which the target belongs. - /// ID of the deployment target. - /// Maximum number of completed requests to return. Default is **50** - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForDeploymentTargetAsync( - string project, - int deploymentGroupId, - int targetId, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2fac0be3-8c8f-4473-ab93-c1389b08a2c9"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - queryParams.Add("targetId", targetId.ToString(CultureInfo.InvariantCulture)); - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get agent requests for a deployment target. - /// - /// Project ID - /// ID of the deployment group to which the target belongs. - /// ID of the deployment target. - /// Maximum number of completed requests to return. Default is **50** - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForDeploymentTargetAsync( - Guid project, - int deploymentGroupId, - int targetId, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2fac0be3-8c8f-4473-ab93-c1389b08a2c9"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - queryParams.Add("targetId", targetId.ToString(CultureInfo.InvariantCulture)); - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get agent requests for a list deployment targets. - /// - /// Project ID or project name - /// ID of the deployment group to which the targets belong. - /// Comma separated list of IDs of the deployment targets. - /// Id of owner of agent job request. - /// Datetime to return request after this time. - /// Maximum number of completed requests to return for each target. Default is **50** - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForDeploymentTargetsAsync( - string project, - int deploymentGroupId, - IEnumerable targetIds = null, - int? ownerId = null, - DateTime? completedOn = null, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2fac0be3-8c8f-4473-ab93-c1389b08a2c9"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (targetIds != null && targetIds.Any()) - { - queryParams.Add("targetIds", string.Join(",", targetIds)); - } - if (ownerId != null) - { - queryParams.Add("ownerId", ownerId.Value.ToString(CultureInfo.InvariantCulture)); - } - if (completedOn != null) - { - AddDateTimeToQueryParams(queryParams, "completedOn", completedOn.Value); - } - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get agent requests for a list deployment targets. - /// - /// Project ID - /// ID of the deployment group to which the targets belong. - /// Comma separated list of IDs of the deployment targets. - /// Id of owner of agent job request. - /// Datetime to return request after this time. - /// Maximum number of completed requests to return for each target. Default is **50** - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForDeploymentTargetsAsync( - Guid project, - int deploymentGroupId, - IEnumerable targetIds = null, - int? ownerId = null, - DateTime? completedOn = null, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2fac0be3-8c8f-4473-ab93-c1389b08a2c9"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (targetIds != null && targetIds.Any()) - { - queryParams.Add("targetIds", string.Join(",", targetIds)); - } - if (ownerId != null) - { - queryParams.Add("ownerId", ownerId.Value.ToString(CultureInfo.InvariantCulture)); - } - if (completedOn != null) - { - AddDateTimeToQueryParams(queryParams, "completedOn", completedOn.Value); - } - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Upgrade the deployment targets in a deployment group. - /// - /// Project ID or project name - /// ID of the deployment group. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task RefreshDeploymentTargetsAsync( - string project, - int deploymentGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("1c1a817f-f23d-41c6-bf8d-14b638f64152"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Upgrade the deployment targets in a deployment group. - /// - /// Project ID - /// ID of the deployment group. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task RefreshDeploymentTargetsAsync( - Guid project, - int deploymentGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("1c1a817f-f23d-41c6-bf8d-14b638f64152"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Proxy for a GET request defined by an 'endpoint'. The request is authorized using a service connection. The response is filtered using an XPath/Json based selector. - /// - /// Describes the URL to fetch. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> QueryEndpointAsync( - TaskDefinitionEndpoint endpoint, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("f223b809-8c33-4b7d-b53f-07232569b5d6"); - HttpContent content = new ObjectContent(endpoint, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Get environment deployment execution history - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetEnvironmentDeploymentExecutionRecordsAsync( - string project, - int environmentId, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("51bb5d21-4305-4ea6-9dbb-b7488af73334"); - object routeValues = new { project = project, environmentId = environmentId }; - - List> queryParams = new List>(); - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get environment deployment execution history - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetEnvironmentDeploymentExecutionRecordsAsync( - Guid project, - int environmentId, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("51bb5d21-4305-4ea6-9dbb-b7488af73334"); - object routeValues = new { project = project, environmentId = environmentId }; - - List> queryParams = new List>(); - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Create an environment. - /// - /// Project ID or project name - /// Environment to create. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddEnvironmentAsync( - string project, - EnvironmentCreateParameter environmentCreateParameter, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(environmentCreateParameter, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Create an environment. - /// - /// Project ID - /// Environment to create. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddEnvironmentAsync( - Guid project, - EnvironmentCreateParameter environmentCreateParameter, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(environmentCreateParameter, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Delete the specified environment. - /// - /// Project ID or project name - /// ID of the environment. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteEnvironmentAsync( - string project, - int environmentId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project, environmentId = environmentId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Delete the specified environment. - /// - /// Project ID - /// ID of the environment. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteEnvironmentAsync( - Guid project, - int environmentId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project, environmentId = environmentId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Get an environment by its ID. - /// - /// Project ID or project name - /// ID of the environment. - /// Include these additional details in the returned objects. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetEnvironmentByIdAsync( - string project, - int environmentId, - EnvironmentExpands? expands = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project, environmentId = environmentId }; - - List> queryParams = new List>(); - if (expands != null) - { - queryParams.Add("expands", expands.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get an environment by its ID. - /// - /// Project ID - /// ID of the environment. - /// Include these additional details in the returned objects. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetEnvironmentByIdAsync( - Guid project, - int environmentId, - EnvironmentExpands? expands = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project, environmentId = environmentId }; - - List> queryParams = new List>(); - if (expands != null) - { - queryParams.Add("expands", expands.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get all environments. - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetEnvironmentsAsync( - string project, - string name = null, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (name != null) - { - queryParams.Add("name", name); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get all environments. - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetEnvironmentsAsync( - Guid project, - string name = null, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (name != null) - { - queryParams.Add("name", name); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Update the specified environment. - /// - /// Project ID or project name - /// ID of the environment. - /// Environment data to update. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateEnvironmentAsync( - string project, - int environmentId, - EnvironmentUpdateParameter environmentUpdateParameter, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project, environmentId = environmentId }; - HttpContent content = new ObjectContent(environmentUpdateParameter, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update the specified environment. - /// - /// Project ID - /// ID of the environment. - /// Environment data to update. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateEnvironmentAsync( - Guid project, - int environmentId, - EnvironmentUpdateParameter environmentUpdateParameter, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("8572b1fc-2482-47fa-8f74-7e3ed53ee54b"); - object routeValues = new { project = project, environmentId = environmentId }; - HttpContent content = new ObjectContent(environmentUpdateParameter, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetTaskHubLicenseDetailsAsync( - string hubName, - bool? includeEnterpriseUsersCount = null, - bool? includeHostedAgentMinutesCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("f9f0f436-b8a1-4475-9041-1ccdbf8f0128"); - object routeValues = new { hubName = hubName }; - - List> queryParams = new List>(); - if (includeEnterpriseUsersCount != null) - { - queryParams.Add("includeEnterpriseUsersCount", includeEnterpriseUsersCount.Value.ToString()); - } - if (includeHostedAgentMinutesCount != null) - { - queryParams.Add("includeHostedAgentMinutesCount", includeHostedAgentMinutesCount.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 3), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateTaskHubLicenseDetailsAsync( - string hubName, - TaskHubLicenseDetails taskHubLicenseDetails, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("f9f0f436-b8a1-4475-9041-1ccdbf8f0128"); - object routeValues = new { hubName = hubName }; - HttpContent content = new ObjectContent(taskHubLicenseDetails, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 3), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetTaskIconAsync( - Guid taskId, - string versionString, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("63463108-174d-49d4-b8cb-235eea42a5e1"); - object routeValues = new { taskId = taskId, versionString = versionString }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task ValidateInputsAsync( - InputValidationRequest inputValidationRequest, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("58475b1e-adaf-4155-9bc1-e04bf1fff4c2"); - HttpContent content = new ObjectContent(inputValidationRequest, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - /// /// [Preview API] /// @@ -2228,186 +371,6 @@ namespace GitHub.DistributedTask.WebApi cancellationToken: cancellationToken); } - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsAsync( - int poolId, - int top, - string continuationToken = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("fc825784-c92a-4299-9221-998a02d1b54f"); - object routeValues = new { poolId = poolId }; - - List> queryParams = new List>(); - queryParams.Add("$top", top.ToString(CultureInfo.InvariantCulture)); - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForAgentAsync( - int poolId, - int agentId, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("fc825784-c92a-4299-9221-998a02d1b54f"); - object routeValues = new { poolId = poolId }; - - List> queryParams = new List>(); - queryParams.Add("agentId", agentId.ToString(CultureInfo.InvariantCulture)); - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForAgentsAsync( - int poolId, - IEnumerable agentIds = null, - int? completedRequestCount = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("fc825784-c92a-4299-9221-998a02d1b54f"); - object routeValues = new { poolId = poolId }; - - List> queryParams = new List>(); - if (agentIds != null && agentIds.Any()) - { - queryParams.Add("agentIds", string.Join(",", agentIds)); - } - if (completedRequestCount != null) - { - queryParams.Add("completedRequestCount", completedRequestCount.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentRequestsForPlanAsync( - int poolId, - Guid planId, - Guid? jobId = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("fc825784-c92a-4299-9221-998a02d1b54f"); - object routeValues = new { poolId = poolId }; - - List> queryParams = new List>(); - queryParams.Add("planId", planId.ToString()); - if (jobId != null) - { - queryParams.Add("jobId", jobId.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task QueueAgentRequestByPoolAsync( - int poolId, - TaskAgentJobRequest request, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("fc825784-c92a-4299-9221-998a02d1b54f"); - object routeValues = new { poolId = poolId }; - HttpContent content = new ObjectContent(request, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - /// /// [Preview API] /// @@ -2445,1536 +408,6 @@ namespace GitHub.DistributedTask.WebApi content: content); } - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddKubernetesResourceAsync( - string project, - int environmentId, - KubernetesResourceCreateParameters createParameters, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("73fba52f-15ab-42b3-a538-ce67a9223a04"); - object routeValues = new { project = project, environmentId = environmentId }; - HttpContent content = new ObjectContent(createParameters, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddKubernetesResourceAsync( - Guid project, - int environmentId, - KubernetesResourceCreateParameters createParameters, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("73fba52f-15ab-42b3-a538-ce67a9223a04"); - object routeValues = new { project = project, environmentId = environmentId }; - HttpContent content = new ObjectContent(createParameters, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteKubernetesResourceAsync( - string project, - int environmentId, - int resourceId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("73fba52f-15ab-42b3-a538-ce67a9223a04"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteKubernetesResourceAsync( - Guid project, - int environmentId, - int resourceId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("73fba52f-15ab-42b3-a538-ce67a9223a04"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetKubernetesResourceAsync( - string project, - int environmentId, - int resourceId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("73fba52f-15ab-42b3-a538-ce67a9223a04"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetKubernetesResourceAsync( - Guid project, - int environmentId, - int resourceId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("73fba52f-15ab-42b3-a538-ce67a9223a04"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GenerateDeploymentMachineGroupAccessTokenAsync( - string project, - int machineGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("f8c7c0de-ac0d-469b-9cb1-c21f72d67693"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GenerateDeploymentMachineGroupAccessTokenAsync( - Guid project, - int machineGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("f8c7c0de-ac0d-469b-9cb1-c21f72d67693"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddDeploymentMachineGroupAsync( - string project, - DeploymentMachineGroup machineGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(machineGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddDeploymentMachineGroupAsync( - Guid project, - DeploymentMachineGroup machineGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(machineGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteDeploymentMachineGroupAsync( - string project, - int machineGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteDeploymentMachineGroupAsync( - Guid project, - int machineGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetDeploymentMachineGroupAsync( - string project, - int machineGroupId, - MachineGroupActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - - List> queryParams = new List>(); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetDeploymentMachineGroupAsync( - Guid project, - int machineGroupId, - MachineGroupActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - - List> queryParams = new List>(); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentMachineGroupsAsync( - string project, - string machineGroupName = null, - MachineGroupActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (machineGroupName != null) - { - queryParams.Add("machineGroupName", machineGroupName); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentMachineGroupsAsync( - Guid project, - string machineGroupName = null, - MachineGroupActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (machineGroupName != null) - { - queryParams.Add("machineGroupName", machineGroupName); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateDeploymentMachineGroupAsync( - string project, - int machineGroupId, - DeploymentMachineGroup machineGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - HttpContent content = new ObjectContent(machineGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateDeploymentMachineGroupAsync( - Guid project, - int machineGroupId, - DeploymentMachineGroup machineGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("d4adf50f-80c6-4ac8-9ca1-6e4e544286e9"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - HttpContent content = new ObjectContent(machineGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentMachineGroupMachinesAsync( - string project, - int machineGroupId, - IEnumerable tagFilters = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("966c3874-c347-4b18-a90c-d509116717fd"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - - List> queryParams = new List>(); - if (tagFilters != null && tagFilters.Any()) - { - queryParams.Add("tagFilters", string.Join(",", tagFilters)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentMachineGroupMachinesAsync( - Guid project, - int machineGroupId, - IEnumerable tagFilters = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("966c3874-c347-4b18-a90c-d509116717fd"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - - List> queryParams = new List>(); - if (tagFilters != null && tagFilters.Any()) - { - queryParams.Add("tagFilters", string.Join(",", tagFilters)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UpdateDeploymentMachineGroupMachinesAsync( - string project, - int machineGroupId, - IEnumerable deploymentMachines, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("966c3874-c347-4b18-a90c-d509116717fd"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - HttpContent content = new ObjectContent>(deploymentMachines, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UpdateDeploymentMachineGroupMachinesAsync( - Guid project, - int machineGroupId, - IEnumerable deploymentMachines, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("966c3874-c347-4b18-a90c-d509116717fd"); - object routeValues = new { project = project, machineGroupId = machineGroupId }; - HttpContent content = new ObjectContent>(deploymentMachines, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddDeploymentMachineAsync( - string project, - int deploymentGroupId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddDeploymentMachineAsync( - Guid project, - int deploymentGroupId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteDeploymentMachineAsync( - string project, - int deploymentGroupId, - int machineId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, machineId = machineId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteDeploymentMachineAsync( - Guid project, - int deploymentGroupId, - int machineId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, machineId = machineId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetDeploymentMachineAsync( - string project, - int deploymentGroupId, - int machineId, - DeploymentMachineExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, machineId = machineId }; - - List> queryParams = new List>(); - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetDeploymentMachineAsync( - Guid project, - int deploymentGroupId, - int machineId, - DeploymentMachineExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, machineId = machineId }; - - List> queryParams = new List>(); - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentMachinesAsync( - string project, - int deploymentGroupId, - IEnumerable tags = null, - string name = null, - DeploymentMachineExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (tags != null && tags.Any()) - { - queryParams.Add("tags", string.Join(",", tags)); - } - if (name != null) - { - queryParams.Add("name", name); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetDeploymentMachinesAsync( - Guid project, - int deploymentGroupId, - IEnumerable tags = null, - string name = null, - DeploymentMachineExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (tags != null && tags.Any()) - { - queryParams.Add("tags", string.Join(",", tags)); - } - if (name != null) - { - queryParams.Add("name", name); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task ReplaceDeploymentMachineAsync( - string project, - int deploymentGroupId, - int machineId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, machineId = machineId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task ReplaceDeploymentMachineAsync( - Guid project, - int deploymentGroupId, - int machineId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, machineId = machineId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateDeploymentMachineAsync( - string project, - int deploymentGroupId, - int machineId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, machineId = machineId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateDeploymentMachineAsync( - Guid project, - int deploymentGroupId, - int machineId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, machineId = machineId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UpdateDeploymentMachinesAsync( - string project, - int deploymentGroupId, - IEnumerable machines, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent>(machines, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UpdateDeploymentMachinesAsync( - Guid project, - int deploymentGroupId, - IEnumerable machines, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("6f6d406f-cfe6-409c-9327-7009928077e7"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent>(machines, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task CreateAgentPoolMaintenanceDefinitionAsync( - int poolId, - TaskAgentPoolMaintenanceDefinition definition, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("80572e16-58f0-4419-ac07-d19fde32195c"); - object routeValues = new { poolId = poolId }; - HttpContent content = new ObjectContent(definition, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteAgentPoolMaintenanceDefinitionAsync( - int poolId, - int definitionId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("80572e16-58f0-4419-ac07-d19fde32195c"); - object routeValues = new { poolId = poolId, definitionId = definitionId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetAgentPoolMaintenanceDefinitionAsync( - int poolId, - int definitionId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("80572e16-58f0-4419-ac07-d19fde32195c"); - object routeValues = new { poolId = poolId, definitionId = definitionId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentPoolMaintenanceDefinitionsAsync( - int poolId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("80572e16-58f0-4419-ac07-d19fde32195c"); - object routeValues = new { poolId = poolId }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateAgentPoolMaintenanceDefinitionAsync( - int poolId, - int definitionId, - TaskAgentPoolMaintenanceDefinition definition, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("80572e16-58f0-4419-ac07-d19fde32195c"); - object routeValues = new { poolId = poolId, definitionId = definitionId }; - HttpContent content = new ObjectContent(definition, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteAgentPoolMaintenanceJobAsync( - int poolId, - int jobId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("15e7ab6e-abce-4601-a6d8-e111fe148f46"); - object routeValues = new { poolId = poolId, jobId = jobId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetAgentPoolMaintenanceJobAsync( - int poolId, - int jobId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("15e7ab6e-abce-4601-a6d8-e111fe148f46"); - object routeValues = new { poolId = poolId, jobId = jobId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task GetAgentPoolMaintenanceJobLogsAsync( - int poolId, - int jobId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("15e7ab6e-abce-4601-a6d8-e111fe148f46"); - object routeValues = new { poolId = poolId, jobId = jobId }; - HttpResponseMessage response; - using (HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("5.1-preview.1"), - mediaType: "application/zip", - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - } - response.EnsureSuccessStatusCode(); - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - return new GZipStream(responseStream, CompressionMode.Decompress); - } - else - { - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetAgentPoolMaintenanceJobsAsync( - int poolId, - int? definitionId = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("15e7ab6e-abce-4601-a6d8-e111fe148f46"); - object routeValues = new { poolId = poolId }; - - List> queryParams = new List>(); - if (definitionId != null) - { - queryParams.Add("definitionId", definitionId.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task QueueAgentPoolMaintenanceJobAsync( - int poolId, - TaskAgentPoolMaintenanceJob job, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("15e7ab6e-abce-4601-a6d8-e111fe148f46"); - object routeValues = new { poolId = poolId }; - HttpContent content = new ObjectContent(job, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateAgentPoolMaintenanceJobAsync( - int poolId, - int jobId, - TaskAgentPoolMaintenanceJob job, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("15e7ab6e-abce-4601-a6d8-e111fe148f46"); - object routeValues = new { poolId = poolId, jobId = jobId }; - HttpContent content = new ObjectContent(job, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - /// /// [Preview API] /// @@ -4213,135 +646,6 @@ namespace GitHub.DistributedTask.WebApi cancellationToken: cancellationToken); } - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task GetAgentPoolMetadataAsync( - int poolId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("0d62f887-9f53-48b9-9161-4c35d5735b0f"); - object routeValues = new { poolId = poolId }; - HttpResponseMessage response; - using (HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("5.1-preview.1"), - mediaType: "text/plain", - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - } - response.EnsureSuccessStatusCode(); - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - return new GZipStream(responseStream, CompressionMode.Decompress); - } - else - { - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - } - - /// - /// [Preview API] Create an agent pool. - /// - /// Details about the new agent pool - /// - /// The cancellation token to cancel operation. - public virtual Task AddAgentPoolAsync( - TaskAgentPool pool, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("a8c47e17-4d56-4a56-92bb-de7ea7dc65be"); - HttpContent content = new ObjectContent(pool, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Delete an agent pool. - /// - /// ID of the agent pool to delete - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteAgentPoolAsync( - int poolId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("a8c47e17-4d56-4a56-92bb-de7ea7dc65be"); - object routeValues = new { poolId = poolId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Get information about an agent pool. - /// - /// An agent pool ID - /// Agent pool properties (comma-separated) - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task GetAgentPoolAsync( - int poolId, - IEnumerable properties = null, - TaskAgentPoolActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("a8c47e17-4d56-4a56-92bb-de7ea7dc65be"); - object routeValues = new { poolId = poolId }; - - List> queryParams = new List>(); - if (properties != null && properties.Any()) - { - queryParams.Add("properties", string.Join(",", properties)); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - /// /// [Preview API] Get a list of agent pools. /// @@ -4389,1752 +693,6 @@ namespace GitHub.DistributedTask.WebApi cancellationToken: cancellationToken); } - /// - /// [Preview API] Get a list of agent pools. - /// - /// pool Ids to fetch - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentPoolsByIdsAsync( - IEnumerable poolIds, - TaskAgentPoolActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("a8c47e17-4d56-4a56-92bb-de7ea7dc65be"); - - List> queryParams = new List>(); - string poolIdsAsString = null; - if (poolIds != null) - { - poolIdsAsString = string.Join(",", poolIds); - } - queryParams.Add("poolIds", poolIdsAsString); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Update properties on an agent pool - /// - /// The agent pool to update - /// Updated agent pool details - /// - /// The cancellation token to cancel operation. - public virtual Task UpdateAgentPoolAsync( - int poolId, - TaskAgentPool pool, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("a8c47e17-4d56-4a56-92bb-de7ea7dc65be"); - object routeValues = new { poolId = poolId }; - HttpContent content = new ObjectContent(pool, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Create a new agent queue to connect a project to an agent pool. - /// - /// Details about the queue to create - /// Automatically authorize this queue when using YAML - /// - /// The cancellation token to cancel operation. - public virtual Task AddAgentQueueAsync( - TaskAgentQueue queue, - bool? authorizePipelines = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - HttpContent content = new ObjectContent(queue, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - if (authorizePipelines != null) - { - queryParams.Add("authorizePipelines", authorizePipelines.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Create a new agent queue to connect a project to an agent pool. - /// - /// Project ID or project name - /// Details about the queue to create - /// Automatically authorize this queue when using YAML - /// - /// The cancellation token to cancel operation. - public virtual Task AddAgentQueueAsync( - string project, - TaskAgentQueue queue, - bool? authorizePipelines = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(queue, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - if (authorizePipelines != null) - { - queryParams.Add("authorizePipelines", authorizePipelines.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Create a new agent queue to connect a project to an agent pool. - /// - /// Project ID - /// Details about the queue to create - /// Automatically authorize this queue when using YAML - /// - /// The cancellation token to cancel operation. - public virtual Task AddAgentQueueAsync( - Guid project, - TaskAgentQueue queue, - bool? authorizePipelines = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(queue, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - if (authorizePipelines != null) - { - queryParams.Add("authorizePipelines", authorizePipelines.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Create a new team project. - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task CreateTeamProjectAsync( - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Create a new team project. - /// - /// Project ID or project name - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task CreateTeamProjectAsync( - string project, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Create a new team project. - /// - /// Project ID - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task CreateTeamProjectAsync( - Guid project, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Removes an agent queue from a project. - /// - /// The agent queue to remove - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteAgentQueueAsync( - int queueId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { queueId = queueId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Removes an agent queue from a project. - /// - /// Project ID or project name - /// The agent queue to remove - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteAgentQueueAsync( - string project, - int queueId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project, queueId = queueId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Removes an agent queue from a project. - /// - /// Project ID - /// The agent queue to remove - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteAgentQueueAsync( - Guid project, - int queueId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project, queueId = queueId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Get information about an agent queue. - /// - /// Project ID or project name - /// The agent queue to get information about - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task GetAgentQueueAsync( - string project, - int queueId, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project, queueId = queueId }; - - List> queryParams = new List>(); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get information about an agent queue. - /// - /// Project ID - /// The agent queue to get information about - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task GetAgentQueueAsync( - Guid project, - int queueId, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project, queueId = queueId }; - - List> queryParams = new List>(); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get information about an agent queue. - /// - /// The agent queue to get information about - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task GetAgentQueueAsync( - int queueId, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { queueId = queueId }; - - List> queryParams = new List>(); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues. - /// - /// Project ID or project name - /// Filter on the agent queue name - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesAsync( - string project, - string queueName = null, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (queueName != null) - { - queryParams.Add("queueName", queueName); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues. - /// - /// Project ID - /// Filter on the agent queue name - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesAsync( - Guid project, - string queueName = null, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (queueName != null) - { - queryParams.Add("queueName", queueName); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues. - /// - /// Filter on the agent queue name - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesAsync( - string queueName = null, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - - List> queryParams = new List>(); - if (queueName != null) - { - queryParams.Add("queueName", queueName); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues by their IDs - /// - /// Project ID or project name - /// A comma-separated list of agent queue IDs to retrieve - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesByIdsAsync( - string project, - IEnumerable queueIds, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string queueIdsAsString = null; - if (queueIds != null) - { - queueIdsAsString = string.Join(",", queueIds); - } - queryParams.Add("queueIds", queueIdsAsString); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues by their IDs - /// - /// Project ID - /// A comma-separated list of agent queue IDs to retrieve - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesByIdsAsync( - Guid project, - IEnumerable queueIds, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string queueIdsAsString = null; - if (queueIds != null) - { - queueIdsAsString = string.Join(",", queueIds); - } - queryParams.Add("queueIds", queueIdsAsString); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues by their IDs - /// - /// A comma-separated list of agent queue IDs to retrieve - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesByIdsAsync( - IEnumerable queueIds, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - - List> queryParams = new List>(); - string queueIdsAsString = null; - if (queueIds != null) - { - queueIdsAsString = string.Join(",", queueIds); - } - queryParams.Add("queueIds", queueIdsAsString); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues by their names - /// - /// Project ID or project name - /// A comma-separated list of agent names to retrieve - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesByNamesAsync( - string project, - IEnumerable queueNames, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string queueNamesAsString = null; - if (queueNames != null) - { - queueNamesAsString = string.Join(",", queueNames); - } - queryParams.Add("queueNames", queueNamesAsString); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues by their names - /// - /// Project ID - /// A comma-separated list of agent names to retrieve - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesByNamesAsync( - Guid project, - IEnumerable queueNames, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string queueNamesAsString = null; - if (queueNames != null) - { - queueNamesAsString = string.Join(",", queueNames); - } - queryParams.Add("queueNames", queueNamesAsString); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agent queues by their names - /// - /// A comma-separated list of agent names to retrieve - /// Filter by whether the calling user has use or manage permissions - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentQueuesByNamesAsync( - IEnumerable queueNames, - TaskAgentQueueActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("900fa995-c559-4923-aae7-f8424fe4fbea"); - - List> queryParams = new List>(); - string queueNamesAsString = null; - if (queueNames != null) - { - queueNamesAsString = string.Join(",", queueNames); - } - queryParams.Add("queueNames", queueNamesAsString); - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAgentCloudRequestsAsync( - int agentCloudId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("20189bd7-5134-49c2-b8e9-f9e856eea2b2"); - object routeValues = new { agentCloudId = agentCloudId }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetResourceLimitsAsync( - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("1f1f0557-c445-42a6-b4a0-0df605a3a0f8"); - - return SendAsync>( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetResourceUsageAsync( - string parallelismTag = null, - bool? poolIsHosted = null, - bool? includeRunningRequests = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("eae1d376-a8b1-4475-9041-1dfdbe8f0143"); - - List> queryParams = new List>(); - if (parallelismTag != null) - { - queryParams.Add("parallelismTag", parallelismTag); - } - if (poolIsHosted != null) - { - queryParams.Add("poolIsHosted", poolIsHosted.Value.ToString()); - } - if (includeRunningRequests != null) - { - queryParams.Add("includeRunningRequests", includeRunningRequests.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 2), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetTaskGroupHistoryAsync( - string project, - Guid taskGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("100cc92a-b255-47fa-9ab3-e44a2985a3ac"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetTaskGroupHistoryAsync( - Guid project, - Guid taskGroupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("100cc92a-b255-47fa-9ab3-e44a2985a3ac"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Delete a secure file - /// - /// Project ID or project name - /// The unique secure file Id - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteSecureFileAsync( - string project, - Guid secureFileId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project, secureFileId = secureFileId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Delete a secure file - /// - /// Project ID - /// The unique secure file Id - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteSecureFileAsync( - Guid project, - Guid secureFileId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project, secureFileId = secureFileId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Download a secure file by Id - /// - /// Project ID or project name - /// The unique secure file Id - /// A valid download ticket - /// If download is true, the file is sent as attachement in the response body. If download is false, the response body contains the file stream. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DownloadSecureFileAsync( - string project, - Guid secureFileId, - string ticket, - bool? download = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project, secureFileId = secureFileId }; - - List> queryParams = new List>(); - queryParams.Add("ticket", ticket); - if (download != null) - { - queryParams.Add("download", download.Value.ToString()); - } - HttpResponseMessage response; - using (HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("5.1-preview.1"), - queryParameters: queryParams, - mediaType: "application/octet-stream", - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - } - response.EnsureSuccessStatusCode(); - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - return new GZipStream(responseStream, CompressionMode.Decompress); - } - else - { - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - } - - /// - /// [Preview API] Download a secure file by Id - /// - /// Project ID - /// The unique secure file Id - /// A valid download ticket - /// If download is true, the file is sent as attachement in the response body. If download is false, the response body contains the file stream. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DownloadSecureFileAsync( - Guid project, - Guid secureFileId, - string ticket, - bool? download = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project, secureFileId = secureFileId }; - - List> queryParams = new List>(); - queryParams.Add("ticket", ticket); - if (download != null) - { - queryParams.Add("download", download.Value.ToString()); - } - HttpResponseMessage response; - using (HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("5.1-preview.1"), - queryParameters: queryParams, - mediaType: "application/octet-stream", - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - } - response.EnsureSuccessStatusCode(); - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - return new GZipStream(responseStream, CompressionMode.Decompress); - } - else - { - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - } - - /// - /// [Preview API] Get a secure file - /// - /// Project ID or project name - /// The unique secure file Id - /// If includeDownloadTicket is true and the caller has permissions, a download ticket is included in the response. - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetSecureFileAsync( - string project, - Guid secureFileId, - bool? includeDownloadTicket = null, - SecureFileActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project, secureFileId = secureFileId }; - - List> queryParams = new List>(); - if (includeDownloadTicket != null) - { - queryParams.Add("includeDownloadTicket", includeDownloadTicket.Value.ToString()); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a secure file - /// - /// Project ID - /// The unique secure file Id - /// If includeDownloadTicket is true and the caller has permissions, a download ticket is included in the response. - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetSecureFileAsync( - Guid project, - Guid secureFileId, - bool? includeDownloadTicket = null, - SecureFileActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project, secureFileId = secureFileId }; - - List> queryParams = new List>(); - if (includeDownloadTicket != null) - { - queryParams.Add("includeDownloadTicket", includeDownloadTicket.Value.ToString()); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID or project name - /// Name of the secure file to match. Can include wildcards to match multiple files. - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// Filter by secure file permissions for View, Manage or Use action. Defaults to View. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetSecureFilesAsync( - string project, - string namePattern = null, - bool? includeDownloadTickets = null, - SecureFileActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (namePattern != null) - { - queryParams.Add("namePattern", namePattern); - } - if (includeDownloadTickets != null) - { - queryParams.Add("includeDownloadTickets", includeDownloadTickets.Value.ToString()); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID - /// Name of the secure file to match. Can include wildcards to match multiple files. - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// Filter by secure file permissions for View, Manage or Use action. Defaults to View. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetSecureFilesAsync( - Guid project, - string namePattern = null, - bool? includeDownloadTickets = null, - SecureFileActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (namePattern != null) - { - queryParams.Add("namePattern", namePattern); - } - if (includeDownloadTickets != null) - { - queryParams.Add("includeDownloadTickets", includeDownloadTickets.Value.ToString()); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID or project name - /// A list of secure file Ids - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetSecureFilesByIdsAsync( - string project, - IEnumerable secureFileIds, - bool? includeDownloadTickets = null, - SecureFileActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string secureFileIdsAsString = null; - if (secureFileIds != null) - { - secureFileIdsAsString = string.Join(",", secureFileIds); - } - queryParams.Add("secureFileIds", secureFileIdsAsString); - if (includeDownloadTickets != null) - { - queryParams.Add("includeDownloadTickets", includeDownloadTickets.Value.ToString()); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID - /// A list of secure file Ids - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetSecureFilesByIdsAsync( - Guid project, - IEnumerable secureFileIds, - bool? includeDownloadTickets = null, - SecureFileActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string secureFileIdsAsString = null; - if (secureFileIds != null) - { - secureFileIdsAsString = string.Join(",", secureFileIds); - } - queryParams.Add("secureFileIds", secureFileIdsAsString); - if (includeDownloadTickets != null) - { - queryParams.Add("includeDownloadTickets", includeDownloadTickets.Value.ToString()); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID or project name - /// A list of secure file Ids - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetSecureFilesByNamesAsync( - string project, - IEnumerable secureFileNames, - bool? includeDownloadTickets = null, - SecureFileActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string secureFileNamesAsString = null; - if (secureFileNames != null) - { - secureFileNamesAsString = string.Join(",", secureFileNames); - } - queryParams.Add("secureFileNames", secureFileNamesAsString); - if (includeDownloadTickets != null) - { - queryParams.Add("includeDownloadTickets", includeDownloadTickets.Value.ToString()); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID - /// A list of secure file Ids - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetSecureFilesByNamesAsync( - Guid project, - IEnumerable secureFileNames, - bool? includeDownloadTickets = null, - SecureFileActionFilter? actionFilter = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string secureFileNamesAsString = null; - if (secureFileNames != null) - { - secureFileNamesAsString = string.Join(",", secureFileNames); - } - queryParams.Add("secureFileNames", secureFileNamesAsString); - if (includeDownloadTickets != null) - { - queryParams.Add("includeDownloadTickets", includeDownloadTickets.Value.ToString()); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Query secure files using a name pattern and a condition on file properties. - /// - /// Project ID or project name - /// The main condition syntax is described [here](https://go.microsoft.com/fwlink/?linkid=842996). Use the *property('property-name')* function to access the value of the specified property of a secure file. It returns null if the property is not set. E.g. ``` and( eq( property('devices'), '2' ), in( property('provisioning profile type'), 'ad hoc', 'development' ) ) ``` - /// Name of the secure file to match. Can include wildcards to match multiple files. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> QuerySecureFilesByPropertiesAsync( - string project, - string condition, - string namePattern = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(condition, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - if (namePattern != null) - { - queryParams.Add("namePattern", namePattern); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Query secure files using a name pattern and a condition on file properties. - /// - /// Project ID - /// The main condition syntax is described [here](https://go.microsoft.com/fwlink/?linkid=842996). Use the *property('property-name')* function to access the value of the specified property of a secure file. It returns null if the property is not set. E.g. ``` and( eq( property('devices'), '2' ), in( property('provisioning profile type'), 'ad hoc', 'development' ) ) ``` - /// Name of the secure file to match. Can include wildcards to match multiple files. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> QuerySecureFilesByPropertiesAsync( - Guid project, - string condition, - string namePattern = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(condition, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - if (namePattern != null) - { - queryParams.Add("namePattern", namePattern); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update the name or properties of an existing secure file - /// - /// Project ID or project name - /// The unique secure file Id - /// The secure file with updated name and/or properties - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateSecureFileAsync( - string project, - Guid secureFileId, - SecureFile secureFile, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project, secureFileId = secureFileId }; - HttpContent content = new ObjectContent(secureFile, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update the name or properties of an existing secure file - /// - /// Project ID - /// The unique secure file Id - /// The secure file with updated name and/or properties - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateSecureFileAsync( - Guid project, - Guid secureFileId, - SecureFile secureFile, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project, secureFileId = secureFileId }; - HttpContent content = new ObjectContent(secureFile, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update properties and/or names of a set of secure files. Files are identified by their IDs. Properties provided override the existing one entirely, i.e. do not merge. - /// - /// Project ID or project name - /// A list of secure file objects. Only three field must be populated Id, Name, and Properties. The rest of fields in the object are ignored. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UpdateSecureFilesAsync( - string project, - IEnumerable secureFiles, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent>(secureFiles, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update properties and/or names of a set of secure files. Files are identified by their IDs. Properties provided override the existing one entirely, i.e. do not merge. - /// - /// Project ID - /// A list of secure file objects. Only three field must be populated Id, Name, and Properties. The rest of fields in the object are ignored. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UpdateSecureFilesAsync( - Guid project, - IEnumerable secureFiles, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent>(secureFiles, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Upload a secure file, include the file stream in the request body - /// - /// Project ID or project name - /// Stream to upload - /// Name of the file to upload - /// If authorizePipelines is true, then the secure file is authorized for use by all pipelines in the project. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UploadSecureFileAsync( - string project, - Stream uploadStream, - string name, - bool? authorizePipelines = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - HttpContent content = new StreamContent(uploadStream); - content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); - - List> queryParams = new List>(); - queryParams.Add("name", name); - if (authorizePipelines != null) - { - queryParams.Add("authorizePipelines", authorizePipelines.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Upload a secure file, include the file stream in the request body - /// - /// Project ID - /// Stream to upload - /// Name of the file to upload - /// If authorizePipelines is true, then the secure file is authorized for use by all pipelines in the project. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UploadSecureFileAsync( - Guid project, - Stream uploadStream, - string name, - bool? authorizePipelines = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("adcfd8bc-b184-43ba-bd84-7c8c6a2ff421"); - object routeValues = new { project = project }; - HttpContent content = new StreamContent(uploadStream); - content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); - - List> queryParams = new List>(); - queryParams.Add("name", name); - if (authorizePipelines != null) - { - queryParams.Add("authorizePipelines", authorizePipelines.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - /// /// [Preview API] /// @@ -6194,1502 +752,6 @@ namespace GitHub.DistributedTask.WebApi } } - /// - /// [Preview API] Register a deployment target to a deployment group. Generally this is called by agent configuration tool. - /// - /// Project ID or project name - /// ID of the deployment group to which the deployment target is registered. - /// Deployment target to register. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddDeploymentTargetAsync( - string project, - int deploymentGroupId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Register a deployment target to a deployment group. Generally this is called by agent configuration tool. - /// - /// Project ID - /// ID of the deployment group to which the deployment target is registered. - /// Deployment target to register. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddDeploymentTargetAsync( - Guid project, - int deploymentGroupId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Delete a deployment target in a deployment group. This deletes the agent from associated deployment pool too. - /// - /// Project ID or project name - /// ID of the deployment group in which deployment target is deleted. - /// ID of the deployment target to delete. - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteDeploymentTargetAsync( - string project, - int deploymentGroupId, - int targetId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, targetId = targetId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Delete a deployment target in a deployment group. This deletes the agent from associated deployment pool too. - /// - /// Project ID - /// ID of the deployment group in which deployment target is deleted. - /// ID of the deployment target to delete. - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteDeploymentTargetAsync( - Guid project, - int deploymentGroupId, - int targetId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, targetId = targetId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Get a deployment target by its ID in a deployment group - /// - /// Project ID or project name - /// ID of the deployment group to which deployment target belongs. - /// ID of the deployment target to return. - /// Include these additional details in the returned objects. - /// - /// The cancellation token to cancel operation. - public virtual Task GetDeploymentTargetAsync( - string project, - int deploymentGroupId, - int targetId, - DeploymentTargetExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, targetId = targetId }; - - List> queryParams = new List>(); - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a deployment target by its ID in a deployment group - /// - /// Project ID - /// ID of the deployment group to which deployment target belongs. - /// ID of the deployment target to return. - /// Include these additional details in the returned objects. - /// - /// The cancellation token to cancel operation. - public virtual Task GetDeploymentTargetAsync( - Guid project, - int deploymentGroupId, - int targetId, - DeploymentTargetExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, targetId = targetId }; - - List> queryParams = new List>(); - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of deployment targets in a deployment group. - /// - /// Project ID or project name - /// ID of the deployment group. - /// Get only the deployment targets that contain all these comma separted list of tags. - /// Name pattern of the deployment targets to return. - /// When set to true, treats **name** as pattern. Else treats it as absolute match. Default is **false**. - /// Include these additional details in the returned objects. - /// Get only deployment targets that have this status. - /// Get only deployment targets that have this last job result. - /// Get deployment targets with names greater than this continuationToken lexicographically. - /// Maximum number of deployment targets to return. Default is **1000**. - /// Get only deployment targets that are enabled or disabled. Default is 'null' which returns all the targets. - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetDeploymentTargetsAsync( - string project, - int deploymentGroupId, - IEnumerable tags = null, - string name = null, - bool? partialNameMatch = null, - DeploymentTargetExpands? expand = null, - TaskAgentStatusFilter? agentStatus = null, - TaskAgentJobResultFilter? agentJobResult = null, - string continuationToken = null, - int? top = null, - bool? enabled = null, - IEnumerable propertyFilters = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (tags != null && tags.Any()) - { - queryParams.Add("tags", string.Join(",", tags)); - } - if (name != null) - { - queryParams.Add("name", name); - } - if (partialNameMatch != null) - { - queryParams.Add("partialNameMatch", partialNameMatch.Value.ToString()); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - if (agentStatus != null) - { - queryParams.Add("agentStatus", agentStatus.Value.ToString()); - } - if (agentJobResult != null) - { - queryParams.Add("agentJobResult", agentJobResult.Value.ToString()); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (enabled != null) - { - queryParams.Add("enabled", enabled.Value.ToString()); - } - if (propertyFilters != null && propertyFilters.Any()) - { - queryParams.Add("propertyFilters", string.Join(",", propertyFilters)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of deployment targets in a deployment group. - /// - /// Project ID - /// ID of the deployment group. - /// Get only the deployment targets that contain all these comma separted list of tags. - /// Name pattern of the deployment targets to return. - /// When set to true, treats **name** as pattern. Else treats it as absolute match. Default is **false**. - /// Include these additional details in the returned objects. - /// Get only deployment targets that have this status. - /// Get only deployment targets that have this last job result. - /// Get deployment targets with names greater than this continuationToken lexicographically. - /// Maximum number of deployment targets to return. Default is **1000**. - /// Get only deployment targets that are enabled or disabled. Default is 'null' which returns all the targets. - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetDeploymentTargetsAsync( - Guid project, - int deploymentGroupId, - IEnumerable tags = null, - string name = null, - bool? partialNameMatch = null, - DeploymentTargetExpands? expand = null, - TaskAgentStatusFilter? agentStatus = null, - TaskAgentJobResultFilter? agentJobResult = null, - string continuationToken = null, - int? top = null, - bool? enabled = null, - IEnumerable propertyFilters = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (tags != null && tags.Any()) - { - queryParams.Add("tags", string.Join(",", tags)); - } - if (name != null) - { - queryParams.Add("name", name); - } - if (partialNameMatch != null) - { - queryParams.Add("partialNameMatch", partialNameMatch.Value.ToString()); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - if (agentStatus != null) - { - queryParams.Add("agentStatus", agentStatus.Value.ToString()); - } - if (agentJobResult != null) - { - queryParams.Add("agentJobResult", agentJobResult.Value.ToString()); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (enabled != null) - { - queryParams.Add("enabled", enabled.Value.ToString()); - } - if (propertyFilters != null && propertyFilters.Any()) - { - queryParams.Add("propertyFilters", string.Join(",", propertyFilters)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Replace a deployment target in a deployment group. Generally this is called by agent configuration tool. - /// - /// Project ID or project name - /// ID of the deployment group in which deployment target is replaced. - /// ID of the deployment target to replace. - /// New deployment target. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task ReplaceDeploymentTargetAsync( - string project, - int deploymentGroupId, - int targetId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, targetId = targetId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Replace a deployment target in a deployment group. Generally this is called by agent configuration tool. - /// - /// Project ID - /// ID of the deployment group in which deployment target is replaced. - /// ID of the deployment target to replace. - /// New deployment target. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task ReplaceDeploymentTargetAsync( - Guid project, - int deploymentGroupId, - int targetId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, targetId = targetId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update a deployment target and its agent properties in a deployment group. Generally this is called by agent configuration tool. - /// - /// Project ID or project name - /// ID of the deployment group in which deployment target is updated. - /// ID of the deployment target to update. - /// Deployment target to update. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateDeploymentTargetAsync( - string project, - int deploymentGroupId, - int targetId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, targetId = targetId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update a deployment target and its agent properties in a deployment group. Generally this is called by agent configuration tool. - /// - /// Project ID - /// ID of the deployment group in which deployment target is updated. - /// ID of the deployment target to update. - /// Deployment target to update. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateDeploymentTargetAsync( - Guid project, - int deploymentGroupId, - int targetId, - DeploymentMachine machine, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId, targetId = targetId }; - HttpContent content = new ObjectContent(machine, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update tags of a list of deployment targets in a deployment group. - /// - /// Project ID or project name - /// ID of the deployment group in which deployment targets are updated. - /// Deployment targets with tags to udpdate. - /// - /// The cancellation token to cancel operation. - public virtual Task> UpdateDeploymentTargetsAsync( - string project, - int deploymentGroupId, - IEnumerable machines, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent>(machines, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update tags of a list of deployment targets in a deployment group. - /// - /// Project ID - /// ID of the deployment group in which deployment targets are updated. - /// Deployment targets with tags to udpdate. - /// - /// The cancellation token to cancel operation. - public virtual Task> UpdateDeploymentTargetsAsync( - Guid project, - int deploymentGroupId, - IEnumerable machines, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - HttpContent content = new ObjectContent>(machines, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Create a task group. - /// - /// Project ID or project name - /// Task group object to create. - /// - /// The cancellation token to cancel operation. - public virtual Task AddTaskGroupAsync( - string project, - TaskGroupCreateParameter taskGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Create a task group. - /// - /// Project ID - /// Task group object to create. - /// - /// The cancellation token to cancel operation. - public virtual Task AddTaskGroupAsync( - Guid project, - TaskGroupCreateParameter taskGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Delete a task group. - /// - /// Project ID or project name - /// Id of the task group to be deleted. - /// Comments to delete. - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteTaskGroupAsync( - string project, - Guid taskGroupId, - string comment = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - if (comment != null) - { - queryParams.Add("comment", comment); - } - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Delete a task group. - /// - /// Project ID - /// Id of the task group to be deleted. - /// Comments to delete. - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteTaskGroupAsync( - Guid project, - Guid taskGroupId, - string comment = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - if (comment != null) - { - queryParams.Add("comment", comment); - } - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Get task group. - /// - /// Project ID or project name - /// Id of the task group. - /// version specification of the task group. examples: 1, 1.0. - /// The properties that should be expanded. example $expand=Tasks will expand nested task groups. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetTaskGroupAsync( - string project, - Guid taskGroupId, - string versionSpec, - TaskGroupExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - queryParams.Add("versionSpec", versionSpec); - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get task group. - /// - /// Project ID - /// Id of the task group. - /// version specification of the task group. examples: 1, 1.0. - /// The properties that should be expanded. example $expand=Tasks will expand nested task groups. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetTaskGroupAsync( - Guid project, - Guid taskGroupId, - string versionSpec, - TaskGroupExpands? expand = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - queryParams.Add("versionSpec", versionSpec); - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task GetTaskGroupRevisionAsync( - string project, - Guid taskGroupId, - int revision, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - queryParams.Add("revision", revision.ToString(CultureInfo.InvariantCulture)); - HttpResponseMessage response; - using (HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("5.1-preview.1"), - queryParameters: queryParams, - mediaType: "text/plain", - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - } - response.EnsureSuccessStatusCode(); - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - return new GZipStream(responseStream, CompressionMode.Decompress); - } - else - { - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task GetTaskGroupRevisionAsync( - Guid project, - Guid taskGroupId, - int revision, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - queryParams.Add("revision", revision.ToString(CultureInfo.InvariantCulture)); - HttpResponseMessage response; - using (HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("5.1-preview.1"), - queryParameters: queryParams, - mediaType: "text/plain", - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - } - response.EnsureSuccessStatusCode(); - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - return new GZipStream(responseStream, CompressionMode.Decompress); - } - else - { - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - } - - /// - /// [Preview API] List task groups. - /// - /// Project ID or project name - /// Id of the task group. - /// 'true' to recursively expand task groups. Default is 'false'. - /// Guid of the taskId to filter. - /// 'true'to include deleted task groups. Default is 'false'. - /// Number of task groups to get. - /// Gets the task groups after the continuation token provided. - /// Gets the results in the defined order. Default is 'CreatedOnDescending'. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetTaskGroupsAsync( - string project, - Guid? taskGroupId = null, - bool? expanded = null, - Guid? taskIdFilter = null, - bool? deleted = null, - int? top = null, - DateTime? continuationToken = null, - TaskGroupQueryOrder? queryOrder = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - if (expanded != null) - { - queryParams.Add("expanded", expanded.Value.ToString()); - } - if (taskIdFilter != null) - { - queryParams.Add("taskIdFilter", taskIdFilter.Value.ToString()); - } - if (deleted != null) - { - queryParams.Add("deleted", deleted.Value.ToString()); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (continuationToken != null) - { - AddDateTimeToQueryParams(queryParams, "continuationToken", continuationToken.Value); - } - if (queryOrder != null) - { - queryParams.Add("queryOrder", queryOrder.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] List task groups. - /// - /// Project ID - /// Id of the task group. - /// 'true' to recursively expand task groups. Default is 'false'. - /// Guid of the taskId to filter. - /// 'true'to include deleted task groups. Default is 'false'. - /// Number of task groups to get. - /// Gets the task groups after the continuation token provided. - /// Gets the results in the defined order. Default is 'CreatedOnDescending'. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetTaskGroupsAsync( - Guid project, - Guid? taskGroupId = null, - bool? expanded = null, - Guid? taskIdFilter = null, - bool? deleted = null, - int? top = null, - DateTime? continuationToken = null, - TaskGroupQueryOrder? queryOrder = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - if (expanded != null) - { - queryParams.Add("expanded", expanded.Value.ToString()); - } - if (taskIdFilter != null) - { - queryParams.Add("taskIdFilter", taskIdFilter.Value.ToString()); - } - if (deleted != null) - { - queryParams.Add("deleted", deleted.Value.ToString()); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (continuationToken != null) - { - AddDateTimeToQueryParams(queryParams, "continuationToken", continuationToken.Value); - } - if (queryOrder != null) - { - queryParams.Add("queryOrder", queryOrder.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> PublishPreviewTaskGroupAsync( - string project, - Guid taskGroupId, - TaskGroup taskGroup, - bool? disablePriorVersions = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - if (disablePriorVersions != null) - { - queryParams.Add("disablePriorVersions", disablePriorVersions.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> PublishPreviewTaskGroupAsync( - Guid project, - Guid taskGroupId, - TaskGroup taskGroup, - bool? disablePriorVersions = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - if (disablePriorVersions != null) - { - queryParams.Add("disablePriorVersions", disablePriorVersions.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> PublishTaskGroupAsync( - string project, - Guid parentTaskGroupId, - PublishTaskGroupMetadata taskGroupMetadata, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(taskGroupMetadata, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - queryParams.Add("parentTaskGroupId", parentTaskGroupId.ToString()); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> PublishTaskGroupAsync( - Guid project, - Guid parentTaskGroupId, - PublishTaskGroupMetadata taskGroupMetadata, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(taskGroupMetadata, new VssJsonMediaTypeFormatter(true)); - - List> queryParams = new List>(); - queryParams.Add("parentTaskGroupId", parentTaskGroupId.ToString()); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UndeleteTaskGroupAsync( - string project, - TaskGroup taskGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UndeleteTaskGroupAsync( - Guid project, - TaskGroup taskGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update a task group. - /// - /// Project ID or project name - /// Task group to update. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Use UpdateTaskGroup(Guid taskGroupId, [FromBody] TaskGroupUpdateParameter taskGroup) instead")] - public virtual Task UpdateTaskGroupAsync( - string project, - TaskGroupUpdateParameter taskGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update a task group. - /// - /// Project ID - /// Task group to update. - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Use UpdateTaskGroup(Guid taskGroupId, [FromBody] TaskGroupUpdateParameter taskGroup) instead")] - public virtual Task UpdateTaskGroupAsync( - Guid project, - TaskGroupUpdateParameter taskGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update a task group. - /// - /// Project ID or project name - /// Id of the task group to update. - /// Task group to update. - /// - /// The cancellation token to cancel operation. - public virtual Task UpdateTaskGroupAsync( - string project, - Guid taskGroupId, - TaskGroupUpdateParameter taskGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update a task group. - /// - /// Project ID - /// Id of the task group to update. - /// Task group to update. - /// - /// The cancellation token to cancel operation. - public virtual Task UpdateTaskGroupAsync( - Guid project, - Guid taskGroupId, - TaskGroupUpdateParameter taskGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - HttpContent content = new ObjectContent(taskGroup, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteTaskDefinitionAsync( - Guid taskId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd"); - object routeValues = new { taskId = taskId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task GetTaskContentZipAsync( - Guid taskId, - string versionString, - IEnumerable visibility = null, - bool? scopeLocal = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd"); - object routeValues = new { taskId = taskId, versionString = versionString }; - - List> queryParams = new List>(); - if (visibility != null) - { - AddIEnumerableAsQueryParams(queryParams, "visibility", visibility); - } - if (scopeLocal != null) - { - queryParams.Add("scopeLocal", scopeLocal.Value.ToString()); - } - HttpResponseMessage response; - using (HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("5.1-preview.1"), - queryParameters: queryParams, - mediaType: "application/zip", - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - } - response.EnsureSuccessStatusCode(); - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - return new GZipStream(responseStream, CompressionMode.Decompress); - } - else - { - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetTaskDefinitionAsync( - Guid taskId, - string versionString, - IEnumerable visibility = null, - bool? scopeLocal = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd"); - object routeValues = new { taskId = taskId, versionString = versionString }; - - List> queryParams = new List>(); - if (visibility != null) - { - AddIEnumerableAsQueryParams(queryParams, "visibility", visibility); - } - if (scopeLocal != null) - { - queryParams.Add("scopeLocal", scopeLocal.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetTaskDefinitionsAsync( - Guid? taskId = null, - IEnumerable visibility = null, - bool? scopeLocal = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("60aac929-f0cd-4bc8-9ce4-6b30e8f1b1bd"); - object routeValues = new { taskId = taskId }; - - List> queryParams = new List>(); - if (visibility != null) - { - AddIEnumerableAsQueryParams(queryParams, "visibility", visibility); - } - if (scopeLocal != null) - { - queryParams.Add("scopeLocal", scopeLocal.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - /// /// [Preview API] /// @@ -7722,1065 +784,5 @@ namespace GitHub.DistributedTask.WebApi userState: userState, cancellationToken: cancellationToken); } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateAgentUserCapabilitiesAsync( - int poolId, - int agentId, - IDictionary userCapabilities, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("30ba3ada-fedf-4da8-bbb5-dacf2f82e176"); - object routeValues = new { poolId = poolId, agentId = agentId }; - HttpContent content = new ObjectContent>(userCapabilities, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Add a variable group. - /// - /// Project ID or project name - /// Variable group to add. - /// - /// The cancellation token to cancel operation. - public virtual Task AddVariableGroupAsync( - string project, - VariableGroupParameters group, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(group, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Add a variable group. - /// - /// Project ID - /// Variable group to add. - /// - /// The cancellation token to cancel operation. - public virtual Task AddVariableGroupAsync( - Guid project, - VariableGroupParameters group, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project }; - HttpContent content = new ObjectContent(group, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Delete a variable group - /// - /// Project ID or project name - /// Id of the variable group. - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteVariableGroupAsync( - string project, - int groupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project, groupId = groupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Delete a variable group - /// - /// Project ID - /// Id of the variable group. - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteVariableGroupAsync( - Guid project, - int groupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project, groupId = groupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] Get a variable group. - /// - /// Project ID or project name - /// Id of the variable group. - /// - /// The cancellation token to cancel operation. - public virtual Task GetVariableGroupAsync( - string project, - int groupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project, groupId = groupId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a variable group. - /// - /// Project ID - /// Id of the variable group. - /// - /// The cancellation token to cancel operation. - public virtual Task GetVariableGroupAsync( - Guid project, - int groupId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project, groupId = groupId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get variable groups. - /// - /// Project ID or project name - /// Name of variable group. - /// Action filter for the variable group. It specifies the action which can be performed on the variable groups. - /// Number of variable groups to get. - /// Gets the variable groups after the continuation token provided. - /// Gets the results in the defined order. Default is 'IdDescending'. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetVariableGroupsAsync( - string project, - string groupName = null, - VariableGroupActionFilter? actionFilter = null, - int? top = null, - int? continuationToken = null, - VariableGroupQueryOrder? queryOrder = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (groupName != null) - { - queryParams.Add("groupName", groupName); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken.Value.ToString(CultureInfo.InvariantCulture)); - } - if (queryOrder != null) - { - queryParams.Add("queryOrder", queryOrder.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get variable groups. - /// - /// Project ID - /// Name of variable group. - /// Action filter for the variable group. It specifies the action which can be performed on the variable groups. - /// Number of variable groups to get. - /// Gets the variable groups after the continuation token provided. - /// Gets the results in the defined order. Default is 'IdDescending'. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetVariableGroupsAsync( - Guid project, - string groupName = null, - VariableGroupActionFilter? actionFilter = null, - int? top = null, - int? continuationToken = null, - VariableGroupQueryOrder? queryOrder = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (groupName != null) - { - queryParams.Add("groupName", groupName); - } - if (actionFilter != null) - { - queryParams.Add("actionFilter", actionFilter.Value.ToString()); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken.Value.ToString(CultureInfo.InvariantCulture)); - } - if (queryOrder != null) - { - queryParams.Add("queryOrder", queryOrder.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get variable groups by ids. - /// - /// Project ID or project name - /// Comma separated list of Ids of variable groups. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetVariableGroupsByIdAsync( - string project, - IEnumerable groupIds, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string groupIdsAsString = null; - if (groupIds != null) - { - groupIdsAsString = string.Join(",", groupIds); - } - queryParams.Add("groupIds", groupIdsAsString); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get variable groups by ids. - /// - /// Project ID - /// Comma separated list of Ids of variable groups. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetVariableGroupsByIdAsync( - Guid project, - IEnumerable groupIds, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - string groupIdsAsString = null; - if (groupIds != null) - { - groupIdsAsString = string.Join(",", groupIds); - } - queryParams.Add("groupIds", groupIdsAsString); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Update a variable group. - /// - /// Project ID or project name - /// Id of the variable group to update. - /// Variable group to update. - /// - /// The cancellation token to cancel operation. - public virtual Task UpdateVariableGroupAsync( - string project, - int groupId, - VariableGroupParameters group, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project, groupId = groupId }; - HttpContent content = new ObjectContent(group, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] Update a variable group. - /// - /// Project ID - /// Id of the variable group to update. - /// Variable group to update. - /// - /// The cancellation token to cancel operation. - public virtual Task UpdateVariableGroupAsync( - Guid project, - int groupId, - VariableGroupParameters group, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PUT"); - Guid locationId = new Guid("f5b09dd5-9d54-45a1-8b5a-1c8287d634cc"); - object routeValues = new { project = project, groupId = groupId }; - HttpContent content = new ObjectContent(group, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> QuerySharedProjectsForVariableGroupAsync( - int groupId, - string project, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("74455598-def7-499a-b7a3-a41d1c8225f8"); - object routeValues = new { groupId = groupId }; - - List> queryParams = new List>(); - queryParams.Add("project", project); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task ShareVariableGroupWithProjectAsync( - int groupId, - string fromProject, - string withProject, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("74455598-def7-499a-b7a3-a41d1c8225f8"); - object routeValues = new { groupId = groupId }; - - List> queryParams = new List>(); - queryParams.Add("fromProject", fromProject); - queryParams.Add("withProject", withProject); - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddVirtualMachineGroupAsync( - string project, - int environmentId, - VirtualMachineGroupCreateParameters createParameters, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("9e597901-4af7-4cc3-8d92-47d54db8ebfb"); - object routeValues = new { project = project, environmentId = environmentId }; - HttpContent content = new ObjectContent(createParameters, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AddVirtualMachineGroupAsync( - Guid project, - int environmentId, - VirtualMachineGroupCreateParameters createParameters, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("9e597901-4af7-4cc3-8d92-47d54db8ebfb"); - object routeValues = new { project = project, environmentId = environmentId }; - HttpContent content = new ObjectContent(createParameters, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteVirtualMachineGroupAsync( - string project, - int environmentId, - int resourceId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("9e597901-4af7-4cc3-8d92-47d54db8ebfb"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual async Task DeleteVirtualMachineGroupAsync( - Guid project, - int environmentId, - int resourceId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("9e597901-4af7-4cc3-8d92-47d54db8ebfb"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetVirtualMachineGroupAsync( - string project, - int environmentId, - int resourceId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("9e597901-4af7-4cc3-8d92-47d54db8ebfb"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetVirtualMachineGroupAsync( - Guid project, - int environmentId, - int resourceId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("9e597901-4af7-4cc3-8d92-47d54db8ebfb"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateVirtualMachineGroupAsync( - string project, - int environmentId, - VirtualMachineGroup resource, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("9e597901-4af7-4cc3-8d92-47d54db8ebfb"); - object routeValues = new { project = project, environmentId = environmentId }; - HttpContent content = new ObjectContent(resource, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task UpdateVirtualMachineGroupAsync( - Guid project, - int environmentId, - VirtualMachineGroup resource, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("9e597901-4af7-4cc3-8d92-47d54db8ebfb"); - object routeValues = new { project = project, environmentId = environmentId }; - HttpContent content = new ObjectContent(resource, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetVirtualMachinesAsync( - string project, - int environmentId, - int resourceId, - string continuationToken = null, - string name = null, - bool? partialNameMatch = null, - IEnumerable tags = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("48700676-2ba5-4282-8ec8-083280d169c7"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - List> queryParams = new List>(); - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (name != null) - { - queryParams.Add("name", name); - } - if (partialNameMatch != null) - { - queryParams.Add("partialNameMatch", partialNameMatch.Value.ToString()); - } - if (tags != null && tags.Any()) - { - queryParams.Add("tags", string.Join(",", tags)); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetVirtualMachinesAsync( - Guid project, - int environmentId, - int resourceId, - string continuationToken = null, - string name = null, - bool? partialNameMatch = null, - IEnumerable tags = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("48700676-2ba5-4282-8ec8-083280d169c7"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - - List> queryParams = new List>(); - if (continuationToken != null) - { - queryParams.Add("continuationToken", continuationToken); - } - if (name != null) - { - queryParams.Add("name", name); - } - if (partialNameMatch != null) - { - queryParams.Add("partialNameMatch", partialNameMatch.Value.ToString()); - } - if (tags != null && tags.Any()) - { - queryParams.Add("tags", string.Join(",", tags)); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UpdateVirtualMachinesAsync( - string project, - int environmentId, - int resourceId, - IEnumerable machines, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("48700676-2ba5-4282-8ec8-083280d169c7"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - HttpContent content = new ObjectContent>(machines, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> UpdateVirtualMachinesAsync( - Guid project, - int environmentId, - int resourceId, - IEnumerable machines, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("PATCH"); - Guid locationId = new Guid("48700676-2ba5-4282-8ec8-083280d169c7"); - object routeValues = new { project = project, environmentId = environmentId, resourceId = resourceId }; - HttpContent content = new ObjectContent>(machines, new VssJsonMediaTypeFormatter(true)); - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task AcquireAccessTokenAsync( - AadOauthTokenRequest authenticationRequest, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("9c63205e-3a0f-42a0-ad88-095200f13607"); - HttpContent content = new ObjectContent(authenticationRequest, new VssJsonMediaTypeFormatter(true)); - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken, - content: content); - } - - /// - /// [Preview API] - /// - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("ServiceEndpoint APIs under distributedtask area is deprecated. Use the APIs under serviceendpoint area instead.")] - public virtual Task CreateAadOAuthRequestAsync( - string tenantId, - string redirectUri, - AadLoginPromptOption? promptOption = null, - string completeCallbackPayload = null, - bool? completeCallbackByAuthCode = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("POST"); - Guid locationId = new Guid("9c63205e-3a0f-42a0-ad88-095200f13607"); - - List> queryParams = new List>(); - queryParams.Add("tenantId", tenantId); - queryParams.Add("redirectUri", redirectUri); - if (promptOption != null) - { - queryParams.Add("promptOption", promptOption.Value.ToString()); - } - if (completeCallbackPayload != null) - { - queryParams.Add("completeCallbackPayload", completeCallbackPayload); - } - if (completeCallbackByAuthCode != null) - { - queryParams.Add("completeCallbackByAuthCode", completeCallbackByAuthCode.Value.ToString()); - } - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetVstsAadTenantIdAsync( - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("9c63205e-3a0f-42a0-ad88-095200f13607"); - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// - /// The cancellation token to cancel operation. - public virtual Task GetYamlSchemaAsync( - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("1f9990b9-1dba-441f-9c2e-6485888c42b6"); - - return SendAsync( - httpMethod, - locationId, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } } } diff --git a/src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs b/src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs index 799566eab..867b4f927 100644 --- a/src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs +++ b/src/Sdk/DTGenerated/Generated/TaskHttpClientBase.cs @@ -59,36 +59,6 @@ namespace GitHub.DistributedTask.WebApi { } - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetPlanAttachmentsAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - string type, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("eb55e5d6-2f30-4295-b5ed-38da50b1fc52"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId, type = type }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - /// /// [Preview API] /// @@ -130,126 +100,6 @@ namespace GitHub.DistributedTask.WebApi content: content); } - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task GetAttachmentAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - Guid timelineId, - Guid recordId, - string type, - string name, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("7898f959-9cdf-4096-b29e-7f293031629e"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId, timelineId = timelineId, recordId = recordId, type = type, name = name }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual async Task GetAttachmentContentAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - Guid timelineId, - Guid recordId, - string type, - string name, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("7898f959-9cdf-4096-b29e-7f293031629e"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId, timelineId = timelineId, recordId = recordId, type = type, name = name }; - HttpResponseMessage response; - using (HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("5.1-preview.1"), - mediaType: "application/octet-stream", - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - } - response.EnsureSuccessStatusCode(); - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - Stream responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - return new GZipStream(responseStream, CompressionMode.Decompress); - } - else - { - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetAttachmentsAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - Guid timelineId, - Guid recordId, - string type, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("7898f959-9cdf-4096-b29e-7f293031629e"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId, timelineId = timelineId, recordId = recordId, type = type }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - /// /// [Preview API] /// @@ -290,35 +140,6 @@ namespace GitHub.DistributedTask.WebApi } } - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetJobInstanceAsync( - Guid scopeIdentifier, - string hubName, - string orchestrationId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("0a1efd25-abda-43bd-9629-6c7bdd2e0d60"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, orchestrationId = orchestrationId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - /// /// [Preview API] /// @@ -386,245 +207,6 @@ namespace GitHub.DistributedTask.WebApi content: content); } - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetLogAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - int logId, - long? startLine = null, - long? endLine = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("46f5667d-263a-4684-91b1-dff7fdcf64e2"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId, logId = logId }; - - List> queryParams = new List>(); - if (startLine != null) - { - queryParams.Add("startLine", startLine.Value.ToString(CultureInfo.InvariantCulture)); - } - if (endLine != null) - { - queryParams.Add("endLine", endLine.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetLogsAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("46f5667d-263a-4684-91b1-dff7fdcf64e2"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetPlanGroupsQueueMetricsAsync( - Guid scopeIdentifier, - string hubName, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("038fd4d5-cda7-44ca-92c0-935843fee1a7"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task> GetQueuedPlanGroupsAsync( - Guid scopeIdentifier, - string hubName, - PlanGroupStatus? statusFilter = null, - int? count = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("0dd73091-3e36-4f43-b443-1b76dd426d84"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName }; - - List> queryParams = new List>(); - if (statusFilter != null) - { - queryParams.Add("statusFilter", statusFilter.Value.ToString()); - } - if (count != null) - { - queryParams.Add("count", count.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetQueuedPlanGroupAsync( - Guid scopeIdentifier, - string hubName, - string planGroup, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("65fd0708-bc1e-447b-a731-0587c5464e5b"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planGroup = planGroup }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never)] - public virtual Task GetPlanAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("5cecd946-d704-471e-a45f-3b4064fcfaba"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId }; - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetRecordsAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - Guid timelineId, - int? changeId = null, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("8893bc5b-35b2-4be7-83cb-99e683551db4"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId, timelineId = timelineId }; - - List> queryParams = new List>(); - if (changeId != null) - { - queryParams.Add("changeId", changeId.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - /// /// [Preview API] /// @@ -691,39 +273,6 @@ namespace GitHub.DistributedTask.WebApi content: content); } - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteTimelineAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - Guid timelineId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("83597576-cc2c-453c-bea6-2882ae6a1653"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId, timelineId = timelineId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - /// /// [Preview API] /// @@ -768,33 +317,5 @@ namespace GitHub.DistributedTask.WebApi userState: userState, cancellationToken: cancellationToken); } - - /// - /// [Preview API] - /// - /// The project GUID to scope the request - /// The name of the server hub: "build" for the Build server or "rm" for the Release Management server - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetTimelinesAsync( - Guid scopeIdentifier, - string hubName, - Guid planId, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("83597576-cc2c-453c-bea6-2882ae6a1653"); - object routeValues = new { scopeIdentifier = scopeIdentifier, hubName = hubName, planId = planId }; - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - userState: userState, - cancellationToken: cancellationToken); - } } } diff --git a/src/Sdk/DTLogging/Logging/ValueEncoders.cs b/src/Sdk/DTLogging/Logging/ValueEncoders.cs index 52aed6975..774787991 100644 --- a/src/Sdk/DTLogging/Logging/ValueEncoders.cs +++ b/src/Sdk/DTLogging/Logging/ValueEncoders.cs @@ -39,7 +39,7 @@ namespace GitHub.DistributedTask.Logging public static String ExpressionStringEscape(String value) { - return Expressions.ExpressionUtil.StringEscape(value); + return Expressions2.Sdk.ExpressionUtility.StringEscape(value); } public static String JsonStringEscape(String value) diff --git a/src/Sdk/DTPipelines/Pipelines/AgentJobRequestMessageUtil.cs b/src/Sdk/DTPipelines/Pipelines/AgentJobRequestMessageUtil.cs deleted file mode 100644 index a6d7fe489..000000000 --- a/src/Sdk/DTPipelines/Pipelines/AgentJobRequestMessageUtil.cs +++ /dev/null @@ -1,769 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using System.Text.RegularExpressions; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class AgentJobRequestMessageUtil - { - // Legacy JobRequestMessage -> Pipeline JobRequestMessage - // Used by the agent when the latest version agent connect to old version TFS - // Used by the server when common method only take the new Message contact, like, telemetry logging - public static AgentJobRequestMessage Convert(WebApi.AgentJobRequestMessage message) - { - // construct steps - List jobSteps = new List(); - foreach (var task in message.Tasks) - { - TaskStep taskStep = new TaskStep(task); - jobSteps.Add(taskStep); - } - - Dictionary variables = new Dictionary(StringComparer.OrdinalIgnoreCase); - HashSet maskHints = new HashSet(); - JobResources jobResources = new JobResources(); - WorkspaceOptions workspace = new WorkspaceOptions(); - message.Environment.Extract(variables, maskHints, jobResources); - - // convert repository endpoint into checkout task for Build - if (string.Equals(message.Plan.PlanType, "Build", StringComparison.OrdinalIgnoreCase)) - { - // repositoryId was added sometime after TFS2015, so we need to fall back to find endpoint using endpoint type. - var legacyRepoEndpoint = jobResources.Endpoints.FirstOrDefault(x => x.Data.ContainsKey("repositoryId")); - if (legacyRepoEndpoint == null) - { - legacyRepoEndpoint = jobResources.Endpoints.FirstOrDefault(x => x.Type == LegacyRepositoryTypes.Bitbucket || x.Type == LegacyRepositoryTypes.Git || x.Type == LegacyRepositoryTypes.TfsGit || x.Type == LegacyRepositoryTypes.GitHub || x.Type == LegacyRepositoryTypes.GitHubEnterprise || x.Type == LegacyRepositoryTypes.TfsVersionControl); - } - - // build retention job will not have a repo endpoint. - if (legacyRepoEndpoint != null) - { - // construct checkout task - var checkoutStep = new TaskStep(); - checkoutStep.Id = Guid.NewGuid(); - checkoutStep.DisplayName = PipelineConstants.CheckoutTask.FriendlyName; - checkoutStep.Name = "__system_checkout"; - checkoutStep.Reference = new TaskStepDefinitionReference() - { - Id = PipelineConstants.CheckoutTask.Id, - Name = PipelineConstants.CheckoutTask.Name, - Version = PipelineConstants.CheckoutTask.Version, - }; - checkoutStep.Inputs[PipelineConstants.CheckoutTaskInputs.Repository] = "__legacy_repo_endpoint"; - - // construct self repository resource - var defaultRepo = new RepositoryResource(); - defaultRepo.Alias = "__legacy_repo_endpoint"; - defaultRepo.Properties.Set(RepositoryPropertyNames.Name, legacyRepoEndpoint.Name); - legacyRepoEndpoint.Data.TryGetValue("repositoryId", out string repositoryId); - if (!string.IsNullOrEmpty(repositoryId)) - { - defaultRepo.Id = repositoryId; - } - else - { - defaultRepo.Id = "__legacy_repo_endpoint"; - } - - defaultRepo.Endpoint = new ServiceEndpointReference() - { - Id = Guid.Empty, - Name = legacyRepoEndpoint.Name - }; - defaultRepo.Type = ConvertLegacySourceType(legacyRepoEndpoint.Type); - defaultRepo.Url = legacyRepoEndpoint.Url; - if (variables.TryGetValue("build.sourceVersion", out VariableValue sourceVersion) && !string.IsNullOrEmpty(sourceVersion?.Value)) - { - defaultRepo.Version = sourceVersion.Value; - } - if (variables.TryGetValue("build.sourceBranch", out VariableValue sourceBranch) && !string.IsNullOrEmpty(sourceBranch?.Value)) - { - defaultRepo.Properties.Set(RepositoryPropertyNames.Ref, sourceBranch.Value); - } - - VersionInfo versionInfo = null; - if (variables.TryGetValue("build.sourceVersionAuthor", out VariableValue sourceAuthor) && !string.IsNullOrEmpty(sourceAuthor?.Value)) - { - versionInfo = new VersionInfo(); - versionInfo.Author = sourceAuthor.Value; - } - if (variables.TryGetValue("build.sourceVersionMessage", out VariableValue sourceMessage) && !string.IsNullOrEmpty(sourceMessage?.Value)) - { - if (versionInfo == null) - { - versionInfo = new VersionInfo(); - } - versionInfo.Message = sourceMessage.Value; - } - if (versionInfo != null) - { - defaultRepo.Properties.Set(RepositoryPropertyNames.VersionInfo, versionInfo); - } - - if (defaultRepo.Type == RepositoryTypes.Tfvc) - { - if (variables.TryGetValue("build.sourceTfvcShelveset", out VariableValue shelveset) && !string.IsNullOrEmpty(shelveset?.Value)) - { - defaultRepo.Properties.Set(RepositoryPropertyNames.Shelveset, shelveset.Value); - } - - var legacyTfvcMappingJson = legacyRepoEndpoint.Data["tfvcWorkspaceMapping"]; - var legacyTfvcMapping = JsonUtility.FromString(legacyTfvcMappingJson); - if (legacyTfvcMapping != null) - { - IList tfvcMapping = new List(); - foreach (var mapping in legacyTfvcMapping.Mappings) - { - tfvcMapping.Add(new WorkspaceMapping() { ServerPath = mapping.ServerPath, LocalPath = mapping.LocalPath, Exclude = String.Equals(mapping.MappingType, "cloak", StringComparison.OrdinalIgnoreCase) }); - } - - defaultRepo.Properties.Set>(RepositoryPropertyNames.Mappings, tfvcMapping); - } - } - else if (defaultRepo.Type == RepositoryTypes.Svn) - { - var legacySvnMappingJson = legacyRepoEndpoint.Data["svnWorkspaceMapping"]; - var legacySvnMapping = JsonUtility.FromString(legacySvnMappingJson); - if (legacySvnMapping != null) - { - IList svnMapping = new List(); - foreach (var mapping in legacySvnMapping.Mappings) - { - svnMapping.Add(new WorkspaceMapping() { ServerPath = mapping.ServerPath, LocalPath = mapping.LocalPath, Depth = mapping.Depth, IgnoreExternals = mapping.IgnoreExternals, Revision = mapping.Revision }); - } - - defaultRepo.Properties.Set>(RepositoryPropertyNames.Mappings, svnMapping); - } - } - - legacyRepoEndpoint.Data.TryGetValue("clean", out string cleanString); - if (!string.IsNullOrEmpty(cleanString)) - { - checkoutStep.Inputs[PipelineConstants.CheckoutTaskInputs.Clean] = cleanString; - } - else - { - // Checkout task has clean set tp false as default. - checkoutStep.Inputs[PipelineConstants.CheckoutTaskInputs.Clean] = Boolean.FalseString; - } - - if (legacyRepoEndpoint.Data.TryGetValue("checkoutSubmodules", out string checkoutSubmodulesString) && - Boolean.TryParse(checkoutSubmodulesString, out Boolean checkoutSubmodules) && - checkoutSubmodules) - { - if (legacyRepoEndpoint.Data.TryGetValue("checkoutNestedSubmodules", out string nestedSubmodulesString) && - Boolean.TryParse(nestedSubmodulesString, out Boolean nestedSubmodules) && - nestedSubmodules) - { - checkoutStep.Inputs[PipelineConstants.CheckoutTaskInputs.Submodules] = PipelineConstants.CheckoutTaskInputs.SubmodulesOptions.Recursive; - } - else - { - checkoutStep.Inputs[PipelineConstants.CheckoutTaskInputs.Submodules] = PipelineConstants.CheckoutTaskInputs.SubmodulesOptions.True; - } - } - - if (legacyRepoEndpoint.Data.ContainsKey("fetchDepth")) - { - checkoutStep.Inputs[PipelineConstants.CheckoutTaskInputs.FetchDepth] = legacyRepoEndpoint.Data["fetchDepth"]; - } - - if (legacyRepoEndpoint.Data.ContainsKey("gitLfsSupport")) - { - checkoutStep.Inputs[PipelineConstants.CheckoutTaskInputs.Lfs] = legacyRepoEndpoint.Data["gitLfsSupport"]; - } - - if (VariableUtility.GetEnableAccessTokenType(variables) == EnableAccessTokenType.Variable) - { - checkoutStep.Inputs[PipelineConstants.CheckoutTaskInputs.PersistCredentials] = Boolean.TrueString; - } - - // construct worksapce option - if (Boolean.TryParse(cleanString, out Boolean clean) && clean) - { - if (legacyRepoEndpoint.Data.TryGetValue("cleanOptions", out string cleanOptionsString) && !string.IsNullOrEmpty(cleanOptionsString)) - { - if (string.Equals(cleanOptionsString, "1", StringComparison.OrdinalIgnoreCase)) //RepositoryCleanOptions.SourceAndOutputDir - { - workspace.Clean = PipelineConstants.WorkspaceCleanOptions.Outputs; - } - else if (string.Equals(cleanOptionsString, "2", StringComparison.OrdinalIgnoreCase)) //RepositoryCleanOptions.SourceDir - { - workspace.Clean = PipelineConstants.WorkspaceCleanOptions.Resources; - } - else if (string.Equals(cleanOptionsString, "3", StringComparison.OrdinalIgnoreCase)) //RepositoryCleanOptions.AllBuildDir - { - workspace.Clean = PipelineConstants.WorkspaceCleanOptions.All; - } - } - } - - // add checkout task when build.syncsources and skipSyncSource not set - variables.TryGetValue("build.syncSources", out VariableValue syncSourcesVariable); - legacyRepoEndpoint.Data.TryGetValue("skipSyncSource", out string skipSyncSource); - if (!string.IsNullOrEmpty(syncSourcesVariable?.Value) && Boolean.TryParse(syncSourcesVariable?.Value, out bool syncSource) && !syncSource) - { - checkoutStep.Condition = bool.FalseString; - } - else if (Boolean.TryParse(skipSyncSource, out bool skipSource) && skipSource) - { - checkoutStep.Condition = bool.FalseString; - } - - jobSteps.Insert(0, checkoutStep); - - // always add self repository to job resource - jobResources.Repositories.Add(defaultRepo); - } - } - - AgentJobRequestMessage agentRequestMessage = new AgentJobRequestMessage(message.Plan, message.Timeline, message.JobId, message.JobName, message.JobRefName, null, null, null, variables, maskHints.ToList(), jobResources, null, workspace, jobSteps, null) - { - RequestId = message.RequestId - }; - - return agentRequestMessage; - } - - // Pipeline JobRequestMessage -> Legacy JobRequestMessage - // Used by the server when the connected agent is old version and doesn't support new contract yet. - public static WebApi.AgentJobRequestMessage Convert(AgentJobRequestMessage message) - { - // Old agent can't handle container(s) - if (message.JobContainer != null) - { - throw new NotSupportedException("Job containers are not supported"); - } - if (message.JobServiceContainers != null) - { - throw new NotSupportedException("Job service containers are not supported"); - } - - // Old agent can't handle more than 1 repository - if (message.Resources.Repositories.Count > 1) - { - throw new NotSupportedException(string.Join(", ", message.Resources.Repositories.Select(x => x.Alias))); - } - - // Old agent can't handle more than 1 checkout task - if (message.Steps.Where(x => x.IsCheckoutTask()).Count() > 1) - { - throw new NotSupportedException(PipelineConstants.CheckoutTask.Id.ToString("D")); - } - - // construct tasks - List tasks = new List(); - foreach (var step in message.Steps) - { - // Pipeline builder should add min agent demand when steps contains group - if (step.Type != StepType.Task) - { - throw new NotSupportedException(step.Type.ToString()); - } - - // don't add checkout task, we need to convert the checkout task into endpoint - if (!step.IsCheckoutTask()) - { - TaskInstance task = (step as TaskStep).ToLegacyTaskInstance(); - tasks.Add(task); - } - } - - if (message.Resources != null) - { - foreach (var endpoint in message.Resources.Endpoints) - { - // Legacy message require all endpoint's name equals to endpoint's id - // Guid.Empty is for repository endpoints - if (!String.Equals(endpoint.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase) && - endpoint.Id != Guid.Empty) - { - endpoint.Name = endpoint.Id.ToString("D"); - } - } - - // Make sure we propagate download ticket into the mask hints - foreach (var secureFile in message.Resources.SecureFiles) - { - if (!String.IsNullOrEmpty(secureFile.Ticket)) - { - message.MaskHints.Add(new MaskHint() { Type = MaskType.Regex, Value = Regex.Escape(secureFile.Ticket) }); - } - } - } - - if (String.Equals(message.Plan.PlanType, "Build", StringComparison.OrdinalIgnoreCase)) - { - // create repository endpoint base on checkout task + repository resource + repository endpoint - // repoResource might be null when environment verion is still on 1 - var repoResource = message.Resources?.Repositories.SingleOrDefault(); - if (repoResource != null) - { - var legacyRepoEndpoint = new ServiceEndpoint(); - legacyRepoEndpoint.Name = repoResource.Properties.Get(RepositoryPropertyNames.Name); - legacyRepoEndpoint.Type = ConvertToLegacySourceType(repoResource.Type); - legacyRepoEndpoint.Url = repoResource.Url; - if (repoResource.Endpoint != null) - { - var referencedEndpoint = message.Resources.Endpoints.First(x => (x.Id == repoResource.Endpoint.Id && x.Id != Guid.Empty) || (String.Equals(x.Name, repoResource.Endpoint.Name?.Literal, StringComparison.OrdinalIgnoreCase) && x.Id == Guid.Empty && repoResource.Endpoint.Id == Guid.Empty)); - var endpointAuthCopy = referencedEndpoint.Authorization?.Clone(); - if (endpointAuthCopy != null) - { - if (endpointAuthCopy.Scheme == EndpointAuthorizationSchemes.Token) //InstallationToken (Tabby) or ApiToken (GithubEnterprise) - { - if (referencedEndpoint.Authorization.Parameters.TryGetValue(EndpointAuthorizationParameters.AccessToken, out string accessToken)) //Tabby - { - legacyRepoEndpoint.Authorization = new EndpointAuthorization() - { - Scheme = EndpointAuthorizationSchemes.UsernamePassword, - Parameters = - { - { EndpointAuthorizationParameters.Username, "x-access-token" }, - { EndpointAuthorizationParameters.Password, accessToken } - } - }; - } - else if (referencedEndpoint.Authorization.Parameters.TryGetValue(EndpointAuthorizationParameters.ApiToken, out string apiToken)) //GithubEnterprise - { - legacyRepoEndpoint.Authorization = new EndpointAuthorization() - { - Scheme = EndpointAuthorizationSchemes.UsernamePassword, - Parameters = - { - { EndpointAuthorizationParameters.Username, apiToken }, - { EndpointAuthorizationParameters.Password, "x-oauth-basic" } - } - }; - } - } - else if (endpointAuthCopy.Scheme == EndpointAuthorizationSchemes.PersonalAccessToken) // Github - { - if (referencedEndpoint.Authorization.Parameters.TryGetValue(EndpointAuthorizationParameters.AccessToken, out string accessToken)) //Tabby - { - legacyRepoEndpoint.Authorization = new EndpointAuthorization() - { - Scheme = EndpointAuthorizationSchemes.UsernamePassword, - Parameters = - { - { EndpointAuthorizationParameters.Username, "pat" }, - { EndpointAuthorizationParameters.Password, accessToken } - } - }; - } - } - else - { - legacyRepoEndpoint.Authorization = endpointAuthCopy; - } - } - - // there are 2 properties we put into the legacy repo endpoint directly from connect endpoint - if (referencedEndpoint.Data.TryGetValue("acceptUntrustedCerts", out String acceptUntrustedCerts)) - { - legacyRepoEndpoint.Data["acceptUntrustedCerts"] = acceptUntrustedCerts; - } - if (referencedEndpoint.Data.TryGetValue("realmName", out String realmName)) - { - legacyRepoEndpoint.Data["realmName"] = realmName; - } - } - legacyRepoEndpoint.Data["repositoryId"] = repoResource.Id; - - // default values in the old message format - legacyRepoEndpoint.Data["clean"] = Boolean.FalseString; - legacyRepoEndpoint.Data["checkoutSubmodules"] = Boolean.FalseString; - legacyRepoEndpoint.Data["checkoutNestedSubmodules"] = Boolean.FalseString; - legacyRepoEndpoint.Data["fetchDepth"] = "0"; - legacyRepoEndpoint.Data["gitLfsSupport"] = Boolean.FalseString; - legacyRepoEndpoint.Data["skipSyncSource"] = Boolean.FalseString; - legacyRepoEndpoint.Data["cleanOptions"] = "0"; - legacyRepoEndpoint.Data["rootFolder"] = null; // old tfvc repo endpoint has this set to $/foo, but it doesn't seems to be used at all. - - if (repoResource.Type == RepositoryTypes.Tfvc) - { - var tfvcMapping = repoResource.Properties.Get>(RepositoryPropertyNames.Mappings); - if (tfvcMapping != null) - { - LegacyBuildWorkspace legacyMapping = new LegacyBuildWorkspace(); - foreach (var mapping in tfvcMapping) - { - legacyMapping.Mappings.Add(new LegacyMappingDetails() { ServerPath = mapping.ServerPath, LocalPath = mapping.LocalPath, MappingType = mapping.Exclude ? "cloak" : "map" }); - } - - legacyRepoEndpoint.Data["tfvcWorkspaceMapping"] = JsonUtility.ToString(legacyMapping); - } - } - else if (repoResource.Type == RepositoryTypes.Svn) - { - var svnMapping = repoResource.Properties.Get>(RepositoryPropertyNames.Mappings); - if (svnMapping != null) - { - LegacySvnWorkspace legacyMapping = new LegacySvnWorkspace(); - foreach (var mapping in svnMapping) - { - legacyMapping.Mappings.Add(new LegacySvnMappingDetails() { ServerPath = mapping.ServerPath, LocalPath = mapping.LocalPath, Depth = mapping.Depth, IgnoreExternals = mapping.IgnoreExternals, Revision = mapping.Revision }); - } - - legacyRepoEndpoint.Data["svnWorkspaceMapping"] = JsonUtility.ToString(legacyMapping); - } - } - else if (repoResource.Type == RepositoryTypes.Git) - { - if (message.Variables.TryGetValue(WellKnownDistributedTaskVariables.ServerType, out VariableValue serverType) && String.Equals(serverType?.Value, "Hosted", StringComparison.OrdinalIgnoreCase)) - { - legacyRepoEndpoint.Data["onpremtfsgit"] = Boolean.FalseString; - } - else - { - legacyRepoEndpoint.Data["onpremtfsgit"] = Boolean.TrueString; - } - } - - if (!message.Variables.ContainsKey("build.repository.id") || String.IsNullOrEmpty(message.Variables["build.repository.id"]?.Value)) - { - message.Variables["build.repository.id"] = repoResource.Id; - } - if (!message.Variables.ContainsKey("build.repository.name") || String.IsNullOrEmpty(message.Variables["build.repository.name"]?.Value)) - { - message.Variables["build.repository.name"] = repoResource.Properties.Get(RepositoryPropertyNames.Name); - } - if (!message.Variables.ContainsKey("build.repository.uri") || String.IsNullOrEmpty(message.Variables["build.repository.uri"]?.Value)) - { - message.Variables["build.repository.uri"] = repoResource.Url.AbsoluteUri; - } - - var versionInfo = repoResource.Properties.Get(RepositoryPropertyNames.VersionInfo); - if (!message.Variables.ContainsKey("build.sourceVersionAuthor") || String.IsNullOrEmpty(message.Variables["build.sourceVersionAuthor"]?.Value)) - { - message.Variables["build.sourceVersionAuthor"] = versionInfo?.Author; - } - if (!message.Variables.ContainsKey("build.sourceVersionMessage") || String.IsNullOrEmpty(message.Variables["build.sourceVersionMessage"]?.Value)) - { - message.Variables["build.sourceVersionMessage"] = versionInfo?.Message; - } - if (!message.Variables.ContainsKey("build.sourceVersion") || String.IsNullOrEmpty(message.Variables["build.sourceVersion"]?.Value)) - { - message.Variables["build.sourceVersion"] = repoResource.Version; - } - if (!message.Variables.ContainsKey("build.sourceBranch") || String.IsNullOrEmpty(message.Variables["build.sourceBranch"]?.Value)) - { - message.Variables["build.sourceBranch"] = repoResource.Properties.Get(RepositoryPropertyNames.Ref); - } - if (repoResource.Type == RepositoryTypes.Tfvc) - { - var shelveset = repoResource.Properties.Get(RepositoryPropertyNames.Shelveset); - if (!String.IsNullOrEmpty(shelveset) && (!message.Variables.ContainsKey("build.sourceTfvcShelveset") || String.IsNullOrEmpty(message.Variables["build.sourceTfvcShelveset"]?.Value))) - { - message.Variables["build.sourceTfvcShelveset"] = shelveset; - } - } - - TaskStep checkoutTask = message.Steps.FirstOrDefault(x => x.IsCheckoutTask()) as TaskStep; - if (checkoutTask != null) - { - if (checkoutTask.Inputs.TryGetValue(PipelineConstants.CheckoutTaskInputs.Clean, out string taskInputClean) && !string.IsNullOrEmpty(taskInputClean)) - { - legacyRepoEndpoint.Data["clean"] = taskInputClean; - } - else - { - legacyRepoEndpoint.Data["clean"] = Boolean.FalseString; - } - - if (checkoutTask.Inputs.TryGetValue(PipelineConstants.CheckoutTaskInputs.Submodules, out string taskInputSubmodules) && !string.IsNullOrEmpty(taskInputSubmodules)) - { - legacyRepoEndpoint.Data["checkoutSubmodules"] = Boolean.TrueString; - if (String.Equals(taskInputSubmodules, PipelineConstants.CheckoutTaskInputs.SubmodulesOptions.Recursive, StringComparison.OrdinalIgnoreCase)) - { - legacyRepoEndpoint.Data["checkoutNestedSubmodules"] = Boolean.TrueString; - } - } - - if (checkoutTask.Inputs.TryGetValue(PipelineConstants.CheckoutTaskInputs.FetchDepth, out string taskInputFetchDepth) && !string.IsNullOrEmpty(taskInputFetchDepth)) - { - legacyRepoEndpoint.Data["fetchDepth"] = taskInputFetchDepth; - } - - if (checkoutTask.Inputs.TryGetValue(PipelineConstants.CheckoutTaskInputs.Lfs, out string taskInputfs) && !string.IsNullOrEmpty(taskInputfs)) - { - legacyRepoEndpoint.Data["gitLfsSupport"] = taskInputfs; - } - - // Skip sync sources - if (String.Equals(checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.Repository], PipelineConstants.NoneAlias, StringComparison.OrdinalIgnoreCase)) - { - legacyRepoEndpoint.Data["skipSyncSource"] = Boolean.TrueString; - } - else if (String.Equals(checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.Repository], PipelineConstants.DesignerRepo, StringComparison.OrdinalIgnoreCase) && checkoutTask.Condition == Boolean.FalseString) - { - legacyRepoEndpoint.Data["skipSyncSource"] = Boolean.TrueString; - } - } - - // workspace clean options - legacyRepoEndpoint.Data["cleanOptions"] = "0"; // RepositoryCleanOptions.Source; - if (message.Workspace != null) - { - if (String.Equals(message.Workspace.Clean, PipelineConstants.WorkspaceCleanOptions.Outputs, StringComparison.OrdinalIgnoreCase)) - { - legacyRepoEndpoint.Data["cleanOptions"] = "1"; // RepositoryCleanOptions.SourceAndOutputDir; - } - else if (String.Equals(message.Workspace.Clean, PipelineConstants.WorkspaceCleanOptions.Resources, StringComparison.OrdinalIgnoreCase)) - { - legacyRepoEndpoint.Data["cleanOptions"] = "2"; //RepositoryCleanOptions.SourceDir; - } - else if (String.Equals(message.Workspace.Clean, PipelineConstants.WorkspaceCleanOptions.All, StringComparison.OrdinalIgnoreCase)) - { - legacyRepoEndpoint.Data["cleanOptions"] = "3"; // RepositoryCleanOptions.AllBuildDir; - } - } - - // add reposiotry endpoint to environment - message.Resources.Endpoints.Add(legacyRepoEndpoint); - } - } - - JobEnvironment environment = new JobEnvironment(message.Variables, message.MaskHints, message.Resources); - - WebApi.AgentJobRequestMessage legacyAgentRequestMessage = new WebApi.AgentJobRequestMessage(message.Plan, message.Timeline, message.JobId, message.JobDisplayName, message.JobName, environment, tasks) - { - RequestId = message.RequestId - }; - - return legacyAgentRequestMessage; - } - - private static string ConvertLegacySourceType(string legacySourceType) - { - if (String.Equals(legacySourceType, LegacyRepositoryTypes.Bitbucket, StringComparison.OrdinalIgnoreCase)) - { - return RepositoryTypes.Bitbucket; - } - else if (String.Equals(legacySourceType, LegacyRepositoryTypes.Git, StringComparison.OrdinalIgnoreCase)) - { - return RepositoryTypes.ExternalGit; - } - else if (String.Equals(legacySourceType, LegacyRepositoryTypes.TfsGit, StringComparison.OrdinalIgnoreCase)) - { - return RepositoryTypes.Git; - } - else if (String.Equals(legacySourceType, LegacyRepositoryTypes.GitHub, StringComparison.OrdinalIgnoreCase)) - { - return RepositoryTypes.GitHub; - } - else if (String.Equals(legacySourceType, LegacyRepositoryTypes.GitHubEnterprise, StringComparison.OrdinalIgnoreCase)) - { - return RepositoryTypes.GitHubEnterprise; - } - else if (String.Equals(legacySourceType, LegacyRepositoryTypes.Svn, StringComparison.OrdinalIgnoreCase)) - { - return RepositoryTypes.Svn; - } - else if (String.Equals(legacySourceType, LegacyRepositoryTypes.TfsVersionControl, StringComparison.OrdinalIgnoreCase)) - { - return RepositoryTypes.Tfvc; - } - else - { - throw new NotSupportedException(legacySourceType); - } - } - - private static string ConvertToLegacySourceType(string pipelineSourceType) - { - if (String.Equals(pipelineSourceType, RepositoryTypes.Bitbucket, StringComparison.OrdinalIgnoreCase)) - { - return LegacyRepositoryTypes.Bitbucket; - } - else if (String.Equals(pipelineSourceType, RepositoryTypes.ExternalGit, StringComparison.OrdinalIgnoreCase)) - { - return LegacyRepositoryTypes.Git; - } - else if (String.Equals(pipelineSourceType, RepositoryTypes.Git, StringComparison.OrdinalIgnoreCase)) - { - return LegacyRepositoryTypes.TfsGit; - } - else if (String.Equals(pipelineSourceType, RepositoryTypes.GitHub, StringComparison.OrdinalIgnoreCase)) - { - return LegacyRepositoryTypes.GitHub; - } - else if (String.Equals(pipelineSourceType, RepositoryTypes.GitHubEnterprise, StringComparison.OrdinalIgnoreCase)) - { - return LegacyRepositoryTypes.GitHubEnterprise; - } - else if (String.Equals(pipelineSourceType, RepositoryTypes.Svn, StringComparison.OrdinalIgnoreCase)) - { - return LegacyRepositoryTypes.Svn; - } - else if (String.Equals(pipelineSourceType, RepositoryTypes.Tfvc, StringComparison.OrdinalIgnoreCase)) - { - return LegacyRepositoryTypes.TfsVersionControl; - } - else - { - throw new NotSupportedException(pipelineSourceType); - } - } - - private static class LegacyRepositoryTypes // Copy from Build.Webapi - { - public const String TfsVersionControl = "TfsVersionControl"; - public const String TfsGit = "TfsGit"; - public const String Git = "Git"; - public const String GitHub = "GitHub"; - public const String GitHubEnterprise = "GitHubEnterprise"; - public const String Bitbucket = "Bitbucket"; - public const String Svn = "Svn"; - } - - /// - /// Represents an entry in a workspace mapping. - /// - [DataContract] - private class LegacyMappingDetails - { - /// - /// The server path. - /// - [DataMember(Name = "serverPath")] - public String ServerPath - { - get; - set; - } - - /// - /// The mapping type. - /// - [DataMember(Name = "mappingType")] - public String MappingType - { - get; - set; - } - - /// - /// The local path. - /// - [DataMember(Name = "localPath")] - public String LocalPath - { - get; - set; - } - } - - /// - /// Represents a workspace mapping. - /// - [DataContract] - private class LegacyBuildWorkspace - { - /// - /// The list of workspace mapping entries. - /// - public List Mappings - { - get - { - if (m_mappings == null) - { - m_mappings = new List(); - } - return m_mappings; - } - } - - [DataMember(Name = "mappings")] - private List m_mappings; - } - - /// - /// Represents a Subversion mapping entry. - /// - [DataContract] - private class LegacySvnMappingDetails - { - /// - /// The server path. - /// - [DataMember(Name = "serverPath")] - public String ServerPath - { - get; - set; - } - - /// - /// The local path. - /// - [DataMember(Name = "localPath")] - public String LocalPath - { - get; - set; - } - - /// - /// The revision. - /// - [DataMember(Name = "revision")] - public String Revision - { - get; - set; - } - - /// - /// The depth. - /// - [DataMember(Name = "depth")] - public Int32 Depth - { - get; - set; - } - - /// - /// Indicates whether to ignore externals. - /// - [DataMember(Name = "ignoreExternals")] - public bool IgnoreExternals - { - get; - set; - } - } - - /// - /// Represents a subversion workspace. - /// - [DataContract] - private class LegacySvnWorkspace - { - /// - /// The list of mappings. - /// - public List Mappings - { - get - { - if (m_Mappings == null) - { - m_Mappings = new List(); - } - return m_Mappings; - } - } - - [DataMember(Name = "mappings")] - private List m_Mappings; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/AgentPoolReference.cs b/src/Sdk/DTPipelines/Pipelines/AgentPoolReference.cs deleted file mode 100644 index 9fd06febe..000000000 --- a/src/Sdk/DTPipelines/Pipelines/AgentPoolReference.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class AgentPoolReference : ResourceReference - { - public AgentPoolReference() - { - } - - private AgentPoolReference(AgentPoolReference referenceToCopy) - : base(referenceToCopy) - { - this.Id = referenceToCopy.Id; - } - - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - set; - } - - public AgentPoolReference Clone() - { - return new AgentPoolReference(this); - } - - public override String ToString() - { - return base.ToString() ?? this.Id.ToString(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/AgentPoolStore.cs b/src/Sdk/DTPipelines/Pipelines/AgentPoolStore.cs deleted file mode 100644 index e745c85ad..000000000 --- a/src/Sdk/DTPipelines/Pipelines/AgentPoolStore.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class AgentPoolStore : IAgentPoolStore - { - public AgentPoolStore( - IList pools, - IAgentPoolResolver resolver = null) - { - this.Resolver = resolver; - Add(pools?.ToArray()); - } - - /// - /// Get the queue resolver configured for this store. - /// - public IAgentPoolResolver Resolver - { - get; - } - - public void Authorize(IList pools) - { - if (pools?.Count > 0) - { - foreach (var pool in pools) - { - var authorizedResource = this.Resolver?.Resolve(pool); - if (authorizedResource != null) - { - Add(authorizedResource); - } - } - } - } - - public IList GetAuthorizedReferences() - { - return m_resourcesById.Values.Select(x => new AgentPoolReference { Id = x.Id }).ToList(); - } - - public TaskAgentPool Get(AgentPoolReference reference) - { - if (reference == null) - { - return null; - } - - var referenceId = reference.Id; - var referenceName = reference.Name?.Literal; - if (reference.Id == 0 && String.IsNullOrEmpty(referenceName)) - { - return null; - } - - TaskAgentPool authorizedResource = null; - if (referenceId != 0) - { - if (m_resourcesById.TryGetValue(referenceId, out authorizedResource)) - { - return authorizedResource; - } - } - else if (!String.IsNullOrEmpty(referenceName)) - { - if (m_resourcesByName.TryGetValue(referenceName, out authorizedResource)) - { - return authorizedResource; - } - } - - // If we have an authorizer then attempt to authorize the reference for use - authorizedResource = this.Resolver?.Resolve(reference); - if (authorizedResource != null) - { - Add(authorizedResource); - } - - return authorizedResource; - } - - private void Add(params TaskAgentPool[] resources) - { - if (resources?.Length > 0) - { - foreach (var resource in resources) - { - // Track by ID - if (m_resourcesById.TryGetValue(resource.Id, out _)) - { - continue; - } - - m_resourcesById.Add(resource.Id, resource); - - // Track by name - if (m_resourcesByName.TryGetValue(resource.Name, out _)) - { - continue; - } - - m_resourcesByName.Add(resource.Name, resource); - } - } - } - - private readonly Dictionary m_resourcesById = new Dictionary(); - private readonly Dictionary m_resourcesByName = new Dictionary(StringComparer.OrdinalIgnoreCase); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/AgentPoolTarget.cs b/src/Sdk/DTPipelines/Pipelines/AgentPoolTarget.cs deleted file mode 100644 index 6e1125b4e..000000000 --- a/src/Sdk/DTPipelines/Pipelines/AgentPoolTarget.cs +++ /dev/null @@ -1,169 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class AgentPoolTarget : PhaseTarget - { - public AgentPoolTarget() - : base(PhaseTargetType.Pool) - { - } - - private AgentPoolTarget(AgentPoolTarget targetToClone) - : base(targetToClone) - { - this.Pool = targetToClone.Pool?.Clone(); - - - if (targetToClone.AgentSpecification != null) - { - this.AgentSpecification = new JObject(targetToClone.AgentSpecification); - } - - if (targetToClone.m_agentIds?.Count > 0) - { - this.m_agentIds = targetToClone.m_agentIds; - } - } - - /// - /// Gets or sets the target pool from which agents will be selected. - /// - [DataMember(EmitDefaultValue = false)] - public AgentPoolReference Pool - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public JObject AgentSpecification - { - get; - set; - } - - /// - /// Gets agent Ids filter on which deployment should be done. - /// - public List AgentIds - { - get - { - if (m_agentIds == null) - { - m_agentIds = new List(); - } - return m_agentIds; - } - } - - public override PhaseTarget Clone() - { - return new AgentPoolTarget(this); - } - - public override Boolean IsValid(TaskDefinition task) - { - ArgumentUtility.CheckForNull(task, nameof(task)); - return task.RunsOn.Contains(TaskRunsOnConstants.RunsOnAgent, StringComparer.OrdinalIgnoreCase); - } - - internal override void Validate( - IPipelineContext context, - BuildOptions buildOptions, - ValidationResult result, - IList steps, - ISet taskDemands) - { - // validate pool - Int32 poolId = 0; - String poolName = null; - var pool = this.Pool; - if (pool != null) - { - poolId = pool.Id; - poolName = pool.Name?.GetValue(context)?.Value; - } - - if (poolId == 0 && String.IsNullOrEmpty(poolName) && buildOptions.ValidateResources) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.QueueNotDefined())); - } - else - { - // we have a valid queue. record the reference - result.AddPoolReference(poolId, poolName); - - // Attempt to resolve the queue using any identifier specified. We will look up by either ID - // or name and the ID is preferred since it is immutable and more specific. - if (buildOptions.ValidateResources) - { - TaskAgentPool taskAgentPool = null; - var resourceStore = context.ResourceStore; - if (resourceStore != null) - { - if (poolId != 0) - { - taskAgentPool = resourceStore.GetPool(poolId); - if (taskAgentPool == null) - { - result.UnauthorizedResources.Pools.Add(new AgentPoolReference { Id = poolId }); - result.Errors.Add(new PipelineValidationError(PipelineStrings.QueueNotFound(poolId))); - } - } - else if (!String.IsNullOrEmpty(poolName)) - { - taskAgentPool = resourceStore.GetPool(poolName); - if (taskAgentPool == null) - { - result.UnauthorizedResources.Pools.Add(new AgentPoolReference { Name = poolName }); - result.Errors.Add(new PipelineValidationError(PipelineStrings.QueueNotFound(poolName))); - } - } - } - - // Store the resolved values inline to the resolved resource for this validation run - if (taskAgentPool != null) - { - this.Pool.Id = taskAgentPool.Id; - this.Pool.Name = taskAgentPool.Name; - } - } - } - } - - internal override JobExecutionContext CreateJobContext(PhaseExecutionContext context, string jobName, int attempt, bool continueOnError, int timeoutInMinutes, int cancelTimeoutInMinutes, IJobFactory jobFactory) - { - throw new NotSupportedException(nameof(AgentPoolTarget)); - } - - internal override ExpandPhaseResult Expand(PhaseExecutionContext context, bool continueOnError, int timeoutInMinutes, int cancelTimeoutInMinutes, IJobFactory jobFactory, JobExpansionOptions options) - { - throw new NotSupportedException(nameof(AgentPoolTarget)); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_agentIds?.Count == 0) - { - m_agentIds = null; - } - } - - [DataMember(Name = "AgentIds", EmitDefaultValue = false)] - private List m_agentIds; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/AgentQueueReference.cs b/src/Sdk/DTPipelines/Pipelines/AgentQueueReference.cs deleted file mode 100644 index 9e80f0bcd..000000000 --- a/src/Sdk/DTPipelines/Pipelines/AgentQueueReference.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class AgentQueueReference : ResourceReference - { - public AgentQueueReference() - { - } - - private AgentQueueReference(AgentQueueReference referenceToCopy) - : base(referenceToCopy) - { - this.Id = referenceToCopy.Id; - } - - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - set; - } - - public AgentQueueReference Clone() - { - return new AgentQueueReference(this); - } - - public override String ToString() - { - return base.ToString() ?? this.Id.ToString(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/AgentQueueStore.cs b/src/Sdk/DTPipelines/Pipelines/AgentQueueStore.cs deleted file mode 100644 index b6f8582e4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/AgentQueueStore.cs +++ /dev/null @@ -1,161 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class AgentQueueStore : IAgentQueueStore - { - public AgentQueueStore( - IList queues, - IAgentQueueResolver resolver = null) - { - this.Resolver = resolver; - Add(queues?.ToArray()); - } - - /// - /// Get the queue resolver configured for this store. - /// - public IAgentQueueResolver Resolver - { - get; - } - - public void Authorize(IList queues) - { - if (queues?.Count > 0) - { - foreach (var queue in queues) - { - Add(queue); - } - } - } - - public IList GetAuthorizedReferences() - { - return m_resourcesById.Values.Select(x => new AgentQueueReference { Id = x.Id }).ToList(); - } - - public TaskAgentQueue Get(AgentQueueReference reference) - { - if (reference == null) - { - return null; - } - - var referenceId = reference.Id; - var referenceName = reference.Name?.Literal; - if (reference.Id == 0 && String.IsNullOrEmpty(referenceName)) - { - return null; - } - - TaskAgentQueue authorizedResource = null; - if (referenceId != 0) - { - if (m_resourcesById.TryGetValue(referenceId, out authorizedResource)) - { - return authorizedResource; - } - } - else if (!String.IsNullOrEmpty(referenceName)) - { - if (m_resourcesByName.TryGetValue(referenceName, out List matchingResources)) - { - if (matchingResources.Count > 1) - { - throw new AmbiguousResourceSpecificationException(PipelineStrings.AmbiguousServiceEndpointSpecification(referenceId)); - } - - return matchingResources[0]; - } - } - - // If we have an authorizer then attempt to authorize the reference for use - authorizedResource = this.Resolver?.Resolve(reference); - if (authorizedResource != null) - { - Add(authorizedResource); - } - - return authorizedResource; - } - - private void Add(params TaskAgentQueue[] resources) - { - if (resources?.Length > 0) - { - foreach (var resource in resources) - { - // Track by ID - if (m_resourcesById.TryGetValue(resource.Id, out _)) - { - continue; - } - - m_resourcesById.Add(resource.Id, resource); - - // not all references have names - var name = resource.Name; - if (string.IsNullOrWhiteSpace(name)) - { - continue; - } - - // Track by name - if (!m_resourcesByName.TryGetValue(name, out var list)) - { - list = new List(); - m_resourcesByName.Add(name, list); - } - - // Clobber previously added alternate name, with the real hosted queue. - // For example, during the "Hosted macOS High Sierra" transition, until the real queue - // existed, it was treated as an alternate name for the "Hosted macOS" queue. After the - // real "Hosted macOS High Sierra" queue was created, it took priority. - if (list.Count > 0 && list[0].Pool?.IsHosted == true && resource.Pool?.IsHosted == true) - { - list[0] = resource; - } - // Otherwise add the queue - else - { - list.Add(resource); - } - - // Track by alternate name for specific hosted pools. - // For example, "Hosted macOS Preview" and "Hosted macOS" are equivalent. - if (resource.Pool?.IsHosted == true && s_alternateNames.TryGetValue(name, out var alternateNames)) - { - foreach (var alternateName in alternateNames) - { - if (!m_resourcesByName.TryGetValue(alternateName, out list)) - { - list = new List(); - m_resourcesByName.Add(alternateName, list); - } - - if (list.Count == 0 || list[0].Pool?.IsHosted != true) - { - list.Add(resource); - } - } - } - } - } - } - - private static readonly Dictionary s_alternateNames = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - { "Hosted macOS", new[] { "Hosted macOS Preview" } }, - { "Hosted macOS Preview", new[] { "Hosted macOS" } }, - }; - private readonly Dictionary m_resourcesById = new Dictionary(); - private readonly Dictionary> m_resourcesByName = new Dictionary>(StringComparer.OrdinalIgnoreCase); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/AgentQueueTarget.cs b/src/Sdk/DTPipelines/Pipelines/AgentQueueTarget.cs deleted file mode 100644 index 938009af4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/AgentQueueTarget.cs +++ /dev/null @@ -1,647 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides options for phase execution on an agent within a queue. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class AgentQueueTarget : PhaseTarget - { - public AgentQueueTarget() - : base(PhaseTargetType.Queue) - { - } - - private AgentQueueTarget(AgentQueueTarget targetToClone) - : base(targetToClone) - { - this.Queue = targetToClone.Queue?.Clone(); - this.Execution = targetToClone.Execution?.Clone(); - - if (targetToClone.AgentSpecification != null) - { - this.AgentSpecification = new JObject(targetToClone.AgentSpecification); - } - - if (targetToClone.SidecarContainers?.Count > 0) - { - m_sidecarContainers = new Dictionary>(targetToClone.SidecarContainers, StringComparer.OrdinalIgnoreCase); - } - } - - /// - /// Gets or sets the target queue from which agents will be selected. - /// - [DataMember(EmitDefaultValue = false)] - [JsonConverter(typeof(QueueJsonConverter))] - public AgentQueueReference Queue - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public JObject AgentSpecification - { - get; - set; - } - - /// - /// Gets or sets parallel execution options which control expansion and execution of the phase. - /// - [DataMember(EmitDefaultValue = false)] - public ParallelExecutionOptions Execution - { - get; - set; - } - - /// - /// Gets or sets workspace options which control how agent manage the workspace of the phase. - /// - [DataMember(EmitDefaultValue = false)] - public WorkspaceOptions Workspace - { - get; - set; - } - - /// - /// Gets or sets the container the phase will be run in. - /// - [DataMember(EmitDefaultValue = false)] - [JsonConverter(typeof(ExpressionValueJsonConverter))] - public ExpressionValue Container - { - get; - set; - } - - /// - /// Gets the sidecar containers that will run alongside the phase. - /// - public IDictionary> SidecarContainers - { - get - { - if (m_sidecarContainers == null) - { - m_sidecarContainers = new Dictionary>(StringComparer.OrdinalIgnoreCase); - } - return m_sidecarContainers; - } - } - - public override PhaseTarget Clone() - { - return new AgentQueueTarget(this); - } - - public override Boolean IsValid(TaskDefinition task) - { - ArgumentUtility.CheckForNull(task, nameof(task)); - return task.RunsOn.Contains(TaskRunsOnConstants.RunsOnAgent, StringComparer.OrdinalIgnoreCase); - } - - /// - /// Creates a clone of this and attempts to resolve all expressions and macros. - /// - internal AgentQueueTarget Evaluate( - IPipelineContext context, - ValidationResult result) - { - var qname = String.Empty; - try - { - qname = context.ExpandVariables(this.Queue?.Name?.GetValue(context).Value); - } - catch (DistributedTask.Expressions.ExpressionException ee) - { - result.Errors.Add(new PipelineValidationError(ee.Message)); - return null; - } - - var literalTarget = this.Clone() as AgentQueueTarget; - - var spec = this.AgentSpecification; - if (spec != null) - { - spec = context.Evaluate(this.AgentSpecification).Value; - literalTarget.AgentSpecification = spec; - } - - // Note! The "vmImage" token of the agent spec is currently treated specially. - // This is a temporary relationship that allows vmImage agent specs to specify - // the hosted pool to use. - // It would be better to factor out this work into a separate, plug-in validator. - if (String.IsNullOrEmpty(qname) && spec != null) - { - const string VMImage = "vmImage"; // should be: YamlConstants.VMImage, which is inaccessible :( - spec.TryGetValue(VMImage, out var token); - if (token != null && token.Type == JTokenType.String) - { - var rawTokenValue = token.Value(); - var resolvedPoolName = PoolNameForVMImage(rawTokenValue); - if (resolvedPoolName == null) - { - result.Errors.Add(new PipelineValidationError($"Unexpected vmImage '{rawTokenValue}'")); - return null; - } - else - { - spec.Remove(VMImage); - literalTarget.Queue = new AgentQueueReference - { - Name = resolvedPoolName - }; - } - } - } - else - { - literalTarget.Queue.Name = qname; - } - - return literalTarget; - } - - /// - /// returns true for strings structured like expressions or macros. - /// they could techincally be literals though. - /// - internal static Boolean IsProbablyExpressionOrMacro(String s) - { - return ExpressionValue.IsExpression(s) || VariableUtility.IsVariable(s); - } - - /// - /// returns true if this model is composed only of literal values (no expressions) - /// - internal Boolean IsLiteral() - { - var queue = this.Queue; - if (queue != null) - { - var queueName = queue.Name; - if (queueName != null) - { - if (!queueName.IsLiteral || VariableUtility.IsVariable(queueName.Literal)) - { - return false; - } - } - } - - var spec = this.AgentSpecification; - if (spec != null) - { - bool IsLiteral(JObject o) - { - foreach (var pair in o) - { - switch (pair.Value.Type) - { - case JTokenType.String: - if (IsProbablyExpressionOrMacro(pair.Value.Value())) - { - return false; - } - break; - case JTokenType.Object: - if (!IsLiteral(pair.Value.Value())) - { - return false; - } - break; - default: - break; - } - } - - return true; - } - - if (!IsLiteral(spec)) - { - return false; - } - } - - return true; - } - - /// - /// Temporary code to translate vmImage. Pool providers work will move this to a different layer - /// - /// - /// Hosted pool name - internal static String PoolNameForVMImage(String vmImageValue) - { - switch ((vmImageValue ?? String.Empty).ToUpperInvariant()) - { - case "UBUNTU 16.04": - case "UBUNTU-16.04": - case "UBUNTU LATEST": - case "UBUNTU-LATEST": - return "Hosted Ubuntu 1604"; - case "UBUNTU 18.04": - case "UBUNTU-18.04": - return "Hosted Ubuntu 1804"; - case "VISUAL STUDIO 2015 ON WINDOWS SERVER 2012R2": - case "VS2015-WIN2012R2": - return "Hosted"; - case "VISUAL STUDIO 2017 ON WINDOWS SERVER 2016": - case "VS2017-WIN2016": - return "Hosted VS2017"; - case "WINDOWS-2019-VS2019": - case "WINDOWS-2019": - case "WINDOWS LATEST": - case "WINDOWS-LATEST": - return "Hosted Windows 2019 with VS2019"; - case "WINDOWS SERVER 1803": - case "WIN1803": - return "Hosted Windows Container"; - case "MACOS 10.13": - case "MACOS-10.13": - case "XCODE 9 ON MACOS 10.13": - case "XCODE9-MACOS10.13": - case "XCODE 10 ON MACOS 10.13": - case "XCODE10-MACOS10.13": - return "Hosted macOS High Sierra"; - case "MACOS 10.14": - case "MACOS-10.14": - case "MACOS LATEST": - case "MACOS-LATEST": - return "Hosted macOS"; - default: - return null; - } - } - - /// - /// PipelineBuildContexts have build options. - /// GraphExecutionContexts have dependencies. - /// We might need either depending on the situation. - /// - private TaskAgentPoolReference ValidateQueue( - IPipelineContext context, - ValidationResult result, - BuildOptions buildOptions) - { - var queueId = 0; - var queueName = (String)null; - var queueNameIsUnresolvableExpression = false; // true iff Name is an expression, we're allowed to use them, and it has no current value - var queue = this.Queue; - if (queue != null) - { - queueId = queue.Id; - - // resolve name - var expressionValueName = queue.Name; - if (expressionValueName != null && (buildOptions.EnableResourceExpressions || expressionValueName.IsLiteral)) - { - // resolve expression - try - { - queueName = expressionValueName.GetValue(context).Value; - queueNameIsUnresolvableExpression = !expressionValueName.IsLiteral && String.IsNullOrEmpty(queueName); - } - catch (Exception ee) - { - // something bad happened trying to fetch the value. - // We do not really care what though. Just record the error and move on. - queueName = null; - - if (buildOptions.ValidateExpressions && buildOptions.ValidateResources) - { - result.Errors.Add(new PipelineValidationError(ee.Message)); - } - } - - // resolve name macro - if (buildOptions.EnableResourceExpressions && queueName != null && VariableUtility.IsVariable(queueName)) - { - queueName = context.ExpandVariables(queueName); - if (VariableUtility.IsVariable(queueName)) - { - // name appears to be a macro that is not defined. - queueNameIsUnresolvableExpression = true; - } - } - } - } - - if (queueNameIsUnresolvableExpression || (queueId == 0 && String.IsNullOrEmpty(queueName))) - { - // could not determine what queue user was talking about - if (!buildOptions.AllowEmptyQueueTarget && buildOptions.ValidateResources) - { - // expression-based queue names are allowed to be unresolved at compile time. - // TEMPORARY: literal queue names do not error at compile time if special keys exist - if (!queueNameIsUnresolvableExpression || buildOptions.ValidateExpressions) - { - if (!String.IsNullOrEmpty(queueName)) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.QueueNotFoundByName(queueName))); - } - else - { - var expressionValueName = queue?.Name; - if (expressionValueName == null || expressionValueName.IsLiteral) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.QueueNotDefined())); - } - else if (expressionValueName != null) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.QueueNotFoundByName(expressionValueName.Expression))); - } - } - } - } - } - else - { - // we have a valid queue. record the reference - result.AddQueueReference(id: queueId, name: queueName); - - // Attempt to resolve the queue using any identifier specified. We will look up by either ID - // or name and the ID is preferred since it is immutable and more specific. - if (buildOptions.ValidateResources) - { - TaskAgentQueue taskAgentQueue = null; - var resourceStore = context.ResourceStore; - if (resourceStore != null) - { - if (queueId != 0) - { - taskAgentQueue = resourceStore.GetQueue(queueId); - if (taskAgentQueue == null) - { - result.UnauthorizedResources.Queues.Add(new AgentQueueReference { Id = queueId }); - result.Errors.Add(new PipelineValidationError(PipelineStrings.QueueNotFound(queueId))); - } - } - else if (!String.IsNullOrEmpty(queueName)) - { - taskAgentQueue = resourceStore.GetQueue(queueName); - if (taskAgentQueue == null) - { - result.UnauthorizedResources.Queues.Add(new AgentQueueReference { Name = queueName }); - result.Errors.Add(new PipelineValidationError(PipelineStrings.QueueNotFoundByName(queueName))); - } - } - } - - // Store the resolved values inline to the resolved resource for this validation run - if (taskAgentQueue != null) - { - this.Queue.Id = taskAgentQueue.Id; - return taskAgentQueue.Pool; - } - } - } - - return null; - } - - internal override void Validate( - IPipelineContext context, - BuildOptions buildOptions, - ValidationResult result, - IList steps, - ISet taskDemands) - { - // validate queue - var resolvedPool = ValidateQueue(context, result, buildOptions); - Boolean includeTaskDemands = resolvedPool == null || !resolvedPool.IsHosted; - - // Add advanced-checkout min agent demand - Boolean advancedCheckout = false; - int checkoutTasks = 0; - int injectedSystemTasks = 0; - bool countInjectSystemTasks = true; - for (int index = 0; index < steps.Count; index++) - { - var step = steps[index]; - // Task - if (step.Type == StepType.Task) - { - var task = step as TaskStep; - if (task.Name.StartsWith("__system_")) - { - if (countInjectSystemTasks) - { - injectedSystemTasks++; - } - } - else if (task.IsCheckoutTask()) - { - countInjectSystemTasks = false; - checkoutTasks++; - if (context.EnvironmentVersion < 2) - { - if (index > 0 && index - injectedSystemTasks > 0) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.CheckoutMustBeTheFirstStep())); - } - } - else - { - if (index > 0) - { - advancedCheckout = true; - } - } - - if (task.Inputs.TryGetValue(PipelineConstants.CheckoutTaskInputs.Repository, out String repository) && - !String.Equals(repository, PipelineConstants.SelfAlias, StringComparison.OrdinalIgnoreCase) && - !String.Equals(repository, PipelineConstants.NoneAlias, StringComparison.OrdinalIgnoreCase) && - !String.Equals(repository, PipelineConstants.DesignerRepo, StringComparison.OrdinalIgnoreCase)) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.CheckoutStepRepositoryNotSupported(task.Inputs[PipelineConstants.CheckoutTaskInputs.Repository]))); - } - } - else - { - countInjectSystemTasks = false; - } - } - } - - if (checkoutTasks > 1) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.CheckoutMultipleRepositoryNotSupported())); - } - - if (advancedCheckout) - { - taskDemands.Add(new DemandMinimumVersion(PipelineConstants.AgentVersionDemandName, PipelineConstants.AdvancedCheckoutMinAgentVersion)); - } - - // Now we need to ensure we have only a single demand for the mimimum agent version. We effectively remove - // every agent version demand we find and keep track of the one with the highest value. Assuming we located - // one or more of these demands we will ensure it is merged in at the end. - var minimumAgentVersionDemand = ResolveAgentVersionDemand(taskDemands); - minimumAgentVersionDemand = ResolveAgentVersionDemand(this.Demands, minimumAgentVersionDemand); - - // not include demands from task if phase is running inside container - // container suppose provide any required tool task needs - if (this.Container != null) - { - includeTaskDemands = false; - } - - // Merge the phase demands with the implicit demands from tasks. - if (includeTaskDemands && buildOptions.RollupStepDemands) - { - this.Demands.UnionWith(taskDemands); - } - - // If we resolved a minimum agent version demand then we go ahead and merge it in - // We want to do this even if targetting Hosted - if (minimumAgentVersionDemand != null) - { - this.Demands.Add(minimumAgentVersionDemand); - } - } - - private static DemandMinimumVersion ResolveAgentVersionDemand( - ISet demands, - DemandMinimumVersion currentMinimumVersion = null) - { - var minVersionDemand = DemandMinimumVersion.MaxAndRemove(demands); - if (minVersionDemand != null && (currentMinimumVersion == null || DemandMinimumVersion.CompareVersion(minVersionDemand.Value, currentMinimumVersion.Value) > 0)) - { - return minVersionDemand; - } - else - { - return currentMinimumVersion; - } - } - - internal override JobExecutionContext CreateJobContext( - PhaseExecutionContext context, - String jobName, - Int32 attempt, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory) - { - context.Trace?.EnterProperty("CreateJobContext"); - var execution = this.Execution ?? new ParallelExecutionOptions(); - var jobContext = execution.CreateJobContext( - context, - jobName, - attempt, - this.Container, - this.SidecarContainers, - continueOnError, - timeoutInMinutes, - cancelTimeoutInMinutes, - jobFactory); - context.Trace?.LeaveProperty("CreateJobContext"); - - if (jobContext != null) - { - jobContext.Job.Definition.Workspace = this.Workspace?.Clone(); - } - - return jobContext; - } - - internal override ExpandPhaseResult Expand( - PhaseExecutionContext context, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory, - JobExpansionOptions options) - { - context.Trace?.EnterProperty("Expand"); - var execution = this.Execution ?? new ParallelExecutionOptions(); - var result = execution.Expand( - context, - this.Container, - this.SidecarContainers, - continueOnError, - timeoutInMinutes, - cancelTimeoutInMinutes, - jobFactory, - options); - context.Trace?.LeaveProperty("Expand"); - - foreach (var job in result.Jobs) - { - job.Definition.Workspace = this.Workspace?.Clone(); - } - - return result; - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_sidecarContainers?.Count == 0) - { - m_sidecarContainers = null; - } - } - - [DataMember(Name = "SidecarContainers", EmitDefaultValue = false)] - private IDictionary> m_sidecarContainers; - - /// - /// Ensures conversion of a TaskAgentQueue into an AgentQueueReference works properly when the serializer - /// is configured to write/honor type information. This is a temporary converter that may be removed after - /// M127 ships. - /// - private sealed class QueueJsonConverter : VssSecureJsonConverter - { - public override Boolean CanWrite => false; - - public override Boolean CanConvert(Type objectType) - { - return objectType.Equals(typeof(AgentQueueReference)); - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - var rawValue = JObject.Load(reader); - using (var objectReader = rawValue.CreateReader()) - { - var newValue = new AgentQueueReference(); - serializer.Populate(objectReader, newValue); - return newValue; - } - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Artifacts/ArtifactConstants.cs b/src/Sdk/DTPipelines/Pipelines/Artifacts/ArtifactConstants.cs deleted file mode 100644 index 790250359..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Artifacts/ArtifactConstants.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Pipelines.Artifacts -{ - public static class ArtifactConstants - { - internal static class ArtifactType - { - internal const String Build = nameof(Build); - internal const String Container = nameof(Container); - internal const String Package = nameof(Package); - internal const String SourceControl = nameof(SourceControl); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Artifacts/DownloadStepExtensions.cs b/src/Sdk/DTPipelines/Pipelines/Artifacts/DownloadStepExtensions.cs deleted file mode 100644 index 192e71bd2..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Artifacts/DownloadStepExtensions.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Collections.Generic; - -using GitHub.DistributedTask.Pipelines; -using GitHub.DistributedTask.Pipelines.Artifacts; -namespace GitHub.DistributedTask.Orchestration.Server.Artifacts -{ - public static class DownloadStepExtensions - { - public static Boolean IsDownloadBuildStepExists(this IReadOnlyList steps) - { - foreach (var step in steps) - { - if (step is TaskStep taskStep) - { - if (taskStep.IsDownloadBuildTask()) - { - return true; - } - } - } - - return false; - } - - public static Boolean IsDownloadBuildTask(this Step step) - { - if (step is TaskStep taskStep && - taskStep.Reference != null && - taskStep.Reference.Name.Equals(YamlArtifactConstants.DownloadBuild, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return false; - } - - public static Boolean IsDownloadStepDisabled(this Step step) - { - // either download task or downloadBuild task has none keyword return true. - if (step is TaskStep taskStep && - taskStep.Inputs.TryGetValue(PipelineArtifactConstants.DownloadTaskInputs.Alias, out String alias) && - String.Equals(alias, YamlArtifactConstants.None, StringComparison.OrdinalIgnoreCase) && - (step.IsDownloadBuildTask() || step.IsDownloadTask())) - { - return true; - } - - return false; - } - - public static Boolean IsDownloadTask(this Step step) - { - if (step is TaskStep taskStep && - taskStep.Reference != null && - taskStep.Reference.Id.Equals(PipelineArtifactConstants.DownloadTask.Id) && - taskStep.Reference.Version == PipelineArtifactConstants.DownloadTask.Version) - { - return true; - } - else - { - return false; - } - } - - public static Boolean IsDownloadCurrentPipelineArtifactStep(this Step step) - { - if (step is TaskStep taskStep && - taskStep.IsDownloadTask() && - taskStep.Inputs.TryGetValue(PipelineArtifactConstants.DownloadTaskInputs.Alias, out String alias) && - String.Equals(alias, YamlArtifactConstants.Current, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return false; - } - - public static Boolean IsDownloadPipelineArtifactStepDisabled(this TaskStep step) - { - if (step.IsDownloadTask() && - step.Inputs.TryGetValue(PipelineArtifactConstants.DownloadTaskInputs.Alias, out String alias) && - String.Equals(alias, YamlArtifactConstants.None, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return false; - } - - public static Boolean IsDownloadExternalPipelineArtifactStep(this TaskStep step) - { - if (step.IsDownloadTask() && - step.Inputs != null && - step.Inputs.TryGetValue(PipelineArtifactConstants.DownloadTaskInputs.Alias, out String alias) && - !String.IsNullOrEmpty(alias) && - !alias.Equals(YamlArtifactConstants.Current, StringComparison.OrdinalIgnoreCase) && - !alias.Equals(YamlArtifactConstants.None, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return false; - } - - public static String GetAliasFromTaskStep(this TaskStep step) - { - return step.Inputs.TryGetValue(PipelineArtifactConstants.DownloadTaskInputs.Alias, out String alias) - ? alias - : String.Empty; - } - - public static Boolean IsDownloadPipelineArtifactStepExists(this IReadOnlyList steps) - { - foreach (var step in steps) - { - if (step is TaskStep taskStep) - { - if (taskStep.IsDownloadTask()) - { - return true; - } - } - } - - return false; - } - - public static void Merge( - this IDictionary first, - IDictionary second) - { - foreach (var key in second?.Keys ?? new List()) - { - first[key] = second[key]; - } - } - - public static void Merge( - this IDictionary first, - IReadOnlyDictionary second) - { - foreach (var key in second?.Keys ?? new List()) - { - first[key] = second[key]; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Artifacts/IArtifactResolver.cs b/src/Sdk/DTPipelines/Pipelines/Artifacts/IArtifactResolver.cs deleted file mode 100644 index aee03a05d..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Artifacts/IArtifactResolver.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines.Artifacts -{ - /// - /// Provides a mechanism to resolve the artifacts - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IArtifactResolver - { - /// - /// Given a resource, it gets the corresponding task id from its extension - /// - /// - /// - Guid GetArtifactDownloadTaskId(Resource resource); - - /// - /// Given a resource and step, it maps the resource properties to task inputs - /// - /// - /// - void PopulateMappedTaskInputs(Resource resource, TaskStep taskStep); - - /// - /// Given an artifact step, it resolves the artifact and returns a download artifact task - /// - /// - /// - /// - Boolean ResolveStep(IPipelineContext pipelineContext, JobStep step, out IList resolvedSteps); - - /// - /// Given resource store and task step it translate the taskStep into actual task reference with mapped inputs - /// - /// - /// - /// - Boolean ResolveStep(IResourceStore resourceStore, TaskStep taskStep, out String errorMessage); - - /// - /// Validate the given resource in the YAML file. Also resolve version for the resource if not resolved already - /// - /// - Boolean ValidateDeclaredResource(Resource resource, out PipelineValidationError error); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Artifacts/PipelineArtifactConstants.cs b/src/Sdk/DTPipelines/Pipelines/Artifacts/PipelineArtifactConstants.cs deleted file mode 100644 index 867756bdf..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Artifacts/PipelineArtifactConstants.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; - -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Artifacts -{ - public static class PipelineArtifactConstants - { - internal static class CommonArtifactTaskInputValues - { - internal const String DefaultDownloadPath = "$(Pipeline.Workspace)"; - internal const String DefaultDownloadPattern = "**"; - } - - public static class PipelineArtifactTaskInputs - { - public const String ArtifactName = "artifactName"; - - public const String BuildType = "buildType"; - - public const String BuildId = "buildId"; - - public const String BuildVersionToDownload = "buildVersionToDownload"; - - public const String Definition = "definition"; - - public const String DownloadType = "downloadType"; - - public const String DownloadPath = "downloadPath"; - - public const String FileSharePath = "fileSharePath"; - - public const String ItemPattern = "itemPattern"; - - public const String Project = "project"; - } - - public static class PipelineArtifactTaskInputValues - { - public const String DownloadTypeSingle = "single"; - public const String SpecificBuildType = "specific"; - public const String CurrentBuildType = "current"; - public const String AutomaticMode = "automatic"; - public const String ManualMode = "manual"; - } - - internal static class YamlConstants - { - internal const String Connection = "connection"; - internal const String Current = "current"; - internal const String None = "none"; - } - - public static class ArtifactTypes - { - public const string AzurePipelineArtifactType = "Pipeline"; - } - - public static class DownloadTaskInputs - { - public const String Alias = "alias"; - public const String Artifact = "artifact"; - public const String Mode = "mode"; - public const String Path = "path"; - public const String Patterns = "patterns"; - } - - public static class TraceConstants - { - public const String Area = "PipelineArtifacts"; - public const String DownloadPipelineArtifactFeature = "DownloadPipelineArtifact"; - } - - public static readonly TaskDefinition DownloadTask = new TaskDefinition - { - Id = new Guid("30f35852-3f7e-4c0c-9a88-e127b4f97211"), - Name = "Download", - FriendlyName = "Download Artifact", - Author = "Microsoft", - RunsOn = { TaskRunsOnConstants.RunsOnAgent }, - Version = new TaskVersion("1.0.0"), - Description = "Downloads pipeline type artifacts.", - HelpMarkDown = "[More Information](https://github.com)", - Inputs = { - new TaskInputDefinition() - { - Name = DownloadTaskInputs.Artifact, - Required = true, - InputType = TaskInputType.String - }, - new TaskInputDefinition() - { - Name = DownloadTaskInputs.Patterns, - Required = false, - DefaultValue = "**", - InputType = TaskInputType.String - }, - new TaskInputDefinition() - { - Name = DownloadTaskInputs.Path, - Required = false, - InputType = TaskInputType.String - }, - new TaskInputDefinition() - { - Name=DownloadTaskInputs.Alias, - Required = false, - InputType = TaskInputType.String - } - }, - }; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Artifacts/YamlArtifactConstants.cs b/src/Sdk/DTPipelines/Pipelines/Artifacts/YamlArtifactConstants.cs deleted file mode 100644 index 5fe5bba9a..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Artifacts/YamlArtifactConstants.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace GitHub.DistributedTask.Pipelines.Artifacts -{ - public static class YamlArtifactConstants - { - public const String Alias = "alias"; - public const String Connection = "connection"; - public const String Current = "current"; - public const String Download = "download"; - public const String DownloadBuild = "downloadBuild"; - public const String None = "none"; - public const String Path = "path"; - public const String Patterns = "patterns"; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/BuildOptions.cs b/src/Sdk/DTPipelines/Pipelines/BuildOptions.cs deleted file mode 100644 index c92128945..000000000 --- a/src/Sdk/DTPipelines/Pipelines/BuildOptions.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism for controlling validation behaviors. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class BuildOptions - { - public static BuildOptions None { get; } = new BuildOptions(); - - /// - /// Gets or sets a value indicating whether or not a queue target without a queue should be considered an - /// error. - /// - public Boolean AllowEmptyQueueTarget - { - get; - set; - } - - /// - /// Allow hyphens in names checked by the NameValidator. Used for yaml workflow schema - /// - public Boolean AllowHyphenNames - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether to demand the latest agent version. - /// - public Boolean DemandLatestAgent - { - get; - set; - } - - /// - /// If true, resource definitions are allowed to use expressions - /// - public Boolean EnableResourceExpressions - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether or not to resolve resource version. - /// - public Boolean ResolveResourceVersions - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether input aliases defined in a task definition are honored. - /// - public Boolean ResolveTaskInputAliases - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether or not the individual step demands should be rolled up into their - /// parent phase's demands. Settings this value to true will result in Phase's demand sets being a superset - /// of their children's demands. - /// - public Boolean RollupStepDemands - { - get; - set; - } - - /// - /// If true, all expressions must be resolvable given a provided context. - /// This is normally going to be false for plan compile time and true for plan runtime. - /// - public Boolean ValidateExpressions - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether or not to validate resource existence and other constraints. - /// - public Boolean ValidateResources - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether or not step names provided by the caller should be validated for - /// correctness and uniqueness. Setting this value to false will automatically fix invalid step names and - /// de-duplicate step names which may lead to unexpected behavior at runtime when binding output variables. - /// - public Boolean ValidateStepNames - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether or not to run input validation defined by the task author. - /// - public Boolean ValidateTaskInputs - { - get; - set; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/BuildResource.cs b/src/Sdk/DTPipelines/Pipelines/BuildResource.cs deleted file mode 100644 index b6e6a15a4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/BuildResource.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class BuildPropertyNames - { - public static readonly String Branch = "branch"; - public static readonly String Connection = "connection"; - public static readonly String Source = "source"; - public static readonly String Type = "type"; - public static readonly String Version = "version"; - } - - /// - /// Provides a data contract for a build resource referenced by a pipeline. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class BuildResource : Resource - { - public BuildResource() - { - } - - protected BuildResource(BuildResource resourceToCopy) - : base(resourceToCopy) - { - } - - /// - /// Gets or sets the type of build resource. - /// - public String Type - { - get - { - return this.Properties.Get(BuildPropertyNames.Type); - } - set - { - this.Properties.Set(BuildPropertyNames.Type, value); - } - } - - /// - /// Gets or sets the version of the build resource. - /// - public String Version - { - get - { - return this.Properties.Get(BuildPropertyNames.Version); - } - set - { - this.Properties.Set(BuildPropertyNames.Version, value); - } - } - - public BuildResource Clone() - { - return new BuildResource(this); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointContext.cs b/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointContext.cs deleted file mode 100644 index c33bd72e1..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointContext.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.Services.WebApi.Internal; - -namespace GitHub.DistributedTask.Pipelines.Checkpoints -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - [ClientIgnore] - public class CheckpointContext - { - /// - /// Unique id of the checkpoint, also used as the timeline record id - /// - [DataMember(IsRequired = true)] - public Guid Id { get; set; } - - /// - /// Auth token for querying DistributedTask - /// - [DataMember(IsRequired = true)] - public String Token { get; set; } - - /// - /// Checkpoint Instance Id - /// Use this for sending decision events and tracing telemetry. - /// - [DataMember(IsRequired = true)] - public String OrchestrationId { get; set; } - - /// - /// PlanId - /// - [DataMember(IsRequired = true)] - public Guid PlanId { get; set; } - - /// - /// Which TaskHub to use when sending decision events; - /// Use this for sending decision events. - /// - [DataMember(IsRequired = true)] - public String HubName { get; set; } - - /// - /// The project requesting decision. - /// - [DataMember(EmitDefaultValue = false)] - public CheckpointScope Project { get; set; } - - /// - /// The pipeline (definition) requesting decision. - /// - [DataMember(EmitDefaultValue = false)] - public PipelineScope Pipeline { get; set; } - - /// - /// The graph node requesting decision. - /// - [DataMember(EmitDefaultValue = false)] - public GraphNodeScope GraphNode { get; set; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointDecision.cs b/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointDecision.cs deleted file mode 100644 index 28bdbbdbf..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointDecision.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.Services.WebApi.Internal; - -namespace GitHub.DistributedTask.Pipelines.Checkpoints -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - [ClientIgnore] - public class CheckpointDecision - { - /// - /// Checkpoint id, provided on context - /// - [DataMember(IsRequired = true)] - public Guid Id { get; set; } - - /// - /// Decision - /// - [DataMember(IsRequired = true)] - public String Result { get; set; } - - /// - /// Additional information (optional) - /// - [DataMember(IsRequired = false, EmitDefaultValue = false)] - public String Message { get; set; } - - // Decision possibilities - public const String Approved = "Approved"; - public const String Denied = "Denied"; - public const String Canceled = "Canceled"; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointScope.cs b/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointScope.cs deleted file mode 100644 index bfcab3c79..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Checkpoints/CheckpointScope.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.WebApi.Internal; - -namespace GitHub.DistributedTask.Pipelines.Checkpoints -{ - /// - /// Provides context regarding the state of the orchestration. - /// Consumers may choose to use this information to cache decisions. - /// EG, if you wanted to return the same decision for this and all - /// future requests issuing from the same project / pipeline / stage / run - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - [ClientIgnore] - public class CheckpointScope - { - /// - /// May be used in uniquely identify this scope for future reference. - /// - [DataMember(IsRequired = true)] - public String Id { get; set; } - - /// - /// The friendly name of the scope - /// - [DataMember(EmitDefaultValue = false)] - public String Name { get; set; } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - [ClientIgnore] - public class GraphNodeScope : CheckpointScope - { - /// - /// Facilitates approving only a single attempt of a graph node in a specific run of a pipeline. - /// - [DataMember(IsRequired = true)] - public Int32 Attempt { get; set; } = 1; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - [ClientIgnore] - public class PipelineScope : CheckpointScope - { - /// - /// Pipeline URLs - /// - [DataMember(IsRequired = true)] - public TaskOrchestrationOwner Owner { get; set; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Checkpoints/ResourceInfo.cs b/src/Sdk/DTPipelines/Pipelines/Checkpoints/ResourceInfo.cs deleted file mode 100644 index 66daffc0d..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Checkpoints/ResourceInfo.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.Services.WebApi.Internal; - -namespace GitHub.DistributedTask.Pipelines.Checkpoints -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - [ClientIgnore] - public class ResourceInfo - { - [DataMember(EmitDefaultValue = false)] - public String Id { get; set; } - - [DataMember(EmitDefaultValue = false)] - public String Name { get; set; } - - [DataMember(EmitDefaultValue = false)] - public String TypeName { get; set; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ContinuousIntegrationTrigger.cs b/src/Sdk/DTPipelines/Pipelines/ContinuousIntegrationTrigger.cs deleted file mode 100644 index 1cc138e77..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ContinuousIntegrationTrigger.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class ContinuousIntegrationTrigger : PipelineTrigger - { - public ContinuousIntegrationTrigger() - : base(PipelineTriggerType.ContinuousIntegration) - { - Enabled = true; - } - - [DataMember(EmitDefaultValue = true)] - public Boolean Enabled - { - get; - set; - } - - /// - /// Indicates whether changes should be batched while another CI pipeline is running. - /// - /// - /// If this is true, then changes submitted while a CI pipeline is running will be batched and built in one new CI pipeline when the current pipeline finishes. - /// If this is false, then a new CI pipeline will be triggered for each change to the repository. - /// - [DataMember(EmitDefaultValue = false)] - public Boolean BatchChanges - { - get; - set; - } - - /// - /// A list of filters that describe which branches will trigger pipelines. - /// - public IList BranchFilters - { - get - { - if (m_branchFilters == null) - { - m_branchFilters = new List(); - } - return m_branchFilters; - } - } - - /// - /// A list of filters that describe which paths will trigger pipelines. - /// - public IList PathFilters - { - get - { - if (m_pathFilters == null) - { - m_pathFilters = new List(); - } - return m_pathFilters; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_branchFilters?.Count == 0) - { - m_branchFilters = null; - } - - if (m_pathFilters?.Count == 0) - { - m_pathFilters = null; - } - } - - [DataMember(Name = "BranchFilters", EmitDefaultValue = false)] - private List m_branchFilters; - - [DataMember(Name = "PathFilters", EmitDefaultValue = false)] - private List m_pathFilters; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/CounterStore.cs b/src/Sdk/DTPipelines/Pipelines/CounterStore.cs deleted file mode 100644 index b77ad8a25..000000000 --- a/src/Sdk/DTPipelines/Pipelines/CounterStore.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a default implementation of a counter store. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class CounterStore : ICounterStore - { - public CounterStore( - IDictionary counters = null, - ICounterResolver resolver = null) - { - if (counters?.Count > 0) - { - m_counters.AddRange(counters); - } - - this.Resolver = resolver; - } - - public IReadOnlyDictionary Counters - { - get - { - return m_counters; - } - } - - private ICounterResolver Resolver - { - get; - } - - public Int32 Increment( - IPipelineContext context, - String prefix, - Int32 seed) - { - if (m_counters.TryGetValue(prefix, out Int32 existingValue)) - { - return existingValue; - } - - Int32 newValue = seed; - if (this.Resolver != null) - { - newValue = this.Resolver.Increment(context, prefix, seed); - m_counters[prefix] = newValue; - } - - return newValue; - } - - private readonly Dictionary m_counters = new Dictionary(StringComparer.OrdinalIgnoreCase); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/CreateJobResult.cs b/src/Sdk/DTPipelines/Pipelines/CreateJobResult.cs deleted file mode 100644 index 2802869c0..000000000 --- a/src/Sdk/DTPipelines/Pipelines/CreateJobResult.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.ComponentModel; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public struct CreateJobResult - { - public CreateJobResult( - JobExecutionContext context, - Job job) - { - this.Job = job; - this.Context = context; - } - - public Job Job - { - get; - } - - public JobExecutionContext Context - { - get; - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public struct CreateTaskResult - { - public CreateTaskResult( - TaskStep task, - TaskDefinition definition) - { - this.Task = task; - this.Definition = definition; - } - - public TaskStep Task - { - get; - } - - public TaskDefinition Definition - { - get; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/DeploymentExecutionOptions.cs b/src/Sdk/DTPipelines/Pipelines/DeploymentExecutionOptions.cs deleted file mode 100644 index 5ec777815..000000000 --- a/src/Sdk/DTPipelines/Pipelines/DeploymentExecutionOptions.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Validation; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - internal enum DeploymentRollingOption - { - [EnumMember] - Absolute, - - [EnumMember] - Percentage - } - - [DataContract] - internal class DeploymentExecutionOptions - { - public DeploymentExecutionOptions() - { - } - - private DeploymentExecutionOptions(DeploymentExecutionOptions optionsToCopy) - { - this.RollingOption = optionsToCopy.RollingOption; - this.RollingValue = optionsToCopy.RollingValue; - } - - [DataMember] - public DeploymentRollingOption RollingOption - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public uint RollingValue - { - get; - set; - } - - public DeploymentExecutionOptions Clone() - { - return new DeploymentExecutionOptions(this); - } - - public void Validate( - IPipelineContext context, - ValidationResult result) - { - switch (RollingOption) - { - case DeploymentRollingOption.Absolute: - if (RollingValue == 0) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.InvalidAbsoluteRollingValue())); - } - break; - - case DeploymentRollingOption.Percentage: - if (RollingValue == 0 || RollingValue > 100) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.InvalidPercentageRollingValue())); - } - break; - - default: - result.Errors.Add(new PipelineValidationError(PipelineStrings.InvalidRollingOption(RollingOption))); - break; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/DeploymentGroupTarget.cs b/src/Sdk/DTPipelines/Pipelines/DeploymentGroupTarget.cs deleted file mode 100644 index 9bd5cc6e0..000000000 --- a/src/Sdk/DTPipelines/Pipelines/DeploymentGroupTarget.cs +++ /dev/null @@ -1,158 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - internal class DeploymentGroupTarget : PhaseTarget - { - public DeploymentGroupTarget() - : base(PhaseTargetType.DeploymentGroup) - { - } - - private DeploymentGroupTarget(DeploymentGroupTarget targetToClone) - : base(targetToClone) - { - this.DeploymentGroup = targetToClone.DeploymentGroup?.Clone(); - this.Execution = targetToClone.Execution?.Clone(); - - if (targetToClone.m_tags != null && targetToClone.m_tags.Count > 0) - { - m_tags = new HashSet(targetToClone.m_tags, StringComparer.OrdinalIgnoreCase); - } - } - - [DataMember] - public DeploymentGroupReference DeploymentGroup - { - get; - set; - } - - public ISet Tags - { - get - { - if (m_tags == null) - { - m_tags = new HashSet(StringComparer.OrdinalIgnoreCase); - } - return m_tags; - } - } - - /// - /// Gets targets Ids filter on which deployment should be done. - /// - public List TargetIds - { - get - { - if (m_targetIds == null) - { - m_targetIds = new List(); - } - return m_targetIds; - } - } - - [DataMember(EmitDefaultValue = false)] - public DeploymentExecutionOptions Execution - { - get; - set; - } - - public override PhaseTarget Clone() - { - return new DeploymentGroupTarget(this); - } - - public override Boolean IsValid(TaskDefinition task) - { - return task.RunsOn.Contains(TaskRunsOnConstants.RunsOnDeploymentGroup, StringComparer.OrdinalIgnoreCase); - } - - internal override void Validate( - IPipelineContext context, - BuildOptions buildOptions, - ValidationResult result, - IList steps, - ISet taskDemands) - { - this.Execution?.Validate(context, result); - } - - internal override JobExecutionContext CreateJobContext( - PhaseExecutionContext context, - String jobName, - Int32 attempt, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory) - { - context.Trace?.EnterProperty("CreateJobContext"); - var result = new ParallelExecutionOptions().CreateJobContext( - context, - jobName, - attempt, - null, - null, - continueOnError, - timeoutInMinutes, - cancelTimeoutInMinutes, - jobFactory); - context.Trace?.LeaveProperty("CreateJobContext"); - return result; - } - - internal override ExpandPhaseResult Expand( - PhaseExecutionContext context, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory, - JobExpansionOptions options) - { - context.Trace?.EnterProperty("Expand"); - var result = new ParallelExecutionOptions().Expand( - context: context, - container: null, - sidecarContainers: null, - continueOnError: continueOnError, - timeoutInMinutes: timeoutInMinutes, - cancelTimeoutInMinutes: cancelTimeoutInMinutes, - jobFactory: jobFactory, - options: options); - context.Trace?.LeaveProperty("Expand"); - return result; - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_tags?.Count == 0) - { - m_tags = null; - } - - if (m_targetIds?.Count == 0) - { - m_targetIds = null; - } - } - - [DataMember(Name = "Tags", EmitDefaultValue = false)] - private ISet m_tags; - - [DataMember(Name = "TargetIds")] - private List m_targetIds; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Environment/EnvironmentReference.cs b/src/Sdk/DTPipelines/Pipelines/Environment/EnvironmentReference.cs deleted file mode 100644 index 93e441d75..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Environment/EnvironmentReference.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class EnvironmentReference : ResourceReference - { - public EnvironmentReference() - { - } - - private EnvironmentReference(EnvironmentReference referenceToCopy) - : base(referenceToCopy) - { - this.Id = referenceToCopy.Id; - } - - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - set; - } - - public EnvironmentReference Clone() - { - return new EnvironmentReference(this); - } - - public override String ToString() - { - return base.ToString() ?? this.Id.ToString(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/EnvironmentDeploymentTarget.cs b/src/Sdk/DTPipelines/Pipelines/EnvironmentDeploymentTarget.cs deleted file mode 100644 index c34748631..000000000 --- a/src/Sdk/DTPipelines/Pipelines/EnvironmentDeploymentTarget.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class EnvironmentDeploymentTarget - { - [DataMember] - public Int32 EnvironmentId { get; set; } - - [DataMember] - public String EnvironmentName { get; set; } - - [DataMember] - public EnvironmentResourceReference Resource { get; set; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/EnvironmentStore.cs b/src/Sdk/DTPipelines/Pipelines/EnvironmentStore.cs deleted file mode 100644 index b0e96bf65..000000000 --- a/src/Sdk/DTPipelines/Pipelines/EnvironmentStore.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class EnvironmentStore : IEnvironmentStore - { - public EnvironmentStore( - IList environments, - IEnvironmentResolver resolver = null) - { - m_resolver = resolver; - m_environmentsByName = new Dictionary(StringComparer.OrdinalIgnoreCase); - m_environmentsById = new Dictionary(); - Add(environments?.ToArray()); - } - - public void Add(params EnvironmentInstance[] environments) - { - if (environments is null) - { - return; - } - foreach (var e in environments) - { - if (e != null) - { - m_environmentsById[e.Id] = e; - - var name = e.Name; - if (!string.IsNullOrWhiteSpace(name)) - { - m_environmentsByName[name] = e; - } - } - } - } - - public EnvironmentInstance ResolveEnvironment(String name) - { - if (!m_environmentsByName.TryGetValue(name, out var environment) - && m_resolver != null) - { - environment = m_resolver?.Resolve(name); - Add(environment); - } - - return environment; - } - - public EnvironmentInstance ResolveEnvironment(Int32 id) - { - if (!m_environmentsById.TryGetValue(id, out var environment) - && m_resolver != null) - { - environment = m_resolver?.Resolve(id); - Add(environment); - } - - return environment; - } - - public EnvironmentInstance Get(EnvironmentReference reference) - { - if (reference is null) - { - return null; - } - - if (reference.Name?.IsLiteral == true) - { - return ResolveEnvironment(reference.Name.Literal); - } - - return ResolveEnvironment(reference.Id); - } - - public IList GetReferences() - { - return m_environmentsById.Values - .Select(x => new EnvironmentReference - { - Id = x.Id, - Name = x.Name - }) - .ToList(); - } - - private IEnvironmentResolver m_resolver; - private IDictionary m_environmentsByName; - private IDictionary m_environmentsById; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ExecutionOptions.cs b/src/Sdk/DTPipelines/Pipelines/ExecutionOptions.cs deleted file mode 100644 index 6da517f9b..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ExecutionOptions.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism for controlling runtime behaviors. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class ExecutionOptions - { - public ExecutionOptions() - { - } - - /// - /// Gets or sets a value indicating whether or not to remove secrets from job message. - /// - [DataMember(EmitDefaultValue = false)] - public Boolean RestrictSecrets - { - get; - set; - } - - /// - /// Gets or sets a value indicating what scope the system jwt token will have. - /// - [DataMember(EmitDefaultValue = false)] - public String SystemTokenScope - { - get; - set; - } - - /// - /// Gets or sets value indicating any custom claims the system jwt token will have. - /// - public IDictionary SystemTokenCustomClaims - { - get - { - if (m_systemTokenCustomClaims == null) - { - m_systemTokenCustomClaims = new Dictionary(); - } - return m_systemTokenCustomClaims; - } - } - - /// - /// Gets or sets a value indicating what's the max number jobs we allow after expansion. - /// - [DataMember(EmitDefaultValue = false)] - public Int32? MaxJobExpansion - { - get; - set; - } - - /// - /// Gets or sets a value indicating the max parallelism slots available to overwrite MaxConcurrency of test job slicing - /// - [DataMember(EmitDefaultValue = false)] - public Int32? MaxParallelism - { - get; - set; - } - - /// - /// Gets or sets a value indicating if we should allow expressions to define secured resources. - /// - [DataMember(EmitDefaultValue = false)] - public Boolean EnableResourceExpressions - { - get; - set; - } - - /// - /// Driven by FF: DistributedTask.LegalNodeNames - /// - [DataMember(EmitDefaultValue = false)] - public Boolean EnforceLegalNodeNames - { - get; - set; - } - - /// - /// Allows hyphens in yaml names - /// - [DataMember(EmitDefaultValue = false)] - public Boolean AllowHyphenNames - { - get; - set; - } - - [DataMember(Name = nameof(SystemTokenCustomClaims), EmitDefaultValue = false)] - private IDictionary m_systemTokenCustomClaims; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ExpandPhaseResult.cs b/src/Sdk/DTPipelines/Pipelines/ExpandPhaseResult.cs deleted file mode 100644 index 11c5e736b..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ExpandPhaseResult.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Pipelines.Runtime; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Represents the runtime values of a phase which has been expanded for execution. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class ExpandPhaseResult - { - /// - /// Initializes a new ExpandPhaseResult innstance with a default maximum concurrency of 1. - /// - public ExpandPhaseResult() - { - this.MaxConcurrency = 1; - } - - /// - /// Gets or sets the execution behavior when an error is encountered. - /// - public Boolean ContinueOnError - { - get; - set; - } - - /// - /// Gets or sets the execution behavior when an error is encountered. - /// - public Boolean FailFast - { - get; - set; - } - - /// - /// Gets or sets the maximum concurrency for the jobs. - /// - public Int32 MaxConcurrency - { - get; - set; - } - - /// - /// Gets the list of jobs for this phase. - /// - public IList Jobs - { - get - { - if (m_jobs == null) - { - m_jobs = new List(); - } - return m_jobs; - } - } - - private List m_jobs; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/CounterNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/CounterNode.cs deleted file mode 100644 index ad18857ea..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/CounterNode.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class CounterNode : FunctionNode - { - protected override Object EvaluateCore(EvaluationContext evaluationContext) - { - int seed = 0; - var prefix = String.Empty; - if (Parameters.Count > 0) - { - prefix = Parameters[0].EvaluateString(evaluationContext); - } - - if (Parameters.Count > 1) - { - seed = Convert.ToInt32(Parameters[1].EvaluateNumber(evaluationContext)); - } - - var context = evaluationContext.State as IPipelineContext; - return context.CounterStore?.Increment(context, prefix, seed) ?? seed; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/ExpressionConstants.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/ExpressionConstants.cs deleted file mode 100644 index ad3878098..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/ExpressionConstants.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class ExpressionConstants - { - /// - /// Gets the name of the variables node. - /// - public static readonly String Variables = "variables"; - - /// - /// Gets the pipeline context available in pipeline expressions. - /// - public static readonly INamedValueInfo PipelineNamedValue = new NamedValueInfo("pipeline"); - - /// - /// Gets the variable context available in pipeline expressions. - /// - public static readonly INamedValueInfo VariablesNamedValue = new NamedValueInfo("variables"); - - /// - /// Gets the counter function available in pipeline expressions. - /// - public static readonly IFunctionInfo CounterFunction = new FunctionInfo("counter", 0, 2); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/InputValidationConstants.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/InputValidationConstants.cs deleted file mode 100644 index 657eb4aaa..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/InputValidationConstants.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - internal static class InputValidationConstants - { - public static readonly String IsEmail = "isEmail"; - public static readonly String IsInRange = "isInRange"; - public static readonly String IsIPv4Address = "isIPv4Address"; - public static readonly String IsSha1 = "isSha1"; - public static readonly String IsUrl = "isUrl"; - public static readonly String IsMatch = "isMatch"; - public static readonly String Length = "length"; - - public static readonly IFunctionInfo[] Functions = new IFunctionInfo[] - { - new FunctionInfo(InputValidationConstants.IsEmail, IsEmailNode.minParameters, IsEmailNode.maxParameters), - new FunctionInfo(InputValidationConstants.IsInRange, IsInRangeNode.minParameters, IsInRangeNode.maxParameters), - new FunctionInfo(InputValidationConstants.IsIPv4Address, IsIPv4AddressNode.minParameters, IsIPv4AddressNode.maxParameters), - new FunctionInfo(InputValidationConstants.IsMatch, IsMatchNode.minParameters, IsMatchNode.maxParameters), - new FunctionInfo(InputValidationConstants.IsSha1, IsSHA1Node.minParameters, IsSHA1Node.maxParameters), - new FunctionInfo(InputValidationConstants.IsUrl, IsUrlNode.minParameters, IsUrlNode.maxParameters), - new FunctionInfo(InputValidationConstants.Length, LengthNode.minParameters, LengthNode.maxParameters), - }; - - public static readonly INamedValueInfo[] NamedValues = new INamedValueInfo[] - { - new NamedValueInfo("value"), - }; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/InputValueNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/InputValueNode.cs deleted file mode 100644 index 9c7fd5930..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/InputValueNode.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using GitHub.DistributedTask.Expressions; -using GitHub.DistributedTask.Pipelines.Validation; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - internal class InputValueNode : NamedValueNode - { - protected sealed override Object EvaluateCore(EvaluationContext evaluationContext) - { - var validationContext = evaluationContext.State as InputValidationContext; - return validationContext.Value; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/IsEmailNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/IsEmailNode.cs deleted file mode 100644 index 39ac71010..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/IsEmailNode.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class IsEmailNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - public static Int32 minParameters = 1; - public static Int32 maxParameters = 1; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - // isEmail(value: string) - String value = Parameters[0].EvaluateString(context) ?? String.Empty; - return RegexUtility.IsMatch(value, WellKnownRegularExpressions.Email); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/IsIPv4AddressNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/IsIPv4AddressNode.cs deleted file mode 100644 index 475833213..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/IsIPv4AddressNode.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class IsIPv4AddressNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - public static Int32 minParameters = 1; - public static Int32 maxParameters = 1; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - // isIpV4Address(value: string) - String value = Parameters[0].EvaluateString(context) ?? String.Empty; - return RegexUtility.IsMatch(value, WellKnownRegularExpressions.IPv4Address); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/IsInRangeNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/IsInRangeNode.cs deleted file mode 100644 index e18598949..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/IsInRangeNode.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class IsInRangeNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - public static Int32 minParameters = 3; - public static Int32 maxParameters = 3; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - // isInRange(value: string, min: string, max: string) - decimal value = Parameters[0].EvaluateNumber(context); - decimal min = Parameters[1].EvaluateNumber(context); - decimal max = Parameters[2].EvaluateNumber(context); - return value >= min && value <= max; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/IsMatchNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/IsMatchNode.cs deleted file mode 100644 index 7a45f353c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/IsMatchNode.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class IsMatchNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - public static Int32 minParameters = 2; - public static Int32 maxParameters = 3; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - // isMatch(value: string, regEx: string, options?: string) - String value = Parameters[0].EvaluateString(context) ?? String.Empty; - String regEx = Parameters[1].EvaluateString(context) ?? String.Empty; - String regExOptionsString = String.Empty; - - if (Parameters.Count == 3) - { - regExOptionsString = Parameters[2].EvaluateString(context) ?? String.Empty; - } - - return RegexUtility.IsMatch(value, regEx, regExOptionsString); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/IsSHA1Node.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/IsSHA1Node.cs deleted file mode 100644 index ecc4d8a05..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/IsSHA1Node.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class IsSHA1Node : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - public static Int32 minParameters = 1; - public static Int32 maxParameters = 1; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - // isSha1(value: string) - String value = Parameters[0].EvaluateString(context) ?? String.Empty; - return RegexUtility.IsMatch(value, WellKnownRegularExpressions.SHA1); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/IsUrlNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/IsUrlNode.cs deleted file mode 100644 index 9c94e77ab..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/IsUrlNode.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class IsUrlNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - public static Int32 minParameters = 1; - public static Int32 maxParameters = 1; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - // isUrl(value: string) - String value = Parameters[0].EvaluateString(context) ?? String.Empty; - return RegexUtility.IsMatch(value, WellKnownRegularExpressions.Url); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/LengthNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/LengthNode.cs deleted file mode 100644 index 0675c001f..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/LengthNode.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class LengthNode : FunctionNode - { - protected sealed override Boolean TraceFullyRealized => false; - - public static Int32 minParameters = 1; - public static Int32 maxParameters = 1; - - protected sealed override Object EvaluateCore(EvaluationContext context) - { - // Length(value: object) - var evaluationResult = Parameters[0].Evaluate(context); - bool kindNotSupported = false; - Int32 length = -1; - - switch (evaluationResult.Kind) - { - case ValueKind.Array: - length = ((JArray)evaluationResult.Value).Count; - break; - case ValueKind.String: - length = ((String)evaluationResult.Value).Length; - break; - case ValueKind.Object: - if (evaluationResult.Value is IReadOnlyDictionary) - { - length = ((IReadOnlyDictionary)evaluationResult.Value).Count; - } - else if (evaluationResult.Value is ICollection) - { - length = ((ICollection)evaluationResult.Value).Count; - } - else - { - kindNotSupported = true; - } - break; - case ValueKind.Boolean: - case ValueKind.Null: - case ValueKind.Number: - case ValueKind.Version: - kindNotSupported = true; - break; - } - - if (kindNotSupported) - { - throw new NotSupportedException(PipelineStrings.InvalidTypeForLengthFunction(evaluationResult.Kind)); - } - - return new Decimal(length); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/PipelineContextNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/PipelineContextNode.cs deleted file mode 100644 index 6e35657bf..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/PipelineContextNode.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.ComponentModel; -using System.Collections.Generic; -using GitHub.DistributedTask.Expressions; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - internal sealed class PipelineContextNode : NamedValueNode - { - protected override Object EvaluateCore(EvaluationContext context) - { - var state = context.State as IPipelineContext; - var result = new Dictionary(StringComparer.OrdinalIgnoreCase); - - // startTime - if (state.Variables.TryGetValue(WellKnownDistributedTaskVariables.PipelineStartTime, out VariableValue startTimeVariable) && - !String.IsNullOrEmpty(startTimeVariable.Value)) - { - // Leverage the expression SDK to convert to datetime - var startTimeResult = EvaluationResult.CreateIntermediateResult(context, startTimeVariable.Value, out _); - if (startTimeResult.TryConvertToDateTime(context, out DateTimeOffset startTime)) - { - result["startTime"] = startTime; - } - } - - return result; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Expressions/VariablesContextNode.cs b/src/Sdk/DTPipelines/Pipelines/Expressions/VariablesContextNode.cs deleted file mode 100644 index d548f5ab0..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Expressions/VariablesContextNode.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; - -namespace GitHub.DistributedTask.Pipelines.Expressions -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class VariablesContextNode : NamedValueNode - { - protected override Object EvaluateCore(EvaluationContext context) - { - var executionContext = context.State as IPipelineContext; - return executionContext.Variables; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/GraphCondition.cs b/src/Sdk/DTPipelines/Pipelines/GraphCondition.cs deleted file mode 100644 index 06fd7409c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/GraphCondition.cs +++ /dev/null @@ -1,247 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Text; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Expressions2.Sdk; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.Pipelines.Expressions; -using GitHub.DistributedTask.Pipelines.ObjectTemplating; -using GitHub.DistributedTask.Pipelines.Runtime; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class GraphCondition where TInstance : IGraphNodeInstance - { - private protected GraphCondition(String condition) - { - m_condition = !String.IsNullOrEmpty(condition) ? condition : Default; - m_parser = new ExpressionParser(); - m_parsedCondition = m_parser.CreateTree(m_condition, new ConditionTraceWriter(), s_namedValueInfo, FunctionInfo); - } - - /// - /// Gets the default condition if none is specified - /// - public static String Default - { - get - { - return $"{PipelineTemplateConstants.Success}()"; - } - } - - /// - /// Gets a value indicating whether the event payload is used within the condition - /// - public Boolean RequiresEventPayload - { - get - { - CheckRequiredProperties(); - return m_requiresEventPayload.Value; - } - } - - /// - /// Gets a value indicating whether dependency outputs are used within the condition - /// - public Boolean RequiresOutputs - { - get - { - CheckRequiredProperties(); - return m_requiresOutputs.Value; - } - } - - /// - /// Gets a value indicating whether variables are used within the condition - /// - public Boolean RequiresVariables - { - get - { - return false; - } - } - - private void CheckRequiredProperties() - { - var matches = m_parsedCondition.CheckReferencesContext(PipelineTemplateConstants.EventPattern, PipelineTemplateConstants.OutputsPattern); - m_requiresEventPayload = matches[0]; - m_requiresOutputs = matches[1]; - } - - private static IEnumerable GetNeeds( - IReadOnlyList parameters, - EvaluationContext context, - GraphExecutionContext expressionContext) - { - if (expressionContext.Data.TryGetValue(PipelineTemplateConstants.Needs, out var needsData) && - needsData is DictionaryContextData needs) - { - if (parameters.Count == 0) - { - foreach (var pair in needs) - { - yield return pair.Value as DictionaryContextData; - } - } - else - { - foreach (var parameter in parameters) - { - var parameterResult = parameter.Evaluate(context); - var dependencyName = default(String); - if (parameterResult.IsPrimitive) - { - dependencyName = parameterResult.ConvertToString(); - } - - if (!String.IsNullOrEmpty(dependencyName) && - needs.TryGetValue(dependencyName, out var need)) - { - yield return need as DictionaryContextData; - } - else - { - yield return default; - } - } - } - } - } - - private readonly String m_condition; - private readonly ExpressionParser m_parser; - private Boolean? m_requiresEventPayload; - private Boolean? m_requiresOutputs; - protected readonly IExpressionNode m_parsedCondition; - - private static readonly INamedValueInfo[] s_namedValueInfo = new INamedValueInfo[] - { - new NamedValueInfo>(PipelineTemplateConstants.GitHub), - new NamedValueInfo>(PipelineTemplateConstants.Needs), - }; - - public static readonly IFunctionInfo[] FunctionInfo = new IFunctionInfo[] - { - new FunctionInfo(PipelineTemplateConstants.Always, 0, 0), - new FunctionInfo(PipelineTemplateConstants.Failure, 0, Int32.MaxValue), - new FunctionInfo(PipelineTemplateConstants.Cancelled, 0, 0), - new FunctionInfo(PipelineTemplateConstants.Success, 0, Int32.MaxValue), - }; - - protected sealed class ConditionTraceWriter : ITraceWriter - { - public String Trace - { - get - { - return m_info.ToString(); - } - } - - public void Info(String message) - { - m_info.AppendLine(message); - } - - public void Verbose(String message) - { - // Not interested - } - - private StringBuilder m_info = new StringBuilder(); - } - - private sealed class AlwaysFunction : Function - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - return true; - } - } - - private sealed class CancelledFunction : Function - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - var conditionContext = context.State as GraphExecutionContext; - return conditionContext.State == PipelineState.Canceling; - } - } - - private sealed class FailureFunction : Function - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - var conditionContext = context.State as GraphExecutionContext; - if (conditionContext.State != PipelineState.InProgress) - { - return false; - } - - Boolean anyFailed = false; - foreach (var need in GetNeeds(Parameters, context, conditionContext)) - { - if (need == null || - !need.TryGetValue(PipelineTemplateConstants.Result, out var resultData) || - !(resultData is StringContextData resultString)) - { - return false; - } - - if (String.Equals(resultString, PipelineTemplateConstants.Failure, StringComparison.OrdinalIgnoreCase)) - { - anyFailed = true; - break; - } - } - - return anyFailed; - } - } - - private sealed class SuccessFunction : Function - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - var conditionContext = context.State as GraphExecutionContext; - if (conditionContext.State != PipelineState.InProgress) - { - return false; - } - - Boolean allSucceeded = true; - foreach (var need in GetNeeds(Parameters, context, conditionContext)) - { - if (!allSucceeded || - need == null || - !need.TryGetValue(PipelineTemplateConstants.Result, out var resultData) || - !(resultData is StringContextData resultString) || - !String.Equals(resultString, PipelineTemplateConstants.Success, StringComparison.OrdinalIgnoreCase)) - { - return false; - } - } - - return true; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/GroupStep.cs b/src/Sdk/DTPipelines/Pipelines/GroupStep.cs deleted file mode 100644 index c66bc1a32..000000000 --- a/src/Sdk/DTPipelines/Pipelines/GroupStep.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class GroupStep : JobStep - { - [JsonConstructor] - public GroupStep() - { - } - - private GroupStep(GroupStep groupStepToClone) - : base(groupStepToClone) - { - if (groupStepToClone.m_steps?.Count > 0) - { - foreach (var step in groupStepToClone.m_steps) - { - this.Steps.Add(step.Clone() as TaskStep); - } - } - - if (groupStepToClone.m_outputs?.Count > 0) - { - this.m_outputs = new Dictionary(groupStepToClone.m_outputs, StringComparer.OrdinalIgnoreCase); - } - } - - public override StepType Type => StepType.Group; - - public IList Steps - { - get - { - if (m_steps == null) - { - m_steps = new List(); - } - return m_steps; - } - } - - public IDictionary Outputs - { - get - { - if (m_outputs == null) - { - m_outputs = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_outputs; - } - } - - public override Step Clone() - { - return new GroupStep(this); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_steps?.Count == 0) - { - m_steps = null; - } - - if (m_outputs?.Count == 0) - { - m_outputs = null; - } - } - - [DataMember(Name = "Steps", EmitDefaultValue = false)] - private IList m_steps; - - [DataMember(Name = "Outputs", EmitDefaultValue = false)] - private IDictionary m_outputs; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IAgentPoolResolver.cs b/src/Sdk/DTPipelines/Pipelines/IAgentPoolResolver.cs deleted file mode 100644 index 018605801..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IAgentPoolResolver.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism of resolving an AgentPoolReference to a TaskAgentPool. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IAgentPoolResolver - { - /// - /// Attempts to resolve the agent pool references to TaskAgentPool instances. - /// - /// The agent pools which should be resolved - /// A list containing the resolved agent pools - IList Resolve(ICollection references); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static class IAgentPoolResolverExtensions - { - /// - /// Attempts to resolve the agent pool reference to a TaskAgentPool. - /// - /// The agent pool which should be resolved - /// The agent pool if resolved; otherwise, null - public static TaskAgentPool Resolve( - this IAgentPoolResolver resolver, - AgentPoolReference reference) - { - return resolver.Resolve(new[] { reference }).FirstOrDefault(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IAgentPoolStore.cs b/src/Sdk/DTPipelines/Pipelines/IAgentPoolStore.cs deleted file mode 100644 index f6e6626f4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IAgentPoolStore.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IAgentPoolStore - { - /// - /// Adds a reference which should be considered authorized. Future - /// calls to retrieve this resource will be treated as pre-authorized regardless - /// of authorization context used. - /// - /// The pools which should be authorized - void Authorize(IList pools); - - IList GetAuthorizedReferences(); - - TaskAgentPool Get(AgentPoolReference reference); - - /// - /// Gets the IAgentPoolResolver used by this store, if any. - /// - IAgentPoolResolver Resolver { get; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IAgentQueueResolver.cs b/src/Sdk/DTPipelines/Pipelines/IAgentQueueResolver.cs deleted file mode 100644 index 14771855f..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IAgentQueueResolver.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism of resolving an AgentQueueReference to a TaskAgentQueue. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IAgentQueueResolver - { - /// - /// Attempts to resolve the agent queue references to TaskAgentQueue instances. - /// - /// The agent queues which should be resolved - /// A list containing the resolved agent queues - IList Resolve(ICollection references); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static class IAgentQueueResolverExtensions - { - /// - /// Attempts to resolve the agent queue reference to a TaskAgentQueue. - /// - /// The agent queue which should be resolved - /// The agent queue if resolved; otherwise, null - public static TaskAgentQueue Resolve( - this IAgentQueueResolver resolver, - AgentQueueReference reference) - { - return resolver.Resolve(new[] { reference }).FirstOrDefault(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IAgentQueueStore.cs b/src/Sdk/DTPipelines/Pipelines/IAgentQueueStore.cs deleted file mode 100644 index 16d3f1e21..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IAgentQueueStore.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IAgentQueueStore - { - /// - /// Adds a reference which should be considered authorized. Future - /// calls to retrieve this resource will be treated as pre-authorized regardless - /// of authorization context used. - /// - /// The queue which should be authorized - void Authorize(IList queues); - - IList GetAuthorizedReferences(); - - TaskAgentQueue Get(AgentQueueReference reference); - - /// - /// Gets the IAgentQueueResolver used by this store, if any. - /// - IAgentQueueResolver Resolver { get; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ICounterResolver.cs b/src/Sdk/DTPipelines/Pipelines/ICounterResolver.cs deleted file mode 100644 index bd3e349ef..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ICounterResolver.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ICounterResolver - { - Int32 Increment(IPipelineContext context, String prefix, Int32 seed); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ICounterStore.cs b/src/Sdk/DTPipelines/Pipelines/ICounterStore.cs deleted file mode 100644 index cfaba4c3e..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ICounterStore.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ICounterStore - { - /// - /// Gets the counters which are allocated for this store. - /// - IReadOnlyDictionary Counters { get; } - - /// - /// Increments the counter with the given prefix. If no such counter exists, a new one will be created with - /// as the initial value. - /// - /// The counter prefix - /// The initial value for the counter if the counter does not exist - /// The incremented value - Int32 Increment(IPipelineContext context, String prefix, Int32 seed); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IEnvironmentResolver.cs b/src/Sdk/DTPipelines/Pipelines/IEnvironmentResolver.cs deleted file mode 100644 index b0f58b1c5..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IEnvironmentResolver.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IEnvironmentResolver - { - EnvironmentInstance Resolve(String environmentName); - - EnvironmentInstance Resolve(Int32 environmentId); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IEnvironmentStore.cs b/src/Sdk/DTPipelines/Pipelines/IEnvironmentStore.cs deleted file mode 100644 index 942a08f1b..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IEnvironmentStore.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a contract for resolving environment from a given store. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IEnvironmentStore - { - EnvironmentInstance ResolveEnvironment(String environmentName); - - EnvironmentInstance ResolveEnvironment(Int32 environmentId); - - EnvironmentInstance Get(EnvironmentReference reference); - - IList GetReferences(); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IGraphNode.cs b/src/Sdk/DTPipelines/Pipelines/IGraphNode.cs deleted file mode 100644 index 178041f86..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IGraphNode.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IGraphNode - { - String Name - { - get; - set; - } - - String DisplayName - { - get; - set; - } - - String Condition - { - get; - set; - } - - ISet DependsOn - { - get; - } - - void Validate(PipelineBuildContext context, ValidationResult result); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IGraphNodeInstance - { - Int32 Attempt { get; set; } - String Identifier { get; set; } - String Name { get; set; } - DateTime? StartTime { get; set; } - DateTime? FinishTime { get; set; } - TaskResult? Result { get; set; } - Boolean SecretsAccessed { get; } - IDictionary Outputs { get; } - void ResetSecretsAccessed(); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IJobFactory.cs b/src/Sdk/DTPipelines/Pipelines/IJobFactory.cs deleted file mode 100644 index edfe7050a..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IJobFactory.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using GitHub.DistributedTask.Pipelines.Runtime; - -namespace GitHub.DistributedTask.Pipelines -{ - internal interface IJobFactory - { - String Name { get; } - - Job CreateJob( - JobExecutionContext context, - ExpressionValue container, - IDictionary> sidecarContainers, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - String displayName = null); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IPackageStore.cs b/src/Sdk/DTPipelines/Pipelines/IPackageStore.cs deleted file mode 100644 index 4837420b4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IPackageStore.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IPackageStore - { - PackageVersion GetLatestVersion(String packageType); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IPhaseProvider.cs b/src/Sdk/DTPipelines/Pipelines/IPhaseProvider.cs deleted file mode 100644 index b306d20d4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IPhaseProvider.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using GitHub.DistributedTask.Pipelines.Validation; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// This is a temprary extension point for provider phase to participate in pipeline resource discover - /// This extension point can be removed after we have the schema driven resource discover - /// - public interface IPhaseProvider - { - String Provider { get; } - - /// - /// Validate pipeline with builder context to provide additional validation errors - /// and pipeline resource discover. - /// - ValidationResult Validate(PipelineBuildContext context, ProviderPhase phase); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IPipelineContext.cs b/src/Sdk/DTPipelines/Pipelines/IPipelineContext.cs index 4ceb339cf..258896de6 100644 --- a/src/Sdk/DTPipelines/Pipelines/IPipelineContext.cs +++ b/src/Sdk/DTPipelines/Pipelines/IPipelineContext.cs @@ -15,28 +15,14 @@ namespace GitHub.DistributedTask.Pipelines [EditorBrowsable(EditorBrowsableState.Never)] public interface IPipelineContext { - ICounterStore CounterStore { get; } - DictionaryContextData Data { get; } Int32 EnvironmentVersion { get; } EvaluationOptions ExpressionOptions { get; } - IPipelineIdGenerator IdGenerator { get; } - - IPackageStore PackageStore { get; } - - PipelineResources ReferencedResources { get; } - - IResourceStore ResourceStore { get; } - - IReadOnlyList StepProviders { get; } - ISecretMasker SecretMasker { get; } - ITaskStore TaskStore { get; } - IPipelineTraceWriter Trace { get; } ISet SystemVariableNames { get; } diff --git a/src/Sdk/DTPipelines/Pipelines/IPipelineContextExtensions.cs b/src/Sdk/DTPipelines/Pipelines/IPipelineContextExtensions.cs deleted file mode 100644 index 4affd0923..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IPipelineContextExtensions.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class IPipelineContextExtensions - { - /// - /// Uses the current context to validate the steps provided. - /// - /// The current pipeline context - /// The list of steps which should be validated - /// The options controlling the level of validation performed - /// A list of validation errors which were encountered, if any - public static IList Validate( - this IPipelineContext context, - IList steps, - PhaseTarget target, - BuildOptions options) - { - var builder = new PipelineBuilder(context); - return builder.Validate(steps, target, options); - } - - /// - /// Evaluates a property which is specified as an expression and writes the resulting value to the - /// corresponding trace log if one is specified on the context. - /// - /// The result type of the expression - /// The pipeline context - /// The name of the property being evaluated - /// The expression which should be evaluated - /// The default value if no expression is specified - /// True to write the default value if no expression is specified; otherwise, false - /// The result of the expression evaluation - internal static ExpressionResult Evaluate( - this IPipelineContext context, - String name, - ExpressionValue expression, - T defaultValue, - Boolean traceDefault = true) - { - ExpressionResult result = null; - if (expression != null) - { - if (expression.IsLiteral) - { - context.Trace?.Info($"{name}: {GetTraceValue(expression.Literal)}"); - result = new ExpressionResult(expression.Literal); - } - else - { - context.Trace?.EnterProperty(name); - result = expression.GetValue(context); - context.Trace?.LeaveProperty(name); - } - } - else if (traceDefault && context.Trace != null) - { - context.Trace.Info($"{name}: {defaultValue}"); - } - - return result ?? new ExpressionResult(defaultValue); - } - - private static String GetTraceValue(T value) - { - if (value.GetType().IsValueType) - { - return value.ToString(); - } - else - { - return $"{System.Environment.NewLine}{JsonUtility.ToString(value, indent: true)}"; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IPipelineIdGenerator.cs b/src/Sdk/DTPipelines/Pipelines/IPipelineIdGenerator.cs deleted file mode 100644 index bfb5ca8d4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IPipelineIdGenerator.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IPipelineIdGenerator - { - Guid GetInstanceId(params String[] segments); - - String GetInstanceName(params String[] segments); - - String GetStageIdentifier(String stageName); - - Guid GetStageInstanceId(String stageName, Int32 attempt); - - String GetStageInstanceName(String stageName, Int32 attempt); - - String GetPhaseIdentifier(String stageName, String phaseName); - - Guid GetPhaseInstanceId(String stageName, String phaseName, Int32 attempt); - - String GetPhaseInstanceName(String stageName, String phaseName, Int32 attempt); - - String GetJobIdentifier(String stageName, String phaseName, String jobName); - - Guid GetJobInstanceId(String stageName, String phaseName, String jobName, Int32 attempt); - - String GetJobInstanceName(String stageName, String phaseName, String jobName, Int32 attempt); - - Guid GetTaskInstanceId(String stageName, String phaseName, String jobName, Int32 jobAttempt, String name3); - - String GetTaskInstanceName(String stageName, String phaseName, String jobName, Int32 jobAttempt, String name); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IResourceStore.cs b/src/Sdk/DTPipelines/Pipelines/IResourceStore.cs deleted file mode 100644 index b85ce4933..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IResourceStore.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Pipelines.Artifacts; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - public interface IBuildStore : IStepProvider - { - void Add(BuildResource resource); - void Add(IEnumerable resources); - BuildResource Get(String alias); - IEnumerable GetAll(); - IArtifactResolver Resolver { get; } - } - - public interface IContainerStore - { - void Add(ContainerResource resource); - void Add(IEnumerable resources); - ContainerResource Get(String alias); - IEnumerable GetAll(); - } - - public interface IPipelineStore : IStepProvider - { - void Add(PipelineResource resource); - void Add(IEnumerable resources); - PipelineResource Get(String alias); - IEnumerable GetAll(); - } - - public interface IRepositoryStore : IStepProvider - { - void Add(RepositoryResource resource); - void Add(IEnumerable resources); - RepositoryResource Get(String alias); - IEnumerable GetAll(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IResourceStore : IStepProvider - { - IBuildStore Builds { get; } - - IContainerStore Containers { get; } - - IServiceEndpointStore Endpoints { get; } - - ISecureFileStore Files { get; } - - IEnvironmentStore Environments { get; } - - IPipelineStore Pipelines { get; } - - IAgentQueueStore Queues { get; } - - IAgentPoolStore Pools { get; } - - IRepositoryStore Repositories { get; } - - IVariableGroupStore VariableGroups { get; } - - PipelineResources GetAuthorizedResources(); - - ServiceEndpoint GetEndpoint(Guid endpointId); - - ServiceEndpoint GetEndpoint(String endpointId); - - SecureFile GetFile(Guid fileId); - - SecureFile GetFile(String fileId); - - TaskAgentQueue GetQueue(Int32 queueId); - - TaskAgentQueue GetQueue(String queueId); - - TaskAgentPool GetPool(Int32 poolId); - - TaskAgentPool GetPool(String poolName); - - VariableGroup GetVariableGroup(Int32 groupId); - - VariableGroup GetVariableGroup(String groupId); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IResourceStoreExtensions.cs b/src/Sdk/DTPipelines/Pipelines/IResourceStoreExtensions.cs deleted file mode 100644 index 181edeb2a..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IResourceStoreExtensions.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class IResourceStoreExtensions - { - /// - /// Extracts the full resources from the which are referenced in the - /// collection. - /// - /// The store which contains the resources - /// The resources which should be included with the job - /// A new JobResources instance with the filtered set of resources from the store - public static JobResources GetJobResources( - this IResourceStore store, - PipelineResources resources) - { - var jobResources = new JobResources(); - jobResources.Containers.AddRange(resources.Containers.Select(x => x.Clone())); - - foreach (var endpointRef in resources.Endpoints) - { - var endpoint = store.Endpoints.Get(endpointRef); - if (endpoint != null) - { - jobResources.Endpoints.Add(endpoint); - } - } - - foreach (var fileRef in resources.Files) - { - var file = store.Files.Get(fileRef); - if (file != null) - { - jobResources.SecureFiles.Add(file); - } - } - - foreach (var repository in resources.Repositories) - { - jobResources.Repositories.Add(store.Repositories.Get(repository.Alias)); - } - - return jobResources; - } - - /// - /// Retrieves a service endpoint from the store using the provided reference. - /// - /// The resource store which should be queried - /// The service endpoint reference which should be resolved - /// A ServiceEndpoint instance matching the specified reference if found; otherwise, null - public static ServiceEndpoint GetEndpoint( - this IResourceStore store, - ServiceEndpointReference reference) - { - return store.Endpoints.Get(reference); - } - - /// - /// Retrieves a secure file from the store using the provided reference. - /// - /// The resource store which should be queried - /// The secure file reference which should be resolved - /// A SecureFile instance matching the specified reference if found; otherwise, null - public static SecureFile GetFile( - this IResourceStore store, - SecureFileReference reference) - { - return store.Files.Get(reference); - } - - /// - /// Retrieves an agent queue from the store using the provided reference. - /// - /// The resource store which should be queried - /// The agent queue reference which should be resolved - /// A TaskAgentQueue instance matching the specified reference if found; otherwise, null - public static TaskAgentQueue GetQueue( - this IResourceStore store, - AgentQueueReference reference) - { - return store.Queues.Get(reference); - } - - /// - /// Retrieves an agent pool from the store using the provided reference. - /// - /// The resource store which should be queried - /// The agent pool reference which should be resolved - /// A TaskAgentPool instance matching the specified reference if found; otherwise, null - public static TaskAgentPool GetPool( - this IResourceStore store, - AgentPoolReference reference) - { - return store.Pools.Get(reference); - } - - /// - /// Retrieves a variable group from the store using the provided reference. - /// - /// The resource store which should be queried - /// The variable group reference which should be resolved - /// A VariableGroup instance matching the specified reference if found; otherwise, null - public static VariableGroup GetVariableGroup( - this IResourceStore store, - VariableGroupReference reference) - { - return store.VariableGroups.Get(reference); - } - - /// - /// Given a partially formed reference, returns the associated reference stored with the plan. - /// - public static ResourceReference GetSnappedReference( - this IResourceStore store, - ResourceReference r) - { - if (r is VariableGroupReference vgr) - { - var m = store.VariableGroups.Get(vgr); - if (m != null) - { - return new VariableGroupReference - { - Id = m.Id, - Name = m.Name - }; - } - } - else if (r is AgentQueueReference aqr) - { - var m = store.Queues.Get(aqr); - if (m != null) - { - return new AgentQueueReference - { - Id = m.Id, - Name = m.Name - }; - } - } - else if (r is AgentPoolReference apr) - { - var m = store.Pools.Get(apr); - if (m != null) - { - return new AgentPoolReference - { - Id = m.Id, - Name = m.Name - }; - } - } - else if (r is ServiceEndpointReference ser) - { - var m = store.Endpoints.Get(ser); - if (m != null) - { - return new ServiceEndpointReference - { - Id = m.Id, - Name = m.Name - }; - } - } - else if (r is SecureFileReference sfr) - { - var m = store.Files.Get(sfr); - if (m != null) - { - return new SecureFileReference - { - Id = m.Id, - Name = m.Name - }; - } - } - else if (r is EnvironmentReference er) - { - var m = store.Environments.Get(er); - if (m != null) - { - return new EnvironmentReference - { - Id = m.Id, - Name = m.Name - }; - } - } - - return r; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ISecureFileResolver.cs b/src/Sdk/DTPipelines/Pipelines/ISecureFileResolver.cs deleted file mode 100644 index be08e791e..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ISecureFileResolver.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism of resolving an SecureFileReference to a SecureFile. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ISecureFileResolver - { - /// - /// Attempts to resolve secure file references to a SecureFile instances. - /// - /// The file references which should be resolved - /// The resolved secure files - IList Resolve(ICollection references); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static class ISecureFileResolverExtensions - { - /// - /// Attempts to resolve the secure file reference to a SecureFile. - /// - /// The file reference which should be resolved - /// The secure file if resolved; otherwise, null - public static SecureFile Resolve( - this ISecureFileResolver resolver, - SecureFileReference reference) - { - return resolver.Resolve(new[] { reference }).FirstOrDefault(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ISecureFileStore.cs b/src/Sdk/DTPipelines/Pipelines/ISecureFileStore.cs deleted file mode 100644 index ea695805d..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ISecureFileStore.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ISecureFileStore - { - IList GetAuthorizedReferences(); - - SecureFile Get(SecureFileReference reference); - - /// - /// Gets the ISecureFileResolver used by this store, if any. - /// - ISecureFileResolver Resolver { get; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IServiceEndpointResolver.cs b/src/Sdk/DTPipelines/Pipelines/IServiceEndpointResolver.cs deleted file mode 100644 index c8646f51b..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IServiceEndpointResolver.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism of resolving an ServiceEndpointReference to a ServiceEndpoint. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IServiceEndpointResolver - { - /// - /// Adds the endpoint reference as authorized to ensure future retrievals of the endpoint - /// are allowed regardless of security context. - /// - /// The endpoint reference which should be considered authorized - void Authorize(ServiceEndpointReference reference); - - /// - /// Attempts to resolve endpoint references to ServiceEndpoint instances. - /// - /// The endpoint references which should be resolved - /// The resolved service endpoints - IList Resolve(ICollection references); - - IList GetAuthorizedReferences(); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static class IServiceEndpointResolverExtensions - { - /// - /// Attempts to resolve the endpoint reference to a ServiceEndpoint. - /// - /// The endpoint reference which should be resolved - /// The service endpoint if resolved; otherwise, null - public static ServiceEndpoint Resolve( - this IServiceEndpointResolver resolver, - ServiceEndpointReference reference) - { - return resolver.Resolve(new[] { reference }).FirstOrDefault(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IServiceEndpointStore.cs b/src/Sdk/DTPipelines/Pipelines/IServiceEndpointStore.cs deleted file mode 100644 index b72d7d95b..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IServiceEndpointStore.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides access to service endpoints which are referenced within a pipeline. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IServiceEndpointStore - { - /// - /// Retrieves the list of all endpoints authorized for use in this store. - /// - /// The list of ServiceEndpointReference objects authorized for use - IList GetAuthorizedReferences(); - - /// - /// Adds an endpoint reference which should be considered authorized. Future - /// calls to retrieve this resource will be treated as pre-authorized regardless - /// of authorization context used. - /// - /// The endpoint which should be authorized - void Authorize(ServiceEndpointReference endpoint); - - /// - /// Attempts to authorize an endpoint for use. - /// - /// The endpoint reference to be resolved - /// The endpoint if found and authorized; otherwise, null - ServiceEndpoint Get(ServiceEndpointReference endpoint); - - /// - /// Gets the IServiceEndpointResolver used by this store, if any. - /// - IServiceEndpointResolver Resolver { get; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IStepProvider.cs b/src/Sdk/DTPipelines/Pipelines/IStepProvider.cs deleted file mode 100644 index 4358edd85..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IStepProvider.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.Pipelines -{ - public interface IStepProvider - { - IList GetPreSteps(IPipelineContext context, IReadOnlyList steps); - Dictionary> GetPostTaskSteps(IPipelineContext context, IReadOnlyList steps); - IList GetPostSteps(IPipelineContext context, IReadOnlyList steps); - - /// - /// Given a JobStep (eg., download step) it will translate into corresndponding task steps - /// - /// - /// Input step to be resolved - /// Resolved output steps - /// true if this is resolved, false otherwise. Passing a powershell step to ResolveStep would return false - Boolean ResolveStep(IPipelineContext context, JobStep step, out IList resolvedSteps); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ITaskResolver.cs b/src/Sdk/DTPipelines/Pipelines/ITaskResolver.cs deleted file mode 100644 index 18bba5c67..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ITaskResolver.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ITaskResolver - { - TaskDefinition Resolve(Guid taskId, String versionSpec); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ITaskStore.cs b/src/Sdk/DTPipelines/Pipelines/ITaskStore.cs deleted file mode 100644 index 2afc0673c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ITaskStore.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a contract for resolving tasks from a given store. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ITaskStore - { - /// - /// Resolves a task from the store using the unqiue identifier and version. - /// - /// The unique identifier of the task - /// The version of the task which is desired - /// The closest matching task definition if found; otherwise, null - TaskDefinition ResolveTask(Guid taskId, String version); - - /// - /// Resolves a task from the store using the specified name and version. - /// - /// The name of the task - /// The version of the task which is desired - /// The closest matching task definition if found; otherwise, null - TaskDefinition ResolveTask(String name, String version); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ITaskTemplateResolver.cs b/src/Sdk/DTPipelines/Pipelines/ITaskTemplateResolver.cs deleted file mode 100644 index e9d8ce669..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ITaskTemplateResolver.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ITaskTemplateResolver - { - Boolean CanResolve(TaskTemplateReference template); - - IList ResolveTasks(TaskTemplateStep template); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ITaskTemplateStore.cs b/src/Sdk/DTPipelines/Pipelines/ITaskTemplateStore.cs deleted file mode 100644 index 75b1a994b..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ITaskTemplateStore.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism for task templates to be resolved at build time. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface ITaskTemplateStore - { - void AddProvider(ITaskTemplateResolver provider); - - IEnumerable ResolveTasks(TaskTemplateStep step); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IVariable.cs b/src/Sdk/DTPipelines/Pipelines/IVariable.cs deleted file mode 100644 index afa278990..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IVariable.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - public enum VariableType - { - Inline = 0, - Group = 1, - } - - [JsonConverter(typeof(VariableJsonConverter))] - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IVariable - { - VariableType Type { get; } - } - - internal class VariableJsonConverter : VssSecureJsonConverter - { - public VariableJsonConverter() - { - } - - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Boolean CanConvert(Type objectType) - { - return typeof(IVariable).IsAssignableFrom(objectType); - } - - public override Object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) - { - if (reader.TokenType != JsonToken.StartObject) - { - return null; - } - - var resultObj = JObject.Load(reader); - var variableType = VariableType.Inline; - if (resultObj.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out var rawValue)) - { - if (rawValue.Type == JTokenType.Integer) - { - variableType = (VariableType)(Int32)rawValue; - } - if (rawValue.Type == JTokenType.String) - { - variableType = (VariableType)Enum.Parse(typeof(VariableType), (String)rawValue, true); - } - } - else if (resultObj.TryGetValue("id", StringComparison.OrdinalIgnoreCase, out _) || - resultObj.TryGetValue("groupType", StringComparison.OrdinalIgnoreCase, out _) || - resultObj.TryGetValue("secretStore", StringComparison.OrdinalIgnoreCase, out _)) - { - variableType = VariableType.Group; - } - - IVariable result = null; - switch (variableType) - { - case VariableType.Group: - result = new VariableGroupReference(); - break; - - default: - result = new Variable(); - break; - } - - using (var objectReader = resultObj.CreateReader()) - { - serializer.Populate(objectReader, result); - } - - return result; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IVariableGroupResolver.cs b/src/Sdk/DTPipelines/Pipelines/IVariableGroupResolver.cs deleted file mode 100644 index 3d41ada2d..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IVariableGroupResolver.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism of resolving an VariableGroupReference to a VariableGroup. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IVariableGroupResolver - { - /// - /// Attempts to resolve variable group references to VariableGroup instances. - /// - /// The variable groups which should be resolved - /// The resolved variable groups - IList Resolve(ICollection references); - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static class IVariableGroupResolverExtensions - { - public static VariableGroup Resolve( - this IVariableGroupResolver resolver, - VariableGroupReference reference) - { - return resolver.Resolve(new[] { reference }).FirstOrDefault(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IVariableGroupStore.cs b/src/Sdk/DTPipelines/Pipelines/IVariableGroupStore.cs deleted file mode 100644 index c2f5272b9..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IVariableGroupStore.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IVariableGroupStore : IStepProvider - { - IList GetAuthorizedReferences(); - - VariableGroup Get(VariableGroupReference queue); - - IVariableValueProvider GetValueProvider(VariableGroupReference queue); - - /// - /// Gets the IVariableGroupsResolver used by this store, if any. - /// - IVariableGroupResolver Resolver { get; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/IVariableValueProvider.cs b/src/Sdk/DTPipelines/Pipelines/IVariableValueProvider.cs deleted file mode 100644 index 8cc315963..000000000 --- a/src/Sdk/DTPipelines/Pipelines/IVariableValueProvider.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IVariableValueProvider - { - String GroupType - { - get; - } - - Boolean ShouldGetValues(IPipelineContext context); - - IList GetSteps(IPipelineContext context, VariableGroupReference group, IEnumerable keys); - - IDictionary GetValues(VariableGroup group, ServiceEndpoint endpoint, IEnumerable keys, Boolean includeSecrets); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Job.cs b/src/Sdk/DTPipelines/Pipelines/Job.cs deleted file mode 100644 index aa389b1b8..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Job.cs +++ /dev/null @@ -1,291 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; -using GitHub.Services.WebApi; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class Job - { - [JsonConstructor] - public Job() - { - } - - private Job(Job jobToCopy) - { - this.Id = jobToCopy.Id; - this.Name = jobToCopy.Name; - this.DisplayName = jobToCopy.DisplayName; - this.Container = jobToCopy.Container?.Clone(); - this.ServiceContainers = jobToCopy.ServiceContainers?.Clone(); - this.ContinueOnError = jobToCopy.ContinueOnError; - this.TimeoutInMinutes = jobToCopy.TimeoutInMinutes; - this.CancelTimeoutInMinutes = jobToCopy.CancelTimeoutInMinutes; - this.Workspace = jobToCopy.Workspace?.Clone(); - this.Target = jobToCopy.Target?.Clone(); - this.EnvironmentVariables = jobToCopy.EnvironmentVariables?.Clone(); - - if (jobToCopy.m_demands != null && jobToCopy.m_demands.Count > 0) - { - m_demands = new List(jobToCopy.m_demands.Select(x => x.Clone())); - } - - if (jobToCopy.m_steps != null && jobToCopy.m_steps.Count > 0) - { - m_steps = new List(jobToCopy.m_steps.Select(x => x.Clone() as JobStep)); - } - - if (jobToCopy.m_variables != null && jobToCopy.m_variables.Count > 0) - { - m_variables = new List(jobToCopy.m_variables); - } - - if (jobToCopy.m_sidecarContainers != null && jobToCopy.m_sidecarContainers.Count > 0) - { - m_sidecarContainers = new Dictionary(jobToCopy.m_sidecarContainers, StringComparer.OrdinalIgnoreCase); - } - } - - [DataMember] - public Guid Id - { - get; - set; - } - - [DataMember] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String DisplayName - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken Container - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken ServiceContainers - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean ContinueOnError - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken EnvironmentVariables - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Int32 TimeoutInMinutes - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Int32 CancelTimeoutInMinutes - { - get; - set; - } - - public IList Demands - { - get - { - if (m_demands == null) - { - m_demands = new List(); - } - return m_demands; - } - } - - [DataMember(EmitDefaultValue = false)] - public IdentityRef ExecuteAs - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public WorkspaceOptions Workspace - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public PhaseTarget Target - { - get; - set; - } - - public IList Steps - { - get - { - if (m_steps == null) - { - m_steps = new List(); - } - return m_steps; - } - } - - public IList Scopes - { - get - { - if (m_scopes == null) - { - m_scopes = new List(); - } - return m_scopes; - } - } - - public IDictionary SidecarContainers - { - get - { - if (m_sidecarContainers == null) - { - m_sidecarContainers = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_sidecarContainers; - } - } - - public IList Variables - { - get - { - if (m_variables == null) - { - m_variables = new List(); - } - return m_variables; - } - } - - public Job Clone() - { - return new Job(this); - } - - /// - /// Creates an instance of a task using the specified execution context. - /// - /// The job execution context - /// The name of the task in the steps list - /// - public CreateTaskResult CreateTask( - JobExecutionContext context, - String taskName) - { - ArgumentUtility.CheckStringForNullOrEmpty(taskName, nameof(taskName)); - - TaskDefinition definition = null; - var task = this.Steps.SingleOrDefault(x => taskName.Equals(x.Name, StringComparison.OrdinalIgnoreCase))?.Clone() as TaskStep; - if (task != null) - { - definition = context.TaskStore.ResolveTask(task.Reference.Id, task.Reference.Version); - foreach (var input in definition.Inputs.Where(x => x != null)) - { - var key = input.Name?.Trim() ?? String.Empty; - if (!String.IsNullOrEmpty(key)) - { - if (!task.Inputs.ContainsKey(key)) - { - task.Inputs[key] = input.DefaultValue?.Trim() ?? String.Empty; - } - } - } - - // Now expand any macros which appear in inputs - foreach (var input in task.Inputs.ToArray()) - { - task.Inputs[input.Key] = context.ExpandVariables(input.Value); - } - - // Set the system variables populated while running an individual task - context.Variables[WellKnownDistributedTaskVariables.TaskInstanceId] = task.Id.ToString("D"); - context.Variables[WellKnownDistributedTaskVariables.TaskDisplayName] = task.DisplayName ?? task.Name; - context.Variables[WellKnownDistributedTaskVariables.TaskInstanceName] = task.Name; - } - - return new CreateTaskResult(task, definition); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_demands?.Count == 0) - { - m_demands = null; - } - - if (m_steps?.Count == 0) - { - m_steps = null; - } - - if (m_scopes?.Count == 0) - { - m_scopes = null; - } - - if (m_variables?.Count == 0) - { - m_variables = null; - } - } - - [DataMember(Name = "Demands", EmitDefaultValue = false)] - private List m_demands; - - [DataMember(Name = "Steps", EmitDefaultValue = false)] - private List m_steps; - - [DataMember(Name = "Scopes", EmitDefaultValue = false)] - private List m_scopes; - - [DataMember(Name = "Variables", EmitDefaultValue = false)] - private List m_variables; - - [DataMember(Name = "SidecarContainers", EmitDefaultValue = false)] - private IDictionary m_sidecarContainers; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/JobExpansionOptions.cs b/src/Sdk/DTPipelines/Pipelines/JobExpansionOptions.cs deleted file mode 100644 index 5277822c4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/JobExpansionOptions.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.Pipelines -{ - public class JobExpansionOptions - { - public JobExpansionOptions(ICollection configurations) - { - AddConfigurations(configurations); - } - - internal JobExpansionOptions(IDictionary configurations) - { - UpdateConfigurations(configurations); - } - - internal JobExpansionOptions( - String configuration, - Int32 attemptNumber = NoSpecifiedAttemptNumber) - { - if (!String.IsNullOrEmpty(configuration)) - { - this.Configurations.Add(configuration, attemptNumber); - } - } - - /// - /// Specifies a filter for the expansion of specific Phase configurations. - /// The key is the configuration name, the value is the explicitly requested - /// attempt number. - /// If mapping is null, there is no filter and all configurations will be - /// produced. - /// - internal IDictionary Configurations - { - get - { - if (m_configurations == null) - { - m_configurations = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_configurations; - } - } - - public Boolean IsIncluded(String configuration) - { - return m_configurations == null || m_configurations.ContainsKey(configuration); - } - - /// - /// Add new configurations, with no specified custom attempt number - /// - public void AddConfigurations(ICollection configurations) - { - if (configurations == null) - { - return; - } - - var localConfigs = this.Configurations; - foreach (var c in configurations) - { - if (!localConfigs.ContainsKey(c)) - { - localConfigs[c] = NoSpecifiedAttemptNumber; - } - } - } - - /// - /// add (or replace) any configurations and their associated attempt numbers with new provided values. - /// - public void UpdateConfigurations(IDictionary configurations) - { - if (configurations == null) - { - return; - } - - var localConfigs = this.Configurations; - foreach (var pair in configurations) - { - localConfigs[pair.Key] = pair.Value; - } - } - - /// - /// returns custom attempt number or JobExpansionOptions.NoSpecifiedAttemptNumber if none specified. - /// - /// configuration or "job name" - public Int32 GetAttemptNumber(String configuration) - { - if (m_configurations != null && m_configurations.TryGetValue(configuration, out Int32 number)) - { - return number; - } - - return NoSpecifiedAttemptNumber; - } - - public const Int32 NoSpecifiedAttemptNumber = -1; - private Dictionary m_configurations; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/JobFactory.cs b/src/Sdk/DTPipelines/Pipelines/JobFactory.cs deleted file mode 100644 index 798547fbf..000000000 --- a/src/Sdk/DTPipelines/Pipelines/JobFactory.cs +++ /dev/null @@ -1,480 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.Pipelines.ObjectTemplating; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class JobFactory : PhaseNode - { - public JobFactory() - { - } - - private JobFactory(JobFactory copy) - : base(copy) - { - if (copy.m_steps != null && copy.m_steps.Count > 0) - { - m_steps = new List(copy.m_steps.Select(x => x.Clone())); - } - } - - /// - /// Gets the phase type. - /// - [DataMember(EmitDefaultValue = false)] - public override PhaseType Type => PhaseType.JobFactory; - - public IList Scopes - { - get - { - if (m_scopes == null) - { - m_scopes = new List(); - } - return m_scopes; - } - } - - /// - /// Gets the list of steps associated with this phase. At runtime the steps will be used as a template for - /// the execution of a job. - /// - public IList Steps - { - get - { - if (m_steps == null) - { - m_steps = new List(); - } - return m_steps; - } - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken Strategy - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public ScalarToken JobDisplayName - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken JobTarget - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public ScalarToken JobTimeout - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public ScalarToken JobCancelTimeout - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken JobContainer - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken JobServiceContainers - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken EnvironmentVariables - { - get; - set; - } - - public void CheckExpandReferences( - out bool isEventReferenced, - out bool isOutputsReferenced) - { - isEventReferenced = false; - isOutputsReferenced = false; - var expressionTokens = Strategy.Traverse() - .Concat(JobDisplayName.Traverse()) - .Concat(JobTarget.Traverse()) - .Concat(JobTimeout.Traverse()) - .Concat(JobCancelTimeout.Traverse()) - .OfType() - .ToArray(); - var parser = new ExpressionParser(); - foreach (var expressionToken in expressionTokens) - { - var tree = parser.ValidateSyntax(expressionToken.Expression, null); - var isReferenced = tree.CheckReferencesContext( - PipelineTemplateConstants.EventPattern, - PipelineTemplateConstants.OutputsPattern); - if (!isEventReferenced) - { - isEventReferenced = isReferenced[0]; - } - - if (!isOutputsReferenced) - { - isOutputsReferenced = isReferenced[1]; - } - } - } - - public ExpandPhaseResult Expand( - PhaseExecutionContext context, - JobExpansionOptions options = null) - { - var result = new ExpandPhaseResult(); - - var trace = new JobFactoryTrace(context.Trace); - var schema = new PipelineTemplateSchemaFactory().CreateSchema(); - var templateEvaluator = new PipelineTemplateEvaluator(trace, schema); - - trace.Info("Evaluating strategy"); - var displayName = JobDisplayName is ExpressionToken ? null : DisplayName; - var strategy = templateEvaluator.EvaluateStrategy(Strategy, context.Data, displayName); - - foreach (var jobContext in ExpandContexts(context, options, strategy, trace, templateEvaluator)) - { - result.Jobs.Add(jobContext.Job); - } - - if (strategy.MaxParallel > 0) - { - result.MaxConcurrency = strategy.MaxParallel; - } - else - { - result.MaxConcurrency = result.Jobs.Count; - } - - result.FailFast = strategy.FailFast; - - return result; - } - - public IEnumerable ExpandContexts( - PhaseExecutionContext context, - JobExpansionOptions options = null, - StrategyResult strategy = null, - DistributedTask.ObjectTemplating.ITraceWriter trace = null, - PipelineTemplateEvaluator templateEvaluator = null) - { - if (trace == null) - { - trace = new JobFactoryTrace(context.Trace); - } - - if (templateEvaluator == null) - { - var schema = new PipelineTemplateSchemaFactory().CreateSchema(); - templateEvaluator = new PipelineTemplateEvaluator(trace, schema); - } - - // Strategy - if (strategy == null) - { - trace.Info("Evaluating strategy"); - var displayName = JobDisplayName is ExpressionToken ? null : DisplayName; - strategy = templateEvaluator.EvaluateStrategy(Strategy, context.Data, displayName); - } - - // Check max jobs - var maxJobs = context.ExecutionOptions.MaxJobExpansion ?? 100; - if (strategy.Configurations.Count > maxJobs) - { - throw new MaxJobExpansionException($"Strategy produced more than {maxJobs}"); - } - - // Create jobs - for (var i = 0; i < strategy.Configurations.Count; i++) - { - var configuration = strategy.Configurations[i]; - var jobName = configuration.Name; - var attempt = 1; - if (options?.Configurations.Count > 0) - { - if (!options.Configurations.TryGetValue(jobName, out attempt)) - { - continue; - } - } - - yield return CreateJob(trace, context, templateEvaluator, jobName, configuration.DisplayName, attempt, i + 1, strategy.Configurations.Count, configuration.ContextData); - } - } - - /// - /// Resolves external references and ensures the steps are compatible with the selected target. - /// - /// The validation context - public override void Validate( - PipelineBuildContext context, - ValidationResult result) - { - base.Validate(context, result); - - var phaseStepValidationResult = new Phase.StepValidationResult(); - - // Require the latest agent version. - if (context.BuildOptions.DemandLatestAgent) - { - var latestPackageVersion = context.PackageStore?.GetLatestVersion(WellKnownPackageTypes.Agent); - if (latestPackageVersion == null) - { - throw new NotSupportedException("Unable to determine the latest agent package version"); - } - - phaseStepValidationResult.MinAgentVersion = latestPackageVersion.ToString(); - } - - Phase.ValidateSteps(context, this, new AgentQueueTarget(), result, Steps, phaseStepValidationResult); - - // Resolve the target to ensure we have stable identifiers for the orchestration engine - // phase targets with expressions need to be evaluated against resolved job contexts. - bool validateTarget = false; - if (this.Target.Type == PhaseTargetType.Pool || this.Target.Type == PhaseTargetType.Server) - { - validateTarget = true; - } - else if (this.Target is AgentQueueTarget agentQueueTarget && agentQueueTarget.IsLiteral()) - { - validateTarget = true; - } - - if (validateTarget) - { - this.Target.Validate( - context, - context.BuildOptions, - result, - this.Steps, - phaseStepValidationResult.TaskDemands); - } - } - - private JobExecutionContext CreateJob( - DistributedTask.ObjectTemplating.ITraceWriter trace, - PhaseExecutionContext phaseContext, - PipelineTemplateEvaluator templateEvaluator, - String jobName, - String configurationDisplayName, - Int32 attempt, - Int32 positionInPhase, - Int32 totalJobsInPhase, - IDictionary contextData) - { - trace.Info($"Creating job '{jobName}'"); - var jobContext = new JobExecutionContext( - context: phaseContext, - job: new JobInstance(jobName, attempt), - variables: null, - positionInPhase: positionInPhase, - totalJobsInPhase: totalJobsInPhase, - data: contextData); - var job = new Job - { - Id = jobContext.GetInstanceId(), - Name = jobContext.Job.Name, - EnvironmentVariables = EnvironmentVariables, - Container = JobContainer, - ServiceContainers = JobServiceContainers, - }; - - if (JobDisplayName is ExpressionToken) - { - trace.Info("Evaluating display name"); - job.DisplayName = templateEvaluator.EvaluateJobDisplayName(JobDisplayName, jobContext.Data, DisplayName); - } - else if (!String.IsNullOrEmpty(configurationDisplayName)) - { - job.DisplayName = configurationDisplayName; - } - else - { - job.DisplayName = DisplayName; - } - - trace.Info("Evaluating timeout"); - job.TimeoutInMinutes = templateEvaluator.EvaluateJobTimeout(JobTimeout, jobContext.Data); - trace.Info("Evaluating cancel timeout"); - job.CancelTimeoutInMinutes = templateEvaluator.EvaluateJobCancelTimeout(JobCancelTimeout, jobContext.Data); - trace.Info("Evaluating target"); - job.Target = templateEvaluator.EvaluateJobTarget(JobTarget, jobContext.Data); - - jobContext.Job.Definition = job; - - // Resolve the pool by name - if (job.Target is AgentPoolTarget pool && - pool.Pool?.Id == 0 && - !String.IsNullOrEmpty(pool.Pool.Name?.Literal)) - { - var resolved = jobContext.ResourceStore.GetPool(pool.Pool.Name.Literal); - if (resolved != null) - { - pool.Pool = new AgentPoolReference { Id = resolved.Id, Name = resolved.Name }; - } - } - - // Resolve the queue by name - if (job.Target is AgentQueueTarget queue && - queue.Queue?.Id == 0 && - !String.IsNullOrEmpty(queue.Queue.Name?.Literal)) - { - var resolved = jobContext.ResourceStore.GetQueue(queue.Queue.Name.Literal); - if (resolved != null) - { - queue.Queue = new AgentQueueReference { Id = resolved.Id, Name = resolved.Name }; - } - } - - // Always add self - var self = jobContext.ResourceStore?.Repositories.Get(PipelineConstants.SelfAlias); - if (self == null) - { - throw new InvalidOperationException($"Repository '{PipelineConstants.SelfAlias}' not found"); - } - - jobContext.ReferencedResources.Repositories.Add(self); - - // Add the endpoint - if (self.Endpoint != null) - { - jobContext.ReferencedResources.AddEndpointReference(self.Endpoint); - var repositoryEndpoint = jobContext.ResourceStore?.GetEndpoint(self.Endpoint); - if (repositoryEndpoint == null) - { - throw new ResourceNotFoundException(PipelineStrings.ServiceEndpointNotFound(self.Endpoint)); - } - } - - // Update the execution context with the job-specific system variables - UpdateJobContextVariablesFromJob(jobContext, job); - - var steps = new List(); - var identifier = jobContext.GetInstanceName(); - foreach (var step in Steps) - { - if (step.Type == StepType.Action) - { - job.Steps.Add(Phase.CreateJobActionStep(jobContext, identifier, step as ActionStep)); - } - else - { - throw new NotSupportedException($"Unexpected step type '{step.Type}'"); - } - } - - foreach (var scope in Scopes) - { - job.Scopes.Add(scope); - } - - return jobContext; - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_scopes?.Count == 0) - { - m_scopes = null; - } - - if (m_steps?.Count == 0) - { - m_steps = null; - } - } - - private sealed class JobFactoryTrace : DistributedTask.ObjectTemplating.ITraceWriter - { - public JobFactoryTrace(DistributedTask.Expressions2.ITraceWriter trace) - { - m_trace = trace; - } - - public void Error( - String message, - params Object[] args) - { - Info("##[error]", message, args); - } - - public void Info( - String message, - params Object[] args) - { - Info(String.Empty, message, args); - } - - public void Verbose( - String message, - params Object[] args) - { - Info("##[debug]", message, args); - } - - private void Info( - String prefix, - String message, - params Object[] args) - { - if (m_trace == null) - { - return; - } - - if (args?.Length > 0) - { - m_trace.Info(String.Format(CultureInfo.InvariantCulture, $"{prefix}{message}", args)); - } - else - { - m_trace.Info($"{prefix}{message}"); - } - } - - private DistributedTask.Expressions2.ITraceWriter m_trace; - } - - [DataMember(Name = "Scopes", EmitDefaultValue = false)] - private IList m_scopes; - - [DataMember(Name = "Steps", EmitDefaultValue = false)] - private IList m_steps; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/JobResources.cs b/src/Sdk/DTPipelines/Pipelines/JobResources.cs index 7136b0775..fc9ba7618 100644 --- a/src/Sdk/DTPipelines/Pipelines/JobResources.cs +++ b/src/Sdk/DTPipelines/Pipelines/JobResources.cs @@ -54,21 +54,6 @@ namespace GitHub.DistributedTask.Pipelines } } - /// - /// Gets the collection of secure files associated with the current job - /// - public List SecureFiles - { - get - { - if (m_secureFiles == null) - { - m_secureFiles = new List(); - } - return m_secureFiles; - } - } - [OnSerializing] private void OnSerializing(StreamingContext context) { @@ -86,11 +71,6 @@ namespace GitHub.DistributedTask.Pipelines { m_repositories = null; } - - if (m_secureFiles?.Count == 0) - { - m_secureFiles = null; - } } [DataMember(Name = "Containers", EmitDefaultValue = false)] @@ -101,8 +81,5 @@ namespace GitHub.DistributedTask.Pipelines [DataMember(Name = "Repositories", EmitDefaultValue = false)] private List m_repositories; - - [DataMember(Name = "SecureFiles", EmitDefaultValue = false)] - private List m_secureFiles; } } diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/GraphConditionNamedValue.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/GraphConditionNamedValue.cs deleted file mode 100644 index cccc24d1b..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/GraphConditionNamedValue.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions2.Sdk; -using GitHub.DistributedTask.Pipelines.Runtime; - -namespace GitHub.DistributedTask.Pipelines.ObjectTemplating -{ - /// - /// Named-value node used when evaluating graph-node conditions - /// - [EditorBrowsable(EditorBrowsableState.Never)] - internal sealed class GraphConditionNamedValue : NamedValue where TInstance : IGraphNodeInstance - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - var graphContext = context.State as GraphExecutionContext; - graphContext.Data.TryGetValue(Name, out var result); - return result; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/MatrixBuilder.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/MatrixBuilder.cs deleted file mode 100644 index a23feaab1..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/MatrixBuilder.cs +++ /dev/null @@ -1,445 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Expressions2.Sdk; -using GitHub.DistributedTask.ObjectTemplating; -using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.Pipelines.ContextData; - -namespace GitHub.DistributedTask.Pipelines.ObjectTemplating -{ - internal sealed class MatrixBuilder - { - internal MatrixBuilder( - TemplateContext context, - String jobFactoryDisplayName) - { - m_context = context; - m_jobFactoryDisplayName = jobFactoryDisplayName; - } - - internal void AddVector( - String name, - SequenceToken vector) - { - m_vectors.Add(name, vector.ToContextData()); - } - - internal DictionaryContextData Vectors => m_vectors; - - internal void Exclude(SequenceToken exclude) - { - m_excludeSequence = exclude; - } - - internal void Include(SequenceToken include) - { - m_includeSequence = include; - } - - internal IEnumerable Build() - { - if (m_vectors.Count > 0) - { - // Parse includes/excludes - var include = new MatrixInclude(m_context, m_vectors, m_includeSequence); - var exclude = new MatrixExclude(m_context, m_vectors, m_excludeSequence); - - // Calculate the cross product size - var productSize = 1; - foreach (var vectorPair in m_vectors) - { - checked - { - var vector = vectorPair.Value.AssertArray("vector"); - productSize *= vector.Count; - } - } - - var nameBuilder = new ReferenceNameBuilder(); - var displayNameBuilder = new JobDisplayNameBuilder(m_jobFactoryDisplayName); - - // Cross product - for (var productIndex = 0; productIndex < productSize; productIndex++) - { - // Matrix - var matrix = new DictionaryContextData(); - var blockSize = productSize; - foreach (var vectorPair in m_vectors) - { - var vectorName = vectorPair.Key; - var vector = vectorPair.Value.AssertArray("vector"); - blockSize = blockSize / vector.Count; - var vectorIndex = (productIndex / blockSize) % vector.Count; - matrix.Add(vectorName, vector[vectorIndex]); - } - - // Exclude - if (exclude.Match(matrix)) - { - continue; - } - - // New configuration - var configuration = new StrategyConfiguration(); - m_context.Memory.AddBytes(TemplateMemory.MinObjectSize); - - // Gather segments for name and display name - foreach (var matrixData in matrix.Traverse(omitKeys: true)) - { - var segment = default(String); - switch (matrixData?.Type) - { - case PipelineContextDataType.Boolean: - case PipelineContextDataType.Number: - case PipelineContextDataType.String: - segment = matrixData.ToString(); - break; - } - - if (!String.IsNullOrEmpty(segment)) - { - // Name segment - nameBuilder.AppendSegment(segment); - - // Display name segment - displayNameBuilder.AppendSegment(segment); - } - } - - // Name - configuration.Name = nameBuilder.Build(); - m_context.Memory.AddBytes(configuration.Name); - - // Display name - configuration.DisplayName = displayNameBuilder.Build(); - m_context.Memory.AddBytes(configuration.DisplayName); - - // Include - if (include.Match(matrix, out var extra)) - { - matrix.Add(extra); - } - - // Matrix context - configuration.ContextData.Add(PipelineTemplateConstants.Matrix, matrix); - m_context.Memory.AddBytes(PipelineTemplateConstants.Matrix); - m_context.Memory.AddBytes(matrix, traverse: true); - - // Add configuration - yield return configuration; - } - } - } - - private sealed class MatrixInclude - { - public MatrixInclude( - TemplateContext context, - DictionaryContextData vectors, - SequenceToken includeSequence) - { - // Convert to excludes sets - if (includeSequence?.Count > 0) - { - foreach (var includeItem in includeSequence) - { - var includeMapping = includeItem.AssertMapping("matrix includes item"); - - // Distinguish filters versus extra - var filter = new MappingToken(null, null, null); - var extra = new DictionaryContextData(); - foreach (var includePair in includeMapping) - { - var includeKeyLiteral = includePair.Key.AssertString("matrix include item key"); - if (vectors.ContainsKey(includeKeyLiteral.Value)) - { - filter.Add(includeKeyLiteral, includePair.Value); - } - else - { - extra.Add(includeKeyLiteral.Value, includePair.Value.ToContextData()); - } - } - - // At least one filter - if (filter.Count == 0) - { - context.Error(includeMapping, $"Matrix include mapping does not contain any filters"); - continue; - } - - // At least one extra - if (extra.Count == 0) - { - context.Error(includeMapping, $"Matrix include mapping does not contain any extra values to include"); - continue; - } - - // Add filter - m_filters.Add(new MatrixIncludeFilter(filter, extra)); - } - } - } - - public Boolean Match( - DictionaryContextData matrix, - out DictionaryContextData extra) - { - extra = default(DictionaryContextData); - foreach (var filter in m_filters) - { - if (filter.Match(matrix, out var items)) - { - if (extra == null) - { - extra = new DictionaryContextData(); - } - - foreach (var pair in items) - { - extra[pair.Key] = pair.Value; - } - } - } - - return extra != null; - } - - private readonly List m_filters = new List(); - } - - private sealed class MatrixIncludeFilter : MatrixFilter - { - public MatrixIncludeFilter( - MappingToken filter, - DictionaryContextData extra) - : base(filter) - { - m_extra = extra; - } - - public Boolean Match( - DictionaryContextData matrix, - out DictionaryContextData extra) - { - if (base.Match(matrix)) - { - extra = m_extra; - return true; - } - - extra = null; - return false; - } - - private readonly DictionaryContextData m_extra; - } - - private sealed class MatrixExclude - { - public MatrixExclude( - TemplateContext context, - DictionaryContextData vectors, - SequenceToken excludeSequence) - { - // Convert to excludes sets - if (excludeSequence?.Count > 0) - { - foreach (var excludeItem in excludeSequence) - { - var excludeMapping = excludeItem.AssertMapping("matrix excludes item"); - - // Check empty - if (excludeMapping.Count == 0) - { - context.Error(excludeMapping, $"Matrix exclude filter must not be empty"); - continue; - } - - // Validate first-level keys - foreach (var excludePair in excludeMapping) - { - var excludeKey = excludePair.Key.AssertString("matrix excludes item key"); - if (!vectors.ContainsKey(excludeKey.Value)) - { - context.Error(excludeKey, $"Matrix exclude key '{excludeKey.Value}' does not match any key within the matrix"); - continue; - } - } - - // Add filter - m_filters.Add(new MatrixExcludeFilter(excludeMapping)); - } - } - } - - public Boolean Match(DictionaryContextData matrix) - { - foreach (var filter in m_filters) - { - if (filter.Match(matrix)) - { - return true; - } - } - - return false; - } - - private readonly List m_filters = new List(); - } - - private sealed class MatrixExcludeFilter : MatrixFilter - { - public MatrixExcludeFilter(MappingToken filter) - : base(filter) - { - } - - public new Boolean Match(DictionaryContextData matrix) - { - return base.Match(matrix); - } - } - - private abstract class MatrixFilter - { - protected MatrixFilter(MappingToken matrixFilter) - { - var state = new MappingState(null, matrixFilter); - while (state != null) - { - if (state.MoveNext()) - { - var value = state.Mapping[state.Index].Value; - if (value is LiteralToken literal) - { - AddExpression(state, literal); - } - else - { - var mapping = state.Mapping[state.Index].Value.AssertMapping("matrix filter"); - state = new MappingState(state, mapping); - } - } - else - { - state = state.Parent; - } - } - } - - protected Boolean Match(DictionaryContextData matrix) - { - if (matrix.Count == 0) - { - throw new InvalidOperationException("Matrix filter cannot be empty"); - } - - foreach (var expression in m_expressions) - { - var result = expression.Evaluate(null, null, matrix, null); - if (result.IsFalsy) - { - return false; - } - } - - return true; - } - - private void AddExpression( - MappingState state, - LiteralToken literal) - { - var expressionLiteral = default(String); - switch (literal.Type) - { - case TokenType.Null: - expressionLiteral = ExpressionConstants.Null; - break; - - case TokenType.Boolean: - var booleanToken = literal as BooleanToken; - expressionLiteral = booleanToken.Value ? ExpressionConstants.True : ExpressionConstants.False; - break; - - case TokenType.Number: - var numberToken = literal as NumberToken; - expressionLiteral = String.Format(CultureInfo.InvariantCulture, ExpressionConstants.NumberFormat, numberToken.Value); - break; - - case TokenType.String: - var stringToken = literal as StringToken; - expressionLiteral = $"'{ExpressionUtility.StringEscape(stringToken.Value)}'"; - break; - - default: - throw new NotSupportedException($"Unexpected literal type '{literal.Type}'"); - } - - var str = $"{state.Path} == {expressionLiteral}"; - var parser = new ExpressionParser(); - var expression = parser.CreateTree(str, null, s_matrixFilterNamedValues, null); - m_expressions.Add(expression); - } - - private static readonly INamedValueInfo[] s_matrixFilterNamedValues = new INamedValueInfo[] - { - new NamedValueInfo(PipelineTemplateConstants.Matrix), - }; - private readonly List m_expressions = new List(); - } - - private sealed class MappingState - { - public MappingState( - MappingState parent, - MappingToken mapping) - { - Parent = parent; - Mapping = mapping; - Index = -1; - } - - public Boolean MoveNext() - { - if (++Index < Mapping.Count) - { - var keyLiteral = Mapping[Index].Key.AssertString("matrix filter key"); - var parentPath = Parent?.Path ?? PipelineTemplateConstants.Matrix; - Path = $"{parentPath}['{ExpressionUtility.StringEscape(keyLiteral.Value)}']"; - return true; - } - else - { - return false; - } - } - - public MappingState Parent; - public MappingToken Mapping; - public Int32 Index; - public String Path; - } - - private sealed class MatrixNamedValue : NamedValue - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - return context.State; - } - } - - private readonly TemplateContext m_context; - private readonly String m_jobFactoryDisplayName; - private readonly DictionaryContextData m_vectors = new DictionaryContextData(); - private SequenceToken m_excludeSequence; - private SequenceToken m_includeSequence; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs index 45f6dc697..a3fbe244f 100644 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs +++ b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs @@ -16,72 +16,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating { internal static class PipelineTemplateConverter { - internal static PipelineTemplate ConvertToPipeline( - TemplateContext context, - RepositoryResource self, - TemplateToken pipeline) - { - var result = new PipelineTemplate(); - result.Resources.Repositories.Add(self); - var defaultStage = new Stage - { - Name = PipelineConstants.DefaultJobName, - }; - result.Stages.Add(defaultStage); - - try - { - if (pipeline == null || context.Errors.Count > 0) - { - return result; - } - - var pipelineMapping = pipeline.AssertMapping("root"); - - foreach (var pipelinePair in pipelineMapping) - { - var pipelineKey = pipelinePair.Key.AssertString("root key"); - - switch (pipelineKey.Value) - { - case PipelineTemplateConstants.On: - break; - - case PipelineTemplateConstants.Name: - break; - - case PipelineTemplateConstants.Env: - result.EnvironmentVariables = pipelinePair.Value; - break; - - case PipelineTemplateConstants.Jobs: - defaultStage.Phases.AddRange(ConvertToJobFactories(context, result.Resources, pipelinePair.Value)); - break; - - default: - pipelineKey.AssertUnexpectedValue("root key"); // throws - break; - } - } - } - catch (Exception ex) - { - context.Errors.Add(ex); - } - finally - { - if (context.Errors.Count > 0) - { - foreach (var error in context.Errors) - { - result.Errors.Add(new PipelineValidationError(error.Code, error.Message)); - } - } - } - - return result; - } - internal static String ConvertToJobDisplayName( TemplateContext context, TemplateToken displayName, @@ -100,68 +34,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating result = displayNameString.Value; return result; } - - internal static PhaseTarget ConvertToJobTarget( - TemplateContext context, - TemplateToken runsOn, - Boolean allowExpressions = false) - { - var result = new AgentPoolTarget(); - - // Expression - if (allowExpressions && runsOn is ExpressionToken) - { - return result; - } - - // String - if (runsOn is StringToken runsOnString) - { - result.Pool = new AgentPoolReference { Name = "GitHub Actions" }; - result.AgentSpecification = new JObject - { - { PipelineTemplateConstants.VmImage, runsOnString.Value } - }; - } - // Mapping - else - { - var runsOnMapping = runsOn.AssertMapping($"job {PipelineTemplateConstants.RunsOn}"); - foreach (var runsOnProperty in runsOnMapping) - { - // Expression - if (allowExpressions && runsOnProperty.Key is ExpressionToken) - { - continue; - } - - // String - var propertyName = runsOnProperty.Key.AssertString($"job {PipelineTemplateConstants.RunsOn} key"); - - switch (propertyName.Value) - { - case PipelineTemplateConstants.Pool: - // Expression - if (allowExpressions && runsOnProperty.Value is ExpressionToken) - { - continue; - } - - // Literal - var pool = runsOnProperty.Value.AssertString($"job {PipelineTemplateConstants.RunsOn} key"); - result.Pool = new AgentPoolReference { Name = pool.Value }; - break; - - default: - propertyName.AssertUnexpectedValue($"job {PipelineTemplateConstants.RunsOn} key"); // throws - break; - } - } - } - - return result; - } - internal static Int32? ConvertToJobTimeout( TemplateContext context, TemplateToken token, @@ -315,203 +187,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating return (Int32)numberToken.Value; } - internal static StrategyResult ConvertToStrategy( - TemplateContext context, - TemplateToken token, - String jobFactoryDisplayName, - Boolean allowExpressions = false) - { - var result = new StrategyResult(); - - // Expression - if (allowExpressions && token is ExpressionToken) - { - return result; - } - - var strategyMapping = token.AssertMapping(PipelineTemplateConstants.Strategy); - var matrixBuilder = default(MatrixBuilder); - var hasExpressions = false; - - foreach (var strategyPair in strategyMapping) - { - // Expression key - if (allowExpressions && strategyPair.Key is ExpressionToken) - { - hasExpressions = true; - continue; - } - - // Literal key - var strategyKey = strategyPair.Key.AssertString("strategy key"); - - switch (strategyKey.Value) - { - // Fail-Fast - case PipelineTemplateConstants.FailFast: - if (allowExpressions && strategyPair.Value is ExpressionToken) - { - hasExpressions = true; - continue; - } - - var failFastBooleanToken = strategyPair.Value.AssertBoolean($"strategy {PipelineTemplateConstants.FailFast}"); - result.FailFast = failFastBooleanToken.Value; - break; - - // Max-Parallel - case PipelineTemplateConstants.MaxParallel: - if (allowExpressions && strategyPair.Value is ExpressionToken) - { - hasExpressions = true; - continue; - } - - var maxParallelNumberToken = strategyPair.Value.AssertNumber($"strategy {PipelineTemplateConstants.MaxParallel}"); - result.MaxParallel = (Int32)maxParallelNumberToken.Value; - break; - - // Matrix - case PipelineTemplateConstants.Matrix: - - // Expression - if (allowExpressions && strategyPair.Value is ExpressionToken) - { - hasExpressions = true; - continue; - } - - var matrix = strategyPair.Value.AssertMapping("matrix"); - hasExpressions = hasExpressions || matrix.Traverse().Any(x => x is ExpressionToken); - matrixBuilder = new MatrixBuilder(context, jobFactoryDisplayName); - var hasVector = false; - - foreach (var matrixPair in matrix) - { - // Expression key - if (allowExpressions && matrixPair.Key is ExpressionToken) - { - hasVector = true; // For validation, treat as if a vector is defined - continue; - } - - var matrixKey = matrixPair.Key.AssertString("matrix key"); - switch (matrixKey.Value) - { - case PipelineTemplateConstants.Include: - if (allowExpressions && matrixPair.Value is ExpressionToken) - { - continue; - } - - var includeSequence = matrixPair.Value.AssertSequence("matrix includes"); - matrixBuilder.Include(includeSequence); - break; - - case PipelineTemplateConstants.Exclude: - if (allowExpressions && matrixPair.Value is ExpressionToken) - { - continue; - } - - var excludeSequence = matrixPair.Value.AssertSequence("matrix excludes"); - matrixBuilder.Exclude(excludeSequence); - break; - - default: - hasVector = true; - - if (allowExpressions && matrixPair.Value is ExpressionToken) - { - continue; - } - - var vectorName = matrixKey.Value; - var vectorSequence = matrixPair.Value.AssertSequence("matrix vector value"); - if (vectorSequence.Count == 0) - { - context.Error(vectorSequence, $"Matrix vector '{vectorName}' does not contain any values"); - } - else - { - matrixBuilder.AddVector(vectorName, vectorSequence); - } - break; - } - } - - if (!hasVector) - { - context.Error(matrix, $"Matrix must defined at least one vector"); - } - - break; - - default: - strategyKey.AssertUnexpectedValue("strategy key"); // throws - break; - } - } - - if (hasExpressions) - { - return result; - } - - if (matrixBuilder != null) - { - result.Configurations.AddRange(matrixBuilder.Build()); - } - - for (var i = 0; i < result.Configurations.Count; i++) - { - var configuration = result.Configurations[i]; - - var strategy = new DictionaryContextData() - { - { - "fail-fast", - new BooleanContextData(result.FailFast) - }, - { - "job-index", - new NumberContextData(i) - }, - { - "job-total", - new NumberContextData(result.Configurations.Count) - } - }; - - if (result.MaxParallel > 0) - { - strategy.Add( - "max-parallel", - new NumberContextData(result.MaxParallel) - ); - } - else - { - strategy.Add( - "max-parallel", - new NumberContextData(result.Configurations.Count) - ); - } - - configuration.ContextData.Add(PipelineTemplateConstants.Strategy, strategy); - context.Memory.AddBytes(PipelineTemplateConstants.Strategy); - context.Memory.AddBytes(strategy, traverse: true); - - if (!configuration.ContextData.ContainsKey(PipelineTemplateConstants.Matrix)) - { - configuration.ContextData.Add(PipelineTemplateConstants.Matrix, null); - context.Memory.AddBytes(PipelineTemplateConstants.Matrix); - } - } - - return result; - } - internal static JobContainer ConvertToJobContainer( TemplateContext context, TemplateToken value, @@ -617,169 +292,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating return result; } - private static IEnumerable ConvertToJobFactories( - TemplateContext context, - PipelineResources resources, - TemplateToken workflow) - { - var jobsMapping = workflow.AssertMapping(PipelineTemplateConstants.Jobs); - - foreach (var jobsPair in jobsMapping) - { - var jobNameToken = jobsPair.Key.AssertString($"{PipelineTemplateConstants.Jobs} key"); - if (!NameValidation.IsValid(jobNameToken.Value, true)) - { - context.Error(jobNameToken, $"Job name {jobNameToken.Value} is invalid. Names must start with a letter or '_' and contain only alphanumeric characters, '-', or '_'"); - } - var result = new JobFactory - { - Name = jobNameToken.Value - }; - - var jobFactoryDefinition = jobsPair.Value.AssertMapping($"{PipelineTemplateConstants.Jobs} value"); - - foreach (var jobFactoryProperty in jobFactoryDefinition) - { - var propertyName = jobFactoryProperty.Key.AssertString($"job property name"); - - switch (propertyName.Value) - { - case PipelineTemplateConstants.ContinueOnError: - var continueOnErrorBooleanToken = jobFactoryProperty.Value.AssertBoolean($"job {PipelineTemplateConstants.ContinueOnError}"); - result.ContinueOnError = continueOnErrorBooleanToken.Value; - break; - - case PipelineTemplateConstants.If: - var ifCondition = jobFactoryProperty.Value.AssertString($"job {PipelineTemplateConstants.If}"); - result.Condition = ConvertToIfCondition(context, ifCondition, true, true); - break; - - case PipelineTemplateConstants.Name: - var displayName = jobFactoryProperty.Value.AssertScalar($"job {PipelineTemplateConstants.Name}"); - ConvertToJobDisplayName(context, displayName, allowExpressions: true); // Validate early if possible - if (displayName is StringToken) - { - result.DisplayName = displayName.ToString(); - } - else - { - result.JobDisplayName = displayName.Clone(true) as ExpressionToken; - } - break; - - case PipelineTemplateConstants.Needs: - if (jobFactoryProperty.Value is StringToken needsLiteral) - { - result.DependsOn.Add(needsLiteral.Value); - } - else - { - var needs = jobFactoryProperty.Value.AssertSequence($"job {PipelineTemplateConstants.Needs}"); - foreach (var needsItem in needs) - { - var need = needsItem.AssertString($"job {PipelineTemplateConstants.Needs} item"); - result.DependsOn.Add(need.Value); - } - } - break; - - case PipelineTemplateConstants.RunsOn: - ConvertToJobTarget(context, jobFactoryProperty.Value, allowExpressions: true); // Validate early if possible - result.JobTarget = jobFactoryProperty.Value.Clone(true); - break; - - case PipelineTemplateConstants.Scopes: - foreach (var scope in ConvertToScopes(context, jobFactoryProperty.Value)) - { - result.Scopes.Add(scope); - } - break; - - case PipelineTemplateConstants.Steps: - result.Steps.AddRange(ConvertToSteps(context, jobFactoryProperty.Value)); - break; - - case PipelineTemplateConstants.Strategy: - ConvertToStrategy(context, jobFactoryProperty.Value, null, allowExpressions: true); // Validate early if possible - result.Strategy = jobFactoryProperty.Value.Clone(true); - break; - - case PipelineTemplateConstants.TimeoutMinutes: - ConvertToJobTimeout(context, jobFactoryProperty.Value, allowExpressions: true); // Validate early if possible - result.JobTimeout = jobFactoryProperty.Value.Clone(true) as ScalarToken; - break; - - case PipelineTemplateConstants.CancelTimeoutMinutes: - ConvertToJobCancelTimeout(context, jobFactoryProperty.Value, allowExpressions: true); // Validate early if possible - result.JobCancelTimeout = jobFactoryProperty.Value.Clone(true) as ScalarToken; - break; - - case PipelineTemplateConstants.Container: - ConvertToJobContainer(context, jobFactoryProperty.Value, allowExpressions: true); - result.JobContainer = jobFactoryProperty.Value.Clone(true); - break; - - case PipelineTemplateConstants.Services: - ConvertToJobServiceContainers(context, jobFactoryProperty.Value, allowExpressions: true); - result.JobServiceContainers = jobFactoryProperty.Value.Clone(true); - break; - - case PipelineTemplateConstants.Env: - result.EnvironmentVariables = jobFactoryProperty.Value.Clone(true); - break; - - default: - propertyName.AssertUnexpectedValue("job key"); // throws - break; - } - } - - // todo: Move "required" support into schema validation - if (result.JobTarget == null) - { - context.Error(jobFactoryDefinition, $"The '{PipelineTemplateConstants.RunsOn}' property is required"); - } - - if (String.IsNullOrEmpty(result.DisplayName)) - { - result.DisplayName = result.Name; - } - - if (result.Scopes.Count > 0) - { - result.Steps.Insert( - 0, - new ActionStep - { - Reference = new ScriptReference(), - DisplayName = "WARNING: TEMPLATES ARE HIGHLY EXPERIMENTAL", - Inputs = new MappingToken(null, null, null) - { - { - new StringToken(null, null, null, PipelineConstants.ScriptStepInputs.Script), - new StringToken(null, null, null, "echo WARNING: TEMPLATES ARE HIGHLY EXPERIMENTAL") - } - } - }); - result.Steps.Add( - new ActionStep - { - Reference = new ScriptReference(), - DisplayName = "WARNING: TEMPLATES ARE HIGHLY EXPERIMENTAL", - Inputs = new MappingToken(null, null, null) - { - { - new StringToken(null, null, null, PipelineConstants.ScriptStepInputs.Script), - new StringToken(null, null, null, "echo WARNING: TEMPLATES ARE HIGHLY EXPERIMENTAL") - } - } - }); - } - - yield return result; - } - } - private static IEnumerable ConvertToScopes( TemplateContext context, TemplateToken scopes) @@ -816,301 +328,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating } } - private static List ConvertToSteps( - TemplateContext context, - TemplateToken steps) - { - var stepsSequence = steps.AssertSequence($"job {PipelineTemplateConstants.Steps}"); - - var result = new List(); - foreach (var stepsItem in stepsSequence) - { - var step = ConvertToStep(context, stepsItem); - if (step != null) // step = null means we are hitting error during step conversion, there should be an error in context.errors - { - if (step.Enabled) - { - result.Add(step); - } - } - } - - return result; - } - - private static ActionStep ConvertToStep( - TemplateContext context, - TemplateToken stepsItem) - { - var step = stepsItem.AssertMapping($"{PipelineTemplateConstants.Steps} item"); - var continueOnError = default(ScalarToken); - var env = default(TemplateToken); - var id = default(StringToken); - var ifCondition = default(String); - var ifToken = default(StringToken); - var name = default(ScalarToken); - var run = default(ScalarToken); - var scope = default(StringToken); - var timeoutMinutes = default(ScalarToken); - var uses = default(StringToken); - var with = default(TemplateToken); - var workingDir = default(ScalarToken); - var path = default(ScalarToken); - var clean = default(ScalarToken); - var fetchDepth = default(ScalarToken); - var lfs = default(ScalarToken); - var submodules = default(ScalarToken); - var shell = default(ScalarToken); - - foreach (var stepProperty in step) - { - var propertyName = stepProperty.Key.AssertString($"{PipelineTemplateConstants.Steps} item key"); - - switch (propertyName.Value) - { - case PipelineTemplateConstants.Clean: - clean = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Clean}"); - break; - - case PipelineTemplateConstants.ContinueOnError: - ConvertToStepContinueOnError(context, stepProperty.Value, allowExpressions: true); // Validate early if possible - continueOnError = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} {PipelineTemplateConstants.ContinueOnError}"); - break; - - case PipelineTemplateConstants.Env: - ConvertToStepEnvironment(context, stepProperty.Value, StringComparer.Ordinal, allowExpressions: true); // Validate early if possible - env = stepProperty.Value; - break; - - case PipelineTemplateConstants.FetchDepth: - fetchDepth = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.FetchDepth}"); - break; - - case PipelineTemplateConstants.Id: - id = stepProperty.Value.AssertString($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Id}"); - if (!NameValidation.IsValid(id.Value, true)) - { - context.Error(id, $"Step id {id.Value} is invalid. Ids must start with a letter or '_' and contain only alphanumeric characters, '-', or '_'"); - } - break; - - case PipelineTemplateConstants.If: - ifToken = stepProperty.Value.AssertString($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.If}"); - break; - - case PipelineTemplateConstants.Lfs: - lfs = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Lfs}"); - break; - - case PipelineTemplateConstants.Name: - name = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Name}"); - break; - - case PipelineTemplateConstants.Path: - path = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Path}"); - break; - - case PipelineTemplateConstants.Run: - run = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Run}"); - break; - - case PipelineTemplateConstants.Shell: - shell = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Shell}"); - break; - - case PipelineTemplateConstants.Scope: - scope = stepProperty.Value.AssertString($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Scope}"); - break; - - case PipelineTemplateConstants.Submodules: - submodules = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Submodules}"); - break; - - case PipelineTemplateConstants.TimeoutMinutes: - ConvertToStepTimeout(context, stepProperty.Value, allowExpressions: true); // Validate early if possible - timeoutMinutes = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.TimeoutMinutes}"); - break; - - case PipelineTemplateConstants.Uses: - uses = stepProperty.Value.AssertString($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.Uses}"); - break; - - case PipelineTemplateConstants.With: - ConvertToStepInputs(context, stepProperty.Value, allowExpressions: true); // Validate early if possible - with = stepProperty.Value; - break; - - case PipelineTemplateConstants.WorkingDirectory: - workingDir = stepProperty.Value.AssertScalar($"{PipelineTemplateConstants.Steps} item {PipelineTemplateConstants.WorkingDirectory}"); - break; - - default: - propertyName.AssertUnexpectedValue($"{PipelineTemplateConstants.Steps} item key"); // throws - break; - } - } - - // Fixup the if-condition - var isDefaultScope = String.IsNullOrEmpty(scope?.Value); - ifCondition = ConvertToIfCondition(context, ifToken, false, isDefaultScope); - - if (run != null) - { - var result = new ActionStep - { - ScopeName = scope?.Value, - ContextName = id?.Value, - ContinueOnError = continueOnError?.Clone(true) as ScalarToken, - DisplayNameToken = name?.Clone(true) as ScalarToken, - Condition = ifCondition, - TimeoutInMinutes = timeoutMinutes?.Clone(true) as ScalarToken, - Environment = env?.Clone(true), - Reference = new ScriptReference(), - }; - - var inputs = new MappingToken(null, null, null); - inputs.Add(new StringToken(null, null, null, PipelineConstants.ScriptStepInputs.Script), run.Clone(true)); - - if (workingDir != null) - { - inputs.Add(new StringToken(null, null, null, PipelineConstants.ScriptStepInputs.WorkingDirectory), workingDir.Clone(true)); - } - - if (shell != null) - { - inputs.Add(new StringToken(null, null, null, PipelineConstants.ScriptStepInputs.Shell), shell.Clone(true)); - } - - result.Inputs = inputs; - - return result; - } - else if (uses != null) - { - var result = new ActionStep - { - ScopeName = scope?.Value, - ContextName = id?.Value, - ContinueOnError = continueOnError?.Clone(true) as ScalarToken, - DisplayNameToken = name?.Clone(true) as ScalarToken, - Condition = ifCondition, - TimeoutInMinutes = timeoutMinutes?.Clone(true) as ScalarToken, - Inputs = with, - Environment = env, - }; - - if (uses.Value.StartsWith("docker://", StringComparison.Ordinal)) - { - var image = uses.Value.Substring("docker://".Length); - result.Reference = new ContainerRegistryReference { Image = image }; - } - else if (uses.Value.StartsWith("./") || uses.Value.StartsWith(".\\")) - { - result.Reference = new RepositoryPathReference - { - RepositoryType = PipelineConstants.SelfAlias, - Path = uses.Value - }; - } - else - { - var usesSegments = uses.Value.Split('@'); - var pathSegments = usesSegments[0].Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); - var gitRef = usesSegments.Length == 2 ? usesSegments[1] : String.Empty; - - if (usesSegments.Length != 2 || - pathSegments.Length < 2 || - String.IsNullOrEmpty(pathSegments[0]) || - String.IsNullOrEmpty(pathSegments[1]) || - String.IsNullOrEmpty(gitRef)) - { - // todo: loc - context.Error(uses, $"Expected format {{org}}/{{repo}}[/path]@ref. Actual '{uses.Value}'"); - } - else - { - var repositoryName = $"{pathSegments[0]}/{pathSegments[1]}"; - var directoryPath = pathSegments.Length > 2 ? String.Join("/", pathSegments.Skip(2)) : String.Empty; - - result.Reference = new RepositoryPathReference - { - RepositoryType = RepositoryTypes.GitHub, - Name = repositoryName, - Ref = gitRef, - Path = directoryPath, - }; - } - } - - return result; - } - else - { - // todo: build a "required" concept into the parser - context.Error(step, $"Either '{PipelineTemplateConstants.Uses}' or '{PipelineTemplateConstants.Run}' is required"); - return null; - } - } - - private static String ConvertToIfCondition( - TemplateContext context, - StringToken ifCondition, - Boolean isJob, - Boolean isDefaultScope) - { - if (String.IsNullOrWhiteSpace(ifCondition?.Value)) - { - return $"{PipelineTemplateConstants.Success}()"; - } - - var condition = ifCondition.Value; - - var expressionParser = new ExpressionParser(); - var functions = default(IFunctionInfo[]); - var namedValues = default(INamedValueInfo[]); - if (isJob) - { - namedValues = s_jobIfNamedValues; - functions = PhaseCondition.FunctionInfo; - } - else - { - namedValues = isDefaultScope ? s_stepNamedValues : s_stepInTemplateNamedValues; - functions = s_stepConditionFunctions; - } - - var node = default(ExpressionNode); - try - { - node = expressionParser.CreateTree(condition, null, namedValues, functions) as ExpressionNode; - } - catch (Exception ex) - { - context.Error(ifCondition, ex); - return null; - } - - if (node == null) - { - return $"{PipelineTemplateConstants.Success}()"; - } - - var hasStatusFunction = node.Traverse().Any(x => - { - if (x is Function function) - { - return String.Equals(function.Name, PipelineTemplateConstants.Always, StringComparison.OrdinalIgnoreCase) || - String.Equals(function.Name, PipelineTemplateConstants.Cancelled, StringComparison.OrdinalIgnoreCase) || - String.Equals(function.Name, PipelineTemplateConstants.Failure, StringComparison.OrdinalIgnoreCase) || - String.Equals(function.Name, PipelineTemplateConstants.Success, StringComparison.OrdinalIgnoreCase); - } - - return false; - }); - - return hasStatusFunction ? condition : $"{PipelineTemplateConstants.Success}() && ({condition})"; - } - private static readonly INamedValueInfo[] s_jobIfNamedValues = new INamedValueInfo[] { new NamedValueInfo(PipelineTemplateConstants.GitHub), diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs index fc69ca272..c753d8670 100644 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs +++ b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateEvaluator.cs @@ -46,65 +46,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating public Int32 MaxResultSize { get; set; } = 10 * 1024 * 1024; // 10 mb - public StrategyResult EvaluateStrategy( - TemplateToken token, - DictionaryContextData contextData, - String jobFactoryDisplayName) - { - var result = new StrategyResult(); - - if (token != null && token.Type != TokenType.Null) - { - var context = CreateContext(contextData); - try - { - token = TemplateEvaluator.Evaluate(context, PipelineTemplateConstants.Strategy, token, 0, null, omitHeader: true); - context.Errors.Check(); - result = PipelineTemplateConverter.ConvertToStrategy(context, token, jobFactoryDisplayName); - } - catch (Exception ex) when (!(ex is TemplateValidationException)) - { - context.Errors.Add(ex); - } - - context.Errors.Check(); - } - - if (result.Configurations.Count == 0) - { - var configuration = new StrategyConfiguration - { - Name = PipelineConstants.DefaultJobName, - DisplayName = new JobDisplayNameBuilder(jobFactoryDisplayName).Build(), - }; - configuration.ContextData.Add(PipelineTemplateConstants.Matrix, null); - configuration.ContextData.Add( - PipelineTemplateConstants.Strategy, - new DictionaryContextData - { - { - "fail-fast", - new BooleanContextData(result.FailFast) - }, - { - "job-index", - new NumberContextData(0) - }, - { - "job-total", - new NumberContextData(1) - }, - { - "max-parallel", - new NumberContextData(1) - } - }); - result.Configurations.Add(configuration); - } - - return result; - } - public String EvaluateJobDisplayName( TemplateToken token, DictionaryContextData contextData, @@ -132,32 +73,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating return !String.IsNullOrEmpty(result) ? result : defaultDisplayName; } - public PhaseTarget EvaluateJobTarget( - TemplateToken token, - DictionaryContextData contextData) - { - var result = default(PhaseTarget); - - if (token != null && token.Type != TokenType.Null) - { - var context = CreateContext(contextData); - try - { - token = TemplateEvaluator.Evaluate(context, PipelineTemplateConstants.RunsOn, token, 0, null, omitHeader: true); - context.Errors.Check(); - result = PipelineTemplateConverter.ConvertToJobTarget(context, token); - } - catch (Exception ex) when (!(ex is TemplateValidationException)) - { - context.Errors.Add(ex); - } - - context.Errors.Check(); - } - - return result ?? throw new InvalidOperationException("Job target cannot be null"); - } - public Int32 EvaluateJobTimeout( TemplateToken token, DictionaryContextData contextData) diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateParser.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateParser.cs deleted file mode 100644 index 62557d38c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateParser.cs +++ /dev/null @@ -1,239 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Threading; -using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.ObjectTemplating.Schema; - -namespace GitHub.DistributedTask.Pipelines.ObjectTemplating -{ - using GitHub.DistributedTask.ObjectTemplating; - - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PipelineTemplateParser - { - static PipelineTemplateParser() - { - var schemaFactory = new PipelineTemplateSchemaFactory(); - s_schema = schemaFactory.CreateSchema(); - } - - public PipelineTemplateParser( - ITraceWriter trace, - ParseOptions options) - { - m_trace = trace ?? throw new ArgumentNullException(nameof(trace)); - m_parseOptions = new ParseOptions(options ?? throw new ArgumentNullException(nameof(options))); - } - - /// - /// Loads the YAML pipeline template - /// - /// Thrown when the entry YAML file does not exist - public PipelineTemplate LoadPipeline( - IFileProvider fileProvider, - RepositoryResource self, - String path, - CancellationToken cancellationToken) - { - fileProvider = fileProvider ?? throw new ArgumentNullException(nameof(fileProvider)); - self = self ?? throw new ArgumentNullException(nameof(self)); - var parseResult = LoadPipelineInternal(fileProvider, path, cancellationToken); - return PipelineTemplateConverter.ConvertToPipeline(parseResult.Context, self, parseResult.Value); - } - - internal ParseResult LoadPipelineInternal( - IFileProvider fileProvider, - String path, - CancellationToken cancellationToken) - { - // Setup the context - var templateLoader = new YamlTemplateLoader(new ParseOptions(m_parseOptions), fileProvider); - var context = new TemplateContext - { - CancellationToken = cancellationToken, - Errors = new TemplateValidationErrors(m_parseOptions.MaxErrors, m_parseOptions.MaxErrorMessageLength), - Memory = new TemplateMemory( - maxDepth: m_parseOptions.MaxDepth, - maxEvents: m_parseOptions.MaxParseEvents, - maxBytes: m_parseOptions.MaxResultSize), - Schema = s_schema, - TraceWriter = m_trace, - }; - - // Load the entry file - var token = default(TemplateToken); - try - { - token = templateLoader.LoadFile(context, null, null, path, PipelineTemplateConstants.WorkflowRoot); - } - catch (Exception ex) - { - context.Errors.Add(ex); - } - - var result = new ParseResult - { - Context = context, - Value = token, - }; - - if (token != null && context.Errors.Count == 0) - { - var templateReferenceCount = ResolveWorkflowTemplateReferences(context, templateLoader, token); - if (templateReferenceCount > 0 && context.Errors.Count == 0) - { - context.TraceWriter.Info(String.Empty); - context.TraceWriter.Info("# "); - context.TraceWriter.Info("# Template resolution complete. Final runtime YAML document:"); - context.TraceWriter.Info("# "); - context.TraceWriter.Info("{0}", result.ToYaml()); - } - } - - return result; - } - - private Int32 ResolveWorkflowTemplateReferences( - TemplateContext context, - YamlTemplateLoader templateLoader, - TemplateToken token) - { - var resolvedCount = 0; - var workflow = token.AssertMapping("workflow"); - foreach (var workflowProperty in workflow) - { - var workflowPropertyName = workflowProperty.Key.AssertString("workflow property"); - switch (workflowPropertyName.Value) - { - case PipelineTemplateConstants.Jobs: - resolvedCount += ResolveJobsTemplateReferences(context, templateLoader, workflowProperty.Value); - break; - - case PipelineTemplateConstants.Workflow: - resolvedCount += ResolveJobsTemplateReferences(context, templateLoader, workflowProperty.Value); - break; - } - } - - return resolvedCount; - } - - private Int32 ResolveJobsTemplateReferences( - TemplateContext context, - YamlTemplateLoader templateLoader, - TemplateToken token) - { - var resolvedCount = 0; - var jobs = token.AssertMapping("jobs"); - foreach (var jobsProperty in jobs) - { - var job = jobsProperty.Value.AssertMapping("jobs property value"); - var scopes = new SequenceToken(null, null, null); - foreach (var jobProperty in job) - { - var jobPropertyName = jobProperty.Key.AssertString("job property name"); - switch (jobPropertyName.Value) - { - case PipelineTemplateConstants.Steps: - resolvedCount += ResolveStepsTemplateReferences(context, templateLoader, jobProperty.Value, scopes); - break; - } - } - - if (scopes.Count > 0) - { - var scopesPropertyName = new StringToken(null, null, null, PipelineTemplateConstants.Scopes); - job.Add(scopesPropertyName, scopes); - context.Memory.AddBytes(scopesPropertyName); - context.Memory.AddBytes(scopes); // Do not traverse, nested objects already accounted for - } - } - - return resolvedCount; - } - - private Int32 ResolveStepsTemplateReferences( - TemplateContext context, - YamlTemplateLoader templateLoader, - TemplateToken token, - SequenceToken scopes) - { - var resolvedCount = 0; - var steps = token.AssertSequence("steps"); - var stepIndex = 0; - while (stepIndex < steps.Count && context.Errors.Count == 0) - { - var step = steps[stepIndex].AssertMapping("step"); - if (!TemplateReference.TryCreate(step, out var reference)) - { - stepIndex++; - continue; - } - - resolvedCount++; - var template = templateLoader.LoadFile( - context, - reference.TemplatePath.FileId, - reference.TemplateScope, - reference.TemplatePath.Value, - PipelineTemplateConstants.StepsTemplateRoot); - - if (context.Errors.Count != 0) - { - break; - } - - var scope = reference.CreateScope(context, template); - - if (context.Errors.Count != 0) - { - break; - } - - // Remove the template reference and memory overhead - steps.RemoveAt(stepIndex); - context.Memory.SubtractBytes(step, true); // Traverse - - // Remove the template memory overhead - context.Memory.SubtractBytes(template, true); // Traverse - - var templateSteps = GetSteps(template); - if (templateSteps?.Count > 0) - { - // Add the steps from the template - steps.InsertRange(stepIndex, templateSteps); - context.Memory.AddBytes(templateSteps, true); // Traverse - context.Memory.SubtractBytes(templateSteps, false); - - // Add the scope - scopes.Add(scope); - context.Memory.AddBytes(scope, true); // Traverse - } - } - - return resolvedCount; - } - - private SequenceToken GetSteps(TemplateToken template) - { - var mapping = template.AssertMapping("steps template"); - foreach (var property in mapping) - { - var propertyName = property.Key.AssertString("steps template property name"); - switch (propertyName.Value) - { - case PipelineTemplateConstants.Steps: - return property.Value.AssertSequence("steps template steps property value"); - } - } - - return null; - } - - private static TemplateSchema s_schema; - private readonly ParseOptions m_parseOptions; - private readonly ITraceWriter m_trace; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/ReferenceNameBuilder.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/ReferenceNameBuilder.cs deleted file mode 100644 index 2b42f2918..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/ReferenceNameBuilder.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using GitHub.DistributedTask.Pipelines.Validation; - -namespace GitHub.DistributedTask.Pipelines.ObjectTemplating -{ - internal sealed class ReferenceNameBuilder - { - internal void AppendSegment(String value) - { - if (String.IsNullOrEmpty(value)) - { - return; - } - - if (m_name.Length == 0) - { - var first = value[0]; - if ((first >= 'a' && first <= 'z') || - (first >= 'A' && first <= 'Z') || - first == '_') - { - // Legal first char - } - else if ((first >= '0' && first <= '9') || first == '-') - { - // Illegal first char, but legal char. - // Prepend "_". - m_name.Append("_"); - } - else - { - // Illegal char - } - } - else - { - // Separator - m_name.Append(c_separator); - } - - foreach (var c in value) - { - if ((c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || - c == '_' || - c == '-') - { - // Legal - m_name.Append(c); - } - else - { - // Illegal - m_name.Append("_"); - } - } - } - - internal String Build() - { - var original = m_name.Length > 0 ? m_name.ToString() : "job"; - - var attempt = 1; - var suffix = default(String); - while (true) - { - if (attempt == 1) - { - suffix = String.Empty; - } - else if (attempt < 1000) - { - suffix = String.Format(CultureInfo.InvariantCulture, "_{0}", attempt); - } - else - { - throw new InvalidOperationException("Unable to create a unique name"); - } - - var candidate = original.Substring(0, Math.Min(original.Length, PipelineConstants.MaxNodeNameLength - suffix.Length)) + suffix; - - if (m_distinctNames.Add(candidate)) - { - m_name.Clear(); - return candidate; - } - - attempt++; - } - } - - internal Boolean TryAddKnownName( - String value, - out String error) - { - if (!NameValidation.IsValid(value, allowHyphens: true) && value.Length < PipelineConstants.MaxNodeNameLength) - { - error = $"The identifier '{value}' is invalid. IDs may only contain alphanumeric characters, '_', and '-'. IDs must start with a letter or '_' and and must be less than {PipelineConstants.MaxNodeNameLength} characters."; - return false; - } - else if (!m_distinctNames.Add(value)) - { - error = $"The identifier '{value}' may not be used more than once within the same scope."; - return false; - } - else - { - error = null; - return true; - } - } - - private const String c_separator = "_"; - private readonly HashSet m_distinctNames = new HashSet(StringComparer.OrdinalIgnoreCase); - private readonly StringBuilder m_name = new StringBuilder(); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/YamlTemplateLoader.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/YamlTemplateLoader.cs deleted file mode 100644 index 3d44a299d..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/YamlTemplateLoader.cs +++ /dev/null @@ -1,251 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using GitHub.DistributedTask.ObjectTemplating; -using GitHub.DistributedTask.ObjectTemplating.Tokens; - -namespace GitHub.DistributedTask.Pipelines.ObjectTemplating -{ - /// - /// Loads a YAML file, and returns the parsed TemplateToken - /// - internal sealed class YamlTemplateLoader - { - public YamlTemplateLoader( - ParseOptions parseOptions, - IFileProvider fileProvider) - { - m_parseOptions = new ParseOptions(parseOptions); - m_fileProvider = fileProvider ?? throw new ArgumentNullException(nameof(fileProvider)); - } - - public TemplateToken LoadFile( - TemplateContext context, - Int32? rootFileId, - String scope, - String path, - String templateType) - { - if (context.Errors.Count > 0) - { - throw new InvalidOperationException("Expected error count to be 0 when attempting to load a new file"); - } - - // Is entry file? - var isEntryFile = m_referencedFiles.Count == 0; - - // Root the path - path = m_fileProvider.ResolvePath(null, path); - - // Validate max files - m_referencedFiles.Add(path); - if (m_parseOptions.MaxFiles > 0 && m_referencedFiles.Count > m_parseOptions.MaxFiles) - { - throw new InvalidOperationException($"The maximum file count of {m_parseOptions.MaxFiles} has been exceeded"); - } - - // Get the file ID - var fileId = context.GetFileId(path); - - // Check the cache - if (!m_cache.TryGetValue(path, out String fileContent)) - { - // Fetch the file - context.CancellationToken.ThrowIfCancellationRequested(); - fileContent = m_fileProvider.GetFileContent(path); - - // Validate max file size - if (fileContent.Length > m_parseOptions.MaxFileSize) - { - throw new InvalidOperationException($"The maximum file size of {m_parseOptions.MaxFileSize} characters has been exceeded"); - } - - // Cache - m_cache[path] = fileContent; - } - - // Deserialize - var token = default(TemplateToken); - using (var stringReader = new StringReader(fileContent)) - { - var yamlObjectReader = new YamlObjectReader(fileId, stringReader); - token = TemplateReader.Read(context, templateType, yamlObjectReader, fileId, out _); - } - - // Trace - if (!isEntryFile) - { - context.TraceWriter.Info(String.Empty); - } - context.TraceWriter.Info("# "); - context.TraceWriter.Info("# {0}", path); - context.TraceWriter.Info("# "); - - // Validate ref names - if (context.Errors.Count == 0) - { - switch (templateType) - { - case PipelineTemplateConstants.WorkflowRoot: - ValidateWorkflow(context, scope, token); - break; - case PipelineTemplateConstants.StepsTemplateRoot: - var stepsTemplate = token.AssertMapping("steps template"); - foreach (var stepsTemplateProperty in stepsTemplate) - { - var stepsTemplatePropertyName = stepsTemplateProperty.Key.AssertString("steps template property name"); - switch (stepsTemplatePropertyName.Value) - { - case PipelineTemplateConstants.Steps: - ValidateSteps(context, scope, stepsTemplateProperty.Value); - break; - } - } - break; - default: - throw new NotImplementedException($"Unexpected template type '{templateType}' when loading yaml file"); - } - } - - return token; - } - - private void ValidateWorkflow( - TemplateContext context, - String scope, - TemplateToken token) - { - var workflow = token.AssertMapping("workflow"); - foreach (var workflowProperty in workflow) - { - var workflowPropertyName = workflowProperty.Key.AssertString("workflow property name"); - switch (workflowPropertyName.Value) - { - case PipelineTemplateConstants.Jobs: - case PipelineTemplateConstants.Workflow: - var jobs = workflowProperty.Value.AssertMapping("workflow property value"); - foreach (var jobsProperty in jobs) - { - var job = jobsProperty.Value.AssertMapping("jobs property value"); - foreach (var jobProperty in job) - { - var jobPropertyName = jobProperty.Key.AssertString("job property name"); - switch (jobPropertyName.Value) - { - case PipelineTemplateConstants.Steps: - ValidateSteps(context, scope, jobProperty.Value); - break; - } - } - } - break; - } - } - } - - private void ValidateSteps( - TemplateContext context, - String scope, - TemplateToken token) - { - var nameBuilder = new ReferenceNameBuilder(); - var steps = token.AssertSequence("steps"); - var needsReferenceName = new List(); - foreach (var stepsItem in steps) - { - var step = stepsItem.AssertMapping("steps item"); - var isTemplateReference = false; - var hasReferenceName = false; - foreach (var stepProperty in step) - { - var stepPropertyKey = stepProperty.Key.AssertString("step property name"); - switch (stepPropertyKey.Value) - { - // Validate reference names - case PipelineTemplateConstants.Id: - var referenceNameLiteral = stepProperty.Value.AssertString("step ID"); - var referenceName = referenceNameLiteral.Value; - if (String.IsNullOrEmpty(referenceName)) - { - continue; - } - - if (!nameBuilder.TryAddKnownName(referenceName, out var error)) - { - context.Error(referenceNameLiteral, error); - } - - hasReferenceName = true; - break; - - case PipelineTemplateConstants.Template: - isTemplateReference = true; - break; - } - } - - // No reference name - if (isTemplateReference && !hasReferenceName) - { - needsReferenceName.Add(step); - } - - // Stamp the scope - if (!String.IsNullOrEmpty(scope)) - { - var scopePropertyName = new StringToken(null, null, null, PipelineTemplateConstants.Scope); - var scopePropertyValue = new StringToken(null, null, null, scope); - step.Add(scopePropertyName, scopePropertyValue); - context.Memory.AddBytes(scopePropertyName); - context.Memory.AddBytes(scopePropertyValue); - } - } - - // Generate reference names - if (needsReferenceName.Count > 0 && context.Errors.Count == 0) - { - foreach (var step in needsReferenceName) - { - // Get the template path - var templatePath = default(String); - foreach (var stepProperty in step) - { - var stepPropertyKey = stepProperty.Key.AssertString("step property name"); - switch (stepPropertyKey.Value) - { - case PipelineTemplateConstants.Template: - var templateStringToken = stepProperty.Value.AssertString("step template path"); - templatePath = templateStringToken.Value; - break; - } - } - - // Generate reference name - if (!String.IsNullOrEmpty(templatePath)) - { - nameBuilder.AppendSegment(templatePath); - var generatedIdPropertyName = new StringToken(null, null, null, PipelineTemplateConstants.GeneratedId); - var generatedIdPropertyValue = new StringToken(null, null, null, nameBuilder.Build()); - step.Add(generatedIdPropertyName, generatedIdPropertyValue); - context.Memory.AddBytes(generatedIdPropertyName); - context.Memory.AddBytes(generatedIdPropertyValue); - } - } - } - } - - /// - /// Cache of file content - /// - private readonly Dictionary m_cache = new Dictionary(StringComparer.OrdinalIgnoreCase); - - private readonly IFileProvider m_fileProvider; - - private readonly ParseOptions m_parseOptions; - - /// - /// Tracks unique file references - /// - private readonly HashSet m_referencedFiles = new HashSet(StringComparer.OrdinalIgnoreCase); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PackageStore.cs b/src/Sdk/DTPipelines/Pipelines/PackageStore.cs deleted file mode 100644 index 20fc8704a..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PackageStore.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - public interface IPackageResolver - { - IList GetPackages(String packageType); - } - - public class PackageStore : IPackageStore - { - public PackageStore(params PackageMetadata[] packages) - : this(packages, null) - { - } - - public PackageStore( - IEnumerable packages = null, - IPackageResolver resolver = null) - { - this.Resolver = resolver; - m_packages = packages?.GroupBy(x => x.Type).ToDictionary(x => x.Key, x => x.ToList(), StringComparer.OrdinalIgnoreCase) ?? - new Dictionary>(StringComparer.OrdinalIgnoreCase); - } - - public IPackageResolver Resolver - { - get; - } - - public PackageVersion GetLatestVersion(String packageType) - { - if (!m_packages.TryGetValue(packageType, out var existingPackages)) - { - var resolvedPackages = this.Resolver?.GetPackages(packageType); - if (resolvedPackages?.Count > 0) - { - existingPackages = resolvedPackages.ToList(); - m_packages[packageType] = existingPackages; - } - } - - return existingPackages?.OrderByDescending(x => x.Version).Select(x => x.Version).FirstOrDefault(); - } - - private Dictionary> m_packages; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ParallelExecutionOptions.cs b/src/Sdk/DTPipelines/Pipelines/ParallelExecutionOptions.cs deleted file mode 100644 index 5bd5be2c4..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ParallelExecutionOptions.cs +++ /dev/null @@ -1,315 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class ParallelExecutionOptions - { - public ParallelExecutionOptions() - { - } - - private ParallelExecutionOptions(ParallelExecutionOptions optionsToCopy) - { - this.Matrix = optionsToCopy.Matrix; - this.MaxConcurrency = optionsToCopy.MaxConcurrency; - } - - [DataMember(EmitDefaultValue = false)] - [JsonConverter(typeof(ExpressionValueJsonConverter>>))] - public ExpressionValue>> Matrix - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - [JsonConverter(typeof(ExpressionValueJsonConverter))] - public ExpressionValue MaxConcurrency - { - get; - set; - } - - public ParallelExecutionOptions Clone() - { - return new ParallelExecutionOptions(this); - } - - internal JobExecutionContext CreateJobContext( - PhaseExecutionContext context, - String jobName, - Int32 attempt, - ExpressionValue container, - IDictionary> sidecarContainers, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory) - { - // perform regular expansion with a filter - var options = new JobExpansionOptions(jobName, attempt); - - return GenerateJobContexts( - context, - container, - sidecarContainers, - continueOnError, - timeoutInMinutes, - cancelTimeoutInMinutes, - jobFactory, - options) - .FirstOrDefault(); - } - - internal ExpandPhaseResult Expand( - PhaseExecutionContext context, - ExpressionValue container, - IDictionary> sidecarContainers, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory, - JobExpansionOptions options) - { - var jobContexts = GenerateJobContexts( - context, - container, - sidecarContainers, - continueOnError, - timeoutInMinutes, - cancelTimeoutInMinutes, - jobFactory, - options); - - var result = new ExpandPhaseResult(); - foreach (var c in jobContexts) - { - result.Jobs.Add(c.Job); - } - - // parse MaxConcurrency request - var numberOfJobs = jobContexts.Count; - var userProvidedValue = context.Evaluate( - name: nameof(MaxConcurrency), - expression: this.MaxConcurrency, - defaultValue: 0).Value; - - // setting max to 0 or less is shorthand for "unlimited" - if (userProvidedValue <= 0) - { - userProvidedValue = numberOfJobs; - } - - result.MaxConcurrency = userProvidedValue; - return result; - } - - internal IList GenerateJobContexts( - PhaseExecutionContext context, - ExpressionValue container, - IDictionary> sidecarContainers, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory, - JobExpansionOptions options) - { - // We don't want job variables to be set into the phase context so we create a child context for each unique configuration - var jobContexts = new List(); - void GenerateContext( - String displayName, - String configuration, - IDictionary configurationVariables = null, - String parallelExecutionType = null, - Int32 positionInPhase = 1, - Int32 totalJobsInPhase = 1) - { - // configurations should (eventually) follow configuration naming conventions - if (String.IsNullOrEmpty(configuration)) - { - configuration = PipelineConstants.DefaultJobName; - } - - // Determine attempt number. - // if we have a custom value, it wins. - // if we have previously attempted this configuration, - // the new attempt number is one greater than the previous. - // 1 is the minimum attempt number - var attemptNumber = options?.GetAttemptNumber(configuration) ?? -1; - if (attemptNumber < 1) - { - var previousAttempt = context.PreviousAttempt; - if (previousAttempt != null) - { - var jobInstance = context.PreviousAttempt?.Jobs.FirstOrDefault(x => x.Job.Name.Equals(configuration, StringComparison.OrdinalIgnoreCase)); - if (jobInstance != null) - { - attemptNumber = jobInstance.Job.Attempt + 1; - } - } - } - - if (attemptNumber < 1) - { - attemptNumber = 1; - } - - var jobContext = context.CreateJobContext( - name: configuration, - attempt: attemptNumber, - positionInPhase, - totalJobsInPhase); - - // add parallel execution type - if (parallelExecutionType != null) - { - jobContext.SetSystemVariables(new List - { - new Variable - { - Name = WellKnownDistributedTaskVariables.ParallelExecutionType, - Value = parallelExecutionType - } - }); - } - - if (configurationVariables != null) - { - jobContext.SetUserVariables(configurationVariables); - } - - // create job model from factory - jobContext.Job.Definition = jobFactory.CreateJob( - jobContext, - container, - sidecarContainers, - continueOnError, - timeoutInMinutes, - cancelTimeoutInMinutes, - displayName); - - jobContexts.Add(jobContext); - - if (jobContexts.Count > context.ExecutionOptions.MaxJobExpansion) - { - // Note: this is a little weird: it might be that the max concurrency is greater than the max expansion, - // but we only throw if we actually try to generate more jobs than the max expansion. - throw new MaxJobExpansionException(PipelineStrings.PhaseJobSlicingExpansionExceedLimit(jobContexts.Count.ToString(), context.ExecutionOptions.MaxJobExpansion)); - } - } - - if (this.Matrix != null) - { - var matrixValue = context.Evaluate(nameof(Matrix), this.Matrix, null, traceDefault: false).Value; - var numberOfConfigurations = matrixValue?.Count ?? 0; - if (numberOfConfigurations > 0) - { - var positionInPhase = 1; - foreach (var pair in matrixValue) - { - // user-provided configuration key - var configuration = pair.Key; - var refName = configuration; - if (!PipelineUtilities.IsLegalNodeName(refName)) - { - var legalNodeName = PipelineConstants.DefaultJobDisplayName + positionInPhase.ToString(); - context.Trace?.Info($"\"{refName}\" is not a legal node name; node will be named \"{legalNodeName}\"."); - if (context.ExecutionOptions.EnforceLegalNodeNames) - { - refName = legalNodeName; - } - } - - if (options == null || options.IsIncluded(refName)) - { - GenerateContext( - displayName: Phase.GenerateDisplayName(context.Phase.Definition, configuration), - configuration: refName, - configurationVariables: pair.Value, - parallelExecutionType: "MultiConfiguration", - positionInPhase: positionInPhase, - totalJobsInPhase: numberOfConfigurations); - } - - ++positionInPhase; - } - } - } - else if (this.MaxConcurrency is var maxConcurrencyPipelineValue && maxConcurrencyPipelineValue != null) - { - var maxConcurrency = context.Evaluate(nameof(maxConcurrencyPipelineValue), maxConcurrencyPipelineValue, 1).Value; - - //If the value of context.ExecutionOptions.MaxParallelism is set, we will enforce MaxConcurrency value to be not more than context.ExecutionOptions.MaxParallelism. - //context.ExecutionOptions.MaxParallelism is currently set if the current context is hosted and public, especially to avoid abuse of services. - if (maxConcurrency > context.ExecutionOptions.MaxParallelism) - { - maxConcurrency = context.ExecutionOptions.MaxParallelism.Value; - } - - if (maxConcurrency > 1) - { - if (options == null || options.Configurations == null || options.Configurations.Count == 0) - { - // generate all slices - for (var positionInPhase = 1; positionInPhase <= maxConcurrency; ++positionInPhase) - { - // NOTE: for historical reasons, the reference name of a slice is "Job" plus the slice number: "Job1" - var positionInPhaseString = positionInPhase.ToString(); - GenerateContext( - displayName: Phase.GenerateDisplayName(context.Phase.Definition, positionInPhaseString), - configuration: PipelineConstants.DefaultJobDisplayName + positionInPhaseString, - configurationVariables: null, - parallelExecutionType: "MultiMachine", - positionInPhase: positionInPhase, - totalJobsInPhase: maxConcurrency); - } - } - else - { - // generate only the requested slices - foreach (var configuration in options.Configurations.Keys) - { - // determine which slices are required by parsing the configuration name (see generation code above) - var prefix = PipelineConstants.DefaultJobDisplayName; - if (!configuration.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) - || !int.TryParse(configuration.Substring(prefix.Length), out var positionInPhase)) - throw new PipelineValidationException(PipelineStrings.PipelineNotValid()); - - GenerateContext( - displayName: Phase.GenerateDisplayName(context.Phase.Definition, positionInPhase.ToString()), - configuration: configuration, - configurationVariables: null, - parallelExecutionType: "MultiMachine", - positionInPhase: positionInPhase, - totalJobsInPhase: maxConcurrency); - } - } - } - } - - // if no contexts are produced otherwise, create a default context. - if (jobContexts.Count == 0) - { - var configuration = PipelineConstants.DefaultJobName; - if (options == null || options.IsIncluded(configuration)) - { - // the default display name is just the JobFactory display name - GenerateContext( - displayName: Phase.GenerateDisplayName(context.Phase.Definition), - configuration: configuration); - } - } - - return jobContexts; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Phase.cs b/src/Sdk/DTPipelines/Pipelines/Phase.cs deleted file mode 100644 index 2f44e4afc..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Phase.cs +++ /dev/null @@ -1,1677 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class Phase : PhaseNode, IJobFactory - { - public Phase() - { - } - - private Phase(Phase phaseToCopy) - : base(phaseToCopy) - { - if (phaseToCopy.m_steps != null && phaseToCopy.m_steps.Count > 0) - { - m_steps = new List(phaseToCopy.m_steps.Select(x => x.Clone())); - } - } - - /// - /// Gets the phase type. - /// - [DataMember(EmitDefaultValue = false)] - public override PhaseType Type => PhaseType.Phase; - - /// - /// Gets the list of steps associated with this phase. At runtime the steps will be used as a template for - /// the execution of a job. - /// - public IList Steps - { - get - { - if (m_steps == null) - { - m_steps = new List(); - } - return m_steps; - } - } - - /// - /// Creates the specified job using the provided execution context and name. A new execution context is - /// returned which includes new variables set by the job. - /// - /// The execution context - /// The name of the job which should be created - /// A job and execution context if the specified name exists; otherwise, null - public JobExecutionContext CreateJobContext( - PhaseExecutionContext context, - String name, - Int32 attempt) - { - ArgumentUtility.CheckForNull(this.Target, nameof(this.Target)); - - // Create a copy of the context so the same root context may be used to create multiple jobs - // without impacting the input context. - return this.Target.CreateJobContext(context, name, attempt, this); - } - - /// - /// Creates a job context using the provided phase context and existing job instance. A new context is - /// returned which includes new variables set by the job. - /// - /// The execution context - /// The existing job instance - /// A job execution context - public JobExecutionContext CreateJobContext( - PhaseExecutionContext context, - JobInstance jobInstance) - { - var jobContext = context.CreateJobContext(jobInstance); - jobContext.Job.Definition.Id = jobContext.GetInstanceId(); - - var options = new BuildOptions(); - var builder = new PipelineBuilder(context); - var result = builder.GetReferenceResources(jobInstance.Definition.Steps.OfType().ToList(), jobInstance.Definition.Target); - jobContext.ReferencedResources.MergeWith(result); - - // Update the execution context with referenced job containers - var containerAlias = (jobInstance.Definition.Container as DistributedTask.ObjectTemplating.Tokens.StringToken)?.Value; - if (!String.IsNullOrEmpty(containerAlias)) - { - UpdateJobContextReferencedContainers(jobContext, containerAlias); - } - var sidecarContainers = jobInstance.Definition.SidecarContainers; - if (sidecarContainers != null) - { - foreach (var sidecar in sidecarContainers) - { - // Sidecar is serviceName -> containerAlias, e.g. ngnix: containerAlias - UpdateJobContextReferencedContainers(jobContext, sidecar.Value); - } - } - // Update the execution context with the job-specific system variables - UpdateJobContextVariablesFromJob(jobContext, jobInstance.Definition); - - return jobContext; - } - - /// - /// Expands the template using the provided execution context and returns the list of jobs. - /// - /// The execution context - /// The expansion options to use - /// A list of jobs which should be executed for this phase - public ExpandPhaseResult Expand( - PhaseExecutionContext context, - JobExpansionOptions options = null) - { - ArgumentUtility.CheckForNull(this.Target, nameof(this.Target)); - - var result = this.Target.Expand(context, this, options); - if (result != null) - { - var runtimeValue = this.ContinueOnError?.GetValue(context); - result.ContinueOnError = runtimeValue?.Value ?? false; - } - - return result; - } - - internal static String GetErrorMessage( - String code, - params Object[] values) - { - var stageName = (String)values[0]; - if (String.IsNullOrEmpty(stageName) || - stageName.Equals(PipelineConstants.DefaultJobName, StringComparison.OrdinalIgnoreCase)) - { - switch (code) - { - case PipelineConstants.NameInvalid: - return PipelineStrings.PhaseNameInvalid(values[1]); - - case PipelineConstants.NameNotUnique: - return PipelineStrings.PhaseNamesMustBeUnique(values[1]); - - case PipelineConstants.StartingPointNotFound: - return PipelineStrings.PipelineNotValidNoStartingPhase(); - - case PipelineConstants.DependencyNotFound: - return PipelineStrings.PhaseDependencyNotFound(values[1], values[2]); - - case PipelineConstants.GraphContainsCycle: - return PipelineStrings.PhaseGraphCycleDetected(values[1], values[2]); - } - } - else - { - switch (code) - { - case PipelineConstants.NameInvalid: - return PipelineStrings.StagePhaseNameInvalid(values[0], values[1]); - - case PipelineConstants.NameNotUnique: - return PipelineStrings.StagePhaseNamesMustBeUnique(values[0], values[1]); - - case PipelineConstants.StartingPointNotFound: - return PipelineStrings.StageNotValidNoStartingPhase(values[0]); - - case PipelineConstants.DependencyNotFound: - return PipelineStrings.StagePhaseDependencyNotFound(values[0], values[1], values[2]); - - case PipelineConstants.GraphContainsCycle: - return PipelineStrings.StagePhaseGraphCycleDetected(values[0], values[1], values[2]); - } - } - - throw new NotSupportedException(); - } - - /// - /// Resolves external references and ensures the steps are compatible with the selected target. - /// - /// The validation context - public override void Validate( - PipelineBuildContext context, - ValidationResult result) - { - base.Validate(context, result); - - StepValidationResult phaseStepValidationResult = new StepValidationResult(); - // Require the latest agent version. - if (context.BuildOptions.DemandLatestAgent) - { - var latestPackageVersion = context.PackageStore?.GetLatestVersion(WellKnownPackageTypes.Agent); - if (latestPackageVersion == null) - { - throw new NotSupportedException("Unable to determine the latest agent package version"); - } - - phaseStepValidationResult.MinAgentVersion = latestPackageVersion.ToString(); - } - - if (context.EnvironmentVersion < 2) - { - // environment version 1 should has at most 1 checkout step, the position of the checkout task might not be the fisrt one of there is an Azure keyvault task - var checkoutStep = this.Steps.SingleOrDefault(x => x.IsCheckoutTask()); - if (checkoutStep != null) - { - if ((checkoutStep as TaskStep).Inputs[PipelineConstants.CheckoutTaskInputs.Repository] == PipelineConstants.NoneAlias) - { - this.Variables.Add(new Variable() { Name = "agent.source.skip", Value = Boolean.TrueString }); - } - - this.Steps.Remove(checkoutStep); - } - } - - ValidateSteps(context, this, Target, result, this.Steps, phaseStepValidationResult); - - // Resolve the target to ensure we have stable identifiers for the orchestration engine - // phase targets with expressions need to be evaluated against resolved job contexts. - bool validateTarget = false; - if (this.Target.Type == PhaseTargetType.Pool || this.Target.Type == PhaseTargetType.Server) - { - validateTarget = true; - } - else if (this.Target is AgentQueueTarget agentQueueTarget && agentQueueTarget.IsLiteral()) - { - validateTarget = true; - } - - if (validateTarget) - { - this.Target.Validate( - context, - context.BuildOptions, - result, - this.Steps, - phaseStepValidationResult.TaskDemands); - } - } - - // todo: merge JobFactory.cs and Phase.cs and then make this private - internal static void ValidateSteps( - PipelineBuildContext context, - PhaseNode phase, - PhaseTarget phaseTarget, - ValidationResult result, - IList steps, - StepValidationResult phaseStepValidationResult) - { - var stepsCopy = new List(); - foreach (var step in steps) - { - // Skip if not enabled on the definition. - if (!step.Enabled) - { - continue; - } - - if (step.Type == StepType.Task) - { - var taskErrors = ValidateTaskStep(context, phase, phaseTarget, result.ReferencedResources, result.UnauthorizedResources, (step as TaskStep), phaseStepValidationResult); - if (taskErrors.Count == 0) - { - stepsCopy.Add(step); - } - else - { - result.Errors.AddRange(taskErrors); - } - } - else if (step.Type == StepType.Group) - { - var groupErrors = ValidateGroupStep(context, phase, phaseTarget, result.ReferencedResources, result.UnauthorizedResources, (step as GroupStep), phaseStepValidationResult); - if (groupErrors.Count == 0) - { - stepsCopy.Add(step); - } - else - { - result.Errors.AddRange(groupErrors); - } - } - else if (step.Type == StepType.Action) - { - var actionErrors = ValidateActionStep(context, phase, step as ActionStep, phaseStepValidationResult); - if (actionErrors.Count == 0) - { - stepsCopy.Add(step); - } - else - { - result.Errors.AddRange(actionErrors); - } - } - else - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.StepNotSupported())); - } - } - - // Now replace the steps list with our updated list based on disabled/missing tasks - steps.Clear(); - steps.AddRange(stepsCopy); - - // Now go through any tasks which did not have a name specified and name them according to how many - // of that specific task is present. - if (phaseStepValidationResult.UnnamedSteps.Count > 0) - { - GenerateDefaultTaskNames(phaseStepValidationResult.KnownNames, phaseStepValidationResult.UnnamedSteps); - } - - // Make sure our computed minimum agent version is included with the task demands - if (phaseStepValidationResult.MinAgentVersion != null) - { - phaseStepValidationResult.TaskDemands.Add(new DemandMinimumVersion(PipelineConstants.AgentVersionDemandName, phaseStepValidationResult.MinAgentVersion)); - } - } - - private static List ValidateActionStep( - PipelineBuildContext context, - PhaseNode phase, - ActionStep actionStep, - StepValidationResult stepValidationResult) - { - List actionErrors = new List(); - - // We need an action reference to a contianer image or repository - if (actionStep.Reference == null) - { - // Stop checking further since we can't even find an action definition - actionErrors.Add(new PipelineValidationError(PipelineStrings.StepActionReferenceInvalid(phase.Name, actionStep.Name))); - return actionErrors; - } - - string defaultActionName = ""; - if (actionStep.Reference.Type == ActionSourceType.ContainerRegistry) - { - // action is reference to an image from container registry - var containerAction = actionStep.Reference as ContainerRegistryReference; - defaultActionName = NameValidation.Sanitize(containerAction.Image, context.BuildOptions.AllowHyphenNames); - } - else if (actionStep.Reference.Type == ActionSourceType.Repository) - { - // action is reference to dockerfile or action.js from a git repository - var repoAction = actionStep.Reference as RepositoryPathReference; - defaultActionName = NameValidation.Sanitize(repoAction.Name ?? PipelineConstants.SelfAlias, context.BuildOptions.AllowHyphenNames); - } - else if (actionStep.Reference.Type == ActionSourceType.Script) - { - defaultActionName = "run"; - } - else - { - actionErrors.Add(new PipelineValidationError(PipelineStrings.TaskStepReferenceInvalid(phase.Name, actionStep.Name, actionStep.Reference.Type))); - } - - // Validate task name - var stepNameError = ValidateStepName(context, phase, stepValidationResult, actionStep, defaultActionName); - if (stepNameError != null) - { - actionErrors.Add(stepNameError); - } - - return actionErrors; - } - - private static List ValidateTaskStep( - PipelineBuildContext context, - PhaseNode phase, - PhaseTarget phaseTarget, - PipelineResources referencedResources, - PipelineResources unauthorizedResources, - TaskStep taskStep, - StepValidationResult stepValidationResult) - { - List taskErrors = new List(); - - // We need either a task name or an identifier and a version. - if (taskStep.Reference == null || - taskStep.Reference.Version == null || - (taskStep.Reference.Id == Guid.Empty && String.IsNullOrEmpty(taskStep.Reference.Name))) - { - // Stop checking further since we can't even resolve task definition - taskErrors.Add(new PipelineValidationError(PipelineStrings.StepTaskReferenceInvalid(phase.Name, taskStep.Name))); - return taskErrors; - } - - // Try to resolve by the identifier first, then by name - TaskDefinition resolvedTask = null; - try - { - if (taskStep.Reference.Id != Guid.Empty) - { - resolvedTask = context.TaskStore?.ResolveTask(taskStep.Reference.Id, taskStep.Reference.Version); - } - else if (!String.IsNullOrEmpty(taskStep.Reference.Name)) - { - resolvedTask = context.TaskStore?.ResolveTask(taskStep.Reference.Name, taskStep.Reference.Version); - } - } - catch (AmbiguousTaskSpecificationException ex) - { - // Stop checking further since we can't even resolve task definition - taskErrors.Add(new PipelineValidationError(PipelineStrings.TaskStepReferenceInvalid(phase.Name, taskStep.Name, ex.Message))); - return taskErrors; - } - - // Make sure we were able to find the task with the provided reference data - if (resolvedTask == null || resolvedTask.Disabled) - { - // Stop checking further since we can't even resolve task definition - String name = taskStep.Reference.Id != Guid.Empty ? taskStep.Reference.Id.ToString() : taskStep.Reference.Name; - taskErrors.Add(new PipelineValidationError(PipelineStrings.TaskMissing(phase.Name, taskStep.Name, name, taskStep.Reference.Version))); - return taskErrors; - } - - // Make sure this step is compatible with the target used by this phase - if (phaseTarget.IsValid(resolvedTask) == false) - { - // Stop checking further since the task is not for valid for the target - taskErrors.Add(new PipelineValidationError(PipelineStrings.TaskInvalidForGivenTarget(phase.Name, taskStep.Name, resolvedTask.Name, resolvedTask.Version))); - return taskErrors; - } - - // Resolve the task version to pin a given task for the duration of the plan - taskStep.Reference.Id = resolvedTask.Id; - taskStep.Reference.Name = resolvedTask.Name; - taskStep.Reference.Version = resolvedTask.Version; - - // Make sure that we have valid syntax for a condition statement - var conditionError = ValidateStepCondition(context, phase, taskStep.Name, taskStep.Condition); - if (conditionError != null) - { - taskErrors.Add(conditionError); - } - - // Resolves values from inputs based on the provided validation options - var inputErrors = ResolveInputs(context, phase, referencedResources, unauthorizedResources, taskStep, resolvedTask); - if (inputErrors.Count > 0) - { - taskErrors.AddRange(inputErrors); - } - - // Task names do not have to correspond to the same rules as reference names, so we need to remove - // any characters which are considered invalid for a reference name from the task definition name. - var defaultTaskName = NameValidation.Sanitize(taskStep.Reference.Name, context.BuildOptions.AllowHyphenNames); - - // Validate task name - var stepNameError = ValidateStepName(context, phase, stepValidationResult, taskStep, defaultTaskName); - if (stepNameError != null) - { - taskErrors.Add(stepNameError); - } - - // Now union any demand which are satisifed by tasks within the job - stepValidationResult.TasksSatisfy.UnionWith(resolvedTask.Satisfies); - - stepValidationResult.MinAgentVersion = resolvedTask.GetMinimumAgentVersion(stepValidationResult.MinAgentVersion); - - // Add demands from task - var unsatisfiedDemands = resolvedTask.Demands.Where(d => !stepValidationResult.TasksSatisfy.Contains(d.Name)); - if (unsatisfiedDemands.Any()) - { - stepValidationResult.TaskDemands.UnionWith(unsatisfiedDemands); - } - - return taskErrors; - } - - private static List ValidateGroupStep( - PipelineBuildContext context, - PhaseNode phase, - PhaseTarget phaseTarget, - PipelineResources referencedResources, - PipelineResources unauthorizedResources, - GroupStep groupStep, - StepValidationResult stepValidationResult) - { - List groupErrors = new List(); - - // Make sure that we have valid syntax for a condition statement - var conditionError = ValidateStepCondition(context, phase, groupStep.Name, groupStep.Condition); - if (conditionError != null) - { - groupErrors.Add(conditionError); - } - - // ValidationResult for steps within group, since only steps within a group need to have unique task.name - StepValidationResult groupStepsValidationResult = new StepValidationResult(); - - var stepsCopy = new List(); - foreach (var step in groupStep.Steps) - { - // Skip if not enabled on the definition. - if (!step.Enabled) - { - continue; - } - - var taskErrors = ValidateTaskStep(context, phase, phaseTarget, referencedResources, unauthorizedResources, step, groupStepsValidationResult); - if (taskErrors.Count == 0) - { - stepsCopy.Add(step); - } - else - { - groupErrors.AddRange(taskErrors); - } - } - - // Now replace the steps list with our updated list based on disabled/missing tasks - groupStep.Steps.Clear(); - groupStep.Steps.AddRange(stepsCopy); - - // Merge group steps validation result - if (groupStepsValidationResult.UnnamedSteps.Count > 0) - { - // Now go through any tasks within a group which did not have a name specified and name them according to how many - // of that specific task is present. - GenerateDefaultTaskNames(groupStepsValidationResult.KnownNames, groupStepsValidationResult.UnnamedSteps); - } - - // If group min agent version > current min agent version - if (DemandMinimumVersion.CompareVersion(groupStepsValidationResult.MinAgentVersion, stepValidationResult.MinAgentVersion) > 0) - { - stepValidationResult.MinAgentVersion = groupStepsValidationResult.MinAgentVersion; - } - - // Add tasks satisfies provided by the group - stepValidationResult.TasksSatisfy.UnionWith(groupStepsValidationResult.TasksSatisfy); - - // Add demands come from tasks within the group - var unsatisfiedDemands = groupStepsValidationResult.TaskDemands.Where(d => !stepValidationResult.TasksSatisfy.Contains(d.Name)); - if (unsatisfiedDemands.Any()) - { - stepValidationResult.TaskDemands.UnionWith(unsatisfiedDemands); - } - - // Validate group name - var stepNameError = ValidateStepName(context, phase, stepValidationResult, groupStep, "group"); - if (stepNameError != null) - { - groupErrors.Add(stepNameError); - } - - return groupErrors; - } - - private static PipelineValidationError ValidateStepName( - PipelineBuildContext context, - PhaseNode phase, - StepValidationResult stepValidationResult, - JobStep step, - String defaultName) - { - if (String.IsNullOrEmpty(step.Name)) - { - List stepsToName; - if (!stepValidationResult.UnnamedSteps.TryGetValue(defaultName, out stepsToName)) - { - stepsToName = new List(); - stepValidationResult.UnnamedSteps.Add(defaultName, stepsToName); - } - - stepsToName.Add(step); - - if (String.IsNullOrEmpty(step.DisplayName)) - { - step.DisplayName = defaultName; - } - } - else - { - bool nameIsValid = NameValidation.IsValid(step.Name, context.BuildOptions.AllowHyphenNames); - if (!nameIsValid) - { - if (context.BuildOptions.ValidateStepNames) - { - return new PipelineValidationError(PipelineStrings.StepNameInvalid(phase.Name, step.Name)); - } - else - { - var sanitizedName = NameValidation.Sanitize(step.Name, context.BuildOptions.AllowHyphenNames); - if (String.IsNullOrEmpty(sanitizedName)) - { - sanitizedName = defaultName; - } - - step.Name = sanitizedName; - nameIsValid = true; - } - } - - if (nameIsValid && !stepValidationResult.KnownNames.Add(step.Name)) - { - if (context.BuildOptions.ValidateStepNames) - { - return new PipelineValidationError(PipelineStrings.StepNamesMustBeUnique(phase.Name, step.Name)); - } - else - { - List stepsToName; - if (!stepValidationResult.UnnamedSteps.TryGetValue(step.Name, out stepsToName)) - { - stepsToName = new List(); - stepValidationResult.UnnamedSteps.Add(step.Name, stepsToName); - } - - stepsToName.Add(step); - } - } - - // If the name was specified but the display name is empty, default the display name to the name - if (String.IsNullOrEmpty(step.DisplayName)) - { - step.DisplayName = step.Name; - } - } - - return null; - } - - private static PipelineValidationError ValidateStepCondition( - PipelineBuildContext context, - PhaseNode phase, - String stepName, - String stepCondition) - { - if (!String.IsNullOrEmpty(stepCondition)) - { - try - { - var parser = new DistributedTask.Expressions.ExpressionParser(); - parser.ValidateSyntax(stepCondition, null); - } - catch (ParseException ex) - { - return new PipelineValidationError(PipelineStrings.StepConditionIsNotValid(phase.Name, stepName, stepCondition, ex.Message)); - } - } - - return null; - } - - private static void GenerateDefaultTaskNames( - ISet knownNames, - IDictionary> unnamedTasks) - { - foreach (var unnamedTasksByName in unnamedTasks) - { - if (unnamedTasksByName.Value.Count == 1 && knownNames.Add(unnamedTasksByName.Key)) - { - unnamedTasksByName.Value[0].Name = unnamedTasksByName.Key; - } - else - { - Int32 taskCounter = 1; - foreach (var unnamedTask in unnamedTasksByName.Value) - { - var candidateName = $"{unnamedTasksByName.Key}{taskCounter}"; - while (!knownNames.Add(candidateName)) - { - taskCounter++; - candidateName = $"{unnamedTasksByName.Key}{taskCounter}"; - } - - taskCounter++; - unnamedTask.Name = candidateName; - } - } - } - } - - private static IList ResolveInputs( - PipelineBuildContext context, - PhaseNode phase, - PipelineResources referencedResources, - PipelineResources unauthorizedResources, - TaskStep step, - TaskDefinition taskDefinition) - { - IList errors = new List(); - foreach (var input in taskDefinition.Inputs) - { - // Resolve by alias - var inputAlias = ResolveAlias(context, step, input); - - // If the input isn't set then there is nothing else to do here - if (!step.Inputs.TryGetValue(input.Name, out String inputValue)) - { - continue; - } - - // If the caller requested input validation and the input provides a validation section then we - // should do a best-effort validation based on what is available in the environment. - errors.AddRange(ValidateInput(context, phase, step, input, inputAlias, inputValue)); - - // Now resolve any resources referenced by task inputs - errors.AddRange(ResolveResources(context, phase, context.BuildOptions, referencedResources, unauthorizedResources, step, input, inputAlias, inputValue, throwOnFailure: false)); - } - - return errors; - } - - private static String ResolveAlias( - PipelineBuildContext context, - TaskStep step, - TaskInputDefinition input) - { - var specifiedName = input.Name; - if (context.BuildOptions.ResolveTaskInputAliases && !step.Inputs.ContainsKey(input.Name)) - { - foreach (String alias in input.Aliases) - { - if (step.Inputs.TryGetValue(alias, out String aliasValue)) - { - specifiedName = alias; - step.Inputs.Remove(alias); - step.Inputs.Add(input.Name, aliasValue); - break; - } - } - } - return specifiedName; - } - - private static IEnumerable ResolveResources( - IPipelineContext context, - PhaseNode phase, - BuildOptions options, - PipelineResources referencedResources, - PipelineResources unauthorizedResources, - TaskStep step, - TaskInputDefinition input, - String inputAlias, - String inputValue, - Boolean throwOnFailure = false) - { - if (String.IsNullOrEmpty(inputValue)) - { - return Enumerable.Empty(); - } - - var errors = new List(); - if (input.InputType.StartsWith(c_endpointInputTypePrefix, StringComparison.OrdinalIgnoreCase)) - { - var resolvedEndpoints = new List(); - var endpointType = input.InputType.Remove(0, c_endpointInputTypePrefix.Length); - var resolvedInputValues = inputValue.Split(',').Select(x => x.Trim()).Where(x => !String.IsNullOrEmpty(x)); - foreach (var value in resolvedInputValues) - { - var replacedValue = context.ExpandVariables(value); - referencedResources.AddEndpointReference(replacedValue); - - // Validate the resource using the provided store if desired - if (options.ValidateResources) - { - var endpoint = context.ResourceStore.GetEndpoint(replacedValue); - if (endpoint == null) - { - if (throwOnFailure) - { - throw new ResourceNotFoundException(PipelineStrings.ServiceEndpointNotFoundForInput(phase.Name, step.Name, inputAlias, replacedValue)); - } - else - { - resolvedEndpoints.Add(replacedValue); - unauthorizedResources?.AddEndpointReference(replacedValue); - errors.Add(new PipelineValidationError(PipelineStrings.ServiceEndpointNotFoundForInput(phase.Name, step.Name, inputAlias, replacedValue))); - } - } - else - { - if (!String.IsNullOrEmpty(endpointType)) - { - var endpointTypeSegments = endpointType.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(); - if (endpointTypeSegments.Count >= 1) - { - var endpointTypeName = endpointTypeSegments[0]; - if (!endpointTypeName.Equals(endpoint.Type, StringComparison.OrdinalIgnoreCase)) - { - if (throwOnFailure) - { - throw new PipelineValidationException(PipelineStrings.StepInputEndpointTypeMismatch(phase.Name, step.Name, inputAlias, endpointTypeName, endpoint.Name, endpoint.Type)); - } - else - { - errors.Add(new PipelineValidationError(PipelineStrings.StepInputEndpointTypeMismatch(phase.Name, step.Name, inputAlias, endpointTypeName, endpoint.Name, endpoint.Type))); - } - } - else if (endpointTypeSegments.Count > 1 && !String.IsNullOrEmpty(endpoint.Authorization?.Scheme)) - { - var supportedAuthSchemes = endpointTypeSegments[1]?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(); - if (supportedAuthSchemes?.Count > 0 && !supportedAuthSchemes.Any(x => x.Equals(endpoint.Authorization.Scheme, StringComparison.OrdinalIgnoreCase))) - { - if (throwOnFailure) - { - throw new PipelineValidationException(PipelineStrings.StepInputEndpointAuthSchemeMismatch(phase.Name, step.Name, inputAlias, endpointTypeName, endpointTypeSegments[1], endpoint.Name, endpoint.Type, endpoint.Authorization.Scheme)); - } - else - { - errors.Add(new PipelineValidationError(PipelineStrings.StepInputEndpointAuthSchemeMismatch(phase.Name, step.Name, inputAlias, endpointTypeName, endpointTypeSegments[1], endpoint.Name, endpoint.Type, endpoint.Authorization.Scheme))); - } - } - } - } - } - - resolvedEndpoints.Add(endpoint.Id.ToString("D")); - } - } - else - { - // Always add the value back so we can update the input below. - resolvedEndpoints.Add(replacedValue); - } - } - - step.Inputs[input.Name] = String.Join(",", resolvedEndpoints); - } - else if (input.InputType.Equals(c_secureFileInputType, StringComparison.OrdinalIgnoreCase)) - { - var resolvedFiles = new List(); - var resolvedInputValues = inputValue.Split(',').Select(x => x.Trim()).Where(x => !String.IsNullOrEmpty(x)); - foreach (var value in resolvedInputValues) - { - var replacedValue = context.ExpandVariables(value); - referencedResources.AddSecureFileReference(replacedValue); - - // Validate the resource using the provided store if desired - if (options.ValidateResources) - { - var secureFile = context.ResourceStore.GetFile(replacedValue); - if (secureFile == null) - { - if (throwOnFailure) - { - throw new ResourceNotFoundException(PipelineStrings.SecureFileNotFoundForInput(phase.Name, step.Name, inputAlias, replacedValue)); - } - else - { - resolvedFiles.Add(replacedValue); - unauthorizedResources?.AddSecureFileReference(replacedValue); - errors.Add(new PipelineValidationError(PipelineStrings.SecureFileNotFoundForInput(phase.Name, step.Name, inputAlias, replacedValue))); - } - } - else - { - resolvedFiles.Add(secureFile.Id.ToString("D")); - } - } - else - { - // Always add the value back so we can update the input below. - resolvedFiles.Add(replacedValue); - } - } - - step.Inputs[input.Name] = String.Join(",", resolvedFiles); - } - else if (input.InputType.Equals(TaskInputType.Repository, StringComparison.OrdinalIgnoreCase)) - { - // Ignore repository alias None - if (!String.Equals(inputValue, PipelineConstants.NoneAlias)) - { - var repository = context.ResourceStore.Repositories.Get(inputValue); - if (repository == null) - { - if (options.ValidateResources) - { - // repository should always be there as full object - if (throwOnFailure) - { - throw new ResourceNotFoundException(PipelineStrings.RepositoryResourceNotFound(inputValue)); - } - else - { - errors.Add(new PipelineValidationError(PipelineStrings.RepositoryResourceNotFound(inputValue))); - } - } - } - else - { - referencedResources.Repositories.Add(repository); - - // Add the endpoint - if (repository.Endpoint != null) - { - referencedResources.AddEndpointReference(repository.Endpoint); - - if (options.ValidateResources) - { - var repositoryEndpoint = context.ResourceStore.GetEndpoint(repository.Endpoint); - if (repositoryEndpoint == null) - { - if (throwOnFailure) - { - throw new ResourceNotFoundException(PipelineStrings.ServiceEndpointNotFound(repository.Endpoint)); - } - else - { - unauthorizedResources?.AddEndpointReference(repository.Endpoint); - errors.Add(new PipelineValidationError(PipelineStrings.ServiceEndpointNotFound(repository.Endpoint))); - } - } - else - { - repository.Endpoint = new ServiceEndpointReference() { Id = repositoryEndpoint.Id }; - } - } - } - } - } - else - { - // always add self repo with checkout: none - var selfRepository = context.ResourceStore.Repositories.Get(PipelineConstants.SelfAlias); - if (selfRepository != null) - { - referencedResources.Repositories.Add(selfRepository); - if (selfRepository.Endpoint != null) - { - referencedResources.AddEndpointReference(selfRepository.Endpoint); - if (options.ValidateResources) - { - var repositoryEndpoint = context.ResourceStore.GetEndpoint(selfRepository.Endpoint); - if (repositoryEndpoint == null) - { - if (throwOnFailure) - { - throw new ResourceNotFoundException(PipelineStrings.ServiceEndpointNotFound(selfRepository.Endpoint)); - } - else - { - unauthorizedResources?.AddEndpointReference(selfRepository.Endpoint); - errors.Add(new PipelineValidationError(PipelineStrings.ServiceEndpointNotFound(selfRepository.Endpoint))); - } - } - else - { - selfRepository.Endpoint = new ServiceEndpointReference() { Id = repositoryEndpoint.Id }; - } - } - } - } - } - } - - return errors; - } - - private String ResolveContainerResource(JobExecutionContext context, String inputAlias) - { - var outputAlias = inputAlias; - // Check if container is an image spec, not an alias - if (inputAlias.Contains(":")) - { - var resource = context.ResourceStore?.Containers.GetAll().FirstOrDefault(x => - x.Endpoint == null && - x.Properties.Count == 1 && - String.Equals(x.Image, inputAlias, StringComparison.Ordinal)); - if (resource == null) - { - resource = new ContainerResource - { - Alias = Guid.NewGuid().ToString("N"), - Image = inputAlias, - }; - context.ResourceStore?.Containers.Add(resource); - } - outputAlias = resource.Alias; - } - - return outputAlias; - } - - private void UpdateJobContextReferencedContainers(JobExecutionContext context, string containerAlias) - { - // Look up the container by alias, and add dereferenced container to ReferencedResources - var containerResource = context.ResourceStore?.Containers.Get(containerAlias); - if (containerResource == null) - { - throw new ResourceNotFoundException(PipelineStrings.ContainerResourceNotFound(containerAlias)); - } - context.ReferencedResources.Containers.Add(containerResource); - if (containerResource.Endpoint != null) - { - context.ReferencedResources.AddEndpointReference(containerResource.Endpoint); - var serviceEndpoint = context.ResourceStore?.GetEndpoint(containerResource.Endpoint); - if (serviceEndpoint == null) - { - throw new ResourceNotFoundException(PipelineStrings.ContainerEndpointNotFound(containerAlias, containerResource.Endpoint)); - } - } - } - - private static IEnumerable ValidateInput( - PipelineBuildContext context, - PhaseNode phase, - TaskStep step, - TaskInputDefinition input, - String inputAlias, - String value) - { - if (!context.BuildOptions.ValidateTaskInputs || input.Validation == null) - { - return Enumerable.Empty(); - } - - // We cannot perform useful validation if the value didn't expand, it may not be populated until it - // executes on the target. If we still have variables we just let it go through optimistically. - var expandedInputValue = context.ExpandVariables(value); - if (VariableUtility.IsVariable(expandedInputValue)) - { - return Enumerable.Empty(); - } - - var inputContext = new InputValidationContext - { - Evaluate = true, - EvaluationOptions = new DistributedTask.Expressions.EvaluationOptions(), - Expression = input.Validation.Expression, - SecretMasker = context.SecretMasker, - TraceWriter = null, - Value = expandedInputValue, - }; - - // Make sure to track any input validation errors encountered - var validationResult = context.InputValidator.Validate(inputContext); - if (validationResult.IsValid) - { - return Enumerable.Empty(); - } - else - { - // Make sure we do not expose secrets when logging errors about expanded input values - var maskedValue = context.SecretMasker.MaskSecrets(expandedInputValue); - var reason = validationResult.Reason ?? input.Validation.Message; - return new[] { new PipelineValidationError(PipelineStrings.StepTaskInputInvalid(phase.Name, step.Name, inputAlias, maskedValue, inputContext.Expression, reason)) }; - } - } - - /// - /// Produces the official display name for this job. - /// Optionally include any of the path components you want to consider. - /// - internal static String GenerateDisplayName( - Stage stage = null, - PhaseNode phase = null, - Job job = null) - { - var stageName = default(string); - if (stage != null) - { - stageName = stage.DisplayName ?? stage.Name; - } - - var factoryName = default(string); - if (phase != null) - { - factoryName = phase.DisplayName ?? phase.Name; - } - - var jobName = default(string); - if (job != null) - { - jobName = job.DisplayName ?? job.Name; - } - - return GenerateDisplayName(stageName, factoryName, jobName); - } - - /// - /// Produces the official display name for this job. - /// Optionally include any of the path components you want to consider. - /// - internal static String GenerateDisplayName( - PhaseNode factory, - String configuration = null) - { - var factoryDisplayName = factory == null - ? String.Empty - : factory.DisplayName ?? factory.Name; - return GenerateDisplayName(factoryDisplayName, configuration); - } - - /// - /// Produces the official display name for this job. - /// Optionally include any of the path components you want to consider. - /// Removes any occurrence of the default node name (the reference name used for default nodes, - /// or when users do not specify any name) - /// - internal static String GenerateDisplayName(params string[] tokens) - { - if (tokens == null) - { - return string.Empty; - } - - var defaultNodeName = PipelineConstants.DefaultJobName; - var l = defaultNodeName.Length; - var formattedTokens = tokens - .Where(x => !string.IsNullOrWhiteSpace(x)) - .Select(x => (x.StartsWith(defaultNodeName) ? x.Substring(l) : x).Trim()) - .Where(x => !string.IsNullOrWhiteSpace(x)); - var result = string.Join(" ", formattedTokens); - - return string.IsNullOrWhiteSpace(result) - ? PipelineConstants.DefaultJobDisplayName - : result; - } - - public Job CreateJob( - JobExecutionContext context, - ExpressionValue container, - IDictionary> sidecarContainers, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - String displayName = null) - { - // default display name is based on the phase. - if (string.IsNullOrWhiteSpace(displayName)) - { - displayName = Phase.GenerateDisplayName(context.Phase.Definition); - } - - var job = new Job - { - Id = context.GetInstanceId(), - Name = context.Job.Name, - DisplayName = displayName, - ContinueOnError = continueOnError, - TimeoutInMinutes = timeoutInMinutes, - CancelTimeoutInMinutes = cancelTimeoutInMinutes - }; - - if (context.ExecutionOptions.EnableResourceExpressions) - { - job.Target = GenerateJobSpecificTarget(context); - } - - if (job.Target == null) - { - ArgumentUtility.CheckForNull(this.Target, nameof(this.Target)); - job.Target = this.Target.Clone(); - } - - if (context.EnvironmentVersion > 1) - { - // always add self or designer repo to repository list - RepositoryResource defaultRepo = null; - var selfRepo = context.ResourceStore?.Repositories.Get(PipelineConstants.SelfAlias); - if (selfRepo == null) - { - var designerRepo = context.ResourceStore?.Repositories.Get(PipelineConstants.DesignerRepo); - if (designerRepo != null) - { - defaultRepo = designerRepo; - } - else - { - Debug.Fail("Repositories are not filled in."); - } - } - else - { - defaultRepo = selfRepo; - } - - if (defaultRepo != null) - { - context.ReferencedResources.Repositories.Add(defaultRepo); - - // Add the endpoint - if (defaultRepo.Endpoint != null) - { - context.ReferencedResources.AddEndpointReference(defaultRepo.Endpoint); - var repositoryEndpoint = context.ResourceStore?.GetEndpoint(defaultRepo.Endpoint); - if (repositoryEndpoint == null) - { - throw new ResourceNotFoundException(PipelineStrings.ServiceEndpointNotFound(defaultRepo.Endpoint)); - } - } - } - } - - // Expand short-syntax inline-containers, resolve resource references and add to new job and context - if (container != null) - { - var containerAlias = container.GetValue(context).Value; - var outputAlias = ResolveContainerResource(context, containerAlias); - job.Container = new DistributedTask.ObjectTemplating.Tokens.StringToken(null, null, null, outputAlias); - UpdateJobContextReferencedContainers(context, outputAlias); - } - if (sidecarContainers != null) - { - foreach (var sidecar in sidecarContainers) - { - var sidecarContainerAlias = sidecar.Value.GetValue(context).Value; - var outputAlias = ResolveContainerResource(context, sidecarContainerAlias); - job.SidecarContainers.Add(sidecar.Key, outputAlias); - UpdateJobContextReferencedContainers(context, outputAlias); - } - } - - // Update the execution context with the job-specific system variables - UpdateJobContextVariablesFromJob(context, job); - - var steps = new List(); - var identifier = context.GetInstanceName(); - foreach (var step in this.Steps) - { - if (step.Type == StepType.Task) - { - // We don't need to add to demands here since they are already part of the plan. - steps.Add(CreateJobTaskStep(context, this, identifier, step as TaskStep)); - } - else if (step.Type == StepType.Group) - { - steps.Add(CreateJobStepGroup(context, this, identifier, step as GroupStep)); - } - else if (step.Type == StepType.Action) - { - steps.Add(CreateJobActionStep(context, identifier, step as ActionStep)); - } - else - { - // Should never happen. - Debug.Fail(step.Type.ToString()); - } - } - - // TODO: remove the whole concept of step providers. - // this work should happen during compilation. -zacox. - // - // This is not ideal but we need to set the job on the context before calling the step providers below. - // This method returns the job and it gets set after. We need to clean this up when we do refactoring. - context.Job.Definition = job; - - var stepProviderDemands = new HashSet(); - - // Add the system-injected tasks before inserting the user tasks. This currently does not handle injecting - // min agent version demands if appropriate. - var systemSteps = new List(); - if (context.StepProviders != null) - { - var jobSteps = new ReadOnlyCollection(steps); - - foreach (IStepProvider stepProvider in context.StepProviders) - { - systemSteps.AddRange(stepProvider.GetPreSteps(context, jobSteps)); - } - } - - if (systemSteps?.Count > 0) - { - for (Int32 i = 0; i < systemSteps.Count; i++) - { - systemSteps[i].Name = $"__system_{i + 1}"; - - IList resolvedSteps = new List(); - if (ResolveTaskStep(context, this, identifier, systemSteps[i], out resolvedSteps, stepProviderDemands)) - { - job.Steps.AddRange(resolvedSteps); - } - else - { - job.Steps.Add(CreateJobTaskStep(context, this, identifier, systemSteps[i], stepProviderDemands)); - } - } - } - - // Resolving user steps - foreach (var step in steps) - { - IList resolvedSteps = new List(); - if (ResolveTaskStep(context, this, identifier, step, out resolvedSteps)) - { - job.Steps.AddRange(resolvedSteps); - } - else - { - job.Steps.Add(step); - } - } - - // Add post job steps, if there are any. - // These are added after the user tasks. - var postJobSteps = new List(); - if (context.StepProviders != null) - { - var jobSteps = new ReadOnlyCollection(job.Steps); - - foreach (IStepProvider stepProvider in context.StepProviders) - { - postJobSteps.AddRange(stepProvider.GetPostSteps(context, jobSteps)); - } - } - - if (postJobSteps?.Count > 0) - { - for (Int32 i = 0; i < postJobSteps.Count; i++) - { - postJobSteps[i].Name = $"__system_post_{i + 1}"; - job.Steps.Add(CreateJobTaskStep(context, this, identifier, postJobSteps[i], stepProviderDemands)); - } - } - - // Add post checkout tasks - // We need to do this after all other tasks are added since checkout could be injected from pre steps or phase steps. - var postCheckoutSteps = new Dictionary>(); - if (context.StepProviders != null) - { - var jobSteps = new ReadOnlyCollection(steps); - - foreach (IStepProvider stepProvider in context.StepProviders) - { - // This will flatten into 1 dictionary of guids to insert after and the tasks to insert - Dictionary> toAdd = stepProvider.GetPostTaskSteps(context, jobSteps); - - foreach (var key in toAdd.Keys) - { - if (!postCheckoutSteps.ContainsKey(key)) - { - postCheckoutSteps[key] = new List(); - } - - postCheckoutSteps[key].AddRange(toAdd[key]); - } - } - } - - if (postCheckoutSteps?.Keys.Count > 0) - { - foreach (var pair in postCheckoutSteps) - { - Int32? indexOfLastInstanceOfTask = null; - for (int i = job.Steps.Count - 1; i >= 0; i--) - { - var taskStep = job.Steps[i] as TaskStep; - - if (taskStep != null && taskStep.Reference.Id.Equals(pair.Key)) - { - indexOfLastInstanceOfTask = i; - break; - } - } - - // This will not insert after if the task doesn't exist. - if (indexOfLastInstanceOfTask.HasValue) - { - for (Int32 i = 0; i < pair.Value.Count; i++) - { - // This is so that we know this was a system injected task. - pair.Value[i].Name = $"__system_postcheckout_{i + 1}"; - - job.Steps.Insert(indexOfLastInstanceOfTask.Value + i + 1, CreateJobTaskStep(context, this, identifier, pair.Value[i], stepProviderDemands)); - } - } - } - } - - // create unique set of job demands - AddDemands(context, job, stepProviderDemands); - AddDemands(context, job, this.Target?.Demands); - - // Copy context variables into job, since job will be saved and read back later before agent job message is sent - foreach (var variable in context.Variables) - { - context.Job.Definition.Variables.Add(new Variable - { - Name = variable.Key, - Value = variable.Value.IsSecret ? null : variable.Value.Value, - Secret = variable.Value.IsSecret - }); - } - - return job; - } - - private void AddDemands( - JobExecutionContext context, - Job job, - ISet demands) - { - if (context == null || job == null || demands == null) - { - return; - } - - var mergedDemands = job.Demands; - foreach (var d in demands) - { - if (d == null) - { - continue; - } - - var demandValue = d.Value; - if (String.IsNullOrEmpty(demandValue)) - { - // if a demand has no value, add it - mergedDemands.Add(d.Clone()); - } - else - { - // if a demand has a non-empty value, any problems encountered while evaluating - // macros should be promoted into PipelineValidationExceptions - var expandedValue = context.ExpandVariables(demandValue, maskSecrets: true); - try - { - var resolvedDemand = d.Clone(); - resolvedDemand.Update(expandedValue); - mergedDemands.Add(resolvedDemand); - } - catch (Exception e) - { - throw new PipelineValidationException(PipelineStrings.DemandExpansionInvalid(d.ToString(), d.Value, expandedValue), e); - } - } - } - } - - private Boolean ResolveTaskStep( - JobExecutionContext context, - PhaseNode phase, - String identifier, - JobStep step, - out IList resolvedSteps, - HashSet resolvedDemands = null) - { - Boolean handled = false; - IList resultSteps = new List(); - resolvedSteps = new List(); - - if (context.ResourceStore?.ResolveStep(context, step, out resultSteps) ?? false) - { - foreach (TaskStep resultStep in resultSteps) - { - resolvedSteps.Add(CreateJobTaskStep(context, phase, identifier, resultStep, resolvedDemands)); - } - - handled = true; - } - - return handled; - } - - /// - /// Evaluate runtime expressions - /// Queue targets are allowed use runtime expressions. - /// Resolve all expressions and produce a literal QueueTarget for execution. - /// - private AgentQueueTarget GenerateJobSpecificTarget(JobExecutionContext context) - { - var phase = context?.Phase?.Definition as Phase; - if (phase == null) - { - return null; - } - - if (!(phase.Target is AgentQueueTarget agentQueueTarget)) - { - return null; - } - - if (agentQueueTarget.IsLiteral()) - { - return null; - } - - // create a clone containing only literals and validate referenced resources - var validationResult = new Validation.ValidationResult(); - var literalTarget = agentQueueTarget.Evaluate(context, validationResult); - literalTarget?.Validate( - context: context, - result: validationResult, - buildOptions: new BuildOptions - { - EnableResourceExpressions = true, - ValidateResources = true, - ValidateExpressions = true, // all expressions must resolve - AllowEmptyQueueTarget = false - }, - steps: new List(), - taskDemands: new HashSet()); - - if (validationResult.Errors.Count > 0) - { - throw new PipelineValidationException(validationResult.Errors); - } - - return literalTarget; - } - - // todo: merge JobFactory.cs and Phase.cs and then make this private - internal static ActionStep CreateJobActionStep( - JobExecutionContext context, - String jobIdentifier, - ActionStep action) - { - var jobStep = (ActionStep)action.Clone(); - - // Setup the identifier based on our current context - var actionIdentifier = context.IdGenerator.GetInstanceName(jobIdentifier, action.Name); - jobStep.Id = context.IdGenerator.GetInstanceId(actionIdentifier); - - // Update the display name of task steps - jobStep.DisplayName = jobStep.DisplayName; - - return jobStep; - } - - // todo: merge JobFactory.cs and Phase.cs and then make this private - internal static TaskStep CreateJobTaskStep( - JobExecutionContext context, - PhaseNode phase, - String jobIdentifier, - TaskStep task, - HashSet resolvedDemands = null) - { - var jobStep = (TaskStep)task.Clone(); - - // Setup the identifier based on our current context - var taskIdentifier = context.IdGenerator.GetInstanceName(jobIdentifier, task.Name); - jobStep.Id = context.IdGenerator.GetInstanceId(taskIdentifier); - - // Update the display name of task steps - jobStep.DisplayName = context.ExpandVariables(jobStep.DisplayName, maskSecrets: true); - - // Now resolve any resources referenced by inputs - var taskDefinition = context.TaskStore.ResolveTask(jobStep.Reference.Id, jobStep.Reference.Version); - if (taskDefinition != null) - { - foreach (var input in taskDefinition.Inputs) - { - if (task.Inputs.TryGetValue(input.Name, out String value)) - { - ResolveResources(context, phase, BuildOptions.None, context.ReferencedResources, null, jobStep, input, input.Name, value, throwOnFailure: true); - } - } - - // Add demands - if (resolvedDemands != null) - { - resolvedDemands.AddRange(taskDefinition.Demands); - - if (!String.IsNullOrEmpty(taskDefinition.MinimumAgentVersion)) - { - resolvedDemands.Add(new DemandMinimumVersion(PipelineConstants.AgentVersionDemandName, taskDefinition.MinimumAgentVersion)); - } - } - } - else - { - throw new TaskDefinitionNotFoundException(PipelineStrings.TaskMissing(phase.Name, jobStep.Name, jobStep.Reference.Id, jobStep.Reference.Version)); - } - - return jobStep; - } - - // todo: merge JobFactory.cs and Phase.cs and then make this private - internal static GroupStep CreateJobStepGroup( - JobExecutionContext context, - PhaseNode phase, - String jobIdentifier, - GroupStep group) - { - var groupStep = (GroupStep)group.Clone(); - - var groupIdentifier = context.IdGenerator.GetInstanceName(jobIdentifier, group.Name); - groupStep.Id = context.IdGenerator.GetInstanceId(groupIdentifier); - - // Update the display name of step group - groupStep.DisplayName = context.ExpandVariables(groupStep.DisplayName, maskSecrets: true); - - // Now resolve every task steps within step group - var stepsCopy = new List(); - foreach (var task in groupStep.Steps) - { - stepsCopy.Add(CreateJobTaskStep(context, phase, groupIdentifier, task)); - } - - groupStep.Steps.Clear(); - groupStep.Steps.AddRange(stepsCopy); - - return groupStep; - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_steps?.Count == 0) - { - m_steps = null; - } - } - - [DataMember(Name = "Steps", EmitDefaultValue = false)] - private IList m_steps; - - private const String c_secureFileInputType = "secureFile"; - private const String c_endpointInputTypePrefix = "connectedService:"; - - // todo: merge JobFactory.cs and Phase.cs and then make this private - internal class StepValidationResult - { - public String MinAgentVersion { get; set; } - - public HashSet TaskDemands - { - get - { - if (m_taskDemands == null) - { - m_taskDemands = new HashSet(); - } - - return m_taskDemands; - } - } - - public HashSet KnownNames - { - get - { - if (m_knownNames == null) - { - m_knownNames = new HashSet(StringComparer.OrdinalIgnoreCase); - } - - return m_knownNames; - } - } - - public HashSet TasksSatisfy - { - get - { - if (m_tasksSatisfy == null) - { - m_tasksSatisfy = new HashSet(StringComparer.OrdinalIgnoreCase); - } - - return m_tasksSatisfy; - } - } - - public Dictionary> UnnamedSteps - { - get - { - if (m_unnamedSteps == null) - { - m_unnamedSteps = new Dictionary>(StringComparer.OrdinalIgnoreCase); - } - - return m_unnamedSteps; - } - } - - HashSet m_taskDemands; - HashSet m_knownNames; - HashSet m_tasksSatisfy; - Dictionary> m_unnamedSteps; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PhaseCondition.cs b/src/Sdk/DTPipelines/Pipelines/PhaseCondition.cs deleted file mode 100644 index eae3ddb45..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PhaseCondition.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Pipelines.Runtime; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PhaseCondition : GraphCondition - { - public PhaseCondition(String condition) - : base(condition) - { - } - - public ConditionResult Evaluate(PhaseExecutionContext context) - { - var traceWriter = new ConditionTraceWriter(); - var evaluationResult = m_parsedCondition.Evaluate(traceWriter, context.SecretMasker, context, context.ExpressionOptions); - return new ConditionResult() { Value = evaluationResult.IsTruthy, Trace = traceWriter.Trace }; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PhaseDependency.cs b/src/Sdk/DTPipelines/Pipelines/PhaseDependency.cs deleted file mode 100644 index 3cccfaeac..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PhaseDependency.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PhaseDependency - { - [JsonConstructor] - public PhaseDependency() - { - } - - private PhaseDependency(PhaseDependency dependencyToCopy) - { - this.Scope = dependencyToCopy.Scope; - this.Event = dependencyToCopy.Event; - } - - [DataMember] - public String Scope - { - get; - set; - } - - [DataMember] - public String Event - { - get; - set; - } - - /// - /// Implicitly converts a Phase to a PhaseDependency to enable easier modeling of graphs. - /// - /// The phase which should be converted to a dependency - public static implicit operator PhaseDependency(Phase dependency) - { - return PhaseCompleted(dependency.Name); - } - - public static PhaseDependency PhaseCompleted(String name) - { - return new PhaseDependency { Scope = name, Event = "Completed" }; - } - - internal PhaseDependency Clone() - { - return new PhaseDependency(this); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PhaseNode.cs b/src/Sdk/DTPipelines/Pipelines/PhaseNode.cs deleted file mode 100644 index 70c9fa3f5..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PhaseNode.cs +++ /dev/null @@ -1,421 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.WebApi; -using GitHub.Services.WebApi.Internal; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [ClientIgnore] - [EditorBrowsable(EditorBrowsableState.Never)] - public enum PhaseType - { - [EnumMember] - Phase, - - [EnumMember] - Provider, - - [EnumMember] - JobFactory, - } - - [DataContract] - [KnownType(typeof(Phase))] - [KnownType(typeof(ProviderPhase))] - [KnownType(typeof(JobFactory))] - [JsonConverter(typeof(PhaseNodeJsonConverter))] - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class PhaseNode : IGraphNode - { - protected PhaseNode() - { - } - - protected PhaseNode(PhaseNode nodeToCopy) - { - this.Name = nodeToCopy.Name; - this.DisplayName = nodeToCopy.DisplayName; - this.Condition = nodeToCopy.Condition; - this.ContinueOnError = nodeToCopy.ContinueOnError; - this.Target = nodeToCopy.Target?.Clone(); - - if (nodeToCopy.m_dependsOn?.Count > 0) - { - m_dependsOn = new HashSet(nodeToCopy.m_dependsOn, StringComparer.OrdinalIgnoreCase); - } - - if (nodeToCopy.m_variables != null && nodeToCopy.m_variables.Count > 0) - { - m_variables = new List(nodeToCopy.m_variables); - } - } - - /// - /// Gets the type of this phase. - /// - [DataMember(EmitDefaultValue = false)] - public abstract PhaseType Type { get; } - - /// - /// Gets or sets the name for this phase. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Gets or sets the display name for this phase. - /// - [DataMember(EmitDefaultValue = false)] - public String DisplayName - { - get; - set; - } - - /// - /// Gets or sets a condition which is evaluated after all dependencies have been satisfied and determines - /// whether or not the jobs within this phase should be executed or skipped. - /// - [DataMember(EmitDefaultValue = false)] - public String Condition - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether or not failed jobs are considered a termination condition for - /// the phase. - /// - [DataMember(EmitDefaultValue = false)] - [JsonConverter(typeof(ExpressionValueJsonConverter))] - public ExpressionValue ContinueOnError - { - get; - set; - } - - /// - /// Gets the set of phases which must complete before this phase begins execution. - /// - public ISet DependsOn - { - get - { - if (m_dependsOn == null) - { - m_dependsOn = new HashSet(StringComparer.OrdinalIgnoreCase); - } - return m_dependsOn; - } - } - - /// - /// Gets or sets the target for this phase. - /// - [DataMember(EmitDefaultValue = false)] - public PhaseTarget Target - { - get; - set; - } - - /// - /// Gets the set of variables which will be provided to the phase steps. - /// - public IList Variables - { - get - { - if (m_variables == null) - { - m_variables = new List(); - } - return m_variables; - } - } - - /// - /// Resolves external references and ensures the steps are compatible with the selected target. - /// - /// The validation context - public virtual void Validate( - PipelineBuildContext context, - ValidationResult result) - { - // Ensure we have a target - if (this.Target == null) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.PhaseTargetRequired(this.Name))); - return; - } - - if (this.Target.Type != PhaseTargetType.Queue && this.Target.Type != PhaseTargetType.Server && this.Target.Type != PhaseTargetType.Pool) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.UnsupportedTargetType(this.Name, this.Target.Type))); - return; - } - - // Default the condition to something reasonable if none is specified - if (String.IsNullOrEmpty(this.Condition)) - { - this.Condition = PhaseCondition.Default; - } - else - { - // Simply construct the condition and make sure the syntax and functions used are valid - var parsedCondition = new PhaseCondition(this.Condition); - } - - if (m_variables?.Count > 0) - { - var variablesCopy = new List(); - foreach (var variable in this.Variables) - { - if (variable is Variable simpleVariable) - { - // Do not allow phase overrides for certain variables. - if (s_nonOverridableVariables.Contains(simpleVariable.Name)) - { - continue; - } - } - else if (variable is VariableGroupReference groupVariable) - { - if (context.EnvironmentVersion < 2) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.PhaseVariableGroupNotSupported(this.Name, groupVariable))); - continue; - } - - result.ReferencedResources.VariableGroups.Add(groupVariable); - - if (context.BuildOptions.ValidateResources) - { - var variableGroup = context.ResourceStore.VariableGroups.Get(groupVariable); - if (variableGroup == null) - { - result.UnauthorizedResources.VariableGroups.Add(groupVariable); - result.Errors.Add(new PipelineValidationError(PipelineStrings.VariableGroupNotFoundForPhase(this.Name, groupVariable))); - } - } - } - - variablesCopy.Add(variable); - } - - m_variables.Clear(); - m_variables.AddRange(variablesCopy); - } - } - - protected virtual void UpdateJobContextVariablesFromJob(JobExecutionContext jobContext, Job job) - { - jobContext.Variables[WellKnownDistributedTaskVariables.JobDisplayName] = job.DisplayName; - jobContext.Variables[WellKnownDistributedTaskVariables.JobId] = job.Id.ToString("D"); - jobContext.Variables[WellKnownDistributedTaskVariables.JobName] = job.Name; - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - if (m_dependencies?.Count > 0) - { - m_dependsOn = new HashSet(m_dependencies.Select(x => x.Scope), StringComparer.OrdinalIgnoreCase); - m_dependencies = null; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_dependsOn?.Count == 0) - { - m_dependsOn = null; - } - - if (m_variables?.Count == 0) - { - m_variables = null; - } - } - - internal readonly static HashSet s_nonOverridableVariables = new HashSet(new[] - { - WellKnownDistributedTaskVariables.AccessTokenScope, - WellKnownDistributedTaskVariables.JobParallelismTag - }, StringComparer.OrdinalIgnoreCase); - - [JsonConverter(typeof(PhaseVariablesJsonConverter))] - [DataMember(Name = "Variables", EmitDefaultValue = false)] - private List m_variables; - - [DataMember(Name = "Dependencies", EmitDefaultValue = false)] - private List m_dependencies; - - [DataMember(Name = "DependsOn", EmitDefaultValue = false)] - private HashSet m_dependsOn; - - private class PhaseVariablesJsonConverter : JsonConverter - { - public PhaseVariablesJsonConverter() - { - } - - public override Boolean CanConvert(Type objectType) - { - return true; - } - - public override Boolean CanWrite => true; - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - if (reader.TokenType == JsonToken.StartArray) - { - return serializer.Deserialize>(reader); - } - else if (reader.TokenType == JsonToken.StartObject) - { - var dictionary = serializer.Deserialize>(reader); - if (dictionary?.Count > 0) - { - return dictionary.Select(x => new Variable { Name = x.Key, Value = x.Value }).Cast().ToList(); - } - } - - return null; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - var variables = value as IList; - if (variables?.Count > 0) - { - if (variables.Any(x => x is VariableGroupReference)) - { - serializer.Serialize(writer, variables); - } - else - { - // This format is only here for back compat with the previous serialization format - var dictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (var variable in variables.OfType()) - { - dictionary[variable.Name] = variable.Value; - } - - serializer.Serialize(writer, dictionary); - } - } - } - } - } - - internal sealed class PhaseNodeJsonConverter : VssSecureJsonConverter - { - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Boolean CanConvert(Type objectType) - { - return typeof(PhaseNode).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - if (reader.TokenType != JsonToken.StartObject) - { - return null; - } - - PhaseType? phaseType = null; - JObject value = JObject.Load(reader); - if (!value.TryGetValue("Type", StringComparison.OrdinalIgnoreCase, out JToken phaseTypeValue)) - { - phaseType = PhaseType.Phase; - } - else - { - if (phaseTypeValue.Type == JTokenType.Integer) - { - phaseType = (PhaseType)(Int32)phaseTypeValue; - } - else if (phaseTypeValue.Type == JTokenType.String) - { - PhaseType parsedType; - if (Enum.TryParse((String)phaseTypeValue, ignoreCase: true, result: out parsedType)) - { - phaseType = parsedType; - } - } - } - - if (phaseType == null) - { - return existingValue; - } - - Object newValue = null; - switch (phaseType) - { - case PhaseType.Phase: - newValue = new Phase(); - break; - - case PhaseType.Provider: - newValue = new ProviderPhase(); - break; - - case PhaseType.JobFactory: - newValue = new JobFactory(); - break; - } - - using (JsonReader objectReader = value.CreateReader()) - { - serializer.Populate(objectReader, newValue); - } - - return newValue; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PhaseTarget.cs b/src/Sdk/DTPipelines/Pipelines/PhaseTarget.cs deleted file mode 100644 index 37f424d73..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PhaseTarget.cs +++ /dev/null @@ -1,260 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [KnownType(typeof(AgentQueueTarget))] - [KnownType(typeof(AgentPoolTarget))] - [KnownType(typeof(ServerTarget))] - [KnownType(typeof(DeploymentGroupTarget))] - [JsonConverter(typeof(PhaseTargetJsonConverter))] - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class PhaseTarget - { - protected PhaseTarget(PhaseTargetType type) - { - this.Type = type; - } - - protected PhaseTarget(PhaseTarget targetToClone) - { - this.Type = targetToClone.Type; - this.ContinueOnError = targetToClone.ContinueOnError; - this.TimeoutInMinutes = targetToClone.TimeoutInMinutes; - this.CancelTimeoutInMinutes = targetToClone.CancelTimeoutInMinutes; - if (targetToClone.m_demands?.Count > 0) - { - m_demands = new HashSet(targetToClone.m_demands.Select(x => x.Clone())); - } - } - - /// - /// Get the type of target. - /// - [DataMember] - public PhaseTargetType Type - { - get; - private set; - } - - /// - /// Gets or sets a value which determines whether or not to treat errors as terminal. - /// - [DataMember(EmitDefaultValue = false)] - [JsonConverter(typeof(ExpressionValueJsonConverter))] - public ExpressionValue ContinueOnError - { - get; - set; - } - - /// - /// Gets or sets a value which determines the maximum amount of time a job is allowed to execute. - /// - [DataMember(EmitDefaultValue = false)] - [JsonConverter(typeof(ExpressionValueJsonConverter))] - public ExpressionValue TimeoutInMinutes - { - get; - set; - } - - /// - /// Gets or sets a value which determines the maximum amount of time a job is allowed for cancellation. - /// - [DataMember(EmitDefaultValue = false)] - [JsonConverter(typeof(ExpressionValueJsonConverter))] - public ExpressionValue CancelTimeoutInMinutes - { - get; - set; - } - - /// - /// Gets the demands which determine where this job may be run. - /// - public ISet Demands - { - get - { - if (m_demands == null) - { - m_demands = new HashSet(); - } - return m_demands; - } - } - - /// - /// Creates a deep copy of the current instance. - /// - /// A new PhaseTarget instance of the current type - public abstract PhaseTarget Clone(); - - /// - /// Indicates whether the task definition can run on the target. - /// - public abstract Boolean IsValid(TaskDefinition task); - - internal abstract JobExecutionContext CreateJobContext(PhaseExecutionContext context, String jobName, Int32 attempt, Boolean continueOnError, Int32 timeoutInMinutes, Int32 cancelTimeoutInMinutes, IJobFactory jobFactory); - - internal void Validate( - IPipelineContext context, - BuildOptions buildOptions, - ValidationResult result) - { - this.Validate(context, buildOptions, result, new List(), new HashSet()); - } - - internal abstract ExpandPhaseResult Expand(PhaseExecutionContext context, Boolean continueOnError, Int32 timeoutInMinutes, Int32 cancelTimeoutInMinutes, IJobFactory jobFactory, JobExpansionOptions options); - - internal virtual void Validate( - IPipelineContext context, - BuildOptions buildOptions, - ValidationResult result, - IList steps, - ISet taskDemands) - { - } - - internal JobExecutionContext CreateJobContext( - PhaseExecutionContext context, - String jobName, - Int32 attempt, - IJobFactory jobFactory) - { - var continueOnError = context.Evaluate(nameof(ContinueOnError), this.ContinueOnError, false).Value; - var timeoutInMinutes = context.Evaluate(nameof(TimeoutInMinutes), this.TimeoutInMinutes, PipelineConstants.DefaultJobTimeoutInMinutes).Value; - var cancelTimeoutInMinutes = context.Evaluate(nameof(CancelTimeoutInMinutes), this.CancelTimeoutInMinutes, PipelineConstants.DefaultJobCancelTimeoutInMinutes).Value; - return this.CreateJobContext(context, jobName, attempt, continueOnError, timeoutInMinutes, cancelTimeoutInMinutes, jobFactory); - } - - internal ExpandPhaseResult Expand( - PhaseExecutionContext context, - IJobFactory jobFactory, - JobExpansionOptions options) - { - var continueOnError = context.Evaluate(nameof(ContinueOnError), this.ContinueOnError, false).Value; - var timeoutInMinutes = context.Evaluate(nameof(TimeoutInMinutes), this.TimeoutInMinutes, PipelineConstants.DefaultJobTimeoutInMinutes).Value; - var cancelTimeoutInMinutes = context.Evaluate(nameof(CancelTimeoutInMinutes), this.CancelTimeoutInMinutes, PipelineConstants.DefaultJobCancelTimeoutInMinutes).Value; - return this.Expand(context, continueOnError, timeoutInMinutes, cancelTimeoutInMinutes, jobFactory, options); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_demands?.Count == 0) - { - m_demands = null; - } - } - - [DataMember(Name = "Demands", EmitDefaultValue = false)] - private ISet m_demands; - } - - internal sealed class PhaseTargetJsonConverter : VssSecureJsonConverter - { - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Boolean CanConvert(Type objectType) - { - return typeof(PhaseTarget).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - if (reader.TokenType != JsonToken.StartObject) - { - return null; - } - - PhaseTargetType? targetType = null; - JObject value = JObject.Load(reader); - if (!value.TryGetValue("Type", StringComparison.OrdinalIgnoreCase, out JToken targetTypeValue)) - { - return existingValue; - } - else - { - if (targetTypeValue.Type == JTokenType.Integer) - { - targetType = (PhaseTargetType)(Int32)targetTypeValue; - } - else if (targetTypeValue.Type == JTokenType.String) - { - PhaseTargetType parsedType; - if (Enum.TryParse((String)targetTypeValue, ignoreCase: true, result: out parsedType)) - { - targetType = parsedType; - } - } - } - - if (targetType == null) - { - return existingValue; - } - - Object newValue = null; - switch (targetType) - { - case PhaseTargetType.DeploymentGroup: - newValue = new DeploymentGroupTarget(); - break; - - case PhaseTargetType.Server: - newValue = new ServerTarget(); - break; - - case PhaseTargetType.Queue: - newValue = new AgentQueueTarget(); - break; - - case PhaseTargetType.Pool: - newValue = new AgentPoolTarget(); - break; - } - - if (value != null) - { - using (JsonReader objectReader = value.CreateReader()) - { - serializer.Populate(objectReader, newValue); - } - } - - return newValue; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PhaseTargetType.cs b/src/Sdk/DTPipelines/Pipelines/PhaseTargetType.cs deleted file mode 100644 index 3163e0b93..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PhaseTargetType.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.Services.WebApi.Internal; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [ClientIgnore] - [EditorBrowsable(EditorBrowsableState.Never)] - public enum PhaseTargetType - { - [EnumMember] - Queue, - - [EnumMember] - Server, - - [EnumMember] - DeploymentGroup, - - [EnumMember] - Pool, - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineBuildContext.cs b/src/Sdk/DTPipelines/Pipelines/PipelineBuildContext.cs deleted file mode 100644 index 828bf64ac..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineBuildContext.cs +++ /dev/null @@ -1,182 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PipelineBuildContext : PipelineContextBase - { - public PipelineBuildContext() - : this(new BuildOptions()) - { - } - - public PipelineBuildContext( - IPipelineContext context, - BuildOptions options) - : base(context) - { - m_buildOptions = options ?? new BuildOptions(); - } - - public PipelineBuildContext( - BuildOptions buildOptions, - DictionaryContextData data = null, - ICounterStore counterStore = null, - IResourceStore resourceStore = null, - IList stepProviders = null, - ITaskStore taskStore = null, - IPackageStore packageStore = null, - IInputValidator inputValidator = null, - IPipelineTraceWriter trace = null, - EvaluationOptions expressionOptions = null, - IList phaseProviders = null) - : base(data, counterStore, packageStore, resourceStore, taskStore, stepProviders, null, trace, expressionOptions) - { - m_buildOptions = buildOptions ?? new BuildOptions(); - m_inputValidator = inputValidator; - m_phaseProviders = phaseProviders; - } - - public BuildOptions BuildOptions - { - get - { - return m_buildOptions; - } - } - - public IInputValidator InputValidator - { - get - { - return m_inputValidator; - } - } - - public IReadOnlyList PhaseProviders - { - get - { - return m_phaseProviders.ToList(); - } - } - - internal ValidationResult Validate(PipelineProcess process) - { - var result = new ValidationResult(); - - // If requested to do so, validate the container resource to ensure it was specified properly. This will - // also handle endpoint authorization if the container requires access to a docker registry. - if (this.ResourceStore != null) - { - foreach (var container in this.ResourceStore.Containers.GetAll().Where(x => x.Endpoint != null)) - { - result.ReferencedResources.AddEndpointReference(container.Endpoint); - - if (this.BuildOptions.ValidateResources) - { - var endpoint = this.ResourceStore.GetEndpoint(container.Endpoint); - if (endpoint == null) - { - result.UnauthorizedResources.AddEndpointReference(container.Endpoint); - result.Errors.Add(new PipelineValidationError(PipelineStrings.ServiceEndpointNotFound(container.Endpoint))); - } - else - { - if (!endpoint.Type.Equals(ServiceEndpointTypes.Docker, StringComparison.OrdinalIgnoreCase)) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.ContainerResourceInvalidRegistryEndpointType(container.Alias, endpoint.Type, endpoint.Name))); - } - else - { - container.Endpoint = new ServiceEndpointReference - { - Id = endpoint.Id, - }; - } - } - } - } - - foreach (var repository in this.ResourceStore.Repositories.GetAll()) - { - var expandedProperties = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (var property in repository.Properties.GetItems()) - { - expandedProperties[property.Key] = this.ExpandVariables(property.Value); - } - - foreach (var expandedProperty in expandedProperties) - { - repository.Properties.Set(expandedProperty.Key, expandedProperty.Value); - } - } - - if (this.EnvironmentVersion > 1) - { - // always add self or designer repo to repository list - RepositoryResource defaultRepo = null; - var selfRepo = this.ResourceStore.Repositories.Get(PipelineConstants.SelfAlias); - if (selfRepo == null) - { - var designerRepo = this.ResourceStore.Repositories.Get(PipelineConstants.DesignerRepo); - if (designerRepo != null) - { - defaultRepo = designerRepo; - } - else - { - System.Diagnostics.Debug.Fail("Repositories are not filled in."); - } - } - else - { - defaultRepo = selfRepo; - } - - if (defaultRepo != null) - { - result.ReferencedResources.Repositories.Add(defaultRepo); - - // Add the endpoint - if (defaultRepo.Endpoint != null) - { - result.ReferencedResources.AddEndpointReference(defaultRepo.Endpoint); - - if (this.BuildOptions.ValidateResources) - { - var repositoryEndpoint = this.ResourceStore.GetEndpoint(defaultRepo.Endpoint); - if (repositoryEndpoint == null) - { - result.UnauthorizedResources?.AddEndpointReference(defaultRepo.Endpoint); - result.Errors.Add(new PipelineValidationError(PipelineStrings.ServiceEndpointNotFound(defaultRepo.Endpoint))); - } - else - { - defaultRepo.Endpoint = new ServiceEndpointReference() { Id = repositoryEndpoint.Id }; - } - } - } - } - } - } - - // Validate the graph of stages - GraphValidator.Validate(this, result, PipelineStrings.StageNameWhenNoNameIsProvided, null, process.Stages, Stage.GetErrorMessage); - - return result; - } - - private IInputValidator m_inputValidator; - private IList m_phaseProviders; - private BuildOptions m_buildOptions; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineBuildResult.cs b/src/Sdk/DTPipelines/Pipelines/PipelineBuildResult.cs deleted file mode 100644 index 817946bc6..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineBuildResult.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Pipelines.Validation; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineBuildResult - { - public PipelineBuildResult( - PipelineEnvironment environment, - PipelineProcess process, - ValidationResult result) - { - this.Environment = environment; - this.Process = process; - m_validationResult = result; - } - - /// - /// Gets the environment which was generated by the builder. - /// - public PipelineEnvironment Environment - { - get; - private set; - } - - /// - /// Gets the process which was generated by the builder. - /// - public PipelineProcess Process - { - get; - private set; - } - - /// - /// Gets the list of errors which occurred while building the pipeline. - /// - public IList Errors - { - get - { - return m_validationResult.Errors; - } - } - - /// - /// Gets the set of all resources which are referenced by the pipeline. - /// - public PipelineResources ReferencedResources - { - get - { - return m_validationResult.ReferencedResources; - } - } - - /// - /// Gets the set of unauthorized resources, if any, which are referenced by the pipeline. - /// - public PipelineResources UnauthorizedResources - { - get - { - return m_validationResult.UnauthorizedResources; - } - } - - private readonly ValidationResult m_validationResult; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineBuilder.cs b/src/Sdk/DTPipelines/Pipelines/PipelineBuilder.cs deleted file mode 100644 index 40095be9b..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineBuilder.cs +++ /dev/null @@ -1,411 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism for customization of pipeline construction by different hosting environments. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineBuilder - { - /// - /// Initializes a new PipelineBuilder instance with default service implementations. - /// - public PipelineBuilder() - : this(null, null, null, null, null, null, null, null, null) - { - } - - /// - /// Initilaizes a new PipelineBuilder instance with the specified services used for resolution of - /// resources available to pipelines. - /// - /// The resources available for use within a pipeline - /// The tasks available for use within a pipeline - /// The secret stores available for use within a pipeline - public PipelineBuilder( - EvaluationOptions expressionOptions = null, - ICounterStore counterStore = null, - IPackageStore packageStore = null, - IResourceStore resourceStore = null, - IList stepProviders = null, - ITaskStore taskStore = null, - ITaskTemplateStore templateStore = null, - IPipelineIdGenerator idGenerator = null, - IList phaseProviders = null) - : this(new PipelineContextBuilder(counterStore, packageStore, resourceStore, stepProviders, taskStore, idGenerator, expressionOptions, phaseProviders), templateStore) - { - } - - /// - /// Initializes a new PipelineBuilder instance for the specified context. - /// - /// The context which should be used for validation - internal PipelineBuilder(IPipelineContext context) - : this(new PipelineContextBuilder(context)) - { - } - - private PipelineBuilder( - PipelineContextBuilder contextBuilder, - ITaskTemplateStore templateStore = null) - { - ArgumentUtility.CheckForNull(contextBuilder, nameof(contextBuilder)); - - m_contextBuilder = contextBuilder; - m_templateStore = templateStore; - } - - /// - /// Gets or sets the default queue which is assigned automatically to phases with no target and existing agent - /// queue targets without a queue specified. - /// - public AgentQueueReference DefaultQueue - { - get; - set; - } - - /// - /// Gets or sets the default agent specification which is assigned automatically to phases with no target and existing agent - /// queue targets without an agent specification specified. - /// - public JObject DefaultAgentSpecification - { - get; - set; - } - - /// - /// Gets or sets the default checkout options which are propagated to all repository resources defined - /// within a pipeline if explicit options are not provided at checkout. - /// - public CheckoutOptions DefaultCheckoutOptions - { - get; - set; - } - - /// - /// Gets or sets the default workspace options which are propagated to all agent jobs which do not explicitly - /// define overrides. - /// - public WorkspaceOptions DefaultWorkspaceOptions - { - get; - set; - } - - /// - /// Gets or sets the environment version which should be used. - /// - public Int32 EnvironmentVersion - { - get - { - return m_contextBuilder.EnvironmentVersion; - } - set - { - m_contextBuilder.EnvironmentVersion = value; - } - } - - /// - /// Gets the counter store configured for this builder. - /// - public ICounterStore CounterStore => m_contextBuilder.CounterStore; - - /// - /// Gets the ID generator configured for this builder. - /// - public IPipelineIdGenerator IdGenerator => m_contextBuilder.IdGenerator; - - /// - /// Gets the package store configured for this builder. - /// - public IPackageStore PackageStore => m_contextBuilder.PackageStore; - - /// - /// Gets the resource store configured for this builder. - /// - public IResourceStore ResourceStore => m_contextBuilder.ResourceStore; - - /// - /// Gets the user variables which have been set for this builder. - /// - public IList UserVariables => m_contextBuilder.UserVariables; - - /// - /// Gets the system variables which have been set for this builder. - /// - public IDictionary SystemVariables => m_contextBuilder.SystemVariables; - - /// - /// Builds a new PipelineProcess instance using the specified environment. - /// - /// A list of phases which should be used to build the process - /// The validation which should be performed on the pipeline - /// A PipelineBuildResult which contains a runnable pipeline process - public PipelineBuildResult Build( - IList phases, - BuildOptions options = null) - { - ArgumentUtility.CheckEnumerableForEmpty(phases, nameof(phases)); - - options = options ?? BuildOptions.None; - - var stage = new Stage - { - Name = PipelineConstants.DefaultJobName, - }; - - stage.Phases.AddRange(phases); - return Build(new[] { stage }, options); - } - - /// - /// Builds a new PipelineProcess instance. - /// - /// A list of stages which should be used to build the process - /// The validation which should be performed on the pipeline - /// A PipelineBuildResult which contains a runnable pipeline process - public PipelineBuildResult Build( - IList stages, - BuildOptions options = null, - TemplateToken environmentVariables = null) - { - var context = CreateBuildContext(options); - - if (this.DefaultCheckoutOptions != null) - { - foreach (var repository in context.ResourceStore.Repositories.GetAll()) - { - if (!repository.Properties.TryGetValue(RepositoryPropertyNames.CheckoutOptions, out _)) - { - repository.Properties.Set(RepositoryPropertyNames.CheckoutOptions, this.DefaultCheckoutOptions.Clone()); - } - } - } - - // First gather any validation errors and all referenced resources - var process = CreateProcess(context, stages); - var result = context.Validate(process); - - // Output the environment - var environment = result.Environment = new PipelineEnvironment(); - environment.Version = context.EnvironmentVersion; - environment.Counters.AddRange(context.CounterStore.Counters); - environment.Resources.MergeWith(context.ResourceStore.GetAuthorizedResources()); - environment.UserVariables.AddRange(m_contextBuilder.UserVariables); - environment.SystemVariables.AddRange(m_contextBuilder.SystemVariables); - environment.EnvironmentVariables = environmentVariables; - - return new PipelineBuildResult(result.Environment, process, result); - } - - public PipelineBuildContext CreateBuildContext( - BuildOptions options, - Boolean includeSecrets = false) - { - return m_contextBuilder.CreateBuildContext(options, this.PackageStore, includeSecrets); - } - - public PhaseExecutionContext CreatePhaseExecutionContext( - StageInstance stage, - PhaseInstance phase, - PipelineState state = PipelineState.InProgress, - DictionaryContextData data = null, - Boolean includeSecrets = false, - IPipelineTraceWriter trace = null, - ExecutionOptions executionOptions = null) - { - return m_contextBuilder.CreatePhaseExecutionContext(stage, phase, state, data, includeSecrets, trace, executionOptions); - } - - public StageExecutionContext CreateStageExecutionContext( - StageInstance stage, - PipelineState state = PipelineState.InProgress, - DictionaryContextData data = null, - Boolean includeSecrets = false, - IPipelineTraceWriter trace = null, - ExecutionOptions executionOptions = null) - { - return m_contextBuilder.CreateStageExecutionContext(stage, state, data, includeSecrets, trace, executionOptions); - } - - public IList Validate( - PipelineProcess process, - BuildOptions options = null) - { - ArgumentUtility.CheckForNull(process, nameof(process)); - - var context = CreateBuildContext(options); - return context.Validate(process).Errors; - } - - public IList Validate( - IList steps, - PhaseTarget target = null, - BuildOptions options = null) - { - ArgumentUtility.CheckForNull(steps, nameof(steps)); - - var phase = new Phase(); - phase.Steps.AddRange(steps); - phase.Target = target; - - var stage = new Stage(PipelineConstants.DefaultJobName, new[] { phase }); - - var context = CreateBuildContext(options); - var process = CreateProcess(context, new[] { stage }); - return context.Validate(process).Errors; - } - - public PipelineResources GetReferenceResources( - IList steps, - PhaseTarget target = null) - { - ArgumentUtility.CheckForNull(steps, nameof(steps)); - - var phase = new Phase(); - phase.Steps.AddRange(steps); - phase.Target = target; - - var stage = new Stage(PipelineConstants.DefaultJobName, new[] { phase }); - - var context = CreateBuildContext(new BuildOptions()); - var process = CreateProcess(context, new[] { stage }); - return context.Validate(process).ReferencedResources; - } - - private PipelineProcess CreateProcess( - PipelineBuildContext context, - IList stages) - { - ArgumentUtility.CheckForNull(context, nameof(context)); - ArgumentUtility.CheckEnumerableForEmpty(stages, nameof(stages)); - - // Now inject the tasks into each appropriate phase - foreach (var stage in stages) - { - foreach (var phaseNode in stage.Phases) - { - // Set the default target to be a queue target and leave it up to the hosting environment to - // specify a default in the resource store. - if (phaseNode.Target == null) - { - phaseNode.Target = new AgentQueueTarget(); - } - - // Agent queues are the default target type - if (phaseNode.Target.Type == PhaseTargetType.Queue && this.DefaultQueue != null) - { - var queueTarget = phaseNode.Target as AgentQueueTarget; - var useDefault = false; - var queue = queueTarget.Queue; - if (queue == null) - { - useDefault = true; - } - else if (queue.Id == 0) - { - var name = queue.Name; - if (name == null || (name.IsLiteral && String.IsNullOrEmpty(name.Literal))) - { - useDefault = true; - } - } - - if (useDefault) - { - queueTarget.Queue = this.DefaultQueue.Clone(); - if (queueTarget.AgentSpecification == null) - { - queueTarget.AgentSpecification = (JObject)DefaultAgentSpecification?.DeepClone(); - } - } - } - - // Set default workspace options - if (phaseNode.Target.Type == PhaseTargetType.Queue && this.DefaultWorkspaceOptions != null) - { - var queueTarget = phaseNode.Target as AgentQueueTarget; - if (queueTarget.Workspace == null) - { - queueTarget.Workspace = this.DefaultWorkspaceOptions.Clone(); - } - } - - var steps = default(IList); - if (phaseNode.Type == PhaseType.Phase) - { - steps = (phaseNode as Phase).Steps; - } - else if (phaseNode.Type == PhaseType.JobFactory) - { - steps = (phaseNode as JobFactory).Steps; - } - - if (steps != null) - { - var resolvedSteps = new List(); - foreach (var step in steps.Where(x => x.Enabled)) - { - if (step.Type == StepType.Task) - { - var taskStep = step as TaskStep; - resolvedSteps.Add(taskStep); - } - else if (step.Type == StepType.Group) - { - var taskStepGroup = step as GroupStep; - resolvedSteps.Add(taskStepGroup); - } - else if (step.Type == StepType.Action) - { - var actionStep = step as ActionStep; - resolvedSteps.Add(actionStep); - } - else if (step.Type == StepType.TaskTemplate) - { - var templateStep = step as TaskTemplateStep; - if (m_templateStore == null) - { - throw new ArgumentException(PipelineStrings.TemplateStoreNotProvided(templateStep.Name, nameof(ITaskTemplateStore))); - } - - var resolvedTasks = m_templateStore.ResolveTasks(templateStep); - resolvedSteps.AddRange(resolvedTasks); - } - else - { - // We should never be here. - Debug.Fail(step.Type.ToString()); - } - } - - steps.Clear(); - steps.AddRange(resolvedSteps); - } - } - } - - return new PipelineProcess(stages); - } - - private readonly ITaskTemplateStore m_templateStore; - private readonly PipelineContextBuilder m_contextBuilder; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineConstants.cs b/src/Sdk/DTPipelines/Pipelines/PipelineConstants.cs index 323f0fee5..40d2caa61 100644 --- a/src/Sdk/DTPipelines/Pipelines/PipelineConstants.cs +++ b/src/Sdk/DTPipelines/Pipelines/PipelineConstants.cs @@ -129,93 +129,11 @@ namespace GitHub.DistributedTask.Pipelines public static readonly String EnvironmentResourceName = "Environment.ResourceName"; } - public static readonly TaskDefinition CheckoutTask = new TaskDefinition - { - Id = new Guid("6d15af64-176c-496d-b583-fd2ae21d4df4"), - Name = "Checkout", - FriendlyName = "Get sources", - Author = "Microsoft", - RunsOn = { TaskRunsOnConstants.RunsOnAgent }, - Version = new TaskVersion("1.0.0"), - Description = "Get sources from a repository. Supports Git, TfsVC, and SVN repositories.", - HelpMarkDown = "[More Information](https://github.com)", - Inputs = { - new TaskInputDefinition() - { - Name = CheckoutTaskInputs.Repository, - Required = true, - InputType = TaskInputType.Repository - }, - new TaskInputDefinition() - { - Name = CheckoutTaskInputs.Clean, - Required = false, - DefaultValue = Boolean.TrueString, - InputType = TaskInputType.Boolean - }, - // Git - new TaskInputDefinition() - { - Name = CheckoutTaskInputs.Submodules, // True or Recursive - Required = false, - InputType = TaskInputType.String - }, - new TaskInputDefinition() - { - Name = CheckoutTaskInputs.Lfs, // Checkout lfs object - Required = false, - DefaultValue = Boolean.FalseString, - InputType = TaskInputType.Boolean - }, - new TaskInputDefinition() - { - Name = CheckoutTaskInputs.FetchDepth, // Enable shallow fetch - Required = false, - InputType = TaskInputType.String - }, - new TaskInputDefinition() - { - Name = CheckoutTaskInputs.PersistCredentials, // Allow script git - Required = false, - DefaultValue = Boolean.FalseString, - InputType = TaskInputType.Boolean - }, - }, - Execution = - { - { - "agentPlugin", - JObject.FromObject(new Dictionary(){ { "target", "Agent.Plugins.Repository.CheckoutTask, Agent.Plugins"} }) - } - }, - PostJobExecution = - { - { - "agentPlugin", - JObject.FromObject(new Dictionary(){ { "target", "Agent.Plugins.Repository.CleanupTask, Agent.Plugins"} }) - } - } - }; - public static class ScriptStepInputs { public static readonly String Script = "script"; public static readonly String WorkingDirectory = "workingDirectory"; public static readonly String Shell = "shell"; } - - public static Boolean IsCheckoutTask(this Step step) - { - if (step is TaskStep task && - task.Reference.Id == PipelineConstants.CheckoutTask.Id && - task.Reference.Version == PipelineConstants.CheckoutTask.Version) - { - return true; - } - else - { - return false; - } - } } } diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineContextBase.cs b/src/Sdk/DTPipelines/Pipelines/PipelineContextBase.cs deleted file mode 100644 index 4daecff3f..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineContextBase.cs +++ /dev/null @@ -1,439 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Logging; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides base functionality for all contexts used during build and execution if a pipeline. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class PipelineContextBase : IPipelineContext - { - private protected PipelineContextBase(IPipelineContext context) - { - this.EnvironmentVersion = context.EnvironmentVersion; - this.SystemVariableNames.UnionWith(context.SystemVariableNames); - this.Variables.AddRange(context.Variables); - m_referencedResources = context.ReferencedResources?.Clone(); - - this.CounterStore = context.CounterStore; - this.IdGenerator = context.IdGenerator ?? new PipelineIdGenerator(); - this.PackageStore = context.PackageStore; - this.ResourceStore = context.ResourceStore; - this.TaskStore = context.TaskStore; - this.Trace = context.Trace; - m_secretMasker = new Lazy(() => CreateSecretMasker()); - - // This is a copy, don't dynamically set pipeline decorators, they are already set. - this.StepProviders = context.StepProviders; - - if (context.Data?.Count > 0) - { - m_data = new DictionaryContextData(); - foreach (var pair in context.Data) - { - m_data[pair.Key] = pair.Value; - } - } - } - - private protected PipelineContextBase( - DictionaryContextData data, - ICounterStore counterStore, - IPackageStore packageStore, - IResourceStore resourceStore, - ITaskStore taskStore, - IList stepProviders, - IPipelineIdGenerator idGenerator = null, - IPipelineTraceWriter trace = null, - EvaluationOptions expressionOptions = null) - { - m_data = data; - this.CounterStore = counterStore; - this.ExpressionOptions = expressionOptions ?? new EvaluationOptions(); - this.IdGenerator = idGenerator ?? new PipelineIdGenerator(); - this.PackageStore = packageStore; - this.ResourceStore = resourceStore; - this.TaskStore = taskStore; - this.Trace = trace; - m_secretMasker = new Lazy(() => CreateSecretMasker()); - - // Setup pipeline decorators - var aggregatedStepProviders = new List(); - - // Add resources first - if (this.ResourceStore != null) - { - aggregatedStepProviders.Add(this.ResourceStore); - } - - // Add custom pipeline decorators - if (stepProviders != null) - { - aggregatedStepProviders.AddRange(stepProviders); - } - - this.StepProviders = aggregatedStepProviders; - } - - /// - /// Gets the counter store for the current context - /// - public ICounterStore CounterStore - { - get; - } - - // Gets the available context when evaluating expressions - public DictionaryContextData Data - { - get - { - if (m_data == null) - { - m_data = new DictionaryContextData(); - } - return m_data; - } - } - - /// - /// Gets or sets the version of the environment - /// - public Int32 EnvironmentVersion - { - get; - internal set; - } - - /// - /// Gets the expression evaluation options for this context. - /// - public EvaluationOptions ExpressionOptions - { - get; - } - - /// - /// Gets the id generator configured for this context. - /// - public IPipelineIdGenerator IdGenerator - { - get; - } - - /// - /// Gets the package store configured for this context. - /// - public IPackageStore PackageStore - { - get; - } - - /// - /// Gets the resources referenced within this context. - /// - public PipelineResources ReferencedResources - { - get - { - if (m_referencedResources == null) - { - m_referencedResources = new PipelineResources(); - } - return m_referencedResources; - } - } - - /// - /// Gets the resource store for the current context - /// - public IResourceStore ResourceStore - { - get; - } - - /// - /// Gets the step providers for the current context - /// - public IReadOnlyList StepProviders - { - get; - } - - /// - /// Gets the secret masker for the current context - /// - public ISecretMasker SecretMasker - { - get - { - return m_secretMasker.Value; - } - } - - /// - /// Gets the task store for the current context - /// - public ITaskStore TaskStore - { - get; - } - - /// - /// Gets the trace for the current context - /// - public IPipelineTraceWriter Trace - { - get; - } - - /// - /// Gets the system variable names for the current context - /// - public ISet SystemVariableNames - { - get - { - if (m_systemVariables == null) - { - m_systemVariables = new HashSet(StringComparer.OrdinalIgnoreCase); - } - return m_systemVariables; - } - } - - /// - /// Gets the variables configured on the context - /// - public IDictionary Variables - { - get - { - if (m_variables == null) - { - m_variables = new VariablesDictionary(); - } - return m_variables; - } - } - - /// - /// Gets a value indicating if secret variables have been accessed - /// - protected virtual Boolean SecretsAccessed - { - get - { - return m_variables?.SecretsAccessed.Count > 0; - } - } - - public virtual ISecretMasker CreateSecretMasker() - { - var secretMasker = new SecretMasker(); - - // Add variable secrets - if (m_variables?.Count > 0) - { - foreach (var variable in m_variables.Values.Where(x => x.IsSecret)) - { - secretMasker.AddValue(variable.Value); - } - } - - return secretMasker; - } - - /// - /// Expand macros of the format $(variableName) using the current context. - /// - /// The value which contains macros to expand - /// True if secrets should be replaced with '***'; otherwise, false - /// The evaluated value with all defined macros expanded to the value in the current context - public String ExpandVariables( - String value, - Boolean maskSecrets = false) - { - if (!String.IsNullOrEmpty(value) && m_variables?.Count > 0) - { - return VariableUtility.ExpandVariables(value, m_variables, false, maskSecrets); - } - else - { - return value; - } - } - - /// - /// Expand macros of the format $(variableName) using the current context. - /// - /// The JToken value which contains macros to expand - /// The evaluated value with all defined macros expanded to the value in the current context - public JToken ExpandVariables(JToken value) - { - if (value != null && m_variables?.Count > 0) - { - return VariableUtility.ExpandVariables(value, m_variables, false); - } - else - { - return value; - } - } - - /// - /// Expand all variables and macros present as values (not keys) in a given JObject. - /// Conditionally record unresolved expressions or macros as errors. - /// - public ExpressionResult Evaluate(JObject value) - { - if (value == null) - { - return null; - } - - var containsSecrets = false; - String ResolveExpression(String s) - { - if (!ExpressionValue.IsExpression(s)) - { - return s; - } - - String resolvedValue = null; - try - { - var expressionResult = Evaluate(ExpressionValue.TrimExpression(s)); - containsSecrets |= expressionResult.ContainsSecrets; - resolvedValue = expressionResult.Value; - } - catch (ExpressionException) - { - return s; - } - - if (!String.IsNullOrEmpty(resolvedValue)) - { - return resolvedValue; - } - - return s; - } - - // recurse through object - var resolvedSpec = new JObject(); - foreach (var pair in value) - { - var v = pair.Value; - switch (v.Type) - { - case JTokenType.Object: - // recurse - var expressionResult = Evaluate(v.Value()); - containsSecrets |= expressionResult.ContainsSecrets; - resolvedSpec[pair.Key] = expressionResult.Value; - break; - case JTokenType.String: - // resolve - resolvedSpec[pair.Key] = ExpandVariables(ResolveExpression(v.Value())); - break; - default: - // no special handling - resolvedSpec[pair.Key] = v; - break; - } - } - - return new ExpressionResult(resolvedSpec, containsSecrets); - } - - /// - /// Evalutes the provided expression using the current context. - /// - /// The type of result expected - /// The expression string to evaluate - /// A value indicating the evaluated result and whether or not secrets were accessed during evaluation - public ExpressionResult Evaluate(String expression) - { - if (!m_parsedExpressions.TryGetValue(expression, out IExpressionNode parsedExpression)) - { - parsedExpression = new ExpressionParser().CreateTree(expression, this.Trace, this.GetSupportedNamedValues(), this.GetSupportedFunctions()); - m_parsedExpressions.Add(expression, parsedExpression); - } - - this.ResetSecretsAccessed(); - var evaluationResult = parsedExpression.Evaluate(this.Trace, this.SecretMasker, this, this.ExpressionOptions); - throw new NotSupportedException(); - } - - protected virtual void ResetSecretsAccessed() - { - m_variables?.SecretsAccessed.Clear(); - } - - protected virtual IEnumerable GetSupportedFunctions() - { - return Enumerable.Empty(); - } - - protected virtual IEnumerable GetSupportedNamedValues() - { - return Enumerable.Empty(); - } - - internal void SetSystemVariables(IEnumerable variables) - { - foreach (var variable in variables) - { - this.SystemVariableNames.Add(variable.Name); - this.Variables[variable.Name] = new VariableValue(variable.Value, variable.Secret); - } - } - - internal void SetUserVariables(IEnumerable variables) - { - foreach (var variable in variables.Where(x=>!x.Name.StartsWith("system.", StringComparison.OrdinalIgnoreCase) && !this.SystemVariableNames.Contains(x.Name))) - { - this.Variables[variable.Name] = new VariableValue(variable.Value, variable.Secret); - } - } - - internal void SetUserVariables(IDictionary variables) - { - // Do not allow user variables to override system variables which were set at a higher scope. In this case - // the system variable should always win rather than the most specific variable winning. - foreach (var variable in variables.Where(x => !x.Key.StartsWith("system.", StringComparison.OrdinalIgnoreCase) && !this.SystemVariableNames.Contains(x.Key))) - { - this.Variables[variable.Key] = variable.Value; - } - } - - internal void SetSystemVariables(IDictionary variables) - { - if (variables?.Count > 0) - { - foreach (var variable in variables) - { - this.SystemVariableNames.Add(variable.Key); - this.Variables[variable.Key] = variable.Value?.Clone(); - } - } - } - - private DictionaryContextData m_data; - private VariablesDictionary m_variables; - private HashSet m_systemVariables; - private Lazy m_secretMasker; - private PipelineResources m_referencedResources; - private Dictionary m_parsedExpressions = new Dictionary(StringComparer.OrdinalIgnoreCase); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineContextBuilder.cs b/src/Sdk/DTPipelines/Pipelines/PipelineContextBuilder.cs deleted file mode 100644 index 79f3939a0..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineContextBuilder.cs +++ /dev/null @@ -1,562 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - internal sealed class PipelineContextBuilder - { - public PipelineContextBuilder() - : this(null, null, null, null, null) - { - } - - public PipelineContextBuilder( - ICounterStore counterStore = null, - IPackageStore packageStore = null, - IResourceStore resourceStore = null, - IList stepProviders = null, - ITaskStore taskStore = null, - IPipelineIdGenerator idGenerator = null, - EvaluationOptions expressionOptions = null, - IList phaseProviders = null) - { - this.EnvironmentVersion = 2; - this.CounterStore = counterStore ?? new CounterStore(); - this.IdGenerator = idGenerator ?? new PipelineIdGenerator(); - this.PackageStore = packageStore ?? new PackageStore(); - this.ResourceStore = resourceStore ?? new ResourceStore(); - this.StepProviders = stepProviders ?? new List(); - this.TaskStore = taskStore ?? new TaskStore(); - this.ExpressionOptions = expressionOptions ?? new EvaluationOptions(); - this.PhaseProviders = phaseProviders ?? new List(); - } - - internal PipelineContextBuilder(IPipelineContext context) - : this(context.CounterStore, context.PackageStore, context.ResourceStore, context.StepProviders.ToList(), context.TaskStore, context.IdGenerator, context.ExpressionOptions) - { - m_context = context; - - var userVariables = new List(); - var systemVariables = new VariablesDictionary(); - foreach (var variable in context.Variables) - { - if (context.SystemVariableNames.Contains(variable.Key)) - { - systemVariables[variable.Key] = variable.Value.Clone(); - } - else - { - var userVariable = new Variable - { - Name = variable.Key, - Secret = variable.Value?.IsSecret ?? false, - Value = variable.Value?.Value, - }; - - userVariables.Add(userVariable); - } - } - - // For simplicity the variables are currently marked as read-only for the explicit - // context scenario. - m_userVariables = userVariables.AsReadOnly(); - m_systemVariables = systemVariables.AsReadOnly(); - } - - /// - /// Gets the counter store configured for the builder. - /// - public ICounterStore CounterStore - { - get; - } - - public IEnvironmentStore EnvironmentStore - { - get; - } - - /// - /// Gets or sets the environment version, controlling behaviors related to variable groups and step injection. - /// - public Int32 EnvironmentVersion - { - get; - set; - } - - /// - /// Gets the generator for pipeline identifiers. - /// - public IPipelineIdGenerator IdGenerator - { - get; - } - - /// - /// Gets the package store configured for the builder. - /// - public IPackageStore PackageStore - { - get; - } - - /// - /// Gets the resource store configured for the builder. - /// - public IResourceStore ResourceStore - { - get; - } - - /// - /// Gets the list of step providers configured for the builder. - /// - public IList StepProviders - { - get; - } - - public IList PhaseProviders - { - get; - } - - /// - /// Gets the task store configured for the builder. - /// - public ITaskStore TaskStore - { - get; - } - - /// - /// Gets the expression evaluation options configured for the builder. - /// - public EvaluationOptions ExpressionOptions - { - get; - } - - /// - /// Gets a list of variable sets included in the pipeline. - /// - public IList UserVariables - { - get - { - if (m_userVariables == null) - { - m_userVariables = new List(); - } - return m_userVariables; - } - } - - /// - /// Gets the system variables included in the pipeline. - /// - public IDictionary SystemVariables - { - get - { - if (m_systemVariables == null) - { - m_systemVariables = new VariablesDictionary(); - } - return m_systemVariables; - } - } - - public PipelineBuildContext CreateBuildContext( - BuildOptions options, - IPackageStore packageStore = null, - Boolean includeSecrets = false) - { - PipelineBuildContext context = null; - if (m_context == null) - { - context = new PipelineBuildContext(options, null, this.CounterStore, this.ResourceStore, this.StepProviders, this.TaskStore, packageStore, new InputValidator(), null, this.ExpressionOptions, this.PhaseProviders); - SetVariables(context, includeSecrets: includeSecrets); - context.EnvironmentVersion = this.EnvironmentVersion; - } - else - { - context = new PipelineBuildContext(m_context, options); - } - - return context; - } - - public StageExecutionContext CreateStageExecutionContext( - StageInstance stage, - PipelineState state = PipelineState.InProgress, - DictionaryContextData data = null, - Boolean includeSecrets = false, - IPipelineTraceWriter trace = null, - ExecutionOptions executionOptions = null) - { - if (m_context != null) - { - throw new NotSupportedException(); - } - - var context = new StageExecutionContext(stage, state, data, this.CounterStore, this.PackageStore, this.ResourceStore, this.TaskStore, this.StepProviders, this.IdGenerator, trace, this.ExpressionOptions, executionOptions); - SetVariables(context, stage, includeSecrets: includeSecrets); - context.EnvironmentVersion = this.EnvironmentVersion; - return context; - } - - public PhaseExecutionContext CreatePhaseExecutionContext( - StageInstance stage, - PhaseInstance phase, - PipelineState state = PipelineState.InProgress, - DictionaryContextData data = null, - Boolean includeSecrets = false, - IPipelineTraceWriter trace = null, - ExecutionOptions executionOptions = null) - { - if (m_context != null) - { - throw new NotSupportedException(); - } - - var context = new PhaseExecutionContext(stage, phase, state, data, this.CounterStore, this.PackageStore, this.ResourceStore, this.TaskStore, this.StepProviders, this.IdGenerator, trace, this.ExpressionOptions, executionOptions); - SetVariables(context, stage, phase, includeSecrets); - context.EnvironmentVersion = this.EnvironmentVersion; - return context; - } - - private void SetVariables( - IPipelineContext context, - StageInstance stage = null, - PhaseInstance phase = null, - Boolean includeSecrets = false) - { - // Next merge variables specified from alternative sources in the order they are presented. This may - // be specified by build/release definitions or lower constructs, or may be specified by the user as - // input variables to override other values. - var referencedVariableGroups = new Dictionary(StringComparer.OrdinalIgnoreCase); - var expressionsToEvaluate = new Dictionary>(StringComparer.OrdinalIgnoreCase); - if (m_userVariables?.Count > 0 || stage?.Definition?.Variables.Count > 0 || phase?.Definition?.Variables.Count > 0) - { - var userVariables = this.UserVariables.Concat(stage?.Definition?.Variables ?? Enumerable.Empty()).Concat(phase?.Definition?.Variables ?? Enumerable.Empty()); - foreach (var variable in userVariables) - { - if (variable is Variable inlineVariable) - { - if (ExpressionValue.TryParse(inlineVariable.Value, out var expression)) - { - expressionsToEvaluate[inlineVariable.Name] = expression; - } - - if (context.Variables.TryGetValue(inlineVariable.Name, out VariableValue existingValue)) - { - existingValue.Value = inlineVariable.Value; - existingValue.IsSecret |= inlineVariable.Secret; - - // Remove the reference to the variable group - referencedVariableGroups.Remove(inlineVariable.Name); - } - else - { - context.Variables[inlineVariable.Name] = new VariableValue(inlineVariable.Value, inlineVariable.Secret); - } - } - else if (variable is VariableGroupReference groupReference) - { - var variableGroup = this.ResourceStore.VariableGroups.Get(groupReference); - if (variableGroup == null) - { - throw new ResourceNotFoundException(PipelineStrings.VariableGroupNotFound(variableGroup)); - } - - // A pre-computed list of keys wins if it is present, otherwise we compute it dynamically - if (groupReference.SecretStore?.Keys.Count > 0) - { - foreach (var key in groupReference.SecretStore.Keys) - { - // Ignore the key if it isn't present in the variable group - if (!variableGroup.Variables.TryGetValue(key, out var variableGroupEntry)) - { - continue; - } - - // Variable groups which have secrets providers use delayed resolution depending on targets - // being invoked, etc. - if (context.Variables.TryGetValue(key, out VariableValue existingValue)) - { - existingValue.Value = variableGroupEntry.Value; - existingValue.IsSecret |= variableGroupEntry.IsSecret; - referencedVariableGroups[key] = variableGroup; - } - else - { - var clonedValue = variableGroupEntry.Clone(); - clonedValue.Value = variableGroupEntry.Value; - context.Variables[key] = clonedValue; - referencedVariableGroups[key] = variableGroup; - } - } - } - else - { - foreach (var variableGroupEntry in variableGroup.Variables.Where(v => v.Value != null)) - { - // Variable groups which have secrets providers use delayed resolution depending on targets - // being invoked, etc. - if (context.Variables.TryGetValue(variableGroupEntry.Key, out VariableValue existingValue)) - { - existingValue.Value = variableGroupEntry.Value.Value; - existingValue.IsSecret |= variableGroupEntry.Value.IsSecret; - referencedVariableGroups[variableGroupEntry.Key] = variableGroup; - } - else - { - var clonedValue = variableGroupEntry.Value.Clone(); - clonedValue.Value = variableGroupEntry.Value.Value; - context.Variables[variableGroupEntry.Key] = clonedValue; - referencedVariableGroups[variableGroupEntry.Key] = variableGroup; - } - } - } - } - } - } - - // System variables get applied last as they always win - if (m_systemVariables?.Count > 0 || stage != null || phase != null) - { - // Start with system variables specified in the pipeline and then overlay scopes in order - var systemVariables = m_systemVariables == null - ? new VariablesDictionary() - : new VariablesDictionary(m_systemVariables); - - // Setup stage variables - if (stage != null) - { - systemVariables[WellKnownDistributedTaskVariables.StageDisplayName] = stage.Definition?.DisplayName ?? stage.Name; - systemVariables[WellKnownDistributedTaskVariables.StageId] = this.IdGenerator.GetStageInstanceId(stage.Name, stage.Attempt).ToString("D"); - systemVariables[WellKnownDistributedTaskVariables.StageName] = stage.Name; - systemVariables[WellKnownDistributedTaskVariables.StageAttempt] = stage.Attempt.ToString(); - } - - // Setup phase variables - if (phase != null) - { - systemVariables[WellKnownDistributedTaskVariables.PhaseDisplayName] = phase.Definition?.DisplayName ?? phase.Name; - systemVariables[WellKnownDistributedTaskVariables.PhaseId] = this.IdGenerator.GetPhaseInstanceId(stage?.Name, phase.Name, phase.Attempt).ToString("D"); - systemVariables[WellKnownDistributedTaskVariables.PhaseName] = phase.Name; - systemVariables[WellKnownDistributedTaskVariables.PhaseAttempt] = phase.Attempt.ToString(); - } - - foreach (var systemVariable in systemVariables) - { - referencedVariableGroups.Remove(systemVariable.Key); - context.Variables[systemVariable.Key] = systemVariable.Value?.Clone(); - - if (ExpressionValue.TryParse(systemVariable.Value?.Value, out var expression)) - { - expressionsToEvaluate[systemVariable.Key] = expression; - } - - context.SystemVariableNames.Add(systemVariable.Key); - } - } - - if (referencedVariableGroups.Count > 0 || expressionsToEvaluate.Count > 0) - { - context.Trace?.EnterProperty("Variables"); - } - - // Now populate the environment with variable group resources which are needed for execution - if (referencedVariableGroups.Count > 0) - { - foreach (var variableGroupData in referencedVariableGroups.GroupBy(x => x.Value, x => x.Key, s_comparer.Value)) - { - // If our variable group accesses an external service via a service endpoint we need to ensure - // that is also tracked as a required resource to execute this pipeline. - var groupReference = ToGroupReference(variableGroupData.Key, variableGroupData.ToList()); - if (groupReference?.SecretStore != null) - { - // Add the variable group reference to the list of required resources - context.ReferencedResources.VariableGroups.Add(groupReference); - - // Add this resource as authorized for use by this pipeline since the variable group requires - // it to function and the variable group was successfully authorized. - if (groupReference.SecretStore.Endpoint != null) - { - this.ResourceStore.Endpoints.Authorize(groupReference.SecretStore.Endpoint); - context.ReferencedResources.Endpoints.Add(groupReference.SecretStore.Endpoint); - } - - if (groupReference.SecretStore.Keys.Count == 0) - { - continue; - } - - // Make sure we don't unnecessarily retrieve values - var valueProvider = this.ResourceStore.VariableGroups.GetValueProvider(groupReference); - if (valueProvider == null) - { - continue; - } - - var variableGroup = this.ResourceStore.GetVariableGroup(groupReference); - ServiceEndpoint endpoint = null; - if (groupReference.SecretStore.Endpoint != null) - { - endpoint = this.ResourceStore.GetEndpoint(groupReference.SecretStore.Endpoint); - if (endpoint == null) - { - throw new DistributedTaskException(PipelineStrings.ServiceConnectionUsedInVariableGroupNotValid(groupReference.SecretStore.Endpoint, groupReference.Name)); - } - } - - if (!valueProvider.ShouldGetValues(context)) - { - // This will ensure that no value is provided by the server since we expect it to be set by a task - foreach (var key in groupReference.SecretStore.Keys) - { - context.Trace?.Info($"{key}: $[ variablegroups.{variableGroup.Name}.{key} ]"); - expressionsToEvaluate.Remove(key); - context.Variables[key] = new VariableValue(null, true); - } - } - else - { - var values = valueProvider.GetValues(variableGroup, endpoint, groupReference.SecretStore.Keys, includeSecrets); - if (values != null) - { - foreach (var value in values) - { - context.Trace?.Info($"{value.Key}: $[ variablegroups.{variableGroup.Name}.{value.Key} ]"); - expressionsToEvaluate.Remove(value.Key); - - if (includeSecrets || !value.Value.IsSecret) - { - context.Variables[value.Key] = value.Value; - } - else - { - context.Variables[value.Key].Value = null; - } - } - } - } - } - } - } - - // Now resolve the expressions discovered earlier - if (expressionsToEvaluate.Count > 0) - { - foreach (var variableExpression in expressionsToEvaluate) - { - context.Trace?.EnterProperty(variableExpression.Key); - var result = variableExpression.Value.GetValue(context); - context.Trace?.LeaveProperty(variableExpression.Key); - - if (context.Variables.TryGetValue(variableExpression.Key, out VariableValue existingValue)) - { - existingValue.Value = result.Value; - existingValue.IsSecret |= result.ContainsSecrets; - } - else - { - context.Variables[variableExpression.Key] = new VariableValue(result.Value, result.ContainsSecrets); - } - } - } - - // Filter out secret variables if we are not supposed to include them in the context - if (!includeSecrets) - { - foreach (var secretValue in context.Variables.Values.Where(x => x.IsSecret)) - { - secretValue.Value = null; - } - } - - if (referencedVariableGroups.Count > 0 || expressionsToEvaluate.Count > 0) - { - context.Trace?.LeaveProperty("Variables"); - } - } - - private static VariableGroupReference ToGroupReference( - VariableGroup group, - IList keys) - { - if (group == null || keys == null || keys.Count == 0) - { - return null; - } - - var storeConfiguration = ToSecretStoreConfiguration(group, keys); - return new VariableGroupReference - { - Id = group.Id, - Name = group.Name, - GroupType = group.Type, - SecretStore = storeConfiguration, - }; - } - - private static SecretStoreConfiguration ToSecretStoreConfiguration( - VariableGroup group, - IList keys) - { - if (keys.Count == 0) - { - return null; - } - - var keyVaultData = group.ProviderData as AzureKeyVaultVariableGroupProviderData; - var configuration = new SecretStoreConfiguration - { - StoreName = keyVaultData?.Vault ?? group.Name, - }; - - if (keyVaultData != null && keyVaultData.ServiceEndpointId != Guid.Empty) - { - configuration.Endpoint = new ServiceEndpointReference - { - Id = keyVaultData.ServiceEndpointId, - }; - } - - configuration.Keys.AddRange(keys); - return configuration; - } - - private sealed class VariableGroupComparer : IEqualityComparer - { - public Boolean Equals( - VariableGroup x, - VariableGroup y) - { - return x?.Id == y?.Id; - } - - public Int32 GetHashCode(VariableGroup obj) - { - return obj.Id.GetHashCode(); - } - } - - private IList m_userVariables; - private VariablesDictionary m_systemVariables; - private readonly IPipelineContext m_context; - private static readonly Lazy s_comparer = new Lazy(() => new VariableGroupComparer()); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineEnvironment.cs b/src/Sdk/DTPipelines/Pipelines/PipelineEnvironment.cs deleted file mode 100644 index a774b4c56..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineEnvironment.cs +++ /dev/null @@ -1,212 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PipelineEnvironment : IOrchestrationEnvironment - { - public PipelineEnvironment() - { - this.Version = 1; - } - - /// - /// Gets the resources available for use within the environment. - /// - public PipelineResources Resources - { - get - { - if (m_resources == null) - { - m_resources = new PipelineResources(); - } - return m_resources; - } - set - { - m_resources = value; - } - } - - /// - /// Gets the counter values, by prefix, which have been allocated for this environment. - /// - public IDictionary Counters - { - get - { - if (m_counters == null) - { - m_counters = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_counters; - } - } - - /// - /// Gets or sets the data value for any context needed to be passed down to the agent - /// - public IDictionary Data - { - get - { - if (m_data == null) - { - m_data = new Dictionary(); - } - return m_data; - } - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken EnvironmentVariables - { - get; - set; - } - - /// - /// Gets or sets the user variables collection. Variables are applied in order, meaning if variable names - /// appear more than once the last value will be represented in the environment. - /// - public IList UserVariables - { - get - { - if (m_userVariables == null) - { - m_userVariables = new List(); - } - return m_userVariables; - } - } - - /// - /// Gets the system variables collection. System variables are always applied last in order to enforce - /// precedence. - /// - public IDictionary SystemVariables - { - get - { - if (m_systemVariables == null) - { - m_systemVariables = new VariablesDictionary(); - } - return m_systemVariables; - } - } - - /// - /// Gets the explicit variables defined for use within the pipeline. - /// - [Obsolete("This property is obsolete. Use UserVariables and/or SystemVariables instead")] - public IDictionary Variables - { - get - { - if (m_variables == null) - { - m_variables = new VariablesDictionary(); - } - return m_variables; - } - } - - /// - /// Gets the execution options for this pipeline. - /// - public ExecutionOptions Options - { - get - { - return m_options; - } - } - - /// - /// Gets the version of the environment. - /// - [DefaultValue(1)] - [DataMember(Name = "Version", EmitDefaultValue = false)] - public Int32 Version - { - get; - set; - } - - OrchestrationProcessType IOrchestrationEnvironment.ProcessType - { - get - { - return m_processType; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_resources?.Count == 0) - { - m_resources = null; - } - - if (m_counters?.Count == 0) - { - m_counters = null; - } - - if (m_data?.Count == 0) - { - m_data = null; - } - - if (m_userVariables?.Count == 0) - { - m_userVariables = null; - } - - if (m_systemVariables?.Count == 0) - { - m_systemVariables = null; - } - - if (m_variables?.Count == 0) - { - m_variables = null; - } - } - - [DataMember(Name = "Counters", EmitDefaultValue = false)] - private Dictionary m_counters; - - [DataMember(Name = "Data", EmitDefaultValue = false)] - private Dictionary m_data; - - [DataMember(Name = "Options")] - private ExecutionOptions m_options = new ExecutionOptions(); - - [DataMember(Name = "ProcessType")] - private OrchestrationProcessType m_processType = OrchestrationProcessType.Pipeline; - - [DataMember(Name = "Resources", EmitDefaultValue = false)] - private PipelineResources m_resources; - - [DataMember(Name = "SystemVariables", EmitDefaultValue = false)] - private VariablesDictionary m_systemVariables; - - [DataMember(Name = "UserVariables", EmitDefaultValue = false)] - private IList m_userVariables; - - [DataMember(Name = "Variables", EmitDefaultValue = false)] - private VariablesDictionary m_variables; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineException.cs b/src/Sdk/DTPipelines/Pipelines/PipelineException.cs deleted file mode 100644 index 1e54cdb84..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineException.cs +++ /dev/null @@ -1,297 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineException : VssServiceException - { - public PipelineException(String message) - : base(message) - { - } - - public PipelineException( - String message, - Exception innerException) - : base(message, innerException) - { - } - - /// - /// Initializes an exception from serialized data - /// - /// object holding the serialized data - /// context info about the source or destination - protected PipelineException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class AmbiguousResourceSpecificationException : PipelineException - { - public AmbiguousResourceSpecificationException(String message) - : base(message) - { - } - - public AmbiguousResourceSpecificationException( - String message, - Exception innerException) - : base(message, innerException) - { - } - - protected AmbiguousResourceSpecificationException( - SerializationInfo info, - StreamingContext context) : base(info, context) - { - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class AmbiguousTaskSpecificationException : PipelineException - { - public AmbiguousTaskSpecificationException(String message) - : base(message) - { - } - - public AmbiguousTaskSpecificationException( - String message, - Exception innerException) - : base(message, innerException) - { - } - - protected AmbiguousTaskSpecificationException( - SerializationInfo info, - StreamingContext context) : base(info, context) - { - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class InvalidPipelineOperationException : PipelineException - { - public InvalidPipelineOperationException(String message) : base(message) - { - } - - public InvalidPipelineOperationException( - String message, - Exception innerException) : base(message, innerException) - { - } - - protected InvalidPipelineOperationException( - SerializationInfo info, - StreamingContext context) : base(info, context) - { - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class ResourceNotFoundException : PipelineException - { - public ResourceNotFoundException(String message) - : base(message) - { - } - - public ResourceNotFoundException( - String message, - Exception innerException) - : base(message, innerException) - { - } - - protected ResourceNotFoundException( - SerializationInfo info, - StreamingContext context) : base(info, context) - { - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class ResourceNotAuthorizedException : PipelineException - { - public ResourceNotAuthorizedException(String message) - : base(message) - { - } - - public ResourceNotAuthorizedException( - String message, - Exception innerException) - : base(message, innerException) - { - } - - protected ResourceNotAuthorizedException( - SerializationInfo info, - StreamingContext context) : base(info, context) - { - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class ResourceValidationException : PipelineException - { - public ResourceValidationException(String message) - : base(message) - { - } - - public ResourceValidationException( - String message, - String propertyName) - : base(message) - { - this.PropertyName = propertyName; - } - - public ResourceValidationException( - String message, - String propertyName, - Exception innerException) - : base(message, innerException) - { - this.PropertyName = propertyName; - } - - public ResourceValidationException( - String message, - Exception innerException) - : base(message, innerException) - { - } - - protected ResourceValidationException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - } - - /// - /// Gets the property name of the resource which caused the error. - /// - public String PropertyName - { - get; - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class StageNotFoundException : PipelineException - { - public StageNotFoundException(String message) - : base(message) - { - } - - public StageNotFoundException( - String message, - Exception innerException) - : base(message, innerException) - { - } - - protected StageNotFoundException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineValidationException : PipelineException - { - public PipelineValidationException() - : this(PipelineStrings.PipelineNotValid()) - { - } - - // Report first 2 error messages, due to space limit on printing this error message in UI - public PipelineValidationException(IEnumerable errors) - : this(PipelineStrings.PipelineNotValidWithErrors(string.Join(",", (errors ?? Enumerable.Empty()).Take(2).Select(e => e.Message)))) - { - m_errors = new List(errors ?? Enumerable.Empty()); - } - - public PipelineValidationException(String message) - : base(message) - { - } - - public PipelineValidationException( - String message, - Exception innerException) - : base(message, innerException) - { - } - - public IList Errors - { - get - { - if (m_errors == null) - { - m_errors = new List(); - } - return m_errors; - } - } - - /// - /// Initializes an exception from serialized data - /// - /// object holding the serialized data - /// context info about the source or destination - protected PipelineValidationException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - } - - private List m_errors; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public class MaxJobExpansionException : PipelineValidationException - { - public MaxJobExpansionException(IEnumerable errors) - : base(errors) - { - } - - public MaxJobExpansionException(String message) - : base(message) - { - } - - public MaxJobExpansionException( - String message, - Exception innerException) - : base(message, innerException) - { - } - protected MaxJobExpansionException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineIdGenerator.cs b/src/Sdk/DTPipelines/Pipelines/PipelineIdGenerator.cs deleted file mode 100644 index 79d63183c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineIdGenerator.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineIdGenerator : IPipelineIdGenerator - { - public PipelineIdGenerator(Boolean preserveCase = false) - { - m_preserveCase = preserveCase; - } - - public Guid GetInstanceId(params String[] segments) - { - return PipelineUtilities.GetInstanceId(GetInstanceName(segments), m_preserveCase); - } - - public String GetInstanceName(params String[] segments) - { - return PipelineUtilities.GetInstanceName(segments); - } - - public String GetStageIdentifier(String stageName) - { - return PipelineUtilities.GetStageIdentifier(stageName); - } - - public Guid GetStageInstanceId( - String stageName, - Int32 attempt) - { - return PipelineUtilities.GetStageInstanceId(stageName, attempt, m_preserveCase); - } - - public String GetStageInstanceName( - String stageName, - Int32 attempt) - { - return PipelineUtilities.GetStageInstanceName(stageName, attempt); - } - - public String GetPhaseIdentifier( - String stageName, - String phaseName) - { - return PipelineUtilities.GetPhaseIdentifier(stageName, phaseName); - } - - public Guid GetPhaseInstanceId( - String stageName, - String phaseName, - Int32 attempt) - { - return PipelineUtilities.GetPhaseInstanceId(stageName, phaseName, attempt, m_preserveCase); - } - - public String GetPhaseInstanceName( - String stageName, - String phaseName, - Int32 attempt) - { - return PipelineUtilities.GetPhaseInstanceName(stageName, phaseName, attempt); - } - - public String GetJobIdentifier( - String stageName, - String phaseName, - String jobName) - { - return PipelineUtilities.GetJobIdentifier(stageName, phaseName, jobName); - } - - public Guid GetJobInstanceId( - String stageName, - String phaseName, - String jobName, - Int32 attempt) - { - return PipelineUtilities.GetJobInstanceId(stageName, phaseName, jobName, attempt, m_preserveCase); - } - - public String GetJobInstanceName( - String stageName, - String phaseName, - String jobName, - Int32 attempt) - { - return PipelineUtilities.GetJobInstanceName(stageName, phaseName, jobName, attempt); - } - - public String GetTaskInstanceName( - String stageName, - String phaseName, - String jobName, - Int32 jobAttempt, - String taskName) - { - return PipelineUtilities.GetTaskInstanceName(stageName, phaseName, jobName, jobAttempt, taskName); - } - - public Guid GetTaskInstanceId( - String stageName, - String phaseName, - String jobName, - Int32 jobAttempt, - String taskName) - { - return PipelineUtilities.GetTaskInstanceId(stageName, phaseName, jobName, jobAttempt, taskName, m_preserveCase); - } - - private Boolean m_preserveCase; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineProcess.cs b/src/Sdk/DTPipelines/Pipelines/PipelineProcess.cs deleted file mode 100644 index d423203f9..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineProcess.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineProcess : IOrchestrationProcess - { - [JsonConstructor] - public PipelineProcess() - { - } - - public PipelineProcess(IList phases) - { - var stage = CreateDefaultStage(); - stage.Phases.AddRange(phases ?? Enumerable.Empty()); - this.Stages.Add(stage); - } - - public PipelineProcess(IList stages) - { - if (stages?.Count > 0) - { - m_stages = new List(stages); - } - } - - public IList Stages - { - get - { - if (m_stages == null) - { - m_stages = new List(); - } - return m_stages; - } - } - - OrchestrationProcessType IOrchestrationProcess.ProcessType - { - get - { - return OrchestrationProcessType.Pipeline; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_stages?.Count == 1 && String.Equals(m_stages[0].Name, PipelineConstants.DefaultJobName, StringComparison.OrdinalIgnoreCase)) - { - m_phases = new List(m_stages[0].Phases); - m_stages = null; - } - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - if (m_phases?.Count > 0) - { - var stage = CreateDefaultStage(); - stage.Phases.AddRange(m_phases); - - m_phases = null; - this.Stages.Add(stage); - } - } - - private static Stage CreateDefaultStage() - { - return new Stage { Name = PipelineConstants.DefaultJobName }; - } - - /// - /// return the node at the given path - /// - public IGraphNode GetNodeAtPath(IList path) - { - var length = path?.Count(); - var node = default(IGraphNode); - if (length > 0) - { - // find stage - node = this.Stages.FirstOrDefault(x => string.Equals(x.Name, path[0], StringComparison.OrdinalIgnoreCase) - || string.Equals(x.Name, PipelineConstants.DefaultJobName, StringComparison.OrdinalIgnoreCase)); - if (length > 1 && node != null) - { - // find phase - node = (node as Stage).Phases.FirstOrDefault(x => string.Equals(x.Name, path[1], StringComparison.OrdinalIgnoreCase) - || string.Equals(x.Name, PipelineConstants.DefaultJobName, StringComparison.OrdinalIgnoreCase)); - - // NOTE: jobs / phase configurations are not IGraphNodes yet - } - } - - return node; - } - - [DataMember(Name = "Stages", EmitDefaultValue = false)] - private List m_stages; - - [DataMember(Name = "Phases", EmitDefaultValue = false)] - private List m_phases; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineResource.cs b/src/Sdk/DTPipelines/Pipelines/PipelineResource.cs deleted file mode 100644 index cb3d34324..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineResource.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class PipelinePropertyNames - { - public static readonly String Artifacts = "artifacts"; - public static readonly String Branch = "branch"; - public static readonly String DefinitionId = "definitionId"; - public static readonly String PipelineId = "pipelineId"; - public static readonly String Project = "project"; - public static readonly String ProjectId = "projectId"; - public static readonly String Source = "source"; - public static readonly String Tags = "tags"; - public static readonly String Version = "version"; - } - - /// - /// Provides a data contract for a pipeline resource referenced by a pipeline. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineResource : Resource - { - public PipelineResource() - { - } - - protected PipelineResource(PipelineResource resourceToCopy) - : base(resourceToCopy) - { - } - - /// - /// Gets or sets the version of the build resource. - /// - public String Version - { - get - { - return this.Properties.Get(PipelinePropertyNames.Version); - } - set - { - this.Properties.Set(PipelinePropertyNames.Version, value); - } - } - - public PipelineResource Clone() - { - return new PipelineResource(this); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineResources.cs b/src/Sdk/DTPipelines/Pipelines/PipelineResources.cs deleted file mode 100644 index fa0d6f7e5..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineResources.cs +++ /dev/null @@ -1,570 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides collections of securable resources available for use within a pipeline. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PipelineResources - { - /// - /// Initializes a new PipelineResources instance with empty resource collections. - /// - public PipelineResources() - { - } - - private PipelineResources(PipelineResources resourcesToCopy) - { - if (resourcesToCopy.m_builds?.Count > 0) - { - m_builds = new HashSet(resourcesToCopy.m_builds.Select(x => x.Clone()), new ResourceComparer()); - } - - if (resourcesToCopy.m_containers?.Count > 0) - { - m_containers = new HashSet(resourcesToCopy.m_containers.Select(x => x.Clone()), new ResourceComparer()); - } - - if (resourcesToCopy.m_endpoints?.Count > 0) - { - m_endpoints = new HashSet(resourcesToCopy.m_endpoints.Select(x => x.Clone()), new EndpointComparer()); - } - - if (resourcesToCopy.m_environments?.Count > 0) - { - m_environments = new HashSet(resourcesToCopy.m_environments.Select(x => x.Clone()), new EnvironmentComparer()); - } - - if (resourcesToCopy.m_files?.Count > 0) - { - m_files = new HashSet(resourcesToCopy.m_files.Select(x => x.Clone()), new FileComparer()); - } - - if (resourcesToCopy.m_pipelines?.Count > 0) - { - m_pipelines = new HashSet(resourcesToCopy.m_pipelines.Select(x => x.Clone()), new ResourceComparer()); - } - - if (resourcesToCopy.m_queues?.Count > 0) - { - m_queues = new HashSet(resourcesToCopy.m_queues.Select(x => x.Clone()), new QueueComparer()); - } - - if (resourcesToCopy.m_pools?.Count > 0) - { - m_pools = new HashSet(resourcesToCopy.m_pools.Select(x => x.Clone()), new PoolComparer()); - } - - if (resourcesToCopy.m_repositories?.Count > 0) - { - m_repositories = new HashSet(resourcesToCopy.m_repositories.Select(x => x.Clone()), new ResourceComparer()); - } - - if (resourcesToCopy.m_variableGroups?.Count > 0) - { - m_variableGroups = new HashSet(resourcesToCopy.m_variableGroups.Select(x => x.Clone()), new VariableGroupComparer()); - } - } - - /// - /// Gets the total count of resources. - /// - public Int32 Count => (m_builds?.Count ?? 0) + - (m_containers?.Count ?? 0) + - (m_endpoints?.Count ?? 0) + - (m_environments?.Count ?? 0) + - (m_files?.Count ?? 0) + - (m_pipelines?.Count ?? 0) + - (m_queues?.Count ?? 0) + - (m_pools?.Count ?? 0) + - (m_repositories?.Count ?? 0) + - (m_variableGroups?.Count ?? 0); - - /// - /// List of all resources that need to be sent to PolicyService - /// - public IEnumerable GetSecurableResources() - { - foreach (var resourceCollection in new IEnumerable[] { - m_endpoints, - m_environments, - m_files, - m_queues, - m_pools, - m_variableGroups - }) - { - if (resourceCollection != null) - { - foreach (var r in resourceCollection) - { - if (r != null) - { - yield return r; - } - } - } - } - } - - /// - /// Gets the collection of build resources defined in the pipeline. - /// - public ISet Builds - { - get - { - if (m_builds == null) - { - m_builds = new HashSet(new ResourceComparer()); - } - return m_builds; - } - } - - /// - /// Gets the collection of container resources defined in the pipeline. - /// - public ISet Containers - { - get - { - if (m_containers == null) - { - m_containers = new HashSet(new ResourceComparer()); - } - return m_containers; - } - } - - /// - /// Gets the collection of endpoint references available in the resources of a pipeline. - /// - public ISet Endpoints - { - get - { - if (m_endpoints == null) - { - m_endpoints = new HashSet(new EndpointComparer()); - } - return m_endpoints; - } - } - - /// - /// Gets the collection of environments listed with deployment job in pipeline. - /// - public ISet Environments - { - get - { - if (m_environments == null) - { - m_environments = new HashSet(new EnvironmentComparer()); - } - return m_environments; - } - } - - /// - /// Gets the collection of secure file references available in the resources of a pipeline. - /// - public ISet Files - { - get - { - if (m_files == null) - { - m_files = new HashSet(new FileComparer()); - } - return m_files; - } - } - - /// - /// Gets the collection of pipeline resources defined in the pipeline. - /// - public ISet Pipelines - { - get - { - if (m_pipelines == null) - { - m_pipelines = new HashSet(new ResourceComparer()); - } - return m_pipelines; - } - } - - /// - /// Gets the collection of agent queue references available in the resources of a pipeline. - /// - public ISet Queues - { - get - { - if (m_queues == null) - { - m_queues = new HashSet(new QueueComparer()); - } - return m_queues; - } - } - - /// - /// Gets the collection of agent pool references available in the resources of a pipeline. - /// - public ISet Pools - { - get - { - if (m_pools == null) - { - m_pools = new HashSet(new PoolComparer()); - } - return m_pools; - } - } - - /// - /// Gets the collection of repository resources defined in the pipeline. - /// - public ISet Repositories - { - get - { - if (m_repositories == null) - { - m_repositories = new HashSet(new ResourceComparer()); - } - return m_repositories; - } - } - - /// - /// Gets the collection of variable group references available in the resources of a pipeline. - /// - public ISet VariableGroups - { - get - { - if (m_variableGroups == null) - { - m_variableGroups = new HashSet(new VariableGroupComparer()); - } - return m_variableGroups; - } - } - - public PipelineResources Clone() - { - return new PipelineResources(this); - } - - public void MergeWith(PipelineResources resources) - { - if (resources != null) - { - this.Builds.UnionWith(resources.Builds); - this.Containers.UnionWith(resources.Containers); - this.Endpoints.UnionWith(resources.Endpoints); - this.Environments.UnionWith(resources.Environments); - this.Files.UnionWith(resources.Files); - this.Pipelines.UnionWith(resources.Pipelines); - this.Queues.UnionWith(resources.Queues); - this.Pools.UnionWith(resources.Pools); - this.Repositories.UnionWith(resources.Repositories); - this.VariableGroups.UnionWith(resources.VariableGroups); - } - } - - internal void AddEndpointReference(String endpointId) - { - if (Guid.TryParse(endpointId, out Guid endpointIdValue)) - { - this.Endpoints.Add(new ServiceEndpointReference { Id = endpointIdValue }); - } - else - { - this.Endpoints.Add(new ServiceEndpointReference { Name = endpointId }); - } - } - - internal void AddEndpointReference(ServiceEndpointReference reference) - { - this.Endpoints.Add(reference); - } - - internal void AddSecureFileReference(String fileId) - { - if (Guid.TryParse(fileId, out Guid fileIdValue)) - { - this.Files.Add(new SecureFileReference { Id = fileIdValue }); - } - else - { - this.Files.Add(new SecureFileReference { Name = fileId }); - } - } - - internal void AddSecureFileReference(SecureFileReference reference) - { - this.Files.Add(reference); - } - - internal void AddAgentQueueReference(AgentQueueReference reference) - { - this.Queues.Add(reference); - } - - internal void AddAgentPoolReference(AgentPoolReference reference) - { - this.Pools.Add(reference); - } - - internal void AddVariableGroupReference(VariableGroupReference reference) - { - this.VariableGroups.Add(reference); - } - - internal void AddEnvironmentReference(EnvironmentReference reference) - { - this.Environments.Add(reference); - } - - internal void Clear() - { - m_builds?.Clear(); - m_containers?.Clear(); - m_endpoints?.Clear(); - m_files?.Clear(); - m_pipelines?.Clear(); - m_queues?.Clear(); - m_pools?.Clear(); - m_repositories?.Clear(); - m_variableGroups?.Clear(); - m_environments?.Clear(); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_builds?.Count == 0) - { - m_builds = null; - } - - if (m_containers?.Count == 0) - { - m_containers = null; - } - - if (m_endpoints?.Count == 0) - { - m_endpoints = null; - } - - if (m_files?.Count == 0) - { - m_files = null; - } - - if (m_pipelines?.Count == 0) - { - m_pipelines = null; - } - - if (m_queues?.Count == 0) - { - m_queues = null; - } - - if (m_pools?.Count == 0) - { - m_pools = null; - } - - if (m_repositories?.Count == 0) - { - m_repositories = null; - } - - if (m_variableGroups?.Count == 0) - { - m_variableGroups = null; - } - - if (m_environments?.Count == 0) - { - m_environments = null; - } - } - - [DataMember(Name = "Builds", EmitDefaultValue = false)] - private HashSet m_builds; - - [DataMember(Name = "Containers", EmitDefaultValue = false)] - private HashSet m_containers; - - [DataMember(Name = "Endpoints", EmitDefaultValue = false)] - private HashSet m_endpoints; - - [DataMember(Name = "Files", EmitDefaultValue = false)] - private HashSet m_files; - - [DataMember(Name = "Pipelines", EmitDefaultValue = false)] - private HashSet m_pipelines; - - [DataMember(Name = "Queues", EmitDefaultValue = false)] - private HashSet m_queues; - - [DataMember(Name = "Pools", EmitDefaultValue = false)] - private HashSet m_pools; - - [DataMember(Name = "Repositories", EmitDefaultValue = false)] - private HashSet m_repositories; - - [DataMember(Name = "VariableGroups", EmitDefaultValue = false)] - private HashSet m_variableGroups; - - [DataMember(Name = "Environments", EmitDefaultValue = false)] - private HashSet m_environments; - - internal abstract class ResourceReferenceComparer : IEqualityComparer where TResource : ResourceReference - { - protected ResourceReferenceComparer(IEqualityComparer idComparer) - { - m_idComparer = idComparer; - } - - public abstract TId GetId(TResource resource); - - public Boolean Equals( - TResource left, - TResource right) - { - if (left == null && right == null) - { - return true; - } - - if ((left != null && right == null) || (left == null && right != null)) - { - return false; - } - - var leftId = GetId(left); - var rightId = GetId(right); - if (m_idComparer.Equals(leftId, default(TId)) && m_idComparer.Equals(rightId, default(TId))) - { - return StringComparer.OrdinalIgnoreCase.Equals(left.Name, right.Name); - } - else - { - return m_idComparer.Equals(leftId, rightId); - } - } - - public Int32 GetHashCode(TResource obj) - { - var identifier = GetId(obj); - if (!m_idComparer.Equals(identifier, default(TId))) - { - return identifier.GetHashCode(); - } - else - { - return StringComparer.OrdinalIgnoreCase.GetHashCode(obj.Name); - } - } - - private readonly IEqualityComparer m_idComparer; - } - - internal class EndpointComparer : ResourceReferenceComparer - { - public EndpointComparer() - : base(EqualityComparer.Default) - { - } - - public override Guid GetId(ServiceEndpointReference resource) - { - return resource.Id; - } - } - - private class FileComparer : ResourceReferenceComparer - { - public FileComparer() - : base(EqualityComparer.Default) - { - } - - public override Guid GetId(SecureFileReference resource) - { - return resource.Id; - } - } - - private class QueueComparer : ResourceReferenceComparer - { - public QueueComparer() - : base(EqualityComparer.Default) - { - } - - public override Int32 GetId(AgentQueueReference resource) - { - return resource.Id; - } - } - - private class PoolComparer : ResourceReferenceComparer - { - public PoolComparer() - : base(EqualityComparer.Default) - { - } - - public override Int32 GetId(AgentPoolReference resource) - { - return resource.Id; - } - } - - private class VariableGroupComparer : ResourceReferenceComparer - { - public VariableGroupComparer() - : base(EqualityComparer.Default) - { - } - - public override Int32 GetId(VariableGroupReference resource) - { - return resource.Id; - } - } - - private class EnvironmentComparer : ResourceReferenceComparer - { - public EnvironmentComparer() - : base(EqualityComparer.Default) - { - } - - public override Int32 GetId(EnvironmentReference resource) - { - return resource.Id; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineState.cs b/src/Sdk/DTPipelines/Pipelines/PipelineState.cs deleted file mode 100644 index f280ef337..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineState.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public enum PipelineState - { - [EnumMember] - NotStarted, - - [EnumMember] - InProgress, - - [EnumMember] - Canceling, - - [EnumMember] - Completed, - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineStepsTemplate.cs b/src/Sdk/DTPipelines/Pipelines/PipelineStepsTemplate.cs deleted file mode 100644 index 04ce0759e..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineStepsTemplate.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineStepsTemplate - { - public IList Steps - { - get - { - if (m_steps == null) - { - m_steps = new List(); - } - return m_steps; - } - } - - public IList Errors - { - get - { - if (m_errors == null) - { - m_errors = new List(); - } - return m_errors; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_steps?.Count == 0) - { - m_steps = null; - } - - if (m_errors?.Count == 0) - { - m_errors = null; - } - } - - [DataMember(Name = "Steps", EmitDefaultValue = false)] - private List m_steps; - - [DataMember(Name = "Errors", EmitDefaultValue = false)] - private List m_errors; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineTemplate.cs b/src/Sdk/DTPipelines/Pipelines/PipelineTemplate.cs deleted file mode 100644 index b2ca72349..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineTemplate.cs +++ /dev/null @@ -1,147 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.ObjectTemplating.Tokens; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineTemplate - { - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public PipelineResources Resources - { - get - { - if (m_resources == null) - { - m_resources = new PipelineResources(); - } - return m_resources; - } - } - - [DataMember(EmitDefaultValue = false)] - public TemplateToken EnvironmentVariables - { - get; - set; - } - - public IList Variables - { - get - { - if (m_variables == null) - { - m_variables = new List(); - } - return m_variables; - } - } - - public IList Stages - { - get - { - if (m_stages == null) - { - m_stages = new List(); - } - return m_stages; - } - } - - public IList Triggers - { - get - { - if (m_triggers == null) - { - m_triggers = new List(); - } - return m_triggers; - } - } - - public IList Errors - { - get - { - if (m_errors == null) - { - m_errors = new List(); - } - return m_errors; - } - } - - [DataMember(EmitDefaultValue = false)] - public String InitializationLog - { - get; - set; - } - - public void CheckErrors() - { - if (m_errors?.Count > 0) - { - throw new PipelineValidationException(m_errors); - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_stages?.Count == 0) - { - m_stages = null; - } - - if (m_errors?.Count == 0) - { - m_errors = null; - } - - if (m_triggers?.Count == 0) - { - m_triggers = null; - } - - if (m_resources?.Count == 0) - { - m_resources = null; - } - - if (m_variables?.Count == 0) - { - m_variables = null; - } - } - - [DataMember(Name = "Stages", EmitDefaultValue = false)] - private List m_stages; - - [DataMember(Name = "Errors", EmitDefaultValue = false)] - private List m_errors; - - [DataMember(Name = "Triggers", EmitDefaultValue = false)] - private List m_triggers; - - [DataMember(Name = "Resources", EmitDefaultValue = false)] - private PipelineResources m_resources; - - [DataMember(Name = "Variables", EmitDefaultValue = false)] - private List m_variables; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineTrigger.cs b/src/Sdk/DTPipelines/Pipelines/PipelineTrigger.cs deleted file mode 100644 index a4f900ae5..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineTrigger.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class PipelineTrigger - { - public PipelineTrigger(PipelineTriggerType triggerType) - { - TriggerType = triggerType; - } - - /// - /// The type of the trigger. - /// - public PipelineTriggerType TriggerType - { - get; - private set; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineTriggerType.cs b/src/Sdk/DTPipelines/Pipelines/PipelineTriggerType.cs deleted file mode 100644 index 4b88d9385..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineTriggerType.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public enum PipelineTriggerType - { - /// - /// A pipeline should be started for each changeset. - /// - ContinuousIntegration = 2, - - /// - /// A pipeline should be triggered when a GitHub pull request is created or updated. - /// - PullRequest = 64, - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineUtilities.cs b/src/Sdk/DTPipelines/Pipelines/PipelineUtilities.cs deleted file mode 100644 index ff9a7db7e..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineUtilities.cs +++ /dev/null @@ -1,407 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class PipelineUtilities - { - public static Guid GetInstanceId( - String identifier, - Boolean preserveCase = false) - { - if (preserveCase) - { - return TimelineRecordIdGenerator.GetId(identifier); - } - else - { - return TimelineRecordIdGenerator.GetId(identifier?.ToLowerInvariant()); - } - } - - /// - /// This is the format for producing "instance names" - /// Instance names are defined to be node "identifiers" (the logical path to the node in the graph) - /// plus a single attempt number suffixed at the end. - /// Identifiers are constant accross different attempts of the same node. - /// Instance names are not, but will differ only in attempt number. - /// - public static String GetInstanceName(params String[] segments) - { - return String.Join(".", segments.Where(x => !String.IsNullOrEmpty(x)).Select(x => x.Trim('.'))); - } - - public static String GetName(String identifier) - { - ArgumentUtility.CheckStringForNullOrEmpty(identifier, nameof(identifier)); - - var separatorIndex = identifier.LastIndexOf('.'); - return separatorIndex >= 0 ? identifier.Substring(separatorIndex + 1) : identifier; - } - - public static Guid GetStageInstanceId( - StageInstance stage, - Boolean preserveCase = false) - { - return GetStageInstanceId(stage.Name, stage.Attempt, preserveCase); - } - - public static String GetStageIdentifier(StageInstance stage) - { - return GetStageIdentifier(stage.Name); - } - - public static String GetStageIdentifier(String stageName) - { - return GetStageInstanceName(stageName, 1); - } - - public static String GetStageInstanceName(StageInstance stage) - { - return GetStageInstanceName(stage.Name, stage.Attempt); - } - - public static Guid GetStageInstanceId( - String stageName, - Int32 stageAttempt, - Boolean preserveCase = false) - { - return GetInstanceId(GetStageInstanceName(stageName, stageAttempt, true), preserveCase); - } - - public static String GetStageInstanceName( - String stageName, - Int32 stageAttempt) - { - return GetStageInstanceName(stageName, stageAttempt, true); - } - - public static String GetStageInstanceName( - String stageName, - Int32 stageAttempt, - Boolean includeDefault) - { - if (!String.IsNullOrEmpty(stageName) && - (includeDefault || !stageName.Equals(PipelineConstants.DefaultJobName, StringComparison.OrdinalIgnoreCase))) - { - var instanceName = stageName; - if (stageAttempt > 1) - { - instanceName = $"{stageName}.{stageAttempt}"; - } - - return instanceName; - } - - return String.Empty; - } - - public static String GetPhaseIdentifier( - StageInstance stage, - PhaseInstance phase) - { - return GetPhaseIdentifier(stage?.Name, phase.Name); - } - - public static String GetPhaseIdentifier( - String stageName, - String phaseName) - { - return GetPhaseInstanceName(stageName, phaseName, 1); - } - - public static Guid GetPhaseInstanceId( - StageInstance stage, - PhaseInstance phase, - Boolean preserveCase = false) - { - return GetPhaseInstanceId(stage?.Name, phase.Name, phase.Attempt, preserveCase); - } - - public static Guid GetPhaseInstanceId( - String stageName, - String phaseName, - Int32 phaseAttempt, - Boolean preserveCase = false) - { - return GetInstanceId(GetPhaseInstanceName(stageName, phaseName, phaseAttempt), preserveCase); - } - - /// - /// The phase "instance name" is the phase identifier suffixed with the phase attempt. - /// - public static String GetPhaseInstanceName( - StageInstance stage, - PhaseInstance phase) - { - var sb = new StringBuilder(GetStageInstanceName(stage?.Name, stageAttempt: 1, false)); - if (sb.Length > 0) - { - sb.Append("."); - } - - sb.Append($"{phase.Name}"); - if (phase.Attempt > 1) - { - sb.Append($".{phase.Attempt}"); - } - - return sb.ToString(); - } - - public static String GetPhaseInstanceName( - String stageName, - String phaseName, - Int32 phaseAttempt) - { - var sb = new StringBuilder(GetStageInstanceName(stageName, stageAttempt: 1, false)); - if (sb.Length > 0) - { - sb.Append("."); - } - - sb.Append($"{phaseName}"); - if (phaseAttempt > 1) - { - sb.Append($".{phaseAttempt}"); - } - - return sb.ToString(); - } - - public static String GetJobIdentifier( - StageInstance stage, - PhaseInstance phase, - JobInstance job) - { - return GetJobIdentifier(stage?.Name, phase.Name, job.Name); - } - - public static String GetJobIdentifier( - String stageName, - String phaseName, - String jobName) - { - return GetJobInstanceName(stageName, phaseName, jobName, 1); - } - - public static Guid GetJobInstanceId( - StageInstance stage, - PhaseInstance phase, - JobInstance job, - Boolean preserveCase = false) - { - return GetJobInstanceId(stage?.Name, phase.Name, job.Name, job.Attempt, preserveCase); - } - - public static Guid GetJobInstanceId( - String stageName, - String phaseName, - String jobName, - Int32 jobAttempt, - Boolean preserveCase = false) - { - return GetInstanceId(GetJobInstanceName(stageName, phaseName, jobName, jobAttempt), preserveCase); - } - - public static String GetJobInstanceName( - StageInstance stage, - PhaseInstance phase, - JobInstance job) - { - return GetJobInstanceName(stage?.Name, phase.Name, job.Name, job.Attempt); - } - - public static String GetJobInstanceName( - String jobIdentifier, - Int32 jobAttempt) - { - var sb = new StringBuilder(jobIdentifier); - if (jobAttempt > 1) - { - sb.Append($".{jobAttempt}"); - } - - return sb.ToString(); - } - - public static String GetJobInstanceName(TimelineRecord job) - { - if (job.Attempt <= 1) - { - return job.Identifier; - } - else - { - return $"{job.Identifier}.{job.Attempt}"; - } - } - - public static String GetJobInstanceName( - String stageName, - String phaseName, - String jobName, - Int32 jobAttempt) - { - var sb = new StringBuilder(GetPhaseInstanceName(stageName, phaseName, 1)); - sb.Append($".{jobName}"); - if (jobAttempt > 1) - { - sb.Append($".{jobAttempt}"); - } - - return sb.ToString(); - } - - public static Guid GetTaskInstanceId( - String stageName, - String phaseName, - String jobName, - Int32 jobAttempt, - String taskName, - Boolean preserveCase = false) - { - return GetInstanceId(GetTaskInstanceName(stageName, phaseName, jobName, jobAttempt, taskName), preserveCase); - } - - public static String GetTaskInstanceName( - String stageName, - String phaseName, - String jobName, - Int32 jobAttempt, - String taskName) - { - return $"{GetJobInstanceName(stageName, phaseName, jobName, jobAttempt)}.{taskName}"; - } - - public static String GetTaskInstanceName( - TimelineRecord jobRecord, - TimelineRecord taskRecord) - { - return $"{GetJobInstanceName(jobRecord)}.{taskRecord.RefName}"; - } - - public static TaskResult MergeResult( - TaskResult result, - TaskResult childResult) - { - // If the final status is already failed then we can't get any worse - if (result == TaskResult.Canceled || result == TaskResult.Failed) - { - return result; - } - - switch (childResult) - { - case TaskResult.Canceled: - result = TaskResult.Canceled; - break; - - case TaskResult.Failed: - case TaskResult.Abandoned: - result = TaskResult.Failed; - break; - - case TaskResult.SucceededWithIssues: - if (result == TaskResult.Succeeded) - { - result = TaskResult.SucceededWithIssues; - } - break; - } - - return result; - } - - public static TaskResult AggregateResult(IEnumerable results) - { - var result = TaskResult.Succeeded; - if (results == default) - { - return result; - } - foreach (var r in results) - { - result = MergeResult(result, r); - } - return result; - } - - /// - /// returns the node path from pipeline root to instance node - /// - public static IList GetPathComponents(String instanceName) - { - var result = new List(); - if (!String.IsNullOrEmpty(instanceName)) - { - var tokens = instanceName.Split('.'); - var i = 0; - if (Guid.TryParse(tokens[i], out var _)) - { - // first parameter might be a guid - i = 1; - } - - // ignore attempt numbers -- these are not meaningful as path components - for (var end = tokens.Length; i < end; ++i) - { - var t = tokens[i]; - - // node names may only contain numbers, letters, and '_' - // node names must begin with at letter. - result.AddIf(!Int32.TryParse(t, out var _), t); - } - } - - return result; - } - - /// - /// A legal node name starts with a letter or '_', and is entirely - /// comprised of alphanumeric characters or the ['_', '-'] characters. - /// - public static Boolean IsLegalNodeName(string name) - { - if (string.IsNullOrWhiteSpace(name)) - { - return false; - } - - if (name.Length > PipelineConstants.MaxNodeNameLength) - { - return false; - } - - if (!char.IsLetter(name[0])) - { - return false; - } - - foreach (var c in name) - { - if (!char.IsLetterOrDigit(c) && c != '_') - { - return false; - } - } - - return true; - } - - public static String GetOrchestrationInstanceId( - Guid planId, - String nodeIdentifier) - { - return PipelineUtilities.GetInstanceName(planId.ToString("D"), nodeIdentifier); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineValidationError.cs b/src/Sdk/DTPipelines/Pipelines/PipelineValidationError.cs deleted file mode 100644 index 539913ebe..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineValidationError.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides information about an error which occurred during pipeline validation. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineValidationError - { - public PipelineValidationError() - { - } - - public PipelineValidationError(String message) - : this(null, message) - { - } - - public PipelineValidationError( - String code, - String message) - { - Code = code; - Message = message; - } - - [DataMember(EmitDefaultValue = false)] - public String Code - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Message - { - get; - set; - } - - public static IEnumerable Create(Exception exception) - { - for (int i = 0; i < 50; i++) - { - yield return new PipelineValidationError(exception.Message); - if (exception.InnerException == null) - { - break; - } - - exception = exception.InnerException; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PipelineValidationErrors.cs b/src/Sdk/DTPipelines/Pipelines/PipelineValidationErrors.cs deleted file mode 100644 index 6ffed4043..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PipelineValidationErrors.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides information about an error which occurred during pipeline validation. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PipelineValidationErrors : IEnumerable - { - public PipelineValidationErrors() - { - } - - public PipelineValidationErrors( - Int32 maxErrors, - Int32 maxMessageLength) - { - m_maxErrors = maxErrors; - m_maxMessageLength = maxMessageLength; - } - - public Int32 Count => m_errors.Count; - - public void Add(String message) - { - Add(new PipelineValidationError(message)); - } - - public void Add(Exception ex) - { - Add(null, ex); - } - - public void Add(String messagePrefix, Exception ex) - { - for (int i = 0; i < 50; i++) - { - String message = !String.IsNullOrEmpty(messagePrefix) ? $"{messagePrefix} {ex.Message}" : ex.Message; - Add(new PipelineValidationError(message)); - if (ex.InnerException == null) - { - break; - } - - ex = ex.InnerException; - } - } - - public void Add(IEnumerable errors) - { - foreach (var error in errors) - { - Add(error); - } - } - - public void Add(PipelineValidationError error) - { - // Check max errors - if (m_maxErrors <= 0 || - m_errors.Count < m_maxErrors) - { - // Check max message length - if (m_maxMessageLength > 0 && - error.Message?.Length > m_maxMessageLength) - { - error = new PipelineValidationError(error.Code, error.Message.Substring(0, m_maxMessageLength) + "[...]"); - } - - m_errors.Add(error); - } - } - - public void Clear() - { - m_errors.Clear(); - } - - public IEnumerator GetEnumerator() - { - return (m_errors as IEnumerable).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return (m_errors as IEnumerable).GetEnumerator(); - } - - private readonly List m_errors = new List(); - private readonly Int32 m_maxErrors; - private readonly Int32 m_maxMessageLength; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ProviderPhase.cs b/src/Sdk/DTPipelines/Pipelines/ProviderPhase.cs deleted file mode 100644 index 1cc116a51..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ProviderPhase.cs +++ /dev/null @@ -1,227 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class ProviderPhase : PhaseNode - { - public ProviderPhase() - { - } - - private ProviderPhase(ProviderPhase phaseToCopy) - : base(phaseToCopy) - { - } - - /// - /// Gets the phase type. - /// - [DataMember(EmitDefaultValue = false)] - public override PhaseType Type => PhaseType.Provider; - - /// - /// Gets or sets the environment target for this phase. - /// - [DataMember(EmitDefaultValue = false)] - public EnvironmentDeploymentTarget EnvironmentTarget - { - get; - set; - } - - /// - /// Gets or sets the provider for this phase. - /// - [DataMember(EmitDefaultValue = false)] - public String Provider - { - get; - set; - } - - /// - /// Gets or sets the strategy for this phase. - /// - [DataMember(EmitDefaultValue = false)] - public Dictionary Strategy - { - get; - set; - } - - /// - /// Resolves external references and ensures the steps are compatible with the selected target. - /// - /// The validation context - public override void Validate( - PipelineBuildContext context, - ValidationResult result) - { - base.Validate(context, result); - - var provider = context.PhaseProviders.FirstOrDefault(x => String.Equals(x.Provider, this.Provider, StringComparison.OrdinalIgnoreCase)); - if (provider == null) - { - result.Errors.Add(new PipelineValidationError($"'{this.Provider}' phase '{this.Name}' is not supported.")); - } - else - { - var providerPhaseResult = provider.Validate(context, this); - if (providerPhaseResult != null) - { - foreach (var error in providerPhaseResult.Errors) - { - result.Errors.Add(error); - } - - result.ReferencedResources.MergeWith(providerPhaseResult.ReferencedResources); - - foreach (var endpointReference in providerPhaseResult.ReferencedResources.Endpoints) - { - var endpoint = context.ResourceStore.GetEndpoint(endpointReference); - if (endpoint == null) - { - result.UnauthorizedResources.AddEndpointReference(endpointReference); - } - } - - foreach (var fileReference in providerPhaseResult.ReferencedResources.Files) - { - var file = context.ResourceStore.GetFile(fileReference); - if (file == null) - { - result.UnauthorizedResources.AddSecureFileReference(fileReference); - } - } - - foreach (var queueReference in providerPhaseResult.ReferencedResources.Queues) - { - var queue = context.ResourceStore.GetQueue(queueReference); - if (queue == null) - { - result.UnauthorizedResources.AddAgentQueueReference(queueReference); - } - } - - foreach (var variableReference in providerPhaseResult.ReferencedResources.VariableGroups) - { - var variableGroup = context.ResourceStore.GetVariableGroup(variableReference); - if (variableGroup == null) - { - result.UnauthorizedResources.AddVariableGroupReference(variableReference); - } - } - } - } - - if (!(this.Target is AgentQueueTarget agentQueueTarget) || agentQueueTarget.IsLiteral()) - { - this.Target?.Validate(context, context.BuildOptions, result); - } - } - public JobExecutionContext CreateJobContext( - PhaseExecutionContext context, - JobInstance jobInstance) - { - var jobContext = context.CreateJobContext(jobInstance); - jobContext.Job.Definition.Id = jobContext.GetInstanceId(); - - var options = new BuildOptions(); - var builder = new PipelineBuilder(context); - var result = builder.GetReferenceResources(jobInstance.Definition.Steps.OfType().ToList(), jobInstance.Definition.Target); - jobContext.ReferencedResources.MergeWith(result); - - // Update the execution context with the job-specific system variables - UpdateJobContextVariablesFromJob(jobContext, jobInstance.Definition); - - return jobContext; - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class ProviderPhaseRequest - { - [DataMember(IsRequired = true)] - public Guid PlanId { get; set; } - - [DataMember(IsRequired = true)] - public String PlanType { get; set; } - - [DataMember(IsRequired = true)] - public Guid ServiceOwner { get; set; } - - [DataMember(IsRequired = true)] - public String PhaseOrchestrationId { get; set; } - - [DataMember(EmitDefaultValue = false)] - public ProviderPhase ProviderPhase { get; set; } - - [DataMember(EmitDefaultValue = false)] - public ProjectReference Project { get; set; } - - [DataMember(EmitDefaultValue = false)] - public TaskOrchestrationOwner Pipeline { get; set; } - - [DataMember(EmitDefaultValue = false)] - public TaskOrchestrationOwner Run { get; set; } - - [DataMember(EmitDefaultValue = false)] - public PipelineGraphNodeReference Stage { get; set; } - - [DataMember(EmitDefaultValue = false)] - public PipelineGraphNodeReference Phase { get; set; } - - [DataMember(EmitDefaultValue = false)] - public IDictionary Variables { get; set; } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class PipelineGraphNodeReference - { - public PipelineGraphNodeReference() - { - } - - public PipelineGraphNodeReference(String id, String name, Int32 attempt = 0) - { - this.Id = id; - this.Name = name; - this.Attempt = attempt; - } - - public PipelineGraphNodeReference(Guid id, String name, Int32 attempt = 0) - { - this.Id = id.ToString("D"); - this.Name = name; - this.Attempt = attempt; - } - - public PipelineGraphNodeReference(Int32 id, String name, Int32 attempt = 0) - { - this.Id = id.ToString(); - this.Name = name; - this.Attempt = attempt; - } - - [DataMember(IsRequired = true)] - public String Id { get; set; } - - [DataMember(EmitDefaultValue = false)] - public String Name { get; set; } - - [DataMember(EmitDefaultValue = false)] - public Int32 Attempt { get; set; } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/PullRequestTrigger.cs b/src/Sdk/DTPipelines/Pipelines/PullRequestTrigger.cs deleted file mode 100644 index 91af1aba8..000000000 --- a/src/Sdk/DTPipelines/Pipelines/PullRequestTrigger.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class PullRequestTrigger : PipelineTrigger - { - public PullRequestTrigger() - : base(PipelineTriggerType.PullRequest) - { - Enabled = true; - AutoCancel = true; - } - - [DataMember(EmitDefaultValue = true)] - public Boolean Enabled - { - get; - set; - } - - [DataMember(EmitDefaultValue = true)] - public Boolean AutoCancel - { - get; - set; - } - - /// - /// A list of filters that describe which branches will trigger pipelines. - /// - public IList BranchFilters - { - get - { - if (m_branchFilters == null) - { - m_branchFilters = new List(); - } - return m_branchFilters; - } - } - - /// - /// A list of filters that describe which paths will trigger pipelines. - /// - public IList PathFilters - { - get - { - if (m_pathFilters == null) - { - m_pathFilters = new List(); - } - return m_pathFilters; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_branchFilters?.Count == 0) - { - m_branchFilters = null; - } - - if (m_pathFilters?.Count == 0) - { - m_pathFilters = null; - } - } - - [DataMember(Name = "BranchFilters", EmitDefaultValue = false)] - private List m_branchFilters; - - [DataMember(Name = "PathFilters", EmitDefaultValue = false)] - private List m_pathFilters; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ResourceComparer.cs b/src/Sdk/DTPipelines/Pipelines/ResourceComparer.cs deleted file mode 100644 index 76aa7eabe..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ResourceComparer.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.Pipelines -{ - internal sealed class ResourceComparer : IEqualityComparer - { - public Boolean Equals( - Resource x, - Resource y) - { - return String.Equals(x?.Alias, y?.Alias, StringComparison.OrdinalIgnoreCase); - } - - public Int32 GetHashCode(Resource obj) - { - return obj?.Alias?.GetHashCode() ?? 0; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ResourceStore.cs b/src/Sdk/DTPipelines/Pipelines/ResourceStore.cs deleted file mode 100644 index c5ce4ba7c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ResourceStore.cs +++ /dev/null @@ -1,666 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.Orchestration.Server.Artifacts; -using GitHub.DistributedTask.Pipelines.Artifacts; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a default implementation of a resource store. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class ResourceStore : IResourceStore - { - /// - /// Initializes a new ResourceStore instance with no resources. - /// - public ResourceStore() - : this(endpoints: null) - { - } - - /// - /// Initializes a new ResourceStore instance with the specified resources. If aliases are provided, - /// an alias overrides lookup by name for the specified resource. - /// - /// The collection of endpoints available in the store - /// The collection of secure files available in the store - /// The collection of agent queues available in the store - /// The collection of variable groups available in the store - public ResourceStore( - IList endpoints = null, - IList files = null, - IList queues = null, - IList variableGroups = null, - IList builds = null, - IList containers = null, - IList repositories = null, - IList pipelines = null, - IList pools = null) - : this(new ServiceEndpointStore(endpoints), new SecureFileStore(files), new AgentQueueStore(queues), new VariableGroupStore(variableGroups), new BuildResourceStore(builds), new ContainerResourceStore(containers), new RepositoryResourceStore(repositories), new PipelineResourceStore(pipelines), new AgentPoolStore(pools), new EnvironmentStore(null)) - { - } - - /// - /// Initializes a new ResourceStore instance with the specified resources and endpoint store. If - /// aliases are provided, an alias overrides lookup by name for the specified resource. - /// - /// The store for retrieving referenced service endpoints - /// The store for retrieving referenced secure files - /// The store for retrieving referenced agent queues - /// The store for retrieving reference variable groups - public ResourceStore( - IServiceEndpointStore endpointStore = null, - ISecureFileStore fileStore = null, - IAgentQueueStore queueStore = null, - IVariableGroupStore variableGroupStore = null, - IBuildStore buildStore = null, - IContainerStore containerStore = null, - IRepositoryStore repositoryStore = null, - IPipelineStore pipelineStore = null, - IAgentPoolStore poolStore = null, - IEnvironmentStore environmentStore = null) - { - this.Builds = buildStore ?? new BuildResourceStore(null); - this.Containers = containerStore ?? new ContainerResourceStore(null); - this.Endpoints = endpointStore ?? new ServiceEndpointStore(null); - this.Files = fileStore ?? new SecureFileStore(null); - this.Pipelines = pipelineStore ?? new PipelineResourceStore(null); - this.Queues = queueStore ?? new AgentQueueStore(null); - this.Pools = poolStore ?? new AgentPoolStore(null); - this.Repositories = repositoryStore ?? new RepositoryResourceStore(null); - this.VariableGroups = variableGroupStore ?? new VariableGroupStore(null); - this.Environments = environmentStore ?? new EnvironmentStore(null); - } - - /// - /// Gets the store used for retrieving build resources. - /// - public IBuildStore Builds - { - get; - } - - /// - /// Gets the store used for retrieving container resources. - /// - public IContainerStore Containers - { - get; - } - - /// - /// Gets the store used for retrieving service endpoints. - /// - public IServiceEndpointStore Endpoints - { - get; - } - - /// - /// Gets the store used for retrieving environment. - /// - public IEnvironmentStore Environments - { - get; - } - - /// - /// Gets the store used for retrieving secure files. - /// - public ISecureFileStore Files - { - get; - } - - /// - /// Get the store used for retrieving pipelines. - /// - public IPipelineStore Pipelines - { - get; - } - - /// - /// Gets the store used for retrieving agent queues. - /// - public IAgentQueueStore Queues - { - get; - } - - /// - /// Gets the store used for retrieving agent pools. - /// - public IAgentPoolStore Pools - { - get; - } - - /// - /// Gets the store used for retrieving repository resources. - /// - public IRepositoryStore Repositories - { - get; - } - - /// - /// Gets the store used for retrieving variable groups. - /// - public IVariableGroupStore VariableGroups - { - get; - } - - /// - /// Gets all resources currently in the resource store. - /// - /// - public PipelineResources GetAuthorizedResources() - { - var resources = new PipelineResources(); - resources.Builds.AddRange(this.Builds.GetAll()); - resources.Containers.AddRange(this.Containers.GetAll()); - resources.Endpoints.AddRange(this.Endpoints.GetAuthorizedReferences()); - resources.Files.AddRange(this.Files.GetAuthorizedReferences()); - resources.Pipelines.AddRange(this.Pipelines.GetAll()); - resources.Queues.AddRange(this.Queues.GetAuthorizedReferences()); - resources.Pools.AddRange(this.Pools.GetAuthorizedReferences()); - resources.Repositories.AddRange(this.Repositories.GetAll()); - resources.VariableGroups.AddRange(this.VariableGroups.GetAuthorizedReferences()); - resources.Environments.AddRange(this.Environments.GetReferences()); - return resources; - } - - /// - /// Gets the steps, if any, which should be inserted into the job based on the resources configured. - /// - /// The execution context - /// The current set of steps for the job - /// A list of steps which should be prepended to the job - public IList GetPreSteps( - IPipelineContext context, - IReadOnlyList steps) - { - var allSteps = new List(); - if (context.EnvironmentVersion > 1 && context is PipelineExecutionContext) - { - // Variable group steps are always set first in case the other steps depend on the values - allSteps.AddRangeIfRangeNotNull(this.VariableGroups.GetPreSteps(context, steps)); - - // Now just do the remaining resources in alphabetical order - allSteps.AddRangeIfRangeNotNull(this.Builds.GetPreSteps(context, steps)); - allSteps.AddRangeIfRangeNotNull(this.Repositories.GetPreSteps(context, steps)); - allSteps.AddRangeIfRangeNotNull(this.Pipelines.GetPreSteps(context, steps)); - } - - return allSteps; - } - - /// - /// Get steps that run after the checkout task. - /// - /// The execution context - /// - /// - public Dictionary> GetPostTaskSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new Dictionary>(); - } - - /// - /// Get steps that are run after all other steps. - /// - /// The execution context - /// - public IList GetPostSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new List(); - } - - public ServiceEndpoint GetEndpoint(Guid endpointId) - { - return this.Endpoints.Get(new ServiceEndpointReference { Id = endpointId }); - } - - public ServiceEndpoint GetEndpoint(String endpointId) - { - ServiceEndpoint endpoint = null; - if (Guid.TryParse(endpointId, out Guid endpointIdValue)) - { - endpoint = GetEndpoint(endpointIdValue); - } - - if (endpoint == null) - { - endpoint = this.Endpoints.Get(new ServiceEndpointReference { Name = endpointId }); - } - - return endpoint; - } - - public SecureFile GetFile(Guid fileId) - { - return this.Files.Get(new SecureFileReference { Id = fileId }); - } - - public SecureFile GetFile(String fileId) - { - SecureFile file = null; - if (Guid.TryParse(fileId, out Guid fileIdValue)) - { - file = GetFile(fileIdValue); - } - - if (file == null) - { - file = this.Files.Get(new SecureFileReference { Name = fileId }); - } - - return file; - } - - public TaskAgentQueue GetQueue(Int32 queueId) - { - return this.Queues.Get(new AgentQueueReference { Id = queueId }); - } - - public TaskAgentQueue GetQueue(String queueId) - { - TaskAgentQueue queue = null; - if (Int32.TryParse(queueId, out Int32 queueIdValue)) - { - queue = GetQueue(queueIdValue); - } - - if (queue == null) - { - queue = this.Queues.Get(new AgentQueueReference { Name = queueId }); - } - - return queue; - } - - public TaskAgentPool GetPool(Int32 poolId) - { - return this.Pools.Get(new AgentPoolReference { Id = poolId }); - } - - public TaskAgentPool GetPool(String poolName) - { - return this.Pools.Get(new AgentPoolReference { Name = poolName }); - } - - public VariableGroup GetVariableGroup(Int32 groupId) - { - return this.VariableGroups.Get(new VariableGroupReference { Id = groupId }); - } - - public VariableGroup GetVariableGroup(String groupId) - { - VariableGroup variableGroup = null; - if (Int32.TryParse(groupId, out Int32 groupIdValue)) - { - variableGroup = GetVariableGroup(groupIdValue); - } - - if (variableGroup == null) - { - variableGroup = this.VariableGroups.Get(new VariableGroupReference { Name = groupId }); - } - - return variableGroup; - } - - public Boolean ResolveStep( - IPipelineContext context, - JobStep step, - out IList resolvedSteps) - { - resolvedSteps = new List(); - if (context.EnvironmentVersion > 1 && context is PipelineExecutionContext) - { - return this.Pipelines.ResolveStep(context, step, out resolvedSteps); - } - - return false; - } - } - - public abstract class InMemoryResourceStore where T : Resource - { - protected InMemoryResourceStore(IEnumerable resources) - { - m_resources = resources?.ToDictionary(x => x.Alias, x => x, StringComparer.OrdinalIgnoreCase) ?? new Dictionary(StringComparer.OrdinalIgnoreCase); - } - - public Int32 Count => m_resources.Count; - - public void Add(T resource) - { - m_resources.Add(resource.Alias, resource); - } - - public void Add(IEnumerable resources) - { - foreach (var resource in resources) - { - m_resources.Add(resource.Alias, resource); - } - } - - public T Get(String alias) - { - if (m_resources.TryGetValue(alias, out T resource)) - { - return resource; - } - - return null; - } - - public IEnumerable GetAll() - { - return m_resources.Values.ToList(); - } - - private Dictionary m_resources; - } - - public class BuildResourceStore : InMemoryResourceStore, IBuildStore - { - public BuildResourceStore( - IEnumerable builds, - IArtifactResolver resolver = null) - : base(builds) - { - this.Resolver = resolver; - } - - public BuildResourceStore(params BuildResource[] builds) - : base(builds) - { - } - - public IArtifactResolver Resolver { get; } - - public IList GetPreSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return null; - } - - public Dictionary> GetPostTaskSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new Dictionary>(); - } - - public IList GetPostSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new List(); - } - - public Boolean ResolveStep( - IPipelineContext context, - JobStep step, - out IList resolvedSteps) - { - resolvedSteps = new List(); - return false; - } - } - - public class ContainerResourceStore : InMemoryResourceStore, IContainerStore - { - public ContainerResourceStore(IEnumerable containers) - : base(containers) - { - } - - public ContainerResourceStore(params ContainerResource[] containers) - : base(containers) - { - } - - public bool ResolveStep( - IPipelineContext context, - JobStep step, - out IList resolvedSteps) - { - resolvedSteps = new List(); - return false; - } - } - - public class PipelineResourceStore : InMemoryResourceStore, IPipelineStore - { - public PipelineResourceStore( - IEnumerable pipelines, - IArtifactResolver artifactResolver = null, - Boolean isEnabled = false, - Boolean useSystemStepsDecorator = false) - : base(pipelines) - { - this.m_artifactResolver = artifactResolver; - this.m_isEnabled = isEnabled; - this.m_useSystemStepsDecorator = useSystemStepsDecorator; - } - - public IList GetPreSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new List(); - } - - public Dictionary> GetPostTaskSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new Dictionary>(); - } - - public IList GetPostSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new List(); - } - - public Boolean ResolveStep( - IPipelineContext context, - JobStep step, - out IList resolvedSteps) - { - resolvedSteps = new List(); - - if (step.IsDownloadTask()) - { - if (!m_isEnabled) - { - // The pre step decorator can't check the FF state. It always adds a download step for a current pipeline. - // To make sure we aren't failing all the existing pipelines, if the DownloadStep FF is not enabled we will return as resolved with empty resolved steps. - return true; - } - - return m_artifactResolver?.ResolveStep(context, step, out resolvedSteps) ?? false; - } - - return false; - } - - private IArtifactResolver m_artifactResolver; - private Boolean m_isEnabled; - private Boolean m_useSystemStepsDecorator; - } - - public class RepositoryResourceStore : InMemoryResourceStore, IRepositoryStore - { - public RepositoryResourceStore(IEnumerable repositories) - : this(repositories, false, false) - { - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public RepositoryResourceStore( - IEnumerable repositories, - Boolean useSystemStepsDecorator, - Boolean includeCheckoutOptions) - : base(repositories) - { - m_useSystemStepsDecorator = useSystemStepsDecorator; - m_includeCheckoutOptions = includeCheckoutOptions; - } - - public IList GetPreSteps( - IPipelineContext context, - IReadOnlyList steps) - { - // If the environment version is 1 we should not inject - if (context.EnvironmentVersion < 2) - { - return null; - } - - var executionContext = context as JobExecutionContext; - if (context is JobExecutionContext jobContext && (jobContext.Phase.Definition as Phase)?.Target.Type != PhaseTargetType.Queue) - { - // only inject checkout step for agent phase - return null; - } - - // Check feature flag DistributedTask.IncludeCheckoutOptions. - // Controls whether the checkout options are merged into the task inputs, - // or whether the checkout task does. - if (!m_includeCheckoutOptions) - { - // Populate default checkout option from repository into task's inputs - foreach (var checkoutTask in steps.Where(x => x.IsCheckoutTask()).OfType()) - { - var repository = Get(checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.Repository]); - if (repository != null && repository.Properties.TryGetValue(RepositoryPropertyNames.CheckoutOptions, out CheckoutOptions checkoutOptions)) - { - MergeCheckoutOptions(checkoutOptions, checkoutTask); - } - } - } - - // Check feature flag DistributedTask.YamlSystemStepsDecorator. - // Controls whether to load the checkout step from a YAML template. - if (m_useSystemStepsDecorator) - { - return null; - } - - var selfRepo = Get(PipelineConstants.SelfAlias); - if (selfRepo == null) - { - // self repository doesn't existing, no needs to inject checkout task. - // self repo is for yaml only, designer build should always provide checkout task - return null; - } - else - { - // If any steps contains checkout task, we will not inject checkout task - if (steps.Any(x => x.IsCheckoutTask())) - { - return null; - } - else - { - //Inject checkout:self task - var checkoutTask = new TaskStep() - { - Enabled = true, - DisplayName = PipelineConstants.CheckoutTask.FriendlyName, - Reference = new TaskStepDefinitionReference() - { - Id = PipelineConstants.CheckoutTask.Id, - Version = PipelineConstants.CheckoutTask.Version, - Name = PipelineConstants.CheckoutTask.Name - } - }; - - checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.Repository] = selfRepo.Alias; - if (selfRepo.Properties.TryGetValue(RepositoryPropertyNames.CheckoutOptions, out CheckoutOptions checkoutOptions)) - { - MergeCheckoutOptions(checkoutOptions, checkoutTask); - } - - return new[] { checkoutTask }; - } - } - } - - public Dictionary> GetPostTaskSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new Dictionary>(); - } - - public IList GetPostSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new List(); - } - - private void MergeCheckoutOptions( - CheckoutOptions checkoutOptions, - TaskStep checkoutTask) - { - if (!checkoutTask.Inputs.ContainsKey(PipelineConstants.CheckoutTaskInputs.Clean) && !String.IsNullOrEmpty(checkoutOptions.Clean)) - { - checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.Clean] = checkoutOptions.Clean; - } - - if (!checkoutTask.Inputs.ContainsKey(PipelineConstants.CheckoutTaskInputs.FetchDepth) && !String.IsNullOrEmpty(checkoutOptions.FetchDepth)) - { - checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.FetchDepth] = checkoutOptions.FetchDepth; - } - - if (!checkoutTask.Inputs.ContainsKey(PipelineConstants.CheckoutTaskInputs.Lfs) && !String.IsNullOrEmpty(checkoutOptions.Lfs)) - { - checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.Lfs] = checkoutOptions.Lfs; - } - - if (!checkoutTask.Inputs.ContainsKey(PipelineConstants.CheckoutTaskInputs.PersistCredentials) && !String.IsNullOrEmpty(checkoutOptions.PersistCredentials)) - { - checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.PersistCredentials] = checkoutOptions.PersistCredentials; - } - - if (!checkoutTask.Inputs.ContainsKey(PipelineConstants.CheckoutTaskInputs.Submodules) && !String.IsNullOrEmpty(checkoutOptions.Submodules)) - { - checkoutTask.Inputs[PipelineConstants.CheckoutTaskInputs.Submodules] = checkoutOptions.Submodules; - } - } - - public Boolean ResolveStep( - IPipelineContext context, - JobStep step, - out IList resolvedSteps) - { - resolvedSteps = new List(); - return false; - } - - private Boolean m_useSystemStepsDecorator; - private Boolean m_includeCheckoutOptions; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/AgentJobStartedData.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/AgentJobStartedData.cs deleted file mode 100644 index a8a68681d..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/AgentJobStartedData.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [DataContract] - public sealed class AgentJobStartedData - { - [DataMember(EmitDefaultValue = false)] - public TaskAgentReference ReservedAgent - { - get; - set; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/GraphExecutionContext.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/GraphExecutionContext.cs deleted file mode 100644 index 31c9b4a2f..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/GraphExecutionContext.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class GraphExecutionContext : PipelineExecutionContext where TInstance : IGraphNodeInstance - { - private protected GraphExecutionContext(GraphExecutionContext context) - : base(context) - { - this.Node = context.Node; - } - - private protected GraphExecutionContext( - TInstance node, - PipelineState state, - DictionaryContextData data, - ICounterStore counterStore, - IPackageStore packageStore, - IResourceStore resourceStore, - ITaskStore taskStore, - IList stepProviders, - IPipelineIdGenerator idGenerator = null, - IPipelineTraceWriter trace = null, - EvaluationOptions expressionOptions = null, - ExecutionOptions executionOptions = null) - : base(data, counterStore, packageStore, resourceStore, taskStore, stepProviders, state, idGenerator, trace, expressionOptions, executionOptions) - { - ArgumentUtility.CheckForNull(node, nameof(node)); - - this.Node = node; - } - - /// - /// Gets the target node for this execution context. - /// - protected TInstance Node - { - get; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/GraphNodeInstance.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/GraphNodeInstance.cs deleted file mode 100644 index c2e65be20..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/GraphNodeInstance.cs +++ /dev/null @@ -1,144 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [DataContract] - public abstract class GraphNodeInstance : IGraphNodeInstance where TNode : IGraphNode - { - private protected GraphNodeInstance() - { - this.Attempt = 1; - } - - private protected GraphNodeInstance( - String name, - Int32 attempt, - TNode definition, - TaskResult result) - { - this.Name = name; - this.Attempt = attempt; - this.Definition = definition; - this.State = PipelineState.NotStarted; - this.Result = result; - } - - /// - /// Gets or sets the identifier of the node. - /// - [DataMember(EmitDefaultValue = false)] - public String Identifier - { - get; - set; - } - - /// - /// Gets or sets the name of the node. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Int32 Attempt - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public DateTime? StartTime - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public DateTime? FinishTime - { - get; - set; - } - - /// - /// Gets the collection of output variables emitted by the instance. - /// - public IDictionary Outputs - { - get - { - if (m_outputs == null) - { - m_outputs = new VariablesDictionary(); - } - return m_outputs; - } - } - - [DataMember(EmitDefaultValue = false)] - public PipelineState State - { - get; - set; - } - - /// - /// Gets or sets the result of the instance. - /// - [DataMember(EmitDefaultValue = false)] - public TaskResult? Result - { - get; - set; - } - - /// - /// Gets the structure defined in the pipeline definition. - /// - public TNode Definition - { - get; - internal set; - } - - /// - /// Gets the timeline record for this instance. - /// - internal TimelineRecord Record - { - get; - } - - public Boolean SecretsAccessed - { - get - { - return m_outputs?.SecretsAccessed.Count > 0; - } - } - - public void ResetSecretsAccessed() - { - m_outputs?.SecretsAccessed.Clear(); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_outputs?.Count == 0) - { - m_outputs = null; - } - } - - [DataMember(Name = "Outputs", EmitDefaultValue = false)] - private VariablesDictionary m_outputs; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/JobAttempt.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/JobAttempt.cs deleted file mode 100644 index bda09e88a..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/JobAttempt.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class JobAttempt - { - public JobInstance Job - { - get; - set; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/JobExecutionContext.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/JobExecutionContext.cs deleted file mode 100644 index d29c3cb51..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/JobExecutionContext.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.Pipelines.ContextData; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class JobExecutionContext : PipelineExecutionContext - { - public JobExecutionContext( - PipelineState state, - IPipelineIdGenerator idGenerator = null) - : base(null, null, null, null, null, null, state, idGenerator) - { - } - - public JobExecutionContext( - PhaseExecutionContext context, - JobInstance job, - IDictionary variables, - Int32 positionInPhase = default, - Int32 totalJobsInPhase = default, - IDictionary data = default) - : base(context) - { - this.Stage = context.Stage; - this.Phase = context.Phase; - this.Job = job; - - // Make sure the identifier is properly set - this.Job.Identifier = this.IdGenerator.GetJobIdentifier(this.Stage?.Name, this.Phase.Name, this.Job.Name); - - if (job.Definition?.Variables?.Count > 0) - { - SetUserVariables(job.Definition.Variables.OfType()); - } - - SetSystemVariables(variables); - - // Add the attempt information into the context - var systemVariables = new List - { - new Variable - { - Name = WellKnownDistributedTaskVariables.JobIdentifier, - Value = job.Identifier - }, - new Variable - { - Name = WellKnownDistributedTaskVariables.JobAttempt, - Value = job.Attempt.ToString() - }, - }; - - if (positionInPhase != default) - { - systemVariables.Add(new Variable - { - Name = WellKnownDistributedTaskVariables.JobPositionInPhase, - Value = positionInPhase.ToString() - }); - } - - if (totalJobsInPhase != default) - { - systemVariables.Add(new Variable - { - Name = WellKnownDistributedTaskVariables.TotalJobsInPhase, - Value = totalJobsInPhase.ToString() - }); - } - - SetSystemVariables(systemVariables); - - if (String.IsNullOrEmpty(this.ExecutionOptions.SystemTokenScope) && - this.Variables.TryGetValue(WellKnownDistributedTaskVariables.AccessTokenScope, out VariableValue tokenScope)) - { - this.ExecutionOptions.SystemTokenScope = tokenScope?.Value; - } - - if (data?.Count > 0) - { - foreach (var pair in data) - { - Data[pair.Key] = pair.Value; - } - } - } - - public StageInstance Stage - { - get; - } - - public PhaseInstance Phase - { - get; - } - - public JobInstance Job - { - get; - } - - internal override String GetInstanceName() - { - return this.IdGenerator.GetJobInstanceName(this.Stage?.Name, this.Phase.Name, this.Job.Name, this.Job.Attempt); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/JobInstance.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/JobInstance.cs deleted file mode 100644 index 45d12e8fa..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/JobInstance.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public sealed class JobInstance - { - public JobInstance() - : this(String.Empty) - { - } - - public JobInstance(String name) - : this(name, 1) - { - } - - public JobInstance( - String name, - Int32 attempt) - { - this.Name = name; - this.Attempt = attempt; - } - - public JobInstance( - String name, - TaskResult result) - : this(name) - { - this.Result = result; - } - - public JobInstance(Job job) - : this(job, 1) - { - } - - public JobInstance( - Job job, - Int32 attempt) - : this(job.Name, attempt) - { - this.Definition = job; - this.State = PipelineState.NotStarted; - } - - [DataMember] - public String Identifier - { - get; - set; - } - - [DataMember] - public String Name - { - get; - set; - } - - [DataMember] - public Int32 Attempt - { - get; - set; - } - - [DataMember] - public DateTime? StartTime - { - get; - set; - } - - [DataMember] - public DateTime? FinishTime - { - get; - set; - } - - [DataMember] - public PipelineState State - { - get; - set; - } - - [DataMember] - public TaskResult? Result - { - get; - set; - } - - [DataMember] - public Job Definition - { - get; - set; - } - - public IDictionary Outputs - { - get - { - if (m_outputs == null) - { - m_outputs = new VariablesDictionary(); - } - return m_outputs; - } - } - - [DataMember(Name = "Outputs")] - private VariablesDictionary m_outputs; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/JobStartedEventData.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/JobStartedEventData.cs deleted file mode 100644 index 84491294e..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/JobStartedEventData.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [DataContract] - public sealed class JobStartedEventData - { - [DataMember(EmitDefaultValue = false)] - public PhaseTargetType JobType - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Guid JobId - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Object Data - { - get; - set; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseAttempt.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseAttempt.cs deleted file mode 100644 index 6995b84ab..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseAttempt.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PhaseAttempt - { - public PhaseInstance Phase - { - get; - set; - } - - public IList Jobs - { - get - { - if (m_jobs == null) - { - m_jobs = new List(); - } - return m_jobs; - } - } - - private List m_jobs; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseExecutionContext.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseExecutionContext.cs deleted file mode 100644 index 41deffce0..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseExecutionContext.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Pipelines.ContextData; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - /// - /// Provides context necessary for the execution of a pipeline. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class PhaseExecutionContext : GraphExecutionContext - { - public PhaseExecutionContext( - StageInstance stage = null, - PhaseInstance phase = null, - DictionaryContextData data = null, - EvaluationOptions expressionOptions = null, - ExecutionOptions executionOptions = null) - : this(stage, phase, PipelineState.InProgress, data, - new CounterStore(), new PackageStore(), new ResourceStore(), new TaskStore(), - null, null, null, expressionOptions, executionOptions) - { - } - - /// - /// Initializes a new PipelineExecutionContext instance using the specified task store. - /// - /// The store which should be utilized for task reference resolution - /// The additional pre-defined resources which should be utilized for resource resolution, like: Container - public PhaseExecutionContext( - StageInstance stage, - PhaseInstance phase, - PipelineState state, - DictionaryContextData data, - ICounterStore counterStore, - IPackageStore packageStore, - IResourceStore resourceStore, - ITaskStore taskStore, - IList stepProviders, - IPipelineIdGenerator idGenerator, - IPipelineTraceWriter trace, - EvaluationOptions expressionOptions, - ExecutionOptions executionOptions) - : base(phase, state, data, counterStore, packageStore, resourceStore, taskStore, stepProviders, idGenerator, trace, expressionOptions, executionOptions) - { - this.Stage = stage; - if (this.Stage != null) - { - this.Stage.Identifier = this.IdGenerator.GetStageIdentifier(this.Stage.Name); - } - - // Set the full identifier according to the current context - this.Phase.Identifier = this.IdGenerator.GetPhaseIdentifier(this.Stage?.Name, this.Phase.Name); - } - - /// - /// The current stage which is being executed. - /// - public StageInstance Stage - { - get; - } - - /// - /// The current phase which is being executed. - /// - public PhaseInstance Phase - { - get - { - return base.Node; - } - } - - /// - /// Gets the previous attempt of the phase if this is a retry of a job which has already executed. - /// - public PhaseAttempt PreviousAttempt - { - get; - set; - } - - public JobExecutionContext CreateJobContext( - String name, - Int32 attempt, - Int32 positionInPhase = default, - Int32 totalJobsInPhase = default) - { - return CreateJobContext( - new JobInstance(name, attempt), - positionInPhase, - totalJobsInPhase); - } - - public JobExecutionContext CreateJobContext( - JobInstance jobInstance, - Int32 positionInPhase = default, - Int32 totalJobsInPhase = default) - { - return new JobExecutionContext( - context: this, - job: jobInstance, - variables: null, - positionInPhase: positionInPhase, - totalJobsInPhase: totalJobsInPhase); - } - - internal override String GetInstanceName() - { - return this.IdGenerator.GetPhaseInstanceName(this.Stage?.Name, this.Phase.Name, this.Phase.Attempt); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseInstance.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseInstance.cs deleted file mode 100644 index 7e13aaea3..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/PhaseInstance.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class PhaseInstance : GraphNodeInstance - { - public PhaseInstance() - { - } - - public PhaseInstance(String name) - : this(name, TaskResult.Succeeded) - { - } - - public PhaseInstance( - String name, - Int32 attempt) - : this(name, attempt, null, TaskResult.Succeeded) - { - } - - public PhaseInstance(PhaseNode phase) - : this(phase, 1) - { - } - - public PhaseInstance( - PhaseNode phase, - Int32 attempt) - : this(phase.Name, attempt, phase, TaskResult.Succeeded) - { - } - - public PhaseInstance( - String name, - TaskResult result) - : this(name, 1, null, result) - { - } - - public PhaseInstance( - String name, - Int32 attempt, - PhaseNode definition, - TaskResult result) - : base(name, attempt, definition, result) - { - } - - public static implicit operator PhaseInstance(String name) - { - return new PhaseInstance(name); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/PipelineAttemptBuilder.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/PipelineAttemptBuilder.cs deleted file mode 100644 index 7cf66fa93..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/PipelineAttemptBuilder.cs +++ /dev/null @@ -1,632 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.Pipelines.Validation; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - /// - /// Provides functionality to build structured data from the timeline store. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class PipelineAttemptBuilder - { - public PipelineAttemptBuilder( - IPipelineIdGenerator idGenerator, - PipelineProcess pipeline, - params Timeline[] timelines) - { - ArgumentUtility.CheckForNull(idGenerator, nameof(idGenerator)); - ArgumentUtility.CheckForNull(pipeline, nameof(pipeline)); - - this.Pipeline = pipeline; - this.IdGenerator = idGenerator; - m_recordsById = new Dictionary(); - m_recordsByParent = new Dictionary>(); - m_stages = new Dictionary>(StringComparer.OrdinalIgnoreCase); - - if (timelines?.Length > 0) - { - foreach (var timeline in timelines) - { - AddStageAttempts(timeline, m_stages); - } - } - } - - /// - /// Gets the ID generator for this pipeline. - /// - public IPipelineIdGenerator IdGenerator - { - get; - } - - /// - /// Gets the pipeline document. - /// - public PipelineProcess Pipeline - { - get; - } - - /// - /// Creates the initial stage attempts for a brand new pipeline. - /// - /// A list of initial attempts which should be run - public IList Initialize() - { - var initialAttempts = new List(); - foreach (var stage in this.Pipeline.Stages) - { - initialAttempts.Add(CreateAttempt(stage)); - } - return initialAttempts; - } - - /// - /// Produce list of stage attempts needed to retry a pipeline. - /// By default, we will reuse previously successful stage attempts, and produce new attempts for - /// failed stages, and any stages downstream from a failed stage. - /// If specific stage names are provided, only these stages and their descendents will be retried, - /// and will be retried irrespective of previous state. - /// - /// tuple of all attempts (the full list of attempts to be added to the plan) and "new attempts" (the retries) - public Tuple, IList> Retry(IList stageNames = null) - { - var allAttempts = new List(); - var newAttempts = new List(); - var stagesToRetry = new HashSet(StringComparer.OrdinalIgnoreCase); - - GraphValidator.Traverse(this.Pipeline.Stages, (stage, dependencies) => - { - var previousAttempt = GetStageAttempt(stage.Name); - if (previousAttempt == null) - { - // nothing to retry - return; - } - - // collect some data - var directlyTargeted = stageNames?.Contains(stage.Name, StringComparer.OrdinalIgnoreCase) is true; - var needsRetry = NeedsRetry(previousAttempt.Stage.Result); - var dependencyNeedsRetry = dependencies.Any(x => stagesToRetry.Contains(x)); - - // create new attempt - var newAttempt = default(StageAttempt); - if (dependencyNeedsRetry - || (stageNames == default && needsRetry) - || (stageNames != default && directlyTargeted)) - { - // try to create new attempt, if it comes back null, no work needs to be done - // force a retry if the stage is directly targeted but the previous attempt was successful. - newAttempt = CreateAttempt( - stage, - previousAttempt, - forceRetry: (directlyTargeted && !needsRetry) || dependencyNeedsRetry); - } - - // update return lists - if (newAttempt == default) - { - // use previous attempt - allAttempts.Add(previousAttempt); - } - else - { - stagesToRetry.Add(previousAttempt.Stage.Name); - allAttempts.Add(newAttempt); - newAttempts.Add(newAttempt); - } - }); - - return Tuple.Create( - allAttempts as IList, - newAttempts as IList); - } - - /// - /// Create a new stage attempt and a new timeline. - /// The new timeline should contain the Pending entries for any stages, phases and jobs that need to be retried. - /// It should contain a full, re-parented, copy of the timeline subgraphs for stages, phases, and jobs that do not need to be retried. - /// - private StageAttempt CreateAttempt( - Stage stage, - StageAttempt previousStageAttempt = null, - Boolean forceRetry = false) - { - // new instance will have attempt number previous + 1 - var newStageAttempt = new StageAttempt - { - Stage = new StageInstance(stage, previousStageAttempt?.Stage.Attempt + 1 ?? 1), - Timeline = new Timeline(), - }; - - // Compute the stage ID for this attempt - var stageIdentifier = this.IdGenerator.GetStageIdentifier(newStageAttempt.Stage.Name); - var stageId = this.IdGenerator.GetStageInstanceId(newStageAttempt.Stage.Name, newStageAttempt.Stage.Attempt); - newStageAttempt.Timeline.Id = stageId; - newStageAttempt.Stage.Identifier = stageIdentifier; - - if (previousStageAttempt != null) - { - // copy the previous timeline record, reset to "Pending" state - var previousRecord = m_recordsById[this.IdGenerator.GetStageInstanceId(previousStageAttempt.Stage.Name, previousStageAttempt.Stage.Attempt)]; - newStageAttempt.Timeline.Records.Add(ResetRecord(previousRecord, null, stageId, newStageAttempt.Stage.Attempt)); - } - else - { - // create a new stage record - newStageAttempt.Timeline.Records.Add(CreateRecord(newStageAttempt.Stage, null, stageId, stage.DisplayName ?? stage.Name, nameof(Stage), m_stageOrder++, stageIdentifier)); - } - - // walk the phases. - // if a phase does not need to be retried, copy its entire timeline subgraph to the new timeline. - var phaseOrder = 1; - var phasesRetried = false; - var phasesToRetry = new HashSet(StringComparer.OrdinalIgnoreCase); - GraphValidator.Traverse(stage.Phases, (phase, dependencies) => - { - var shouldRetry = false; - var previousPhaseAttempt = previousStageAttempt?.Phases.FirstOrDefault(x => String.Equals(x.Phase.Name, phase.Name, StringComparison.OrdinalIgnoreCase)); - var upstreamDependencyNeedsRetry = dependencies.Any(x => phasesToRetry.Contains(x)); - var previousAttemptNeedsRetry = NeedsRetry(previousPhaseAttempt?.Phase.Result); - if (forceRetry || upstreamDependencyNeedsRetry || previousAttemptNeedsRetry) - { - // If the previous attempt a specific phase failed then we should retry it and everything - // downstream regardless of first attempt status. The failed phases are appended as we walk - // the graph and the set is inspected - shouldRetry = true; - phasesToRetry.Add(phase.Name); - } - - if (!shouldRetry && previousPhaseAttempt != null) - { - // This phase does not need to be retried. - // Copy timeline records from previous timeline to new timeline. - // The new timeline should report that this phase has already been run, and the parent should be the new stage. - previousPhaseAttempt.Phase.Definition = phase; - newStageAttempt.Phases.Add(previousPhaseAttempt); - - // clone so as not to mess up our lookup table. - var previousPhaseId = this.IdGenerator.GetPhaseInstanceId(newStageAttempt.Stage.Name, previousPhaseAttempt.Phase.Name, previousPhaseAttempt.Phase.Attempt); - var newPhaseRecord = m_recordsById[previousPhaseId].Clone(); - newPhaseRecord.ParentId = stageId; // this phase is already completed for the new stage. - - phaseOrder = (newPhaseRecord.Order ?? phaseOrder) + 1; // TODO: what does this do? - newStageAttempt.Timeline.Records.Add(newPhaseRecord); - - // if there are any child records of the phase, copy them too. - // they should exist exactly as they are on the new timeline. - // Only the phase needs to reparent. - newStageAttempt.Timeline.Records.AddRange(CollectAllChildren(newPhaseRecord)); - } - else - { - // This phase needs to be retried. - // Track that we are scheduling a phase for retry in this attempt - phasesRetried = true; - - // Create a new attempt record in the pending state. At runtime the job expansion logic, based on the target - // strategy, will determine what needs to be re-run and what doesn't based on the previous attempt. We don't - // make assumptions about the internals of jobs here as that is the piece the orchestrator doesn't deal with - // directly. - var newPhaseAttempt = new PhaseAttempt - { - Phase = new PhaseInstance(phase, previousPhaseAttempt?.Phase.Attempt + 1 ?? 1), - }; - - var phaseId = this.IdGenerator.GetPhaseInstanceId( - newStageAttempt.Stage.Name, - newPhaseAttempt.Phase.Name, - newPhaseAttempt.Phase.Attempt); - - newPhaseAttempt.Phase.Identifier = this.IdGenerator.GetPhaseIdentifier(newStageAttempt.Stage.Name, newPhaseAttempt.Phase.Name); - newStageAttempt.Timeline.Records.Add(CreateRecord( - newPhaseAttempt.Phase, - stageId, - phaseId, - phase.DisplayName ?? phase.Name, - nameof(Phase), - phaseOrder++, - newPhaseAttempt.Phase.Identifier)); - - // The previous attempt failed but we had no upstream failures means that this specific phase - // needs have the failed jobs re-run. - // For this case we just locate the failed jobs and create new - // attempt records to ensure they are re-run. - if (previousAttemptNeedsRetry && !upstreamDependencyNeedsRetry) - { - foreach (var previousJobAttempt in previousPhaseAttempt.Jobs) - { - var previousJobId = this.IdGenerator.GetJobInstanceId( - newStageAttempt.Stage.Name, - newPhaseAttempt.Phase.Name, - previousJobAttempt.Job.Name, - previousJobAttempt.Job.Attempt); - - if (NeedsRetry(previousJobAttempt.Job.Result)) - { - // this job needs to be retried. - // - // NOTE: - // Phases (JobFactories) normally are expanded dynamically to produce jobs. - // The phase expansion routines allow a list of configurations to be supplied. If non-empty, the JobFactories will only - // produce Jobs with the names provided. - // - // In retry attempts, we already know the Job names that will be produced, and we only want to run a subset of them. - // We can define the subset of jobs to be "expanded" by initializing the PhaseAttempt with named JobAttempts. - // See RunPhase for more details. - var newJobAttempt = new JobAttempt - { - Job = new JobInstance(previousJobAttempt.Job.Name, previousJobAttempt.Job.Attempt + 1), - }; - newJobAttempt.Job.Identifier = this.IdGenerator.GetJobIdentifier( - newStageAttempt.Stage.Name, - newPhaseAttempt.Phase.Name, - newJobAttempt.Job.Name); - newPhaseAttempt.Jobs.Add(newJobAttempt); - - // create a new record in "Pending" state based on the previous record. - var newJobId = this.IdGenerator.GetJobInstanceId( - newStageAttempt.Stage.Name, - newPhaseAttempt.Phase.Name, - newJobAttempt.Job.Name, - newJobAttempt.Job.Attempt); - newStageAttempt.Timeline.Records.Add(ResetRecord(m_recordsById[previousJobId], phaseId, newJobId, newJobAttempt.Job.Attempt)); - } - else - { - // this job does not need to be retried. - // deep copy the timeline subgraph to the new timeline. - // reparent the job record to the new phase id so the job looks completed on the new timeline. - var newJobRecord = m_recordsById[previousJobId].Clone(); - newJobRecord.ParentId = phaseId; - newPhaseAttempt.Jobs.Add(previousJobAttempt); - newStageAttempt.Timeline.Records.Add(newJobRecord); - newStageAttempt.Timeline.Records.AddRange(CollectAllChildren(newJobRecord)); - } - } - } - - newStageAttempt.Phases.Add(newPhaseAttempt); - } - }); - - if (!phasesRetried) - { - // The stage will remain complete so there is no reason to register a new attempt - return null; - } - - // If this is a new pipeline store that is empty we need to initialize the attempts for this stage. - if (!m_stages.TryGetValue(stage.Name, out IList attempts)) - { - attempts = new List(); - m_stages[stage.Name] = attempts; - } - - attempts.Add(newStageAttempt); - return newStageAttempt; - } - - public StageAttempt GetStageAttempt( - String name, - Int32 attempt = -1) - { - if (!m_stages.TryGetValue(name, out var attempts)) - { - return null; - } - - if (attempt <= 0) - { - return attempts.OrderByDescending(x => x.Stage.Attempt).FirstOrDefault(); - } - else - { - return attempts.FirstOrDefault(x => x.Stage.Attempt == attempt); - } - } - - /// - /// returns true if result should be retried. - /// - internal static Boolean NeedsRetry(TaskResult? result) - { - return result == TaskResult.Abandoned - || result == TaskResult.Canceled - || result == TaskResult.Failed; - } - - private TimelineRecord CreateRecord( - IGraphNodeInstance node, - Guid? parentId, - Guid recordId, - String name, - String type, - Int32 order, - String identifier) - { - return new TimelineRecord - { - Attempt = node.Attempt, - Id = recordId, - Identifier = identifier, - Name = name, - Order = order, - ParentId = parentId, - RecordType = type, - RefName = node.Name, - State = TimelineRecordState.Pending, - }; - } - - /// - /// creates a new timeline record with Pending state based on the input. - /// - private TimelineRecord ResetRecord( - TimelineRecord record, - Guid? parentId, - Guid newId, - Int32 attempt) - { - return new TimelineRecord - { - // new stuff - Attempt = attempt, - Id = newId, - ParentId = parentId, - State = TimelineRecordState.Pending, - - // old stuff - Identifier = record.Identifier, - Name = record.Name, - Order = record.Order, - RecordType = record.RecordType, - RefName = record.RefName, - }; - } - - /// - /// Returns tuple of recordsById, recordsByParentId - /// - internal static Tuple, IDictionary>> ParseTimeline(Timeline timeline) - { - var recordsById = new Dictionary(); - var recordsByParentId = new Dictionary>(); - - foreach (var record in timeline?.Records) - { - recordsById[record.Id] = record; - - if (record.ParentId != null) - { - if (!recordsByParentId.TryGetValue(record.ParentId.Value, out var childRecords)) - { - childRecords = new List(); - recordsByParentId.Add(record.ParentId.Value, childRecords); - } - - childRecords.Add(record); - } - else if (record.RecordType == nameof(Stage)) - { - FixRecord(record); - } - } - - return Tuple.Create( - recordsById as IDictionary, - recordsByParentId as IDictionary>); - } - - private void AddStageAttempts( - Timeline timeline, - IDictionary> attempts) - { - if (timeline == default) - { - return; // nothing to do - } - - // parse timeline - var tuple = ParseTimeline(timeline); - m_recordsById = tuple.Item1; - m_recordsByParent = tuple.Item2; - - foreach (var stageRecord in m_recordsById.Values.Where(x => x.RecordType == "Stage")) - { - var attempt = new StageAttempt - { - Stage = new StageInstance - { - Attempt = stageRecord.Attempt, - FinishTime = stageRecord.FinishTime, - Identifier = stageRecord.Identifier, - Name = stageRecord.RefName, - Result = stageRecord.Result, - StartTime = stageRecord.StartTime, - State = Convert(stageRecord.State.Value), - }, - Timeline = new Timeline - { - Id = timeline.Id, - }, - }; - - attempt.Timeline.Records.Add(stageRecord); - - if (m_recordsByParent.TryGetValue(stageRecord.Id, out var phaseRecords)) - { - AddPhaseAttempts( - attempt, - phaseRecords.Where(x => x.RecordType == nameof(Phase)), - m_recordsByParent); - } - - if (!attempts.TryGetValue(attempt.Stage.Identifier, out var stageAttempts)) - { - stageAttempts = new List(); - attempts.Add(attempt.Stage.Identifier, stageAttempts); - } - - stageAttempts.Add(attempt); - } - } - - private void AddPhaseAttempts( - StageAttempt stageAttempt, - IEnumerable phaseRecords, - IDictionary> recordsByParent) - { - foreach (var phaseRecord in phaseRecords) - { - FixRecord(phaseRecord); - - var phaseAttempt = new PhaseAttempt - { - Phase = new PhaseInstance - { - Attempt = phaseRecord.Attempt, - FinishTime = phaseRecord.FinishTime, - Identifier = phaseRecord.Identifier, - Name = phaseRecord.RefName, - Result = phaseRecord.Result, - StartTime = phaseRecord.StartTime, - State = Convert(phaseRecord.State.Value), - }, - }; - - stageAttempt.Phases.Add(phaseAttempt); - stageAttempt.Timeline.Records.Add(phaseRecord); - - // Drive down into the individual jobs if they exist - if (recordsByParent.TryGetValue(phaseRecord.Id, out var jobRecords)) - { - AddJobAttempts( - stageAttempt, - phaseAttempt, - jobRecords.Where(x => x.RecordType == nameof(Job)), - recordsByParent); - } - } - } - - private void AddJobAttempts( - StageAttempt stageAttempt, - PhaseAttempt phaseAttempt, - IEnumerable jobRecords, - IDictionary> recordsByParent) - { - foreach (var jobRecord in jobRecords) - { - FixRecord(jobRecord); - - var jobAttempt = new JobAttempt - { - Job = new JobInstance - { - Attempt = jobRecord.Attempt, - FinishTime = jobRecord.FinishTime, - Identifier = jobRecord.Identifier, - Name = jobRecord.RefName, - Result = jobRecord.Result, - StartTime = jobRecord.StartTime, - State = Convert(jobRecord.State.Value), - }, - }; - - phaseAttempt.Jobs.Add(jobAttempt); - stageAttempt.Timeline.Records.Add(jobRecord); - - // Just blindly copy the child records - stageAttempt.Timeline.Records.AddRange(CollectAllChildren(jobRecord)); - } - } - - internal IList CollectAllChildren( - TimelineRecord root, - Int32 maxDepth = int.MaxValue) - { - return CollectAllChildren(root, m_recordsByParent, maxDepth); - } - - internal static IList CollectAllChildren( - TimelineRecord root, - IDictionary> recordsByParent, - Int32 maxDepth = int.MaxValue) - { - var result = new List(); - if (!recordsByParent.TryGetValue(root.Id, out var childRecords)) - { - return result; - } - - // instead of actually recursing, create a queue of record, depth pairs. - var recordQueue = new Queue>(childRecords.Select(x => Tuple.Create(x, 1))); - while (recordQueue.Count > 0) - { - var t = recordQueue.Dequeue(); - var currentRecord = t.Item1; - var currentDepth = t.Item2; - - // collect record - result.Add(currentRecord); - - // check depth - if (currentDepth >= maxDepth) - { - continue; - } - - // enqueue children - var childDepth = currentDepth + 1; - if (recordsByParent.TryGetValue(currentRecord.Id, out var newChildren)) - { - foreach (var newChild in newChildren) - { - recordQueue.Enqueue(Tuple.Create(newChild, childDepth)); - } - } - } - - return result; - } - - private static PipelineState Convert(TimelineRecordState state) - { - switch (state) - { - case TimelineRecordState.Completed: - return PipelineState.Completed; - case TimelineRecordState.InProgress: - return PipelineState.InProgress; - } - - return PipelineState.NotStarted; - } - - /// - /// The timeline records get normalized into strings which are not case-sensitive, meaning the input - /// casing may not match what is output.In order to compensate for this we update the ref name from - /// the identifier, as the identifier reflects the actual value. - /// - private static void FixRecord(TimelineRecord record) - { - if (!String.IsNullOrEmpty(record.Identifier)) - { - record.RefName = PipelineUtilities.GetName(record.Identifier); - } - } - - // Includes all attempts of all stages - private Int32 m_stageOrder = 1; - private IDictionary m_recordsById; - private IDictionary> m_recordsByParent; - private IDictionary> m_stages; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/PipelineExecutionContext.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/PipelineExecutionContext.cs deleted file mode 100644 index f8133bc78..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/PipelineExecutionContext.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Pipelines.ContextData; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public abstract class PipelineExecutionContext : PipelineContextBase - { - private protected PipelineExecutionContext(PipelineExecutionContext context) - : base(context) - { - this.State = context.State; - this.ExecutionOptions = context.ExecutionOptions; - } - - private protected PipelineExecutionContext( - DictionaryContextData data, - ICounterStore counterStore, - IPackageStore packageStore, - IResourceStore resourceStore, - ITaskStore taskStore, - IList stepProviders, - PipelineState state, - IPipelineIdGenerator idGenerator = null, - IPipelineTraceWriter trace = null, - EvaluationOptions expressionOptions = null, - ExecutionOptions executionOptions = null) - : base(data, counterStore, packageStore, resourceStore, taskStore, stepProviders, idGenerator, trace, expressionOptions) - { - this.State = state; - this.ExecutionOptions = executionOptions ?? new ExecutionOptions(); - } - - /// - /// Gets the current state of the pipeline. - /// - public PipelineState State - { - get; - } - - /// - /// Gets the execution options used for the pipeline. - /// - public ExecutionOptions ExecutionOptions - { - get; - } - - /// - /// Gets the instance ID for the current context. - /// - /// - internal Guid GetInstanceId() - { - return this.IdGenerator.GetInstanceId(this.GetInstanceName()); - } - - /// - /// When overridden in a derived class, gets the instance name using . - /// - /// The instance name according to the associated generator - internal abstract String GetInstanceName(); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/StageAttempt.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/StageAttempt.cs deleted file mode 100644 index cbffa1ee7..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/StageAttempt.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class StageAttempt - { - internal StageAttempt() - { - } - - public StageInstance Stage - { - get; - set; - } - - public IList Phases - { - get - { - if (m_phases == null) - { - m_phases = new List(); - } - return m_phases; - } - } - - public Timeline Timeline - { - get; - internal set; - } - - private List m_phases; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/StageExecutionContext.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/StageExecutionContext.cs deleted file mode 100644 index 34a7f00fb..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/StageExecutionContext.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Pipelines.ContextData; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - /// - /// Provides context necessary for the execution of a pipeline. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class StageExecutionContext : GraphExecutionContext - { - public StageExecutionContext( - StageInstance stage = default, - DictionaryContextData data = null) - : this(stage, PipelineState.InProgress, data, new CounterStore(), new PackageStore(), new ResourceStore(), new TaskStore(), null, null, null, null, null) - { - } - - /// - /// Initializes a new StageExecutionContext instance using the specified stage and services. - /// - /// The store which should be utilized for task reference resolution - /// The additional pre-defined resources which should be utilized for resource resolution, like: Container - public StageExecutionContext( - StageInstance stage, - PipelineState state, - DictionaryContextData data, - ICounterStore counterStore, - IPackageStore packageStore, - IResourceStore resourceStore, - ITaskStore taskStore, - IList stepProviders, - IPipelineIdGenerator idGenerator, - IPipelineTraceWriter trace, - EvaluationOptions expressionOptions, - ExecutionOptions executionOptions) - : base(stage, state, data, counterStore, packageStore, resourceStore, taskStore, stepProviders, idGenerator, trace, expressionOptions, executionOptions) - { - this.Stage.Identifier = this.IdGenerator.GetStageIdentifier(stage.Name); - } - - /// - /// The current stage which is being executed. - /// - public StageInstance Stage => this.Node; - - /// - /// Gets the previous attempt of the stage if this is a retry of a job which has already executed. - /// - public StageAttempt PreviousAttempt - { - get; - } - - internal override String GetInstanceName() - { - return this.IdGenerator.GetStageInstanceName(this.Stage.Name, this.Stage.Attempt); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Runtime/StageInstance.cs b/src/Sdk/DTPipelines/Pipelines/Runtime/StageInstance.cs deleted file mode 100644 index 93ef248c5..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Runtime/StageInstance.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Runtime -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class StageInstance : GraphNodeInstance - { - public StageInstance() - { - } - - public StageInstance(String name) - : this(name, TaskResult.Succeeded) - { - } - - public StageInstance( - String name, - Int32 attempt) - : this(name, attempt, null, TaskResult.Succeeded) - { - } - - public StageInstance(Stage stage) - : this(stage, 1) - { - } - - public StageInstance( - Stage stage, - Int32 attempt) - : this(stage.Name, attempt, stage, TaskResult.Succeeded) - { - } - - public StageInstance( - String name, - TaskResult result) - : this(name, 1, null, result) - { - } - - public StageInstance( - String name, - Int32 attempt, - Stage definition, - TaskResult result) - : base(name, attempt, definition, result) - { - } - - public static implicit operator StageInstance(String name) - { - return new StageInstance(name); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/SecretStoreConfiguration.cs b/src/Sdk/DTPipelines/Pipelines/SecretStoreConfiguration.cs deleted file mode 100644 index 544b062a9..000000000 --- a/src/Sdk/DTPipelines/Pipelines/SecretStoreConfiguration.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class SecretStoreConfiguration - { - public SecretStoreConfiguration() - { - } - - private SecretStoreConfiguration(SecretStoreConfiguration configurationToCopy) - { - this.Endpoint = configurationToCopy.Endpoint?.Clone(); - this.StoreName = configurationToCopy.StoreName; - - m_endpointId = configurationToCopy.m_endpointId; - if (configurationToCopy.m_keys?.Count > 0) - { - m_keys = new List(configurationToCopy.m_keys); - } - } - - [DataMember(EmitDefaultValue = false)] - public ServiceEndpointReference Endpoint - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String StoreName - { - get; - set; - } - - public IList Keys - { - get - { - if (m_keys == null) - { - m_keys = new List(); - } - return m_keys; - } - } - - public SecretStoreConfiguration Clone() - { - return new SecretStoreConfiguration(this); - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - if (this.Endpoint == null && m_endpointId != Guid.Empty) - { - this.Endpoint = new ServiceEndpointReference - { - Id = m_endpointId, - }; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_keys?.Count == 0) - { - m_keys = null; - } - - if (this.Endpoint != null && this.Endpoint.Id != Guid.Empty) - { - m_endpointId = this.Endpoint.Id; - } - } - - [DataMember(Name = "EndpointId", EmitDefaultValue = false)] - private Guid m_endpointId; - - [DataMember(Name = "Keys", EmitDefaultValue = false)] - private List m_keys; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/SecureFileReference.cs b/src/Sdk/DTPipelines/Pipelines/SecureFileReference.cs deleted file mode 100644 index 4226c9d18..000000000 --- a/src/Sdk/DTPipelines/Pipelines/SecureFileReference.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class SecureFileReference : ResourceReference - { - public SecureFileReference() - { - } - - private SecureFileReference(SecureFileReference referenceToCopy) - : base(referenceToCopy) - { - this.Id = referenceToCopy.Id; - } - - [DataMember(EmitDefaultValue = false)] - public Guid Id - { - get; - set; - } - - public SecureFileReference Clone() - { - return new SecureFileReference(this); - } - - public override String ToString() - { - return base.ToString() ?? this.Id.ToString("D"); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/SecureFileStore.cs b/src/Sdk/DTPipelines/Pipelines/SecureFileStore.cs deleted file mode 100644 index f2448ec0c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/SecureFileStore.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class SecureFileStore : ISecureFileStore - { - public SecureFileStore( - IList files, - ISecureFileResolver resolver = null) - { - this.Resolver = resolver; - Add(files?.ToArray()); - } - - /// - /// Get the endpoint resolver configured for this store. - /// - public ISecureFileResolver Resolver - { - get; - } - - public IList GetAuthorizedReferences() - { - return m_resourcesById.Values.Select(x => new SecureFileReference { Id = x.Id }).ToList(); - } - - public SecureFile Get(SecureFileReference reference) - { - if (reference == null) - { - return null; - } - - var referenceId = reference.Id; - var referenceName = reference.Name?.Literal; - if (referenceId == Guid.Empty && String.IsNullOrEmpty(referenceName)) - { - return null; - } - - SecureFile authorizedResource = null; - if (referenceId != Guid.Empty) - { - if (m_resourcesById.TryGetValue(referenceId, out authorizedResource)) - { - return authorizedResource; - } - } - else if (!String.IsNullOrEmpty(referenceName)) - { - if (m_resourcesByName.TryGetValue(referenceName, out List matchingResources)) - { - if (matchingResources.Count > 1) - { - throw new AmbiguousResourceSpecificationException(PipelineStrings.AmbiguousServiceEndpointSpecification(referenceId)); - } - - return matchingResources[0]; - } - } - - // If we have an authorizer then attempt to authorize the reference for use - authorizedResource = this.Resolver?.Resolve(reference); - if (authorizedResource != null) - { - Add(authorizedResource); - } - - return authorizedResource; - } - - private void Add(params SecureFile[] resources) - { - if (resources?.Length > 0) - { - foreach (var resource in resources) - { - if (m_resourcesById.TryGetValue(resource.Id, out _)) - { - continue; - } - - m_resourcesById.Add(resource.Id, resource); - - if (!m_resourcesByName.TryGetValue(resource.Name, out List resourcesByName)) - { - resourcesByName = new List(); - m_resourcesByName.Add(resource.Name, resourcesByName); - } - - resourcesByName.Add(resource); - } - } - } - - private readonly Dictionary m_resourcesById = new Dictionary(); - private readonly Dictionary> m_resourcesByName = new Dictionary>(StringComparer.OrdinalIgnoreCase); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ServerTarget.cs b/src/Sdk/DTPipelines/Pipelines/ServerTarget.cs deleted file mode 100644 index f8008352f..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ServerTarget.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.ComponentModel; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class ServerTarget : PhaseTarget - { - public ServerTarget() - : base(PhaseTargetType.Server) - { - } - - private ServerTarget(ServerTarget targetToClone) - : base(targetToClone) - { - this.Execution = targetToClone.Execution?.Clone(); - } - - [DataMember(EmitDefaultValue = false)] - public ParallelExecutionOptions Execution - { - get; - set; - } - - public override PhaseTarget Clone() - { - return new ServerTarget(this); - } - - public override Boolean IsValid(TaskDefinition task) - { - return task.RunsOn.Contains(TaskRunsOnConstants.RunsOnServer, StringComparer.OrdinalIgnoreCase); - } - - internal override JobExecutionContext CreateJobContext( - PhaseExecutionContext context, - String jobName, - Int32 attempt, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory) - { - context.Trace?.EnterProperty("CreateJobContext"); - var e = this.Execution ?? new ParallelExecutionOptions(); - var jobContext = e.CreateJobContext( - context, - jobName, - attempt, - null, - null, - continueOnError, - timeoutInMinutes, - cancelTimeoutInMinutes, - jobFactory); - context.Trace?.LeaveProperty("CreateJobContext"); - - jobContext.Variables[WellKnownDistributedTaskVariables.EnableAccessToken] = Boolean.TrueString; - return jobContext; - } - - internal override ExpandPhaseResult Expand( - PhaseExecutionContext context, - Boolean continueOnError, - Int32 timeoutInMinutes, - Int32 cancelTimeoutInMinutes, - IJobFactory jobFactory, - JobExpansionOptions options) - { - context.Trace?.EnterProperty("Expand"); - var execution = this.Execution ?? new ParallelExecutionOptions(); - var result = execution.Expand( - context: context, - container: null, - sidecarContainers: null, - continueOnError: continueOnError, - timeoutInMinutes: timeoutInMinutes, - cancelTimeoutInMinutes: cancelTimeoutInMinutes, - jobFactory: jobFactory, - options: options); - context.Trace?.LeaveProperty("Expand"); - return result; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/ServiceEndpointStore.cs b/src/Sdk/DTPipelines/Pipelines/ServiceEndpointStore.cs deleted file mode 100644 index 80cf530fd..000000000 --- a/src/Sdk/DTPipelines/Pipelines/ServiceEndpointStore.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class ServiceEndpointStore : IServiceEndpointStore - { - public ServiceEndpointStore( - IList endpoints, - IServiceEndpointResolver resolver = null, - Boolean lazyLoadEndpoints = false) - { - this.Resolver = resolver; - this.LazyLoadEndpoints = lazyLoadEndpoints; - Add(endpoints?.ToArray()); - } - - /// - /// Get the endpoint resolver configured for this store. - /// - public IServiceEndpointResolver Resolver - { - get; - } - - public IList GetAuthorizedReferences() - { - if (LazyLoadEndpoints) - { - return this.Resolver != null ? this.Resolver.GetAuthorizedReferences() - : new List(); - } - - return m_endpointsById.Values.Select(x => new ServiceEndpointReference { Id = x.Id, Name = x.Name }).ToList(); - } - - public void Authorize(ServiceEndpointReference reference) - { - this.Resolver?.Authorize(reference); - } - - public ServiceEndpoint Get(ServiceEndpointReference reference) - { - if (reference == null) - { - return null; - } - - var referenceId = reference.Id; - var referenceName = reference.Name?.Literal; - if (referenceId == Guid.Empty && String.IsNullOrEmpty(referenceName)) - { - return null; - } - - ServiceEndpoint authorizedEndpoint = null; - if (referenceId != Guid.Empty) - { - if (m_endpointsById.TryGetValue(referenceId, out authorizedEndpoint)) - { - return authorizedEndpoint; - } - } - else if (!String.IsNullOrEmpty(referenceName)) - { - if (m_endpointsByName.TryGetValue(referenceName, out List matchingEndpoints)) - { - if (matchingEndpoints.Count > 1) - { - throw new AmbiguousResourceSpecificationException(PipelineStrings.AmbiguousServiceEndpointSpecification(referenceId)); - } - - return matchingEndpoints[0]; - } - } - - authorizedEndpoint = this.Resolver?.Resolve(reference); - if (authorizedEndpoint != null) - { - Add(authorizedEndpoint); - } - - return authorizedEndpoint; - } - - private void Add(params ServiceEndpoint[] endpoints) - { - if (endpoints?.Length > 0) - { - foreach (var endpoint in endpoints) - { - if (m_endpointsById.TryGetValue(endpoint.Id, out _)) - { - continue; - } - - m_endpointsById.Add(endpoint.Id, endpoint); - - if (!m_endpointsByName.TryGetValue(endpoint.Name, out List endpointsByName)) - { - endpointsByName = new List(); - m_endpointsByName.Add(endpoint.Name, endpointsByName); - } - - endpointsByName.Add(endpoint); - } - } - } - - private readonly Dictionary m_endpointsById = new Dictionary(); - private readonly Dictionary> m_endpointsByName = new Dictionary>(StringComparer.OrdinalIgnoreCase); - private readonly Boolean LazyLoadEndpoints; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Stage.cs b/src/Sdk/DTPipelines/Pipelines/Stage.cs deleted file mode 100644 index c94aab45c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Stage.cs +++ /dev/null @@ -1,208 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines.Validation; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class Stage : IGraphNode - { - public Stage() - { - } - - public Stage( - String name, - IList phases) - { - this.Name = name; - - if (phases?.Count > 0) - { - m_phases = new List(phases); - } - } - - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String DisplayName - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Condition - { - get; - set; - } - - public IList Variables - { - get - { - if (m_variables == null) - { - m_variables = new List(); - } - return m_variables; - } - } - - public IList Phases - { - get - { - if (m_phases == null) - { - m_phases = new List(); - } - return m_phases; - } - } - - public ISet DependsOn - { - get - { - if (m_dependsOn == null) - { - m_dependsOn = new HashSet(StringComparer.OrdinalIgnoreCase); - } - return m_dependsOn; - } - } - - void IGraphNode.Validate( - PipelineBuildContext context, - ValidationResult result) - { - // Default the condition to something reasonable if none is specified - if (String.IsNullOrEmpty(this.Condition)) - { - this.Condition = StageCondition.Default; - } - else - { - // Simply construct the condition and make sure the syntax and functions used are valid - var parsedCondition = new StageCondition(this.Condition); - } - - if (m_variables?.Count > 0) - { - var variablesCopy = new List(); - foreach (var variable in this.Variables) - { - if (variable is Variable simpleVariable) - { - // Do not allow phase overrides for certain variables. - if (Phase.s_nonOverridableVariables.Contains(simpleVariable.Name)) - { - continue; - } - } - else if (variable is VariableGroupReference groupVariable) - { - if (context.EnvironmentVersion < 2) - { - result.Errors.Add(new PipelineValidationError(PipelineStrings.StageVariableGroupNotSupported(this.Name, groupVariable))); - continue; - } - - result.ReferencedResources.VariableGroups.Add(groupVariable); - - if (context.BuildOptions.ValidateResources) - { - var variableGroup = context.ResourceStore.VariableGroups.Get(groupVariable); - if (variableGroup == null) - { - result.UnauthorizedResources.VariableGroups.Add(groupVariable); - result.Errors.Add(new PipelineValidationError(PipelineStrings.VariableGroupNotFoundForStage(this.Name, groupVariable))); - } - } - } - - variablesCopy.Add(variable); - } - - m_variables.Clear(); - m_variables.AddRange(variablesCopy); - } - - GraphValidator.Validate(context, result, PipelineStrings.JobNameWhenNoNameIsProvided, this.Name, this.Phases, Phase.GetErrorMessage); - } - - internal static String GetErrorMessage( - String code, - params Object[] values) - { - switch (code) - { - case PipelineConstants.NameInvalid: - // values[0] is the graph name which is null during stage graph validation - // values[1] is the stage name - return PipelineStrings.StageNameInvalid(values[1]); - - case PipelineConstants.NameNotUnique: - // values[0] is the graph name which is null during stage graph validation - // values[1] is the stage name - return PipelineStrings.StageNamesMustBeUnique(values[1]); - - case PipelineConstants.StartingPointNotFound: - return PipelineStrings.PipelineNotValidNoStartingStage(); - - case PipelineConstants.DependencyNotFound: - // values[0] is the graph name which is null during stage graph validation - // values[1] is the node name - // values[2] is the dependency node name - return PipelineStrings.StageDependencyNotFound(values[1], values[2]); - - case PipelineConstants.GraphContainsCycle: - // values[0] is the graph name which is null during stage graph validation - // values[1] is the node name - // values[2] is the dependency node name - return PipelineStrings.StageGraphCycleDetected(values[1], values[2]); - } - - throw new NotSupportedException(); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_dependsOn?.Count == 0) - { - m_dependsOn = null; - } - - if (m_phases?.Count == 0) - { - m_phases = null; - } - - if (m_variables?.Count == 0) - { - m_variables = null; - } - } - - [DataMember(Name = "Variables", EmitDefaultValue = false)] - private List m_variables; - - [DataMember(Name = "Phases", EmitDefaultValue = false)] - private List m_phases; - - [DataMember(Name = "DependsOn", EmitDefaultValue = false)] - private HashSet m_dependsOn; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/StageCondition.cs b/src/Sdk/DTPipelines/Pipelines/StageCondition.cs deleted file mode 100644 index 874fd9862..000000000 --- a/src/Sdk/DTPipelines/Pipelines/StageCondition.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Pipelines.Runtime; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class StageCondition : GraphCondition - { - public StageCondition(String condition) - : base(condition) - { - } - - public ConditionResult Evaluate(StageExecutionContext context) - { - var traceWriter = new ConditionTraceWriter(); - var evaluationResult = m_parsedCondition.Evaluate(traceWriter, context.SecretMasker, context, context.ExpressionOptions); - return new ConditionResult() { Value = evaluationResult.IsTruthy, Trace = traceWriter.Trace }; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Step.cs b/src/Sdk/DTPipelines/Pipelines/Step.cs index 7fe27dca3..8c2492eaa 100644 --- a/src/Sdk/DTPipelines/Pipelines/Step.cs +++ b/src/Sdk/DTPipelines/Pipelines/Step.cs @@ -7,9 +7,6 @@ namespace GitHub.DistributedTask.Pipelines { [DataContract] [KnownType(typeof(ActionStep))] - [KnownType(typeof(TaskStep))] - [KnownType(typeof(TaskTemplateStep))] - [KnownType(typeof(GroupStep))] [JsonConverter(typeof(StepConverter))] [EditorBrowsable(EditorBrowsableState.Never)] public abstract class Step @@ -69,20 +66,7 @@ namespace GitHub.DistributedTask.Pipelines [EditorBrowsable(EditorBrowsableState.Never)] public enum StepType { - [DataMember] - Task = 1, - - [DataMember] - TaskTemplate = 2, - - [DataMember] - Group = 3, - [DataMember] Action = 4, - - [DataMember] - [Obsolete("Deprecated", false)] - Script = 5, } } diff --git a/src/Sdk/DTPipelines/Pipelines/StepConverter.cs b/src/Sdk/DTPipelines/Pipelines/StepConverter.cs index d617d50c6..c6b9ad559 100644 --- a/src/Sdk/DTPipelines/Pipelines/StepConverter.cs +++ b/src/Sdk/DTPipelines/Pipelines/StepConverter.cs @@ -22,9 +22,9 @@ namespace GitHub.DistributedTask.Pipelines } public override object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, + JsonReader reader, + Type objectType, + Object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) @@ -33,26 +33,7 @@ namespace GitHub.DistributedTask.Pipelines } JObject value = JObject.Load(reader); - if (!value.TryGetValue("Type", StringComparison.OrdinalIgnoreCase, out JToken stepTypeValue)) - { - Step compatStepObject; - if (value.TryGetValue("Parameters", StringComparison.OrdinalIgnoreCase, out _)) - { - compatStepObject = new TaskTemplateStep(); - } - else - { - compatStepObject = new TaskStep(); - } - - using (var objectReader = value.CreateReader()) - { - serializer.Populate(objectReader, compatStepObject); - } - - return compatStepObject; - } - else + if (value.TryGetValue("Type", StringComparison.OrdinalIgnoreCase, out JToken stepTypeValue)) { StepType stepType; if (stepTypeValue.Type == JTokenType.Integer) @@ -70,18 +51,6 @@ namespace GitHub.DistributedTask.Pipelines case StepType.Action: stepObject = new ActionStep(); break; - - case StepType.Group: - stepObject = new GroupStep(); - break; - - case StepType.Task: - stepObject = new TaskStep(); - break; - - case StepType.TaskTemplate: - stepObject = new TaskTemplateStep(); - break; } using (var objectReader = value.CreateReader()) @@ -91,6 +60,10 @@ namespace GitHub.DistributedTask.Pipelines return stepObject; } + else + { + return null; + } } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) diff --git a/src/Sdk/DTPipelines/Pipelines/TaskCondition.cs b/src/Sdk/DTPipelines/Pipelines/TaskCondition.cs deleted file mode 100644 index 4be8abd11..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TaskCondition.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System; -using System.ComponentModel; -using System.Linq; -using System.Text; -using GitHub.DistributedTask.Expressions2; -using GitHub.DistributedTask.Expressions2.Sdk; -using GitHub.DistributedTask.Pipelines.Expressions; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class TaskCondition - { - public TaskCondition(String condition) - { - m_condition = condition ?? Default; - m_parser = new ExpressionParser(); - m_parsedCondition = m_parser.CreateTree(m_condition, new ConditionTraceWriter(), s_namedValueInfo, s_functionInfo); - m_requiresVariables = new Lazy(HasVariablesReference); - } - - /// - /// Gets the default condition if none is specified - /// - public static String Default - { - get - { - return "success()"; - } - } - - public Boolean RequiresVariables - { - get - { - return m_requiresVariables.Value; - } - } - - public ConditionResult Evaluate(JobExecutionContext context) - { - var traceWriter = new ConditionTraceWriter(); - var evaluationResult = m_parsedCondition.Evaluate(traceWriter, context.SecretMasker, context, context.ExpressionOptions); - return new ConditionResult() { Value = evaluationResult.IsTruthy, Trace = traceWriter.Trace }; - } - - private Boolean HasVariablesReference() - { - return false; - } - - private readonly String m_condition; - private readonly ExpressionParser m_parser; - private readonly IExpressionNode m_parsedCondition; - private readonly Lazy m_requiresVariables; - - private static readonly INamedValueInfo[] s_namedValueInfo = new INamedValueInfo[] - { - }; - - private static readonly IFunctionInfo[] s_functionInfo = new IFunctionInfo[] - { - new FunctionInfo("always", 0, 0), - new FunctionInfo("failure", 0, 0), - new FunctionInfo("cancelled", 0, 0), - new FunctionInfo("success", 0, 0), - }; - - private sealed class ConditionTraceWriter : ITraceWriter - { - public String Trace - { - get - { - return m_info.ToString(); - } - } - - public void Info(String message) - { - m_info.AppendLine(message); - } - - public void Verbose(String message) - { - // Not interested - } - - private StringBuilder m_info = new StringBuilder(); - } - - private sealed class AlwaysNode : Function - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - return true; - } - } - - private sealed class CancelledNode : Function - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - var conditionContext = context.State as JobExecutionContext; - return conditionContext.State == PipelineState.Canceling; - } - } - - private sealed class FailureNode : Function - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - var executionContext = context.State as JobExecutionContext; - if (executionContext.State != PipelineState.InProgress) - { - return false; - } - - // The variable should always be set into the environment for a job - if (!executionContext.Variables.TryGetValue(WellKnownDistributedTaskVariables.JobStatus, out var value) || - !Enum.TryParse(value.Value, true, out var result)) - { - return false; - } - - return result == TaskResult.Failed; - } - } - - private sealed class SuccessNode : Function - { - protected override Object EvaluateCore( - EvaluationContext context, - out ResultMemory resultMemory) - { - resultMemory = null; - var executionContext = context.State as JobExecutionContext; - if (executionContext.State != PipelineState.InProgress) - { - return false; - } - - // The variable should always be set into the environment for a job - if (!executionContext.Variables.TryGetValue(WellKnownDistributedTaskVariables.JobStatus, out var value) || - !Enum.TryParse(value.Value, true, out var result)) - { - return false; - } - - return result == TaskResult.Succeeded || result == TaskResult.SucceededWithIssues; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/TaskDefinitionExtensions.cs b/src/Sdk/DTPipelines/Pipelines/TaskDefinitionExtensions.cs deleted file mode 100644 index 5c68c5d97..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TaskDefinitionExtensions.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class TaskDefinitionExtensions - { - public static String ComputeDisplayName( - this TaskDefinition taskDefinition, - IDictionary inputs) - { - if (!String.IsNullOrEmpty(taskDefinition.InstanceNameFormat)) - { - return VariableUtility.ExpandVariables(taskDefinition.InstanceNameFormat, inputs); - } - else if (!String.IsNullOrEmpty(taskDefinition.FriendlyName)) - { - return taskDefinition.FriendlyName; - } - else - { - return taskDefinition.Name; - } - } - - /// - /// Returns the maximum of the two versions: the currentMinimum and the task's MinimumAgentVersion - /// - public static String GetMinimumAgentVersion( - this TaskDefinition taskDefinition, - String currentMinimum) - { - String minimumVersion; - - // If task.minAgentVersion > currentMin, this task needs a newer agent. So, return task.minAgentVersion - if (DemandMinimumVersion.CompareVersion(taskDefinition.MinimumAgentVersion, currentMinimum) > 0) - { - minimumVersion = taskDefinition.MinimumAgentVersion; - } - else - { - minimumVersion = currentMinimum; - } - - // If any of the task execution jobs requires Node10, return the minimum agent version that supports it - if (taskDefinition.RequiresNode10() && - DemandMinimumVersion.CompareVersion(s_node10MinAgentVersion, minimumVersion) > 0) - { - minimumVersion = s_node10MinAgentVersion; - } - - return minimumVersion; - } - - private static bool RequiresNode10( - this TaskDefinition taskDefinition) - { - return taskDefinition.PreJobExecution.Keys.Contains(s_node10, StringComparer.OrdinalIgnoreCase) || - taskDefinition.Execution.Keys.Contains(s_node10, StringComparer.OrdinalIgnoreCase) || - taskDefinition.PostJobExecution.Keys.Contains(s_node10, StringComparer.OrdinalIgnoreCase); - } - - private static string s_node10MinAgentVersion = "2.144.0"; - private static string s_node10 = "Node10"; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/TaskStep.cs b/src/Sdk/DTPipelines/Pipelines/TaskStep.cs deleted file mode 100644 index 61be80b0f..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TaskStep.cs +++ /dev/null @@ -1,177 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.ObjectTemplating.Tokens; -using GitHub.DistributedTask.WebApi; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class TaskStep : JobStep - { - [JsonConstructor] - public TaskStep() - { - } - - internal TaskStep(TaskInstance legacyTaskInstance) - { - this.ContinueOnError = new BooleanToken(null, null, null, legacyTaskInstance.ContinueOnError); - this.DisplayName = legacyTaskInstance.DisplayName; - this.Enabled = legacyTaskInstance.Enabled; - this.Id = legacyTaskInstance.InstanceId; - this.Name = legacyTaskInstance.RefName; - this.TimeoutInMinutes = new NumberToken(null, null, null, legacyTaskInstance.TimeoutInMinutes); - this.Reference = new TaskStepDefinitionReference() - { - Id = legacyTaskInstance.Id, - Name = legacyTaskInstance.Name, - Version = legacyTaskInstance.Version - }; - - if (!String.IsNullOrEmpty(legacyTaskInstance.Condition)) - { - this.Condition = legacyTaskInstance.Condition; - } - else if (legacyTaskInstance.AlwaysRun) - { - this.Condition = "succeededOrFailed()"; - } - else - { - this.Condition = "succeeded()"; - } - - foreach (var input in legacyTaskInstance.Inputs) - { - this.Inputs[input.Key] = input.Value; - } - - foreach (var env in legacyTaskInstance.Environment) - { - this.Environment[env.Key] = env.Value; - } - } - - private TaskStep(TaskStep taskToClone) - : base(taskToClone) - { - this.Reference = taskToClone.Reference?.Clone(); - - if (taskToClone.m_environment?.Count > 0) - { - m_environment = new Dictionary(taskToClone.m_environment, StringComparer.OrdinalIgnoreCase); - } - - if (taskToClone.m_inputs?.Count > 0) - { - m_inputs = new Dictionary(taskToClone.m_inputs, StringComparer.OrdinalIgnoreCase); - } - } - - public override StepType Type => StepType.Task; - - [DataMember] - public TaskStepDefinitionReference Reference - { - get; - set; - } - - public IDictionary Environment - { - get - { - if (m_environment == null) - { - m_environment = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_environment; - } - } - - public IDictionary Inputs - { - get - { - if (m_inputs == null) - { - m_inputs = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_inputs; - } - } - - public override Step Clone() - { - return new TaskStep(this); - } - - internal TaskInstance ToLegacyTaskInstance() - { - TaskInstance task = new TaskInstance() - { - AlwaysRun = String.Equals(this.Condition ?? String.Empty, "succeededOrFailed()", StringComparison.Ordinal), - Condition = this.Condition, - ContinueOnError = this.ContinueOnError?.AssertBoolean(null).Value ?? false, - DisplayName = this.DisplayName, - Enabled = this.Enabled, - InstanceId = this.Id, - RefName = this.Name, - TimeoutInMinutes = (Int32)(this.TimeoutInMinutes?.AssertNumber(null).Value ?? 0d), - Id = this.Reference.Id, - Name = this.Reference.Name, - Version = this.Reference.Version, - }; - - foreach (var env in this.Environment) - { - task.Environment[env.Key] = env.Value; - } - - foreach (var input in this.Inputs) - { - task.Inputs[input.Key] = input.Value; - } - - return task; - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_environment?.Count == 0) - { - m_environment = null; - } - - if (m_inputs?.Count == 0) - { - m_inputs = null; - } - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - if (m_environment != null) - { - m_environment = new Dictionary(m_environment, StringComparer.OrdinalIgnoreCase); - } - - if (m_inputs != null) - { - m_inputs = new Dictionary(m_inputs, StringComparer.OrdinalIgnoreCase); - } - } - - [DataMember(Name = "Environment", EmitDefaultValue = false)] - private IDictionary m_environment; - - [DataMember(Name = "Inputs", EmitDefaultValue = false)] - private IDictionary m_inputs; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/TaskStepDefinitionReference.cs b/src/Sdk/DTPipelines/Pipelines/TaskStepDefinitionReference.cs deleted file mode 100644 index b58762acf..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TaskStepDefinitionReference.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.WebApi; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class TaskStepDefinitionReference : ITaskDefinitionReference - { - [JsonConstructor] - public TaskStepDefinitionReference() - { - } - - private TaskStepDefinitionReference(TaskStepDefinitionReference referenceToClone) - { - this.Id = referenceToClone.Id; - this.Name = referenceToClone.Name; - this.Version = referenceToClone.Version; - } - - [DataMember] - public Guid Id - { - get; - set; - } - - [DataMember] - public String Name - { - get; - set; - } - - [DataMember] - public String Version - { - get; - set; - } - - public TaskStepDefinitionReference Clone() - { - return new TaskStepDefinitionReference(this); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/TaskStore.cs b/src/Sdk/DTPipelines/Pipelines/TaskStore.cs deleted file mode 100644 index ce27813a3..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TaskStore.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.Pipelines.Artifacts; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines -{ - /// - /// Provides a mechanism for efficient resolution of task specifications to specific versions of the tasks. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class TaskStore : ITaskStore - { - public TaskStore(params TaskDefinition[] tasks) - : this((IEnumerable)tasks) - { - } - - /// - /// Constructs a new TaskStore instance with the specified tasks. - /// - /// All tasks which should be made available for task resolution - public TaskStore( - IEnumerable tasks, - ITaskResolver resolver = null) - { - m_nameLookup = new Dictionary>>(StringComparer.OrdinalIgnoreCase); - m_tasks = new Dictionary>(); - Resolver = resolver; - - // Filter out legacy tasks with conflicting names. - // - // The PublishBuildArtifacts V0 task ID is different from PublishBuildArtifacts V1. - // Attempts to resolve the PublishBuildArtifacts task by name will result in name conflict. - // The PublishBuildArtfacts V0 task is not in use anymore. It can simply be removed from - // the list of tasks, and the naming conflict averted. - // - // Additional details: The PublishBuildArtifacts V0 split into two tasks: PublishBuildArtifacts V1 - // and CopyPublishBuildArtifacts V1. The CopyPublishBuildArtifacts V1 task retained the GUID and a - // new GUID was generated for PublishBuildArtifacts V0. The split happened before task-major-version-locking - // was implemented. Therefore, no definitions are using the old version. - tasks = WellKnownTaskDefinitions - .Concat(tasks?.Where(x => !(x.Id == s_publishBuildArtifacts_v0_ID && x.Version?.Major == 0)) ?? Enumerable.Empty()) - .ToList(); - - // Build a lookup of all task versions for a given task identifier - foreach (var task in tasks) - { - AddVersion(task); - } - - // Filter the tasks to the latest within each major version so we can provide a lookup by name - var latestTasksByMajorVersion = tasks.GroupBy(x => new { x.Id, x.Version.Major }).Select(x => x.OrderByDescending(y => y.Version).First()); - foreach (var task in latestTasksByMajorVersion) - { - // The name should never be null in production environments but just in case don't provide by-name lookup - // for tasks which don't provide one. - if (!String.IsNullOrEmpty(task.Name)) - { - // Add the name lookup. - IDictionary> tasksByIdLookup; - if (!m_nameLookup.TryGetValue(task.Name, out tasksByIdLookup)) - { - tasksByIdLookup = new Dictionary>(); - m_nameLookup.Add(task.Name, tasksByIdLookup); - } - - IList tasksById; - if (!tasksByIdLookup.TryGetValue(task.Id, out tasksById)) - { - tasksById = new List(); - tasksByIdLookup.Add(task.Id, tasksById); - } - - tasksById.Add(task); - - if (!String.IsNullOrEmpty(task.ContributionIdentifier)) - { - // Add the contribution-qualified-name lookup. - var qualifiedName = $"{task.ContributionIdentifier}.{task.Name}"; - if (!m_nameLookup.TryGetValue(qualifiedName, out tasksByIdLookup)) - { - tasksByIdLookup = new Dictionary>(); - m_nameLookup.Add(qualifiedName, tasksByIdLookup); - } - - if (!tasksByIdLookup.TryGetValue(task.Id, out tasksById)) - { - tasksById = new List(); - tasksByIdLookup.Add(task.Id, tasksById); - } - - tasksById.Add(task); - } - } - } - } - - public ITaskResolver Resolver - { - get; - } - - /// - /// Resolves a task from the store using the unqiue identifier and version. - /// - /// The unique identifier of the task - /// The version of the task which is desired - /// The closest matching task definition if found; otherwise, null - public TaskDefinition ResolveTask( - Guid taskId, - String versionSpec) - { - TaskDefinition task = null; - - // Treat missing version as "*" - if (String.IsNullOrEmpty(versionSpec)) - { - versionSpec = "*"; - } - - if (m_tasks.TryGetValue(taskId, out IDictionary tasks)) - { - var parsedSpec = TaskVersionSpec.Parse(versionSpec); - task = parsedSpec.Match(tasks.Values); - } - - // Read-thru on miss - if (task == null && Resolver != null) - { - task = Resolver.Resolve(taskId, versionSpec); - if (task != null) - { - AddVersion(task); - } - } - - return task; - } - - /// - /// Resolves a task from the store using the specified name and version. - /// - /// The name of the task - /// The version of the task which is desired - /// The closest matching task definition if found; otherwise, null - public TaskDefinition ResolveTask( - String name, - String versionSpec) - { - Guid taskIdentifier; - if (!Guid.TryParse(name, out taskIdentifier)) - { - IDictionary> nameLookup; - if (!m_nameLookup.TryGetValue(name, out nameLookup)) - { - return null; - } - - if (nameLookup.Count == 1) - { - // Exactly one task ID was resolved. - taskIdentifier = nameLookup.Keys.Single(); - } - else - { - // More than one task ID was resolved. - // Prefer in-the-box tasks over extension tasks. - var inTheBoxTaskIdentifiers = - nameLookup - .Where(pair => pair.Value.All(taskDefinition => String.IsNullOrEmpty(taskDefinition.ContributionIdentifier))) - .Select(pair => pair.Key) - .ToList(); - if (inTheBoxTaskIdentifiers.Count == 1) - { - taskIdentifier = inTheBoxTaskIdentifiers[0]; - } - else - { - // Otherwise, ambiguous. - throw new AmbiguousTaskSpecificationException(PipelineStrings.AmbiguousTaskSpecification(name, String.Join(", ", nameLookup.Keys))); - } - } - } - - return ResolveTask(taskIdentifier, versionSpec); - } - - private void AddVersion(TaskDefinition task) - { - IDictionary tasksByVersion; - if (!m_tasks.TryGetValue(task.Id, out tasksByVersion)) - { - tasksByVersion = new Dictionary(StringComparer.OrdinalIgnoreCase); - m_tasks.Add(task.Id, tasksByVersion); - } - - tasksByVersion[task.Version] = task; - } - - private IDictionary> m_tasks; - private IDictionary>> m_nameLookup; - - private static readonly Guid s_publishBuildArtifacts_v0_ID = new Guid("1d341bb0-2106-458c-8422-d00bcea6512a"); - - private static readonly TaskDefinition[] WellKnownTaskDefinitions = new[] - { - PipelineConstants.CheckoutTask, - PipelineArtifactConstants.DownloadTask, - }; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/TaskTemplateReference.cs b/src/Sdk/DTPipelines/Pipelines/TaskTemplateReference.cs deleted file mode 100644 index 532867d20..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TaskTemplateReference.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class TaskTemplateReference - { - public TaskTemplateReference() - { - } - - private TaskTemplateReference(TaskTemplateReference referenceToClone) - { - this.Id = referenceToClone.Id; - this.Name = referenceToClone.Name; - this.Version = referenceToClone.Version; - } - - [DataMember(EmitDefaultValue = false)] - public Guid Id - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Version - { - get; - set; - } - - public TaskTemplateReference Clone() - { - return new TaskTemplateReference(this); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/TaskTemplateStep.cs b/src/Sdk/DTPipelines/Pipelines/TaskTemplateStep.cs deleted file mode 100644 index 708d58455..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TaskTemplateStep.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class TaskTemplateStep : Step - { - public TaskTemplateStep() - { - } - - private TaskTemplateStep(TaskTemplateStep templateToClone) - : base(templateToClone) - { - this.Reference = templateToClone.Reference?.Clone(); - - if (templateToClone.m_parameters?.Count > 0) - { - m_parameters = new Dictionary(templateToClone.m_parameters, StringComparer.OrdinalIgnoreCase); - } - } - - public override StepType Type => StepType.TaskTemplate; - - public IDictionary Parameters - { - get - { - if (m_parameters == null) - { - m_parameters = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_parameters; - } - } - - [DataMember(EmitDefaultValue = false)] - public TaskTemplateReference Reference - { - get; - set; - } - - public override Step Clone() - { - return new TaskTemplateStep(this); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_parameters?.Count == 0) - { - m_parameters = null; - } - } - - [DataMember(Name = "Parameters", EmitDefaultValue = false)] - private IDictionary m_parameters; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/TaskTemplateStore.cs b/src/Sdk/DTPipelines/Pipelines/TaskTemplateStore.cs deleted file mode 100644 index a48762ef7..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TaskTemplateStore.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class TaskTemplateStore : ITaskTemplateStore - { - public TaskTemplateStore(IList resolvers) - { - m_resolvers = new List(resolvers ?? Enumerable.Empty()); - } - - public void AddProvider(ITaskTemplateResolver resolver) - { - ArgumentUtility.CheckForNull(resolver, nameof(resolver)); - m_resolvers.Add(resolver); - } - - public IEnumerable ResolveTasks(TaskTemplateStep step) - { - var resolver = m_resolvers.FirstOrDefault(x => x.CanResolve(step.Reference)); - if (resolver == null) - { - throw new NotSupportedException(PipelineStrings.TaskTemplateNotSupported(step.Reference.Name, step.Reference.Version)); - } - - return resolver.ResolveTasks(step); - } - - private readonly IList m_resolvers; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/TimelineRecordIdGenerator.cs b/src/Sdk/DTPipelines/Pipelines/TimelineRecordIdGenerator.cs deleted file mode 100644 index b6a54e863..000000000 --- a/src/Sdk/DTPipelines/Pipelines/TimelineRecordIdGenerator.cs +++ /dev/null @@ -1,189 +0,0 @@ -using System; -using System.ComponentModel; -using System.Text; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public static class TimelineRecordIdGenerator - { - public static Guid GetId(String refName) - { - byte[] bytes = Encoding.BigEndianUnicode.GetBytes(refName); - var sha1ForNonSecretPurposes = new Sha1ForNonSecretPurposes(); - sha1ForNonSecretPurposes.Start(); - sha1ForNonSecretPurposes.Append(namespaceBytes); - sha1ForNonSecretPurposes.Append(bytes); - Array.Resize(ref bytes, 16); - sha1ForNonSecretPurposes.Finish(bytes); - bytes[7] = (byte)((bytes[7] & 15) | 80); - return new Guid(bytes); - } - - // Value of 'DistributedTask.Pipelines' encoded without the namespace bytes on the front - private static readonly byte[] namespaceBytes = new byte[] - { - 83, - 55, - 27, - 127, - 212, - 97, - 75, - 93, - 197, - 226, - 39, - 51, - 83, - 35, - 223, - 36 - }; - - private struct Sha1ForNonSecretPurposes - { - private long length; - - private uint[] w; - - private int pos; - - public void Start() - { - if (this.w == null) - { - this.w = new uint[85]; - } - this.length = 0L; - this.pos = 0; - this.w[80] = 1732584193u; - this.w[81] = 4023233417u; - this.w[82] = 2562383102u; - this.w[83] = 271733878u; - this.w[84] = 3285377520u; - } - - public void Append(byte input) - { - this.w[this.pos / 4] = (this.w[this.pos / 4] << 8 | (uint)input); - int arg_35_0 = 64; - int num = this.pos + 1; - this.pos = num; - if (arg_35_0 == num) - { - this.Drain(); - } - } - - public void Append(byte[] input) - { - for (int i = 0; i < input.Length; i++) - { - byte input2 = input[i]; - this.Append(input2); - } - } - - public void Finish(byte[] output) - { - long num = this.length + (long)(8 * this.pos); - this.Append(128); - while (this.pos != 56) - { - this.Append(0); - } - this.Append((byte)(num >> 56)); - this.Append((byte)(num >> 48)); - this.Append((byte)(num >> 40)); - this.Append((byte)(num >> 32)); - this.Append((byte)(num >> 24)); - this.Append((byte)(num >> 16)); - this.Append((byte)(num >> 8)); - this.Append((byte)num); - int num2 = (output.Length < 20) ? output.Length : 20; - for (int num3 = 0; num3 != num2; num3++) - { - uint num4 = this.w[80 + num3 / 4]; - output[num3] = (byte)(num4 >> 24); - this.w[80 + num3 / 4] = num4 << 8; - } - } - - private void Drain() - { - for (int num = 16; num != 80; num++) - { - this.w[num] = Rol1(this.w[num - 3] ^ this.w[num - 8] ^ this.w[num - 14] ^ this.w[num - 16]); - } - uint num2 = this.w[80]; - uint num3 = this.w[81]; - uint num4 = this.w[82]; - uint num5 = this.w[83]; - uint num6 = this.w[84]; - for (int num7 = 0; num7 != 20; num7++) - { - uint num8 = (num3 & num4) | (~num3 & num5); - uint num9 = Rol5(num2) + num8 + num6 + 1518500249u + this.w[num7]; - num6 = num5; - num5 = num4; - num4 = Rol30(num3); - num3 = num2; - num2 = num9; - } - for (int num10 = 20; num10 != 40; num10++) - { - uint num11 = num3 ^ num4 ^ num5; - uint num12 = Rol5(num2) + num11 + num6 + 1859775393u + this.w[num10]; - num6 = num5; - num5 = num4; - num4 = Rol30(num3); - num3 = num2; - num2 = num12; - } - for (int num13 = 40; num13 != 60; num13++) - { - uint num14 = (num3 & num4) | (num3 & num5) | (num4 & num5); - uint num15 = Rol5(num2) + num14 + num6 + 2400959708u + this.w[num13]; - num6 = num5; - num5 = num4; - num4 = Rol30(num3); - num3 = num2; - num2 = num15; - } - for (int num16 = 60; num16 != 80; num16++) - { - uint num17 = num3 ^ num4 ^ num5; - uint num18 = Rol5(num2) + num17 + num6 + 3395469782u + this.w[num16]; - num6 = num5; - num5 = num4; - num4 = Rol30(num3); - num3 = num2; - num2 = num18; - } - this.w[80] += num2; - this.w[81] += num3; - this.w[82] += num4; - this.w[83] += num5; - this.w[84] += num6; - this.length += 512L; - this.pos = 0; - } - - private static uint Rol1(uint input) - { - return input << 1 | input >> 31; - } - - private static uint Rol5(uint input) - { - return input << 5 | input >> 27; - } - - private static uint Rol30(uint input) - { - return input << 30 | input >> 2; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Validation/GraphValidator.cs b/src/Sdk/DTPipelines/Pipelines/Validation/GraphValidator.cs deleted file mode 100644 index 8a1d7535f..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Validation/GraphValidator.cs +++ /dev/null @@ -1,186 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace GitHub.DistributedTask.Pipelines.Validation -{ - internal static class GraphValidator - { - internal delegate String ErrorFormatter(String code, params Object[] values); - - internal static void Validate( - PipelineBuildContext context, - ValidationResult result, - Func getBaseRefName, - String graphName, - IList nodes, - ErrorFormatter formatError) where T : class, IGraphNode - { - var unnamedNodes = new List(); - var startingNodes = new List(); - var knownNames = new HashSet(StringComparer.OrdinalIgnoreCase); - Boolean hasDuplicateName = false; - foreach (var node in nodes) - { - if (!String.IsNullOrEmpty(node.Name)) - { - if (!NameValidation.IsValid(node.Name, context.BuildOptions.AllowHyphenNames)) - { - result.Errors.Add(new PipelineValidationError(PipelineConstants.NameInvalid, formatError(PipelineConstants.NameInvalid, graphName, node.Name))); - } - else if (!knownNames.Add(node.Name)) - { - hasDuplicateName = true; - result.Errors.Add(new PipelineValidationError(PipelineConstants.NameNotUnique, formatError(PipelineConstants.NameNotUnique, graphName, node.Name))); - } - } - else - { - unnamedNodes.Add(node); - } - - if (node.DependsOn.Count == 0) - { - startingNodes.Add(node); - } - } - - Int32 nodeCounter = 1; - foreach (var unnamedNode in unnamedNodes) - { - var candidateName = getBaseRefName(nodeCounter); - while (!knownNames.Add(candidateName)) - { - nodeCounter++; - candidateName = getBaseRefName(nodeCounter); - } - - nodeCounter++; - unnamedNode.Name = candidateName; - } - - // Now that we have generated default names we can validate and provide error messages - foreach (var node in nodes) - { - node.Validate(context, result); - } - - if (startingNodes.Count == 0) - { - result.Errors.Add(new PipelineValidationError(PipelineConstants.StartingPointNotFound, formatError(PipelineConstants.StartingPointNotFound, graphName))); - return; - } - - // Skip validating the graph if duplicate phase names - if (hasDuplicateName) - { - return; - } - - var nodesToVisit = new Queue(startingNodes); - var nodeLookup = nodes.ToDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase); - var unsatisfiedDependencies = nodes.ToDictionary(x => x.Name, x => new List(x.DependsOn), StringComparer.OrdinalIgnoreCase); - var visitedNames = new HashSet(StringComparer.OrdinalIgnoreCase); - while (nodesToVisit.Count > 0) - { - var currentPhase = nodesToVisit.Dequeue(); - - visitedNames.Add(currentPhase.Name); - - // Now figure out which nodes would start as a result of this - foreach (var nodeState in unsatisfiedDependencies) - { - for (Int32 i = nodeState.Value.Count - 1; i >= 0; i--) - { - if (nodeState.Value[i].Equals(currentPhase.Name, StringComparison.OrdinalIgnoreCase)) - { - nodeState.Value.RemoveAt(i); - if (nodeState.Value.Count == 0) - { - nodesToVisit.Enqueue(nodeLookup[nodeState.Key]); - } - } - } - } - } - - // There are nodes which are never going to execute, which is generally caused by a cycle in the graph. - var unreachableNodeCount = nodes.Count - visitedNames.Count; - if (unreachableNodeCount > 0) - { - foreach (var unreachableNode in unsatisfiedDependencies.Where(x => x.Value.Count > 0)) - { - foreach (var unsatisifedDependency in unreachableNode.Value) - { - if (!nodeLookup.ContainsKey(unsatisifedDependency)) - { - result.Errors.Add(new PipelineValidationError(PipelineConstants.DependencyNotFound, formatError(PipelineConstants.DependencyNotFound, graphName, unreachableNode.Key, unsatisifedDependency))); - } - else - { - result.Errors.Add(new PipelineValidationError(PipelineConstants.GraphContainsCycle, formatError(PipelineConstants.GraphContainsCycle, graphName, unreachableNode.Key, unsatisifedDependency))); - } - } - } - } - } - - /// - /// Traverses a validated graph running a callback on each node in the order it would execute at runtime. - /// - /// The type of graph node - /// The full set of nodes in the graph - /// A callback which is invoked for each node as execution would begin - internal static void Traverse( - IList nodes, - Action> handleNode) where T : class, IGraphNode - { - var nodeLookup = nodes.ToDictionary(x => x.Name, x => new GraphTraversalState(x), StringComparer.OrdinalIgnoreCase); - var pendingNodes = nodes.ToDictionary(x => x.Name, x => new List(x.DependsOn), StringComparer.OrdinalIgnoreCase); - var nodesToVisit = new Queue>(nodes.Where(x => x.DependsOn.Count == 0).Select(x => new GraphTraversalState(x))); - while (nodesToVisit.Count > 0) - { - var currentNode = nodesToVisit.Dequeue(); - - // Invoke the callback on this node since it would execute next. The dependencies provided to the - // callback is a fully recursive set of all dependencies for context on how a node would execute - // at runtime. - handleNode(currentNode.Node, currentNode.Dependencies); - - // Now figure out which nodes would start as a result of this - foreach (var nodeState in pendingNodes) - { - for (Int32 i = nodeState.Value.Count - 1; i >= 0; i--) - { - if (nodeState.Value[i].Equals(currentNode.Node.Name, StringComparison.OrdinalIgnoreCase)) - { - nodeState.Value.RemoveAt(i); - - // Make sure we include the completed nodes recursive dependency set into the dependent - // node recursive dependency set for accurate hit detection. - var traversalState = nodeLookup[nodeState.Key]; - traversalState.Dependencies.Add(currentNode.Node.Name); - traversalState.Dependencies.UnionWith(currentNode.Dependencies); - - if (nodeState.Value.Count == 0) - { - nodesToVisit.Enqueue(traversalState); - } - } - } - } - } - } - - private class GraphTraversalState where T : class, IGraphNode - { - public GraphTraversalState(T node) - { - this.Node = node; - } - - public T Node { get; } - public ISet Dependencies { get; } = new HashSet(StringComparer.OrdinalIgnoreCase); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Validation/IInputValidator.cs b/src/Sdk/DTPipelines/Pipelines/Validation/IInputValidator.cs deleted file mode 100644 index c517c740e..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Validation/IInputValidator.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.ComponentModel; - -namespace GitHub.DistributedTask.Pipelines.Validation -{ - /// - /// Provides a contract validators must implement to participate in input validation. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public interface IInputValidator - { - /// - /// Validates the input value using the provided context. - /// - /// The current input validation context - /// A result which indicates success or failure of the validation in addition to detailed reason on failure - InputValidationResult Validate(InputValidationContext context); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Validation/InputValidationContext.cs b/src/Sdk/DTPipelines/Pipelines/Validation/InputValidationContext.cs deleted file mode 100644 index 61ce8c88a..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Validation/InputValidationContext.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Expressions; -using GitHub.DistributedTask.Logging; - -namespace GitHub.DistributedTask.Pipelines.Validation -{ - /// - /// Provides the necessary context for performing input value validation. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class InputValidationContext - { - /// - /// Gets or sets an expression which should be used to validate . - /// - [DataMember(EmitDefaultValue = false)] - public String Expression - { - get; - set; - } - - /// - /// Gets or sets a value indicating whether or not to evaluate the expression using . - /// - [DataMember(EmitDefaultValue = false)] - public Boolean Evaluate - { - get; - set; - } - - /// - /// Gets or sets the options used during expression evalation. - /// - public EvaluationOptions EvaluationOptions - { - get; - set; - } - - /// - /// Gets or sets the secret masker implementation. - /// - public ISecretMasker SecretMasker - { - get; - set; - } - - /// - /// Gets or sets the trace writer implementation. - /// - public ITraceWriter TraceWriter - { - get; - set; - } - - /// - /// Gets or sets the value which should be validated. - /// - [DataMember(EmitDefaultValue = false)] - public String Value - { - get; - set; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Validation/InputValidationResult.cs b/src/Sdk/DTPipelines/Pipelines/Validation/InputValidationResult.cs deleted file mode 100644 index f7ce3ad0c..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Validation/InputValidationResult.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines.Validation -{ - /// - /// Provides information about the result of input validation. - /// - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class InputValidationResult - { - public InputValidationResult() - { - } - - /// - /// Gets or sets a value indicating whether or not the input value is valid. - /// - [DataMember(EmitDefaultValue = false)] - public Boolean IsValid - { - get; - set; - } - - /// - /// Gets or sets a value indicating a detailed reason the input value is not valid. - /// - [DataMember(EmitDefaultValue = false)] - public String Reason - { - get; - set; - } - - /// - /// Provides a convenience property to return successful validation results. - /// - public static readonly InputValidationResult Succeeded = new InputValidationResult { IsValid = true }; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Validation/InputValidator.cs b/src/Sdk/DTPipelines/Pipelines/Validation/InputValidator.cs deleted file mode 100644 index 9cfe8ce73..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Validation/InputValidator.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.ComponentModel; -using GitHub.DistributedTask.Expressions; -using GitHub.DistributedTask.Pipelines.Expressions; -using GitHub.DistributedTask.WebApi; - -namespace GitHub.DistributedTask.Pipelines.Validation -{ - /// - /// Provides n validator implementation for task inputs. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public class InputValidator : IInputValidator - { - public InputValidationResult Validate(InputValidationContext context) - { - if (String.IsNullOrEmpty(context.Expression)) - { - return InputValidationResult.Succeeded; - } - - var result = new InputValidationResult(); - try - { - var parser = new ExpressionParser(); - var tree = parser.CreateTree(context.Expression, context.TraceWriter, namedValues: InputValidationConstants.NamedValues, functions: InputValidationConstants.Functions); - if (context.Evaluate) - { - result.IsValid = tree.Evaluate(context.TraceWriter, context.SecretMasker, context, context.EvaluationOptions); - } - else - { - result.IsValid = true; - } - } - catch (Exception ex) when (ex is ParseException || ex is RegularExpressionInvalidOptionsException || ex is NotSupportedException) - { - result.Reason = ex.Message; - } - - return result; - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Validation/ScriptTaskValidator.cs b/src/Sdk/DTPipelines/Pipelines/Validation/ScriptTaskValidator.cs deleted file mode 100644 index 52452096d..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Validation/ScriptTaskValidator.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text.RegularExpressions; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines.Validation -{ - /// - /// Validates script tasks for bad tokens. For best performance, create one instance and reuse - this is - /// thread safe. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class ScriptTaskValidator - { - /// - /// If supplied, combined with to form a single set of bad tokens. - /// - public ScriptTaskValidator(IBadTokenProvider clientTokenPrv = null) - { - var regexToMatch = new HashSet(RegexPatternComparer.Instance); - var tokenToMatch = new HashSet(StringComparer.OrdinalIgnoreCase); - - var tokenPrvs = new List(2) { BaseBadTokenProvider.Instance }; - if (clientTokenPrv != null) - { - tokenPrvs.Add(clientTokenPrv); - } - - foreach (IBadTokenProvider tokenPrv in tokenPrvs) - { - foreach (string pattern in tokenPrv.GetRegexPatternsToMatch()) - { - regexToMatch.Add( - new Regex(pattern, RegexOptions.Compiled, matchTimeout: TimeSpan.FromMilliseconds(100))); - } - - foreach (string staticToken in tokenPrv.GetStaticTokensToMatch()) - { - tokenToMatch.Add(staticToken); - } - } - - m_regexesToMatch = regexToMatch.ToArray(); - m_stringsToMatch = tokenToMatch.ToArray(); - } - - /// - /// Check a string for tokens containing "banned" patterns. This method is thread safe. - /// - public bool HasBadParamOrArgument( - string exeAndArgs, - out string matchedPattern, - out string matchedToken) - { - ArgumentUtility.CheckForNull(exeAndArgs, nameof(exeAndArgs)); - - string[] args = exeAndArgs.Split(); - - // Using for loops b/c they are measurably faster than foreach and this is n^2 - for (int i = 0; i < args.Length; i++) - { - string arg = args[i]; - - // Check static matches - for (int j = 0; j < m_stringsToMatch.Length; j++) - { - string toTest = m_stringsToMatch[j]; - if (arg.IndexOf(toTest, StringComparison.OrdinalIgnoreCase) >= 0) - { - matchedPattern = toTest; - matchedToken = arg; - - return true; - } - } - - // Check regexes - for (int j = 0; j < m_regexesToMatch.Length; j++) - { - Regex toTest = m_regexesToMatch[j]; - if (toTest.IsMatch(arg)) - { - matchedPattern = toTest.ToString(); - matchedToken = arg; - - return true; - } - } - } - - matchedPattern = null; - matchedToken = null; - return false; - } - - // These are arrays for max perf when enumerating/indexing - private readonly Regex[] m_regexesToMatch; - private readonly string[] m_stringsToMatch; - - public interface IBadTokenProvider - { - IEnumerable GetRegexPatternsToMatch(); - - IEnumerable GetStaticTokensToMatch(); - } - - /// - /// Static set of bad tokens we know about. - /// - private sealed class BaseBadTokenProvider : IBadTokenProvider - { - private BaseBadTokenProvider() - { - } - - public IEnumerable GetRegexPatternsToMatch() - { - // https://en.wikipedia.org/wiki/Base58 - const string base58charPattern = "[1-9a-km-zA-HJ-NP-Z]"; - - // We expect arguments to begin with whitespace (i.e. --config-option bla) or an = (i.e. - // --config-option=bla). If whitespace, we'll split the string so there is none to start. - const string beginTokenDelimiter = "(^|=)"; - - // We always expect arguments to end with whitespace, so any match will be the end of the string - const string endTokenDelimiter = "$"; - - string wrapInDelimeters(string argument) - { - return beginTokenDelimiter + argument + endTokenDelimiter; - } - - // Avoid patterns than can cause catastrophic backtracking for perf reasons - // https://www.regular-expressions.info/catastrophic.html - return new[] - { - // Monero wallets. See https://moneroaddress.org/ - // http://monero.wikia.com/wiki/Address_validation - wrapInDelimeters("4" + base58charPattern + "{94}"), - wrapInDelimeters("4" + base58charPattern + "{105}"), - - // Bitcoin wallets. See https://en.bitcoin.it/wiki/Address - // Starts with 1 or 3, total 33-35 base58 chars - wrapInDelimeters("[1-3]" + base58charPattern + "{32,34}"), - // Starts with bc[1-16], then 39(?) to 87 (90-3) base32 chars - // See: https://en.bitcoin.it/wiki/Bech32 - wrapInDelimeters("bc[0-9]{1,2}([0-9a-zA-Z]){39}"), - wrapInDelimeters("bc[0-9]{1,2}([0-9a-zA-Z]){59}"), - }; - } - - public IEnumerable GetStaticTokensToMatch() - { - return new[] - { - // Begin known mining pools - "xmr.suprnova.cc", - "MoneroOcean.stream", - "supportXMR.com", - "xmr.nanopool.org", - "monero.hashvault.pro", - "MoriaXMR.com", - "xmrpool.", - "minergate.com", - "viaxmr.com", - "xmr.suprnova.cc", - // End known mining pools - - // Probable mining argument - "--donate-level", - - // Other probable mining processes - "cpuminer", - "cryptonight", - "sgminer", - "xmrig", - "nheqminer" - }; - } - - public static readonly IBadTokenProvider Instance = new BaseBadTokenProvider(); - } - - private sealed class RegexPatternComparer : IEqualityComparer - { - private RegexPatternComparer() - { - } - - public bool Equals(Regex x, Regex y) => x.ToString() == y.ToString(); - public int GetHashCode(Regex obj) => obj.GetHashCode(); - - public static readonly IEqualityComparer Instance = new RegexPatternComparer(); - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Validation/ValidationResult.cs b/src/Sdk/DTPipelines/Pipelines/Validation/ValidationResult.cs deleted file mode 100644 index 00ed51cd9..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Validation/ValidationResult.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines.Validation -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class ValidationResult - { - public PipelineEnvironment Environment - { - get; - internal set; - } - - public IList Errors - { - get - { - if (m_errors == null) - { - m_errors = new List(); - } - return m_errors; - } - } - - public PipelineResources ReferencedResources - { - get - { - if (m_referencedResources == null) - { - m_referencedResources = new PipelineResources(); - } - return m_referencedResources; - } - } - - public PipelineResources UnauthorizedResources - { - get - { - if (m_unauthorizedResources == null) - { - m_unauthorizedResources = new PipelineResources(); - } - return m_unauthorizedResources; - } - } - - internal void AddQueueReference( - Int32 id, - String name) - { - if (id != 0) - { - this.ReferencedResources.Queues.Add(new AgentQueueReference { Id = id }); - } - else if (!String.IsNullOrEmpty(name)) - { - this.ReferencedResources.Queues.Add(new AgentQueueReference { Name = name }); - } - } - - internal void AddPoolReference( - Int32 id, - String name) - { - if (id != 0) - { - this.ReferencedResources.Pools.Add(new AgentPoolReference { Id = id }); - } - else if (!String.IsNullOrEmpty(name)) - { - this.ReferencedResources.Pools.Add(new AgentPoolReference { Name = name }); - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_errors?.Count == 0) - { - m_errors = null; - } - - if (m_referencedResources?.Count == 0) - { - m_referencedResources = null; - } - - if (m_unauthorizedResources?.Count == 0) - { - m_unauthorizedResources = null; - } - } - - [DataMember(Name = "Errors", EmitDefaultValue = false)] - private List m_errors; - - [DataMember(Name = "ReferencedResources", EmitDefaultValue = false)] - private PipelineResources m_referencedResources; - - [DataMember(Name = "UnauthorizedResources", EmitDefaultValue = false)] - private PipelineResources m_unauthorizedResources; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/Variable.cs b/src/Sdk/DTPipelines/Pipelines/Variable.cs deleted file mode 100644 index 6b99a0321..000000000 --- a/src/Sdk/DTPipelines/Pipelines/Variable.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class Variable : IVariable - { - public Variable() - { - } - - private Variable(Variable variableToClone) - { - this.Name = variableToClone.Name; - this.Secret = variableToClone.Secret; - this.Value = variableToClone.Value; - } - - [DataMember] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean Secret - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Value - { - get; - set; - } - - public Variable Clone() - { - return new Variable(this); - } - - VariableType IVariable.Type => VariableType.Inline; - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/VariableGroupReference.cs b/src/Sdk/DTPipelines/Pipelines/VariableGroupReference.cs deleted file mode 100644 index 46e98b82f..000000000 --- a/src/Sdk/DTPipelines/Pipelines/VariableGroupReference.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class VariableGroupReference : ResourceReference, IVariable - { - public VariableGroupReference() - { - } - - private VariableGroupReference(VariableGroupReference referenceToCopy) - : base(referenceToCopy) - { - this.Id = referenceToCopy.Id; - this.GroupType = referenceToCopy.GroupType; - this.SecretStore = referenceToCopy.SecretStore?.Clone(); - } - - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String GroupType - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public SecretStoreConfiguration SecretStore - { - get; - set; - } - - public VariableGroupReference Clone() - { - return new VariableGroupReference(this); - } - - public override String ToString() - { - return base.ToString() ?? this.Id.ToString(); - } - - [DataMember(Name = nameof(Type))] - VariableType IVariable.Type - { - get - { - return VariableType.Group; - } - } - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/VariableGroupStore.cs b/src/Sdk/DTPipelines/Pipelines/VariableGroupStore.cs deleted file mode 100644 index 3ea48d876..000000000 --- a/src/Sdk/DTPipelines/Pipelines/VariableGroupStore.cs +++ /dev/null @@ -1,187 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using GitHub.DistributedTask.Pipelines.Runtime; -using GitHub.DistributedTask.WebApi; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.Pipelines -{ - [EditorBrowsable(EditorBrowsableState.Never)] - public class VariableGroupStore : IVariableGroupStore - { - public VariableGroupStore( - IList resources, - IVariableGroupResolver resolver = null, - params IVariableValueProvider[] valueProviders) - { - this.Resolver = resolver; - Add(resources?.ToArray()); - - if (valueProviders?.Length > 0) - { - m_valueProviders = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (var valueProvider in valueProviders) - { - if (!m_valueProviders.TryAdd(valueProvider.GroupType, valueProvider)) - { - throw new ArgumentException($"Group type {valueProvider.GroupType} cannot have more than one provider", nameof(valueProviders)); - } - } - } - } - - /// - /// Get the variable group resolver configured for this store. - /// - public IVariableGroupResolver Resolver - { - get; - } - - public IList GetAuthorizedReferences() - { - return m_resourcesById.Values.Select(x => new VariableGroupReference { Id = x.Id }).ToList(); - } - - public VariableGroup Get(VariableGroupReference reference) - { - if (reference == null) - { - return null; - } - - var referenceId = reference.Id; - var referenceName = reference.Name?.Literal; - if (referenceId == 0 && String.IsNullOrEmpty(referenceName)) - { - return null; - } - - VariableGroup authorizedResource = null; - if (referenceId != 0) - { - if (m_resourcesById.TryGetValue(referenceId, out authorizedResource)) - { - return authorizedResource; - } - } - else if (!String.IsNullOrEmpty(referenceName)) - { - if (m_resourcesByName.TryGetValue(referenceName, out List matchingResources)) - { - if (matchingResources.Count > 1) - { - throw new AmbiguousResourceSpecificationException(PipelineStrings.AmbiguousVariableGroupSpecification(referenceName)); - } - - return matchingResources[0]; - } - } - - // If we have an authorizer then attempt to authorize the reference for use - authorizedResource = this.Resolver?.Resolve(reference); - if (authorizedResource != null) - { - Add(authorizedResource); - } - - return authorizedResource; - } - - public IList GetPreSteps( - IPipelineContext context, - IReadOnlyList steps) - { - if (context.ReferencedResources.VariableGroups.Count == 0) - { - return null; - } - - // If the environment version is 1 and it's a build context we should inject - if (context.EnvironmentVersion < 2 && context is PipelineExecutionContext) - { - return null; - } - - var newSteps = new List(); - foreach (var group in context.ReferencedResources.VariableGroups.Where(x => x.SecretStore != null && x.SecretStore.Keys.Count > 0)) - { - // Only inject a task if the provider supports task injection for the current context - var valueProvider = GetValueProvider(group); - if (valueProvider != null && !valueProvider.ShouldGetValues(context)) - { - newSteps.AddRangeIfRangeNotNull(valueProvider.GetSteps(context, group, group.SecretStore.Keys)); - } - } - - return newSteps; - } - - public Dictionary> GetPostTaskSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new Dictionary>(); - } - - public IList GetPostSteps( - IPipelineContext context, - IReadOnlyList steps) - { - return new List(); - } - - public Boolean ResolveStep( - IPipelineContext context, - JobStep step, - out IList resolvedSteps) - { - resolvedSteps = new List(); - return false; - } - - /// - /// Gets the value provider which may be used to retrieve values for the variable group from the data store. - /// - /// The target variable group - /// A provider suitable for retrieving values from the variable group - public IVariableValueProvider GetValueProvider(VariableGroupReference group) - { - if (m_valueProviders != null && m_valueProviders.TryGetValue(group.GroupType, out var valueProvider)) - { - return valueProvider; - } - return null; - } - - private void Add(params VariableGroup[] resources) - { - if (resources?.Length > 0) - { - foreach (var resource in resources) - { - if (m_resourcesById.TryGetValue(resource.Id, out _)) - { - continue; - } - - m_resourcesById.Add(resource.Id, resource); - - if (!m_resourcesByName.TryGetValue(resource.Name, out List resourcesByName)) - { - resourcesByName = new List(); - m_resourcesByName.Add(resource.Name, resourcesByName); - } - - resourcesByName.Add(resource); - } - } - } - - private readonly Dictionary m_valueProviders; - private readonly Dictionary m_resourcesById = new Dictionary(); - private readonly Dictionary> m_resourcesByName = new Dictionary>(StringComparer.OrdinalIgnoreCase); - } -} diff --git a/src/Sdk/DTPipelines/Pipelines/WorkspaceMapping.cs b/src/Sdk/DTPipelines/Pipelines/WorkspaceMapping.cs deleted file mode 100644 index fb193dd5d..000000000 --- a/src/Sdk/DTPipelines/Pipelines/WorkspaceMapping.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.Pipelines -{ - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public class WorkspaceMapping - { - /// - /// The map/cloak in tfvc. - /// - [DataMember(EmitDefaultValue = false)] - public Boolean Exclude - { - get; - set; - } - - /// - /// The server path. - /// - [DataMember(EmitDefaultValue = false)] - public String ServerPath - { - get; - set; - } - - /// - /// The local path. - /// - [DataMember(EmitDefaultValue = false)] - public String LocalPath - { - get; - set; - } - - /// - /// The revision in svn. - /// - [DataMember(EmitDefaultValue = false)] - public String Revision - { - get; - set; - } - - /// - /// The depth in svn. - /// - [DataMember(EmitDefaultValue = false)] - public Int32 Depth - { - get; - set; - } - - /// - /// Indicates whether to ignore externals in svn. - /// - [DataMember(EmitDefaultValue = false)] - public Boolean IgnoreExternals - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/AgentJobRequestMessage.cs b/src/Sdk/DTWebApi/WebApi/AgentJobRequestMessage.cs deleted file mode 100644 index 292e4077d..000000000 --- a/src/Sdk/DTWebApi/WebApi/AgentJobRequestMessage.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Runtime.Serialization; -using GitHub.Services.WebApi; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - - public sealed class AgentJobRequestMessage : JobRequestMessage - { - [JsonConstructor] - internal AgentJobRequestMessage() : base(JobRequestMessageTypes.AgentJobRequest) - { - } - - public AgentJobRequestMessage( - TaskOrchestrationPlanReference plan, - TimelineReference timeline, - Guid jobId, - String jobName, - String jobRefName, - JobEnvironment environment, - IEnumerable tasks) - : base(JobRequestMessageTypes.AgentJobRequest, plan, timeline, jobId, jobName, jobRefName, environment) - { - m_tasks = new List(tasks); - } - - [DataMember] - public Int64 RequestId - { - get; - internal set; - } - - [DataMember] - public Guid LockToken - { - get; - internal set; - } - - [DataMember] - public DateTime LockedUntil - { - get; - internal set; - } - - public ReadOnlyCollection Tasks - { - get - { - if (m_tasks == null) - { - m_tasks = new List(); - } - return m_tasks.AsReadOnly(); - } - } - - public TaskAgentMessage GetAgentMessage() - { - var body = JsonUtility.ToString(this); - - return new TaskAgentMessage - { - Body = body, - MessageType = JobRequestMessageTypes.AgentJobRequest - }; - } - - [DataMember(Name = "Tasks", EmitDefaultValue = false)] - private List m_tasks; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/AuditAction.cs b/src/Sdk/DTWebApi/WebApi/AuditAction.cs deleted file mode 100644 index e133be9d2..000000000 --- a/src/Sdk/DTWebApi/WebApi/AuditAction.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace GitHub.DistributedTask.WebApi -{ - using System.Runtime.Serialization; - - public enum AuditAction - { - [EnumMember] - Add = 1, - - [EnumMember] - Update = 2, - - [EnumMember] - Delete = 3, - - [EnumMember] - Undelete = 4 - } -} diff --git a/src/Sdk/DTWebApi/WebApi/AzureKeyVaultVariableGroupProviderData.cs b/src/Sdk/DTWebApi/WebApi/AzureKeyVaultVariableGroupProviderData.cs deleted file mode 100644 index 756d02326..000000000 --- a/src/Sdk/DTWebApi/WebApi/AzureKeyVaultVariableGroupProviderData.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class AzureKeyVaultVariableGroupProviderData : VariableGroupProviderData - { - [DataMember(EmitDefaultValue = true)] - public Guid ServiceEndpointId - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Vault - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public DateTime LastRefreshedOn - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/AzureKeyVaultVariableValue.cs b/src/Sdk/DTWebApi/WebApi/AzureKeyVaultVariableValue.cs deleted file mode 100644 index 4bae3ac45..000000000 --- a/src/Sdk/DTWebApi/WebApi/AzureKeyVaultVariableValue.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class AzureKeyVaultVariableValue: VariableValue - { - public AzureKeyVaultVariableValue() - { - } - - public AzureKeyVaultVariableValue(AzureKeyVaultVariableValue value) - : this(value.Value, value.IsSecret, value.Enabled, value.ContentType, value.Expires) - { - } - - public AzureKeyVaultVariableValue(String value, Boolean isSecret, Boolean enabled, String contentType, DateTime? expires) - :base(value, isSecret) - { - Enabled = enabled; - ContentType = contentType; - Expires = expires; - } - - [DataMember(EmitDefaultValue = true)] - public Boolean Enabled - { - get; - set; - } - - [DataMember(EmitDefaultValue = true)] - public String ContentType - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public DateTime? Expires - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentGroup.cs b/src/Sdk/DTWebApi/WebApi/DeploymentGroup.cs deleted file mode 100644 index 29dc10085..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentGroup.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Deployment group. - /// - [DataContract] - public class DeploymentGroup : DeploymentGroupReference - { - /// - /// Number of deployment targets in the deployment group. - /// - [DataMember] - public Int32 MachineCount - { - get; - internal set; - } - - /// - /// List of deployment targets in the deployment group. - /// - public IList Machines - { - get - { - if (m_machines == null) - { - m_machines = new List(); - } - return m_machines; - } - internal set - { - m_machines = value; - } - } - - /// - /// Description of the deployment group. - /// - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - - /// - /// List of unique tags across all deployment targets in the deployment group. - /// - public IList MachineTags - { - get - { - if (m_tags == null) - { - m_tags = new List(); - } - return m_tags; - } - internal set - { - m_tags = value; - } - } - - /// - /// List of deployment targets in the deployment group. - /// - [DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Machines")] - private IList m_machines; - - /// - /// List of unique tags across all deployment targets in the deployment group. - /// - [DataMember(IsRequired = false, EmitDefaultValue = false, Name = "MachineTags")] - private IList m_tags; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentGroupActionFilter.cs b/src/Sdk/DTWebApi/WebApi/DeploymentGroupActionFilter.cs deleted file mode 100644 index dbd9d8bc6..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentGroupActionFilter.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// This is useful in getting a list of deployment groups, filtered for which caller has permissions to take a particular action. - /// - [Flags] - [DataContract] - public enum DeploymentGroupActionFilter - { - /// - /// All deployment groups. - /// - [EnumMember] - None = 0, - - /// - /// Only deployment groups for which caller has **manage** permission. - /// - [EnumMember] - Manage = 2, - - /// - /// Only deployment groups for which caller has **use** permission. - /// - [EnumMember] - Use = 16, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentGroupCreateParameter.cs b/src/Sdk/DTWebApi/WebApi/DeploymentGroupCreateParameter.cs deleted file mode 100644 index 61ecb420c..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentGroupCreateParameter.cs +++ /dev/null @@ -1,72 +0,0 @@ -using GitHub.Services.WebApi; -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Properties to create Deployment group. - /// - [DataContract] - public class DeploymentGroupCreateParameter - { - /// - /// Name of the deployment group. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Description of the deployment group. - /// - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - - /// - /// Identifier of the deployment pool in which deployment agents are registered. - /// - [DataMember(EmitDefaultValue = false)] - public Int32 PoolId - { - get; - set; - } - - /// - /// Deployment pool in which deployment agents are registered. - /// This is obsolete. Kept for compatibility. Will be marked obsolete explicitly by M132. - /// - [DataMember(EmitDefaultValue = false)] - [ClientInternalUseOnly(OmitFromTypeScriptDeclareFile = false)] - public DeploymentGroupCreateParameterPoolProperty Pool - { - get; - set; - } - } - - /// - /// Properties of Deployment pool to create Deployment group. - /// - [DataContract] - public class DeploymentGroupCreateParameterPoolProperty - { - /// - /// Deployment pool identifier. - /// - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentGroupExpands.cs b/src/Sdk/DTWebApi/WebApi/DeploymentGroupExpands.cs deleted file mode 100644 index 37ca5c1fe..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentGroupExpands.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Properties to be included or expanded in deployment group objects. This is useful when getting a single or list of deployment grouops. - /// - [Flags] - [DataContract] - public enum DeploymentGroupExpands - { - /// - /// No additional properties. - /// - [EnumMember] - None = 0, - - /// - /// Deprecated: Include all the deployment targets. - /// - [EnumMember] - Machines = 2, - - /// - /// Include unique list of tags across all deployment targets. - /// - [EnumMember] - Tags = 4 - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentGroupMetrics.cs b/src/Sdk/DTWebApi/WebApi/DeploymentGroupMetrics.cs deleted file mode 100644 index 0efd3438e..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentGroupMetrics.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Deployment group metrics. - /// - [DataContract] - public sealed class DeploymentGroupMetrics - { - /// - /// Deployment group. - /// - [DataMember] - public DeploymentGroupReference DeploymentGroup - { - get; - internal set; - } - - /// - /// List of deployment group properties. And types of metrics provided for those properties. - /// - [DataMember] - public MetricsColumnsHeader ColumnsHeader - { - get; - internal set; - } - - /// - /// Values of properties and the metrics. - /// E.g. 1: total count of deployment targets for which 'TargetState' is 'offline'. - /// E.g. 2: Average time of deployment to the deployment targets for which 'LastJobStatus' is 'passed' and 'TargetState' is 'online'. - /// - public IList Rows - { - get - { - if (m_rows == null) - { - m_rows = new List(); - } - - return m_rows; - } - internal set - { - m_rows = value; - } - } - - /// - /// Values of properties and the metrics. - /// E.g. 1: total count of deployment targets for which 'TargetState' is 'offline'. - /// E.g. 2: Average time of deployment to the deployment targets for which 'LastJobStatus' is 'passed' and 'TargetState' is 'online'. - /// - [DataMember(Name = "Rows")] - private IList m_rows; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentGroupReference.cs b/src/Sdk/DTWebApi/WebApi/DeploymentGroupReference.cs deleted file mode 100644 index bdd34601f..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentGroupReference.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Deployment group reference. This is useful for referring a deployment group in another object. - /// - [DataContract] - public class DeploymentGroupReference - { - [JsonConstructor] - public DeploymentGroupReference() - { - } - - private DeploymentGroupReference(DeploymentGroupReference referenceToClone) - { - this.Id = referenceToClone.Id; - this.Name = referenceToClone.Name; - - if (referenceToClone.Project != null) - { - this.Project = new ProjectReference - { - Id = referenceToClone.Project.Id, - Name = referenceToClone.Project.Name, - }; - } - - if (referenceToClone.Pool != null) - { - this.Pool = new TaskAgentPoolReference - { - Id = referenceToClone.Pool.Id, - IsHosted = referenceToClone.Pool.IsHosted, - Name = referenceToClone.Pool.Name, - PoolType = referenceToClone.Pool.PoolType, - Scope = referenceToClone.Pool.Scope, - }; - } - } - - /// - /// Deployment group identifier. - /// - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - internal set; - } - - /// - /// Project to which the deployment group belongs. - /// - [DataMember(EmitDefaultValue = false)] - public ProjectReference Project - { - get; - internal set; - } - - /// - /// Name of the deployment group. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Deployment pool in which deployment agents are registered. - /// - [DataMember(EmitDefaultValue = false)] - public TaskAgentPoolReference Pool - { - get; - set; - } - - public virtual DeploymentGroupReference Clone() - { - return new DeploymentGroupReference(this); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentGroupUpdateParameter.cs b/src/Sdk/DTWebApi/WebApi/DeploymentGroupUpdateParameter.cs deleted file mode 100644 index be382a967..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentGroupUpdateParameter.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Deployment group update parameter. - /// - [DataContract] - public class DeploymentGroupUpdateParameter - { - /// - /// Name of the deployment group. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Description of the deployment group. - /// - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentMachine.cs b/src/Sdk/DTWebApi/WebApi/DeploymentMachine.cs deleted file mode 100644 index 786e2394a..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentMachine.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Deployment target. - /// - [DataContract] - public class DeploymentMachine : ICloneable - { - public DeploymentMachine() - { - } - - private DeploymentMachine(DeploymentMachine machineToBeCloned) - { - this.Id = machineToBeCloned.Id; - this.Tags = (Tags == null) ? null : new List(machineToBeCloned.Tags); - this.Agent = machineToBeCloned.Agent?.Clone(); - } - - /// - /// Deployment target Identifier. - /// - [DataMember] - public Int32 Id - { - get; - set; - } - - /// - /// Tags of the deployment target. - /// - public IList Tags - { - get - { - return m_tags; - } - set - { - m_tags = value; - } - } - - /// - /// Deployment agent. - /// - [DataMember(EmitDefaultValue = false)] - public TaskAgent Agent - { - get; - set; - } - - public PropertiesCollection Properties - { - get - { - if (m_properties == null) - { - m_properties = new PropertiesCollection(); - } - - return m_properties; - } - internal set - { - m_properties = value; - } - } - - object ICloneable.Clone() - { - return this.Clone(); - } - - public DeploymentMachine Clone() - { - return new DeploymentMachine(this); - } - - /// - /// Tags of the deployment target. - /// - [DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Tags")] - private IList m_tags; - - /// - /// Properties of the deployment target. - /// - [DataMember(EmitDefaultValue = false, Name = "Properties")] - private PropertiesCollection m_properties; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentMachineExpands.cs b/src/Sdk/DTWebApi/WebApi/DeploymentMachineExpands.cs deleted file mode 100644 index 732fac64a..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentMachineExpands.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [Flags] - [DataContract] - public enum DeploymentMachineExpands - { - [EnumMember] - None = 0, - - [EnumMember] - Capabilities = 2, - - [EnumMember] - AssignedRequest = 4 - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentMachineGroup.cs b/src/Sdk/DTWebApi/WebApi/DeploymentMachineGroup.cs deleted file mode 100644 index 5db57253b..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentMachineGroup.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class DeploymentMachineGroup : DeploymentMachineGroupReference - { - [DataMember] - public Int32 Size - { - get; - internal set; - } - - public IList Machines - { - get - { - if (m_machines == null) - { - m_machines = new List(); - } - - return m_machines; - } - - internal set - { - m_machines = value; - } - } - - [DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Machines")] - private IList m_machines; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentMachineGroupReference.cs b/src/Sdk/DTWebApi/WebApi/DeploymentMachineGroupReference.cs deleted file mode 100644 index 8b1b05673..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentMachineGroupReference.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class DeploymentMachineGroupReference - { - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - internal set; - } - - [DataMember(EmitDefaultValue = false)] - public ProjectReference Project - { - get; - internal set; - } - - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TaskAgentPoolReference Pool - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentPoolSummary.cs b/src/Sdk/DTWebApi/WebApi/DeploymentPoolSummary.cs deleted file mode 100644 index 4b2cdaab7..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentPoolSummary.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Deployment pool summary. - /// - [DataContract] - public sealed class DeploymentPoolSummary - { - /// - /// Deployment pool. - /// - [DataMember] - public TaskAgentPoolReference Pool - { - get; - internal set; - } - - /// - /// Number of deployment agents that are online. - /// - [DataMember] - public Int32 OnlineAgentsCount - { - get; - internal set; - } - - /// - /// Number of deployment agents that are offline. - /// - [DataMember] - public Int32 OfflineAgentsCount - { - get; - internal set; - } - - /// - /// Virtual machine Resource referring in pool. - /// - [DataMember] - public EnvironmentResourceReference Resource - { - get; - internal set; - } - - /// - /// List of deployment groups referring to the deployment pool. - /// - public IList DeploymentGroups - { - get - { - if (m_deploymentGroups == null) - { - m_deploymentGroups = new List(); - } - return m_deploymentGroups; - } - internal set - { - m_deploymentGroups = value; - } - } - - /// - /// List of deployment groups referring to the deployment pool. - /// - [DataMember(IsRequired = false, EmitDefaultValue = false, Name = "DeploymentGroups")] - private IList m_deploymentGroups; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentPoolSummaryExpands.cs b/src/Sdk/DTWebApi/WebApi/DeploymentPoolSummaryExpands.cs deleted file mode 100644 index 63586be3c..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentPoolSummaryExpands.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Properties to be included or expanded in deployment pool summary objects. This is useful when getting a single or list of deployment pool summaries. - /// - [Flags] - [DataContract] - public enum DeploymentPoolSummaryExpands - { - /// - /// No additional properties - /// - [EnumMember] - None = 0, - - /// - /// Include deployment groups referring to the deployment pool. - /// - [EnumMember] - DeploymentGroups = 2, - - /// - /// Include Resource referring to the deployment pool. - /// - [EnumMember] - Resource = 4 - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentTargetExpands.cs b/src/Sdk/DTWebApi/WebApi/DeploymentTargetExpands.cs deleted file mode 100644 index a1b3e371e..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentTargetExpands.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Properties to be included or expanded in deployment target objects. This is useful when getting a single or list of deployment targets. - /// - [Flags] - [DataContract] - public enum DeploymentTargetExpands - { - /// - /// No additional properties. - /// - [EnumMember] - None = 0, - - /// - /// Include capabilities of the deployment agent. - /// - [EnumMember] - Capabilities = 2, - - /// - /// Include the job request assigned to the deployment agent. - /// - [EnumMember] - AssignedRequest = 4, - - /// - /// Include the last completed job request of the deployment agent. - /// - [EnumMember] - LastCompletedRequest = 8 - } -} diff --git a/src/Sdk/DTWebApi/WebApi/DeploymentTargetUpdateParameter.cs b/src/Sdk/DTWebApi/WebApi/DeploymentTargetUpdateParameter.cs deleted file mode 100644 index 8f2a4835f..000000000 --- a/src/Sdk/DTWebApi/WebApi/DeploymentTargetUpdateParameter.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Deployment target update parameter. - /// - [DataContract] - public class DeploymentTargetUpdateParameter - { - /// - /// Identifier of the deployment target. - /// - [DataMember] - public Int32 Id - { - get; - set; - } - - /// - /// Tags of the deployment target.. - /// - public IList Tags - { - get - { - return m_tags; - } - set - { - m_tags = value; - } - } - - [DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Tags")] - private IList m_tags; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentCreateParameter.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentCreateParameter.cs deleted file mode 100644 index 35085a396..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentCreateParameter.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Properties to create Environment. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class EnvironmentCreateParameter - { - /// - /// Name of the environment. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Description of the environment. - /// - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentDeploymentExecutionRecord.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentDeploymentExecutionRecord.cs deleted file mode 100644 index b37da3949..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentDeploymentExecutionRecord.cs +++ /dev/null @@ -1,192 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// EnvironmentDeploymentExecutionRecord. - /// - [DataContract] - public class EnvironmentDeploymentExecutionRecord - { - /// - /// Id of the Environment deployment execution history record - /// - [DataMember] - public Int64 Id - { - get; - set; - } - - /// - /// Request identifier of the Environment deployment execution history record - /// - [DataMember] - public String RequestIdentifier - { - get; - set; - } - - /// - /// Id of the Environment - /// - [DataMember] - public Int32 EnvironmentId - { - get; - set; - } - - /// - /// Service owner Id - /// - [DataMember(EmitDefaultValue = false)] - public Guid ServiceOwner - { - get; - set; - } - - /// - /// Project Id - /// - [DataMember(EmitDefaultValue = false)] - public Guid ScopeId - { - get; - set; - } - - /// - /// Resource Id - /// - [DataMember(EmitDefaultValue = false)] - public Int32? ResourceId - { - get; - set; - } - - /// - /// Plan type of the environment deployment execution record - /// - [DataMember(EmitDefaultValue = false)] - public String PlanType - { - get; - set; - } - - /// - /// Plan Id - /// - [DataMember(EmitDefaultValue = false)] - public Guid PlanId - { - get; - set; - } - - /// - /// Stage name - /// - [DataMember(EmitDefaultValue = false)] - public String StageName - { - get; - set; - } - - /// - /// Job name - /// - [DataMember(EmitDefaultValue = false)] - public String JobName - { - get; - set; - } - - /// - /// Stage Attempt - /// - [DataMember(EmitDefaultValue = false)] - public Int32 StageAttempt - { - get; - set; - } - - /// - /// Job Attempt - /// - [DataMember(EmitDefaultValue = false)] - public Int32 JobAttempt - { - get; - set; - } - - /// - /// Definition of the environment deployment execution owner - /// - [DataMember(EmitDefaultValue = false)] - public TaskOrchestrationOwner Definition - { - get; - set; - } - - /// - /// Owner of the environment deployment execution record - /// - [DataMember(EmitDefaultValue = false)] - public TaskOrchestrationOwner Owner - { - get; - set; - } - - /// - /// Result of the environment deployment execution - /// - [DataMember(EmitDefaultValue = false)] - public TaskResult? Result - { - get; - set; - } - - /// - /// Queue time of the environment deployment execution - /// - [DataMember(EmitDefaultValue = false)] - public DateTime QueueTime - { - get; - set; - } - - /// - /// Start time of the environment deployment execution - /// - [DataMember(EmitDefaultValue = false)] - public DateTime? StartTime - { - get; - set; - } - - /// - /// Finish time of the environment deployment execution - /// - [DataMember(EmitDefaultValue = false)] - public DateTime? FinishTime - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentExpands.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentExpands.cs deleted file mode 100644 index e7bf1e795..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentExpands.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Properties to be included or expanded in environment objects. This is useful when getting a single environment. - /// - [Flags] - [DataContract] - public enum EnvironmentExpands - { - /// - /// No additional properties - /// - [EnumMember] - None = 0, - - /// - /// Include resource references referring to the environment. - /// - [EnumMember] - ResourceReferences = 1 - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentInstance.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentInstance.cs deleted file mode 100644 index 6fb071004..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentInstance.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Environment. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class EnvironmentInstance - { - /// - /// Id of the Environment - /// - [DataMember] - public Int32 Id - { - get; - set; - } - - /// - /// Name of the Environment. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Description of the Environment. - /// - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - - /// - /// Identity reference of the user who created the Environment. - /// - [DataMember(EmitDefaultValue = false)] - public IdentityRef CreatedBy - { - get; - set; - } - - /// - /// Creation time of the Environment - /// - [DataMember] - public DateTime CreatedOn - { - get; - set; - } - - /// - /// Identity reference of the user who last modified the Environment. - /// - [DataMember(EmitDefaultValue = false)] - public IdentityRef LastModifiedBy - { - get; - set; - } - - /// - /// Last modified time of the Environment - /// - [DataMember] - public DateTime LastModifiedOn - { - get; - set; - } - - /// - /// List of resources - /// - public IList Resources - { - get - { - if (this.resources == null) - { - this.resources = new List(); - } - - return this.resources; - } - } - - /// - /// Resources that defined or used for this environment. - /// We use this for deployment job's resource authorization. - /// - public Pipelines.PipelineResources ReferencedResources - { - get; - set; - } - - [DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Resources")] - private IList resources; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentLinkedResourceReference.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentLinkedResourceReference.cs deleted file mode 100644 index ddc8ffedb..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentLinkedResourceReference.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// EnvironmentLinkedResourceReference. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class EnvironmentLinkedResourceReference - { - /// - /// Id of the resource. - /// - [DataMember] - public String Id - { - get; - set; - } - - /// - /// Type of resource. - /// - [DataMember(EmitDefaultValue = false)] - public String TypeName - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentReference.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentReference.cs deleted file mode 100644 index 75b2012c4..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentReference.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class EnvironmentReference - { - [DataMember] - public Int32 Id { get; set; } - - [DataMember] - public String Name { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResource.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResource.cs deleted file mode 100644 index 89d9f2c94..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResource.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public abstract class EnvironmentResource - { - [DataMember] - public Int32 Id { get; set; } - - [DataMember] - public String Name { get; set; } - - /// - /// Environment resource type - /// - [DataMember] - public EnvironmentResourceType Type { get; set; } - - [DataMember] - public IdentityRef CreatedBy { get; set; } - - [DataMember] - public DateTime CreatedOn { get; set; } - - [DataMember] - public IdentityRef LastModifiedBy { get; set; } - - [DataMember] - public DateTime LastModifiedOn { get; set; } - - [DataMember] - public EnvironmentReference EnvironmentReference { get; set; } - - protected EnvironmentResource() - { - Name = string.Empty; - - CreatedBy = new IdentityRef(); - - LastModifiedBy = new IdentityRef(); - - this.EnvironmentReference = new EnvironmentReference(); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResourceReference.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResourceReference.cs deleted file mode 100644 index d80266964..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResourceReference.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// EnvironmentResourceReference. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class EnvironmentResourceReference - { - /// - /// Id of the resource. - /// - [DataMember] - public Int32 Id - { - get; - set; - } - - /// - /// Name of the resource. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Type of the resource. - /// - [DataMember(EmitDefaultValue = false)] - public EnvironmentResourceType Type - { - get; - set; - } - - /// - /// List of linked resources - /// - public IList LinkedResources - { - get - { - if (m_linkedResources == null) - { - m_linkedResources = new List(); - } - - return m_linkedResources; - } - } - - private IList m_linkedResources; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResourceType.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResourceType.cs deleted file mode 100644 index 87d0be73d..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentResourceType.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.ComponentModel; - - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// EnvironmentResourceType. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Flags] - public enum EnvironmentResourceType - { - Undefined = 0, - - /// - /// Unknown resource type - /// - Generic = 1, - - /// - /// Virtual machine resource type - /// - VirtualMachine = 2, - - /// - /// Kubernetes resource type - /// - Kubernetes = 4 - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentUpdateParameter.cs b/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentUpdateParameter.cs deleted file mode 100644 index 6fdf9fab8..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/EnvironmentUpdateParameter.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Properties to update Environment. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class EnvironmentUpdateParameter - { - /// - /// Name of the environment. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Description of the environment. - /// - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/KubernetesResource.cs b/src/Sdk/DTWebApi/WebApi/Environment/KubernetesResource.cs deleted file mode 100644 index fc0cfee9c..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/KubernetesResource.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class KubernetesResource : EnvironmentResource - { - [DataMember] - public String Namespace { get; set; } - - [DataMember] - public String ClusterName { get; set; } - - [DataMember] - public Guid ServiceEndpointId { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/KubernetesResourceCreateParameters.cs b/src/Sdk/DTWebApi/WebApi/Environment/KubernetesResourceCreateParameters.cs deleted file mode 100644 index c400258c7..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/KubernetesResourceCreateParameters.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class KubernetesResourceCreateParameters - { - [DataMember] - public String Name { get; set; } - - [DataMember] - public String Namespace { get; set; } - - [DataMember] - public String ClusterName { get; set; } - - [DataMember] - public Guid ServiceEndpointId { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachine.cs b/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachine.cs deleted file mode 100644 index 242096ece..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachine.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class VirtualMachine - { - [DataMember] - public Int32 Id { get; set; } - - [DataMember] - public TaskAgent Agent { get; set; } - - /// - /// List of tags - /// - public IList Tags - { - get - { - if (this.tags == null) - { - this.tags = new List(); - } - - return this.tags; - } - set - { - this.tags = value; - } - } - - [DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Tags")] - private IList tags; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachineGroup.cs b/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachineGroup.cs deleted file mode 100644 index 040b7a7e0..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachineGroup.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class VirtualMachineGroup : EnvironmentResource - { - [DataMember] - public Int32 PoolId { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachineGroupCreateParameters.cs b/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachineGroupCreateParameters.cs deleted file mode 100644 index 7a3bee5c1..000000000 --- a/src/Sdk/DTWebApi/WebApi/Environment/VirtualMachineGroupCreateParameters.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class VirtualMachineGroupCreateParameters - { - [DataMember] - public String Name { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/IOrchestrationProcess.cs b/src/Sdk/DTWebApi/WebApi/IOrchestrationProcess.cs deleted file mode 100644 index 3fd813dc0..000000000 --- a/src/Sdk/DTWebApi/WebApi/IOrchestrationProcess.cs +++ /dev/null @@ -1,172 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines; -using GitHub.Services.WebApi; -using GitHub.Services.WebApi.Internal; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.WebApi -{ - [ClientIgnore] - [DataContract] - [EditorBrowsable(EditorBrowsableState.Never)] - public enum OrchestrationProcessType - { - [DataMember] - Container = 1, - - [DataMember] - Pipeline = 2, - } - - [EditorBrowsable(EditorBrowsableState.Never)] - [JsonConverter(typeof(OrchestrationEnvironmentJsonConverter))] - public interface IOrchestrationEnvironment - { - OrchestrationProcessType ProcessType { get; } - - IDictionary Variables { get; } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - [JsonConverter(typeof(OrchestrationProcessJsonConverter))] - public interface IOrchestrationProcess - { - OrchestrationProcessType ProcessType { get; } - } - - internal sealed class OrchestrationProcessJsonConverter : VssSecureJsonConverter - { - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Boolean CanConvert(Type objectType) - { - return typeof(IOrchestrationProcess).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - if (reader.TokenType != JsonToken.StartObject) - { - return null; - } - - JObject value = JObject.Load(reader); - IOrchestrationProcess process = null; - if (value.TryGetValue("stages", StringComparison.OrdinalIgnoreCase, out _) || - value.TryGetValue("phases", StringComparison.OrdinalIgnoreCase, out _)) - { - process = new PipelineProcess(); - } - else if (value.TryGetValue("children", StringComparison.OrdinalIgnoreCase, out _)) - { - process = new TaskOrchestrationContainer(); - } - - if (process != null) - { - using (var objectReader = value.CreateReader()) - { - serializer.Populate(objectReader, process); - } - } - - return process; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } - - internal sealed class OrchestrationEnvironmentJsonConverter : VssSecureJsonConverter - { - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Boolean CanConvert(Type objectType) - { - return typeof(IOrchestrationEnvironment).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - if (reader.TokenType != JsonToken.StartObject) - { - return null; - } - - JToken propertyValue; - JObject value = JObject.Load(reader); - IOrchestrationEnvironment environment = null; - OrchestrationProcessType processType = OrchestrationProcessType.Container; - if (value.TryGetValue("ProcessType", StringComparison.OrdinalIgnoreCase, out propertyValue)) - { - if (propertyValue.Type == JTokenType.Integer) - { - processType = (OrchestrationProcessType)(Int32)propertyValue; - } - else if (propertyValue.Type != JTokenType.String || !Enum.TryParse((String)propertyValue, true, out processType)) - { - return null; - } - } - - switch (processType) - { - case OrchestrationProcessType.Container: - environment = new PlanEnvironment(); - break; - - case OrchestrationProcessType.Pipeline: - environment = new PipelineEnvironment(); - break; - } - - if (environment != null) - { - using (var objectReader = value.CreateReader()) - { - serializer.Populate(objectReader, environment); - } - } - - return environment; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/JobEnvironment.cs b/src/Sdk/DTWebApi/WebApi/JobEnvironment.cs deleted file mode 100644 index a0ba24ffb..000000000 --- a/src/Sdk/DTWebApi/WebApi/JobEnvironment.cs +++ /dev/null @@ -1,294 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Represents the context of variables and vectors for a job request. - /// - [DataContract] - public sealed class JobEnvironment : ICloneable - { - /// - /// Initializes a new JobEnvironment with empty collections of repositories, vectors, - /// and variables. - /// - public JobEnvironment() - { - } - - public JobEnvironment( - IDictionary variables, - List maskhints, - JobResources resources) - { - if (resources!= null) - { - this.Endpoints.AddRange(resources.Endpoints.Where(x => !String.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase))); - this.SystemConnection = resources.Endpoints.FirstOrDefault(x => String.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); - this.SecureFiles.AddRange(resources.SecureFiles); - } - - if (maskhints != null) - { - this.MaskHints.AddRange(maskhints); - } - - if (variables != null) - { - foreach (var variable in variables) - { - this.Variables[variable.Key] = variable.Value?.Value; - - if (variable.Value?.IsSecret == true) - { - // Make sure we propagate secret variables into the mask hints - this.MaskHints.Add(new MaskHint { Type = MaskType.Variable, Value = variable.Key }); - } - } - } - } - - public void Extract( - Dictionary variables, - HashSet maskhints, - JobResources jobResources) - { - // construct variables - HashSet secretVariables = new HashSet(this.MaskHints.Where(t => t.Type == MaskType.Variable).Select(v => v.Value), StringComparer.OrdinalIgnoreCase); - foreach (var variable in this.Variables) - { - variables[variable.Key] = new VariableValue(variable.Value, secretVariables.Contains(variable.Key)); - } - - // construct maskhints - maskhints.AddRange(this.MaskHints.Where(x => !(x.Type == MaskType.Variable && secretVariables.Contains(x.Value))).Select(x => x.Clone())); - - // constuct job resources (endpoints, securefiles and systemconnection) - jobResources.SecureFiles.AddRange(this.SecureFiles.Select(x => x.Clone())); - jobResources.Endpoints.AddRange(this.Endpoints.Select(x => x.Clone())); - - if (this.SystemConnection != null) - { - jobResources.Endpoints.Add(this.SystemConnection.Clone()); - } - } - - public JobEnvironment(PlanEnvironment environment) - { - ArgumentUtility.CheckForNull(environment, nameof(environment)); - - if (environment.MaskHints.Count > 0) - { - m_maskHints = new List(environment.MaskHints.Select(x => x.Clone())); - } - - if (environment.Options.Count > 0) - { - m_options = environment.Options.ToDictionary(x => x.Key, x => x.Value.Clone()); - } - - if (environment.Variables.Count > 0) - { - m_variables = new Dictionary(environment.Variables, StringComparer.OrdinalIgnoreCase); - } - } - - private JobEnvironment(JobEnvironment environmentToClone) - { - if (environmentToClone.SystemConnection != null) - { - this.SystemConnection = environmentToClone.SystemConnection.Clone(); - } - - if (environmentToClone.m_maskHints != null) - { - m_maskHints = environmentToClone.m_maskHints.Select(x => x.Clone()).ToList(); - } - - if (environmentToClone.m_endpoints != null) - { - m_endpoints = environmentToClone.m_endpoints.Select(x => x.Clone()).ToList(); - } - - if (environmentToClone.m_secureFiles != null) - { - m_secureFiles = environmentToClone.m_secureFiles.Select(x => x.Clone()).ToList(); - } - - if (environmentToClone.m_options != null) - { - m_options = environmentToClone.m_options.ToDictionary(x => x.Key, x => x.Value.Clone()); - } - - if (environmentToClone.m_variables != null) - { - m_variables = new Dictionary(environmentToClone.m_variables, StringComparer.OrdinalIgnoreCase); - } - } - - /// - /// Gets or sets the endpoint used for communicating back to the calling service. - /// - [DataMember(EmitDefaultValue = false)] - public ServiceEndpoint SystemConnection - { - get; - set; - } - - /// - /// Gets the collection of mask hints - /// - public List MaskHints - { - get - { - if (m_maskHints == null) - { - m_maskHints = new List(); - } - return m_maskHints; - } - } - - /// - /// Gets the collection of endpoints associated with the current context. - /// - public List Endpoints - { - get - { - if (m_endpoints == null) - { - m_endpoints = new List(); - } - return m_endpoints; - } - } - - /// - /// Gets the collection of secure files associated with the current context - /// - public List SecureFiles - { - get - { - if (m_secureFiles == null) - { - m_secureFiles = new List(); - } - return m_secureFiles; - } - } - - /// - /// Gets the collection of options associated with the current context. (Deprecated, use by 1.x agent) - /// - public IDictionary Options - { - get - { - if (m_options == null) - { - m_options = new Dictionary(); - } - return m_options; - } - } - - /// - /// Gets the collection of variables associated with the current context. - /// - public IDictionary Variables - { - get - { - if (m_variables == null) - { - m_variables = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_variables; - } - } - - Object ICloneable.Clone() - { - return this.Clone(); - } - - /// - /// Creates a deep copy of the job environment. - /// - /// A deep copy of the job environment - public JobEnvironment Clone() - { - return new JobEnvironment(this); - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - if (m_serializedMaskHints != null && m_serializedMaskHints.Count > 0) - { - m_maskHints = new List(m_serializedMaskHints.Distinct()); - } - - m_serializedMaskHints = null; - - SerializationHelper.Copy(ref m_serializedVariables, ref m_variables, true); - SerializationHelper.Copy(ref m_serializedEndpoints, ref m_endpoints, true); - SerializationHelper.Copy(ref m_serializedSecureFiles, ref m_secureFiles, true); - SerializationHelper.Copy(ref m_serializedOptions, ref m_options, true); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (this.m_maskHints != null && this.m_maskHints.Count > 0) - { - m_serializedMaskHints = new List(this.m_maskHints.Distinct()); - } - - SerializationHelper.Copy(ref m_variables, ref m_serializedVariables); - SerializationHelper.Copy(ref m_endpoints, ref m_serializedEndpoints); - SerializationHelper.Copy(ref m_secureFiles, ref m_serializedSecureFiles); - SerializationHelper.Copy(ref m_options, ref m_serializedOptions); - } - - [OnSerialized] - private void OnSerialized(StreamingContext context) - { - m_serializedMaskHints = null; - m_serializedVariables = null; - m_serializedEndpoints = null; - m_serializedSecureFiles = null; - m_serializedOptions = null; - } - - private List m_maskHints; - private List m_endpoints; - private List m_secureFiles; - private IDictionary m_options; - private IDictionary m_variables; - - [DataMember(Name = "Endpoints", EmitDefaultValue = false)] - private List m_serializedEndpoints; - - [DataMember(Name = "SecureFiles", EmitDefaultValue = false)] - private List m_serializedSecureFiles; - - [DataMember(Name = "Options", EmitDefaultValue = false)] - private IDictionary m_serializedOptions; - - [DataMember(Name = "Mask", EmitDefaultValue = false)] - private List m_serializedMaskHints; - - [DataMember(Name = "Variables", EmitDefaultValue = false)] - private IDictionary m_serializedVariables; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/JobEvent.cs b/src/Sdk/DTWebApi/WebApi/JobEvent.cs index b17e44493..3bfbdd53b 100644 --- a/src/Sdk/DTWebApi/WebApi/JobEvent.cs +++ b/src/Sdk/DTWebApi/WebApi/JobEvent.cs @@ -16,22 +16,12 @@ namespace GitHub.DistributedTask.WebApi public const String JobCompleted = "JobCompleted"; public const String JobStarted = "JobStarted"; - - public const String TaskAssigned = "TaskAssigned"; - - public const String TaskStarted = "TaskStarted"; - - public const String TaskCompleted = "TaskCompleted"; } [DataContract] [KnownType(typeof(JobAssignedEvent))] [KnownType(typeof(JobCompletedEvent))] [KnownType(typeof(JobStartedEvent))] - [KnownType(typeof(TaskAssignedEvent))] - [KnownType(typeof(TaskStartedEvent))] - [KnownType(typeof(TaskCompletedEvent))] - [KnownType(typeof(TaskLocalExecutionCompletedEvent))] [JsonConverter(typeof(JobEventJsonConverter))] public abstract class JobEvent { @@ -179,89 +169,6 @@ namespace GitHub.DistributedTask.WebApi } } - [DataContract] - public sealed class TaskAssignedEvent : TaskEvent - { - public TaskAssignedEvent() - : base(JobEventTypes.TaskAssigned) - { - } - - public TaskAssignedEvent( - Guid jobId, - Guid taskId) - : base(JobEventTypes.TaskAssigned, jobId, taskId) - { - } - } - - [DataContract] - public sealed class TaskStartedEvent : TaskEvent - { - public TaskStartedEvent() - : base(JobEventTypes.TaskStarted) - { - } - - public TaskStartedEvent( - Guid jobId, - Guid taskId) - : base(JobEventTypes.TaskStarted, jobId, taskId) - { - } - } - - [DataContract] - public sealed class TaskCompletedEvent : TaskEvent - { - public TaskCompletedEvent() - : base(JobEventTypes.TaskCompleted) - { - } - - public TaskCompletedEvent( - Guid jobId, - Guid taskId, - TaskResult taskResult) - : base(JobEventTypes.TaskCompleted, jobId, taskId) - { - Result = taskResult; - } - - [DataMember] - public TaskResult Result - { - get; - set; - } - } - - [DataContract] - [ClientIgnore] - internal sealed class TaskLocalExecutionCompletedEvent : TaskEvent - { - public TaskLocalExecutionCompletedEvent() - : base(JobEventTypes.TaskCompleted) - { - } - - public TaskLocalExecutionCompletedEvent( - Guid jobId, - Guid taskId, - ServerTaskSectionExecutionOutput data) - : base(JobEventTypes.TaskCompleted, jobId, taskId) - { - EventData = data; - } - - [DataMember] - public ServerTaskSectionExecutionOutput EventData - { - get; - set; - } - } - internal sealed class JobEventJsonConverter : VssSecureJsonConverter { public override Boolean CanWrite @@ -304,18 +211,6 @@ namespace GitHub.DistributedTask.WebApi { jobEvent = new JobStartedEvent(); } - else if (String.Equals(nameValue, JobEventTypes.TaskAssigned, StringComparison.Ordinal)) - { - jobEvent = new TaskAssignedEvent(); - } - else if (String.Equals(nameValue, JobEventTypes.TaskStarted, StringComparison.Ordinal)) - { - jobEvent = new TaskStartedEvent(); - } - else if (String.Equals(nameValue, JobEventTypes.TaskCompleted, StringComparison.Ordinal)) - { - jobEvent = new TaskCompletedEvent(); - } } } diff --git a/src/Sdk/DTWebApi/WebApi/JobRequestMessage.cs b/src/Sdk/DTWebApi/WebApi/JobRequestMessage.cs deleted file mode 100644 index 4f0098178..000000000 --- a/src/Sdk/DTWebApi/WebApi/JobRequestMessage.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Runtime.Serialization; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - [JsonConverter(typeof(JobRequestMessageJsonConverter))] - - public abstract class JobRequestMessage - { - protected JobRequestMessage(string messageType) - { - this.MessageType = messageType; - } - - protected JobRequestMessage( - string messageType, - TaskOrchestrationPlanReference plan, - TimelineReference timeline, - Guid jobId, - String jobName, - String jobRefName, - JobEnvironment environment) - { - this.MessageType = messageType; - this.Plan = plan; - this.JobId = jobId; - this.JobName = jobName; - this.JobRefName = jobRefName; - this.Timeline = timeline; - this.Environment = environment; - } - - [DataMember] - public String MessageType - { - get; - private set; - } - - [DataMember] - public TaskOrchestrationPlanReference Plan - { - get; - private set; - } - - [DataMember] - public TimelineReference Timeline - { - get; - private set; - } - - [DataMember] - public Guid JobId - { - get; - private set; - } - - [DataMember] - public String JobName - { - get; - private set; - } - - [DataMember] - public String JobRefName - { - get; - private set; - } - - [DataMember] - public JobEnvironment Environment - { - get; - private set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/JobRequestMessageJsonConverter.cs b/src/Sdk/DTWebApi/WebApi/JobRequestMessageJsonConverter.cs deleted file mode 100644 index d1810d7b5..000000000 --- a/src/Sdk/DTWebApi/WebApi/JobRequestMessageJsonConverter.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Reflection; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.WebApi -{ - internal sealed class JobRequestMessageJsonConverter : VssSecureJsonConverter - { - public override Boolean CanConvert(Type objectType) - { - return typeof(JobRequestMessage).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - if (reader.TokenType != JsonToken.StartObject) - { - return null; - } - - Object newValue = null; - JToken propertyValue; - JObject value = JObject.Load(reader); - - if (value.TryGetValue("MessageType", StringComparison.OrdinalIgnoreCase, out propertyValue)) - { - if (propertyValue.Type == JTokenType.String) - { - var messageType = (String)propertyValue; - - switch (messageType) - { - case JobRequestMessageTypes.AgentJobRequest: - newValue = new AgentJobRequestMessage(); - break; - - case JobRequestMessageTypes.ServerTaskRequest: - case JobRequestMessageTypes.ServerJobRequest: - newValue = new ServerTaskRequestMessage(); - break; - } - } - } - - if (newValue == null) - { - if (value.TryGetValue("RequestId", StringComparison.OrdinalIgnoreCase, out propertyValue)) - { - newValue = new AgentJobRequestMessage(); - } - } - - if (newValue == null) - { - return existingValue; - } - - using (JsonReader objectReader = value.CreateReader()) - { - serializer.Populate(objectReader, newValue); - } - - return newValue; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - // The virtual method returns false for CanWrite so this should never be invoked - throw new NotSupportedException(); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/MachineGroupActionFilter.cs b/src/Sdk/DTWebApi/WebApi/MachineGroupActionFilter.cs deleted file mode 100644 index 733c02e84..000000000 --- a/src/Sdk/DTWebApi/WebApi/MachineGroupActionFilter.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [Flags] - [DataContract] - public enum MachineGroupActionFilter - { - [EnumMember] - None = 0, - - [EnumMember] - Manage = 2, - - [EnumMember] - Use = 16, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/MarketplacePurchasedLicense.cs b/src/Sdk/DTWebApi/WebApi/MarketplacePurchasedLicense.cs deleted file mode 100644 index 093ecd718..000000000 --- a/src/Sdk/DTWebApi/WebApi/MarketplacePurchasedLicense.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Represents a purchase of resource units in a secondary marketplace. - /// - /// - /// The type of resource purchased (pipelines, minutes) is not represented here. - /// - [DataContract] - public sealed class MarketplacePurchasedLicense - { - /// - /// The Marketplace display name. - /// - /// "GitHub" - [DataMember(EmitDefaultValue = false)] - public String MarketplaceName { get; set; } - - /// - /// The name of the identity making the purchase as seen by the marketplace - /// - /// "AppPreview, Microsoft, etc." - [DataMember(EmitDefaultValue = false)] - public String PurchaserName { get; set; } - - /// - /// The quantity purchased. - /// - [DataMember(EmitDefaultValue = false)] - public Int32 PurchaseUnitCount { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/PlanEnvironment.cs b/src/Sdk/DTWebApi/WebApi/PlanEnvironment.cs deleted file mode 100644 index 8de5134d1..000000000 --- a/src/Sdk/DTWebApi/WebApi/PlanEnvironment.cs +++ /dev/null @@ -1,156 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.DistributedTask.Pipelines; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class PlanEnvironment : IOrchestrationEnvironment - { - public PlanEnvironment() - { - } - - private PlanEnvironment(PlanEnvironment environmentToClone) - { - if (environmentToClone.m_options != null) - { - m_options = m_options.ToDictionary(x => x.Key, x => x.Value.Clone()); - } - - if (environmentToClone.m_maskHints != null) - { - m_maskHints = environmentToClone.m_maskHints.Select(x => x.Clone()).ToList(); - } - - if (environmentToClone.m_variables != null) - { - m_variables = new VariablesDictionary(environmentToClone.m_variables); - } - } - - /// - /// Gets the collection of mask hints - /// - public List MaskHints - { - get - { - if (m_maskHints == null) - { - m_maskHints = new List(); - } - return m_maskHints; - } - } - - /// - /// Gets the collection of options associated with the current context. - /// - /// This is being deprecated and should not be used - public IDictionary Options - { - get - { - if (m_options == null) - { - m_options = new Dictionary(); - } - return m_options; - } - } - - /// - /// Gets the collection of variables associated with the current context. - /// - public IDictionary Variables - { - get - { - if (m_variables == null) - { - m_variables = new VariablesDictionary(); - } - return m_variables; - } - } - - OrchestrationProcessType IOrchestrationEnvironment.ProcessType - { - get - { - return OrchestrationProcessType.Container; - } - } - - IDictionary IOrchestrationEnvironment.Variables - { - get - { - if (m_variables == null) - { - m_variables = new VariablesDictionary(); - } - return m_variables; - } - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - SerializationHelper.Copy(ref m_serializedOptions, ref m_options, true); - SerializationHelper.Copy(ref m_serializedMaskHints, ref m_maskHints, true); - - var secretNames = new HashSet(m_maskHints?.Where(x => x.Type == MaskType.Variable).Select(x => x.Value) ?? new String[0], StringComparer.OrdinalIgnoreCase); - if (m_serializedVariables != null && m_serializedVariables.Count > 0) - { - m_variables = new VariablesDictionary(); - foreach (var variable in m_serializedVariables) - { - m_variables[variable.Key] = new VariableValue(variable.Value, secretNames.Contains(variable.Key)); - } - } - - m_serializedVariables = null; - } - - [OnSerialized] - private void OnSerialized(StreamingContext context) - { - m_serializedOptions = null; - m_serializedMaskHints = null; - m_serializedVariables = null; - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - SerializationHelper.Copy(ref m_options, ref m_serializedOptions); - SerializationHelper.Copy(ref m_maskHints, ref m_serializedMaskHints); - - if (m_variables != null && m_variables.Count > 0) - { - m_serializedVariables = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (var variable in m_variables) - { - m_serializedVariables[variable.Key] = variable.Value?.Value; - } - } - } - - private List m_maskHints; - private Dictionary m_options; - private VariablesDictionary m_variables; - - [DataMember(Name = "Mask", EmitDefaultValue = false)] - private List m_serializedMaskHints; - - [DataMember(Name = "Options", EmitDefaultValue = false)] - private Dictionary m_serializedOptions; - - [DataMember(Name = "Variables", EmitDefaultValue = false)] - private IDictionary m_serializedVariables; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/PublishTaskGroupMetadata.cs b/src/Sdk/DTWebApi/WebApi/PublishTaskGroupMetadata.cs deleted file mode 100644 index 008342781..000000000 --- a/src/Sdk/DTWebApi/WebApi/PublishTaskGroupMetadata.cs +++ /dev/null @@ -1,20 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// 2012-2023, All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - -using System; - -namespace GitHub.DistributedTask.WebApi -{ - public class PublishTaskGroupMetadata - { - public Guid TaskGroupId { get; set; } - // This is revision of task group that is getting published - public int TaskGroupRevision { get; set; } - public int ParentDefinitionRevision { get; set; } - public Boolean Preview { get; set; } - public String Comment { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ResourceLimit.cs b/src/Sdk/DTWebApi/WebApi/ResourceLimit.cs deleted file mode 100644 index cd986695b..000000000 --- a/src/Sdk/DTWebApi/WebApi/ResourceLimit.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class ResourceLimit - { - internal ResourceLimit( - Guid hostId, - String parallelismTag, - Boolean isHosted) - { - HostId = hostId; - ParallelismTag = parallelismTag; - IsHosted = isHosted; - } - - [DataMember] - public Guid HostId - { - get; - set; - } - - [DataMember] - public String ParallelismTag - { - get; - set; - } - - [DataMember] - public Boolean IsHosted - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Int32? TotalCount - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Int32? TotalMinutes - { - get; - set; - } - - [DataMember] - public Boolean IsPremium - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean FailedToReachAllProviders - { - get; - set; - } - - public IDictionary Data - { - get - { - if (m_resourceLimitsData == null) - { - m_resourceLimitsData = new Dictionary(); - } - - return m_resourceLimitsData; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_resourceLimitsData?.Count == 0) - { - m_resourceLimitsData = null; - } - } - - [DataMember(Name = "ResourceLimitsData", EmitDefaultValue = false)] - private IDictionary m_resourceLimitsData; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ResourceUsage.cs b/src/Sdk/DTWebApi/WebApi/ResourceUsage.cs deleted file mode 100644 index 053ad02bb..000000000 --- a/src/Sdk/DTWebApi/WebApi/ResourceUsage.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [EditorBrowsable(EditorBrowsableState.Never)] - [DataContract] - public class ResourceUsage - { - [DataMember] - public ResourceLimit ResourceLimit - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Int32? UsedCount - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Int32? UsedMinutes - { - get; - set; - } - - public IList RunningRequests - { - get - { - if (m_runningRequests == null) - { - m_runningRequests = new List(); - } - - return m_runningRequests; - } - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - if (m_runningRequests?.Count == 0) - { - m_runningRequests = null; - } - } - - [DataMember(Name = "RunningRequests", EmitDefaultValue = false)] - private IList m_runningRequests; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/SecureFile.cs b/src/Sdk/DTWebApi/WebApi/SecureFile.cs deleted file mode 100644 index c9a40b2f3..000000000 --- a/src/Sdk/DTWebApi/WebApi/SecureFile.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class SecureFile - { - public SecureFile() - { - } - - private SecureFile(SecureFile secureFile, Boolean shallow = false) - { - this.Id = secureFile.Id; - this.Name = secureFile.Name; - this.Ticket = secureFile.Ticket; - - if (!shallow) - { - this.Properties = secureFile.Properties; - this.CreatedBy = secureFile.CreatedBy; - this.CreatedOn = secureFile.CreatedOn; - this.ModifiedBy = secureFile.ModifiedBy; - this.ModifiedOn = secureFile.ModifiedOn; - } - } - - [DataMember(EmitDefaultValue = false)] - public Guid Id - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - public IDictionary Properties - { - get - { - if (m_properties == null) - { - m_properties = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - return m_properties; - } - set - { - m_properties = value; - } - } - - [DataMember(EmitDefaultValue = false)] - public IdentityRef CreatedBy - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public DateTime CreatedOn - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public IdentityRef ModifiedBy - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public DateTime ModifiedOn - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Ticket - { - get; - set; - } - - public SecureFile Clone() - { - return new SecureFile(this); - } - - public SecureFile CloneShallow() - { - return new SecureFile(this, true); - } - - [DataMember(EmitDefaultValue = false, Name = "Properties")] - private IDictionary m_properties; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/SecureFileActionFilter.cs b/src/Sdk/DTWebApi/WebApi/SecureFileActionFilter.cs deleted file mode 100644 index 700a458ff..000000000 --- a/src/Sdk/DTWebApi/WebApi/SecureFileActionFilter.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [Flags] - [DataContract] - public enum SecureFileActionFilter - { - [EnumMember] - None = 0, - - [EnumMember] - Manage = 2, - - [EnumMember] - Use = 16, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServerTaskRequestMessage.cs b/src/Sdk/DTWebApi/WebApi/ServerTaskRequestMessage.cs deleted file mode 100644 index e4b62775c..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServerTaskRequestMessage.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class ServerTaskRequestMessage : JobRequestMessage - { - internal ServerTaskRequestMessage() - : base(JobRequestMessageTypes.ServerTaskRequest) - { - } - - public ServerTaskRequestMessage( - TaskOrchestrationPlanReference plan, - TimelineReference timeline, - Guid jobId, - String jobName, - String jobRefName, - JobEnvironment environment, - TaskInstance taskInstance, - TaskDefinition taskDefinition) - : base(JobRequestMessageTypes.ServerJobRequest, plan, timeline, jobId, jobName, jobRefName, environment) - { - TaskDefinition = taskDefinition; - TaskInstance = taskInstance; - } - - [DataMember] - public TaskDefinition TaskDefinition - { - get; - private set; - } - - [DataMember] - public TaskInstance TaskInstance - { - get; - private set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServerTaskSectionExecutionOutput.cs b/src/Sdk/DTWebApi/WebApi/ServerTaskSectionExecutionOutput.cs deleted file mode 100644 index 8cba67674..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServerTaskSectionExecutionOutput.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Runtime.Serialization; -using GitHub.Services.WebApi.Internal; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - [ClientIgnore] - public class ServerTaskSectionExecutionOutput - { - [DataMember] - public Boolean? IsCompleted { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadLoginPromptOption.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadLoginPromptOption.cs deleted file mode 100644 index b13639f9e..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadLoginPromptOption.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public enum AadLoginPromptOption - { - /// - /// Do not provide a prompt option - /// - [EnumMember] - NoOption = 0, - - /// - /// Force the user to login again. - /// - [EnumMember] - Login = 1, - - /// - /// Force the user to select which account they are logging in with instead of - /// automatically picking the user up from the session state. - /// NOTE: This does not work for switching bewtween the variants of a dual-homed user. - /// - [EnumMember] - SelectAccount = 2, - - /// - /// Force the user to login again. - /// - /// Ignore current authentication state and force the user to authenticate again. This option should be used instead of Login. - /// - /// - [EnumMember] - FreshLogin = 3, - - /// - /// Force the user to login again with mfa. - /// - /// Ignore current authentication state and force the user to authenticate again. This option should be used instead of Login, if MFA is required. - /// - /// - [EnumMember] - FreshLoginWithMfa = 4 - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadOauthTokenRequest.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadOauthTokenRequest.cs deleted file mode 100644 index f2de2c74d..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadOauthTokenRequest.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class AadOauthTokenRequest - { - [DataMember] - public String Token { get; set; } - - [DataMember] - public String Resource { get; set; } - - [DataMember] - public String TenantId { get; set; } - - [DataMember] - public Boolean Refresh { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadOauthTokenResult.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadOauthTokenResult.cs deleted file mode 100644 index 89dc4d834..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AadOauthTokenResult.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class AadOauthTokenResult - { - [DataMember] - public String AccessToken { get; set; } - - [DataMember] - public String RefreshTokenCache { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureKeyVaultPermission.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureKeyVaultPermission.cs deleted file mode 100644 index ed53bd305..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureKeyVaultPermission.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class AzureKeyVaultPermission : AzureResourcePermission - { - [DataMember] - public String Vault { get; set; } - - public AzureKeyVaultPermission() : base(AzurePermissionResourceProviders.AzureKeyVaultPermission) - { - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureManagementGroup.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureManagementGroup.cs deleted file mode 100644 index db603f1e3..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureManagementGroup.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Azure Management Group - /// - [DataContract] - public class AzureManagementGroup - { - /// - /// Azure management group name - /// - [DataMember] - [JsonProperty(PropertyName = "Name")] - public String Name { get; set; } - - /// - /// Id of azure management group - /// - [DataMember] - [JsonProperty(PropertyName = "Id")] - public String Id { get; set; } - - /// - /// Display name of azure management group - /// - [DataMember] - [JsonProperty(PropertyName = "displayName")] - public String DisplayName { get; set; } - - /// - /// Id of tenant from which azure management group belogs - /// - [DataMember] - public String TenantId { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureManagementGroupQueryResult.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureManagementGroupQueryResult.cs deleted file mode 100644 index 10e61b421..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureManagementGroupQueryResult.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.Serialization; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Azure management group query result - /// - [DataContract] - public class AzureManagementGroupQueryResult - { - /// - /// List of azure management groups - /// - [DataMember] - [JsonProperty("value")] - public List Value; - - /// - /// Error message in case of an exception - /// - [DataMember] - public string ErrorMessage; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermission.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermission.cs deleted file mode 100644 index 13032068f..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermission.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.Serialization; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [JsonConverter(typeof(AzurePermissionJsonConverter))] - [KnownType(typeof(AzureKeyVaultPermission))] - [DataContract] - public abstract class AzurePermission - { - [DataMember] - public String ResourceProvider { get; set; } - - [DataMember(EmitDefaultValue = true)] - public Boolean Provisioned { get; set; } - - internal AzurePermission(String resourceProvider) - { - this.ResourceProvider = resourceProvider; - } - } - - internal sealed class AzurePermissionJsonConverter : VssSecureJsonConverter - { - public override Boolean CanRead - { - get - { - return true; - } - } - - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Boolean CanConvert(Type objectType) - { - return typeof(AzurePermission).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - if (reader == null) - { - throw new ArgumentNullException("reader"); - } - - if (serializer == null) - { - throw new ArgumentNullException("serializer"); - } - - if (reader.TokenType != JsonToken.StartObject) - { - return existingValue; - } - - var contract = serializer.ContractResolver.ResolveContract(objectType) as JsonObjectContract; - if (contract == null) - { - return existingValue; - } - - JsonProperty resourceProviderProperty = contract.Properties.GetClosestMatchProperty("ResourceProvider"); - if (resourceProviderProperty == null) - { - return existingValue; - } - - JToken itemTypeValue; - JObject value = JObject.Load(reader); - - if (!value.TryGetValue(resourceProviderProperty.PropertyName, StringComparison.OrdinalIgnoreCase, out itemTypeValue)) - { - return existingValue; - } - - if (itemTypeValue.Type != JTokenType.String) - { - throw new NotSupportedException("ResourceProvider property is mandatory for azure permission"); - } - - string resourceProvider = (string)itemTypeValue; - AzurePermission returnValue = null; - switch (resourceProvider) - { - case AzurePermissionResourceProviders.AzureRoleAssignmentPermission: - returnValue = new AzureRoleAssignmentPermission(); - break; - case AzurePermissionResourceProviders.AzureKeyVaultPermission: - returnValue = new AzureKeyVaultPermission(); - break; - default: - throw new NotSupportedException($"{resourceProvider} is not a supported resource provider for azure permission"); - } - - if (returnValue != null) - { - using (JsonReader objectReader = value.CreateReader()) - { - serializer.Populate(objectReader, returnValue); - } - } - - return returnValue; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermissionResourceProviders.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermissionResourceProviders.cs deleted file mode 100644 index 0401d87cd..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermissionResourceProviders.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.WebApi -{ - [GenerateAllConstants] - public static class AzurePermissionResourceProviders - { - public const String AzureRoleAssignmentPermission = "Microsoft.RoleAssignment"; - public const String AzureKeyVaultPermission = "Microsoft.KeyVault"; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureResourcePermission.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureResourcePermission.cs deleted file mode 100644 index 60bdc4c06..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureResourcePermission.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public abstract class AzureResourcePermission : AzurePermission - { - [DataMember] - public String ResourceGroup { get; set; } - - protected AzureResourcePermission(String resourceProvider) : base(resourceProvider) - { - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureRoleAssignmentPermission.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureRoleAssignmentPermission.cs deleted file mode 100644 index a608ae89e..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureRoleAssignmentPermission.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class AzureRoleAssignmentPermission : AzurePermission - { - - [DataMember] - public Guid RoleAssignmentId { get; set; } - - public AzureRoleAssignmentPermission() : base(AzurePermissionResourceProviders.AzureRoleAssignmentPermission) - { - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureSubscription.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureSubscription.cs deleted file mode 100644 index ec592bbb2..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureSubscription.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Runtime.Serialization; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class AzureSubscription - { - [DataMember] - [JsonProperty(PropertyName = "displayName")] - public String DisplayName { get; set; } - - [DataMember] - [JsonProperty(PropertyName = "subscriptionId")] - public String SubscriptionId { get; set; } - - [DataMember] - public String SubscriptionTenantId { get; set; } - - [DataMember] - public String SubscriptionTenantName { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureSubscriptionQueryResult.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureSubscriptionQueryResult.cs deleted file mode 100644 index 998c44b9d..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzureSubscriptionQueryResult.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using System.Runtime.Serialization; -using Newtonsoft.Json; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class AzureSubscriptionQueryResult - { - [DataMember] - [JsonProperty("value")] - public List Value; - - [DataMember] - public string ErrorMessage; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/DataSourceBinding.cs b/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/DataSourceBinding.cs deleted file mode 100644 index e80fb9f13..000000000 --- a/src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/DataSourceBinding.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using CommonContracts = GitHub.DistributedTask.Common.Contracts; - -namespace GitHub.DistributedTask.WebApi -{ - public class DataSourceBinding : CommonContracts.DataSourceBindingBase - { - public DataSourceBinding() - : base() - { - } - - private DataSourceBinding(DataSourceBinding inputDefinitionToClone) - : base(inputDefinitionToClone) - { - - } - - public DataSourceBinding Clone() - { - return new DataSourceBinding(this); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentHttpClient.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentHttpClient.cs index 337d55354..792647bc2 100644 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentHttpClient.cs +++ b/src/Sdk/DTWebApi/WebApi/TaskAgentHttpClient.cs @@ -96,162 +96,6 @@ namespace GitHub.DistributedTask.WebApi return GetAgentsAsync(poolId, agentName, includeCapabilities, includeAssignedRequest, includeLastCompletedRequest, propertyFilters, demandStrings, userState, cancellationToken); } - /// - /// [Preview API] Get a secure file - /// - /// Project ID - /// The unique secure file Id - /// If includeDownloadTicket is true and the caller has permissions, a download ticket is included in the response. - /// - /// The cancellation token to cancel operation. - public virtual Task GetSecureFileAsync( - Guid project, - Guid secureFileId, - bool? includeDownloadTicket = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - return GetSecureFileAsync(project, secureFileId, includeDownloadTicket, actionFilter: null, userState: userState, cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID or project name - /// Name of the secure file to match. Can include wildcards to match multiple files. - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetSecureFilesAsync( - string project, - string namePattern = null, - bool? includeDownloadTickets = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - return GetSecureFilesAsync(project, namePattern, includeDownloadTickets, actionFilter: null, userState: userState, cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID - /// Name of the secure file to match. Can include wildcards to match multiple files. - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetSecureFilesAsync( - Guid project, - string namePattern = null, - bool? includeDownloadTickets = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - return GetSecureFilesAsync(project, namePattern, includeDownloadTickets, actionFilter: null, userState: userState, cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID or project name - /// A list of secure file Ids - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetSecureFilesByIdsAsync( - string project, - IEnumerable secureFileIds, - bool? includeDownloadTickets = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - return GetSecureFilesByIdsAsync(project, secureFileIds, includeDownloadTickets, actionFilter: null, userState: userState, cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get secure files - /// - /// Project ID - /// A list of secure file Ids - /// If includeDownloadTickets is true and the caller has permissions, a download ticket for each secure file is included in the response. - /// - /// The cancellation token to cancel operation. - public virtual Task> GetSecureFilesByIdsAsync( - Guid project, - IEnumerable secureFileIds, - bool? includeDownloadTickets = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - return GetSecureFilesByIdsAsync(project, secureFileIds, includeDownloadTickets, actionFilter: null, userState: userState, cancellationToken: cancellationToken); - } - - public async Task GetTaskContentZipAsync( - Guid taskId, - TaskVersion version, - Object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - var routeValues = new { taskId = taskId, versionString = version.ToString() }; - HttpRequestMessage requestMessage = await CreateRequestMessageAsync( - HttpMethod.Get, - TaskResourceIds.Tasks, - routeValues: routeValues, - version: m_currentApiVersion).ConfigureAwait(false); - - requestMessage.Headers.Accept.Clear(); - var header = new MediaTypeWithQualityHeaderValue("application/zip"); - header.Parameters.Add(new NameValueHeaderValue("api-version", m_currentApiVersion.ApiVersionString)); - header.Parameters.Add(new NameValueHeaderValue("res-version", "1")); - requestMessage.Headers.Accept.Add(header); - - HttpResponseMessage response = await SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, userState, cancellationToken).ConfigureAwait(false); - - response.EnsureSuccessStatusCode(); - - if (response.StatusCode == HttpStatusCode.NoContent) - { - throw new Exception("no content"); - } - - if (!VssStringComparer.ContentType.Equals(response.Content.Headers.ContentType.MediaType, "application/zip")) - { - throw new Exception("bad content type"); - } - - if (response.Content.Headers.ContentEncoding.Contains("gzip", StringComparer.OrdinalIgnoreCase)) - { - return new GZipStream(await response.Content.ReadAsStreamAsync().ConfigureAwait(false), CompressionMode.Decompress); - } - - return await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - } - - public Task QueueAgentRequestByPoolAsync( - Int32 poolId, - IList demands, - Guid serviceOwner, - Guid hostId, - Guid scopeIdentifier, - String hubName, - Guid planId, - Guid jobId, - Object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - var request = new TaskAgentJobRequest - { - ServiceOwner = serviceOwner, - HostId = hostId, - PlanType = hubName, - ScopeId = scopeIdentifier, - PlanId = planId, - JobId = jobId - }; - - return QueueAgentRequestByPoolAsync(poolId, request, userState, cancellationToken); - } - public Task RenewAgentRequestAsync( Int32 poolId, Int64 requestId, @@ -279,390 +123,6 @@ namespace GitHub.DistributedTask.WebApi return ReplaceAgentAsync(poolId, agent.Id, agent, userState, cancellationToken); } - public Task SendMessageAsync( - Int32 poolId, - Int64 requestId, - AgentJobRequestMessage request, - Object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - var message = new TaskAgentMessage - { - Body = JsonUtility.ToString(request), - MessageType = request.MessageType, - }; - - return SendMessageAsync(poolId, requestId, message, userState: userState, cancellationToken: cancellationToken); - } - - public Task SendMessageAsync( - Int32 poolId, - Int64 requestId, - JobCancelMessage cancel, - Object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - var message = new TaskAgentMessage - { - Body = JsonUtility.ToString(cancel), - MessageType = JobCancelMessage.MessageType, - }; - - return SendMessageAsync(poolId, requestId, message, userState: userState, cancellationToken: cancellationToken); - } - - public async Task UploadTaskZipAsync( - Guid taskId, - Stream fileStream, - Boolean overwrite = false, - Object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - ArgumentUtility.CheckForNull(fileStream, "fileStream"); - - HttpRequestMessage requestMessage; - - if (fileStream.Length == 0) - { - throw new Exception("file stream of length 0 not allowed."); - } - - if (fileStream.Length > 16 * 1024 * 1024) - { - throw new Exception("file stream too big"); - } - - Byte[] dataToSend = new Byte[fileStream.Length]; - - List> queryParameters = null; - if (overwrite) - { - queryParameters = new List>(); - queryParameters.Add("overwrite", "true"); - } - - var routeValues = new - { - taskId = taskId - }; - - requestMessage = await CreateRequestMessageAsync(HttpMethod.Put, - TaskResourceIds.Tasks, - routeValues: routeValues, - version: m_currentApiVersion, - queryParameters: queryParameters, - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false); - - // inorder for the upload to be retryable, we need the content to be re-readable - // to ensure this we copy the chunk into a byte array and send that - // chunk size ensures we can convert the length to an int - int bytesToCopy = (int)fileStream.Length; - using (MemoryStream ms = new MemoryStream(dataToSend)) - { - await fileStream.CopyToAsync(ms, bytesToCopy, cancellationToken).ConfigureAwait(false); - } - - // set the content and the Content-Range header - HttpContent byteArrayContent = new ByteArrayContent(dataToSend, 0, bytesToCopy); - byteArrayContent.Headers.ContentLength = fileStream.Length; - byteArrayContent.Headers.ContentRange = new ContentRangeHeaderValue(0, fileStream.Length - 1, fileStream.Length); - byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); - - requestMessage.Content = byteArrayContent; - return await SendAsync(requestMessage, userState, cancellationToken).ConfigureAwait(false); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetDeploymentGroupsMetricsAsync2( - string project, - string deploymentGroupName = null, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("281c6308-427a-49e1-b83a-dac0f4862189"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (!string.IsNullOrEmpty(deploymentGroupName)) - { - queryParams.Add("deploymentGroupName", deploymentGroupName); - } - if (!string.IsNullOrEmpty(continuationToken)) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("4.0-preview.1"), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - processResponse: GetPagedList); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetDeploymentGroupsMetricsAsync2( - Guid project, - string deploymentGroupName = null, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("281c6308-427a-49e1-b83a-dac0f4862189"); - object routeValues = new { project = project }; - - List> queryParams = new List>(); - if (!string.IsNullOrEmpty(deploymentGroupName)) - { - queryParams.Add("deploymentGroupName", deploymentGroupName); - } - if (!string.IsNullOrEmpty(continuationToken)) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("4.0-preview.1"), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - processResponse: GetPagedList); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - /// - public virtual Task> GetDeploymentTargetsAsyncWithContinuationToken( - string project, - int deploymentGroupId, - IEnumerable tags = null, - string name = null, - bool? partialNameMatch = null, - DeploymentTargetExpands? expand = null, - TaskAgentStatusFilter? agentStatus = null, - TaskAgentJobResultFilter? agentJobResult = null, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken), - Boolean? enabled = null, - IEnumerable propertyFilters = null) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (tags != null && tags.Any()) - { - queryParams.Add("tags", string.Join(",", tags)); - } - if (!string.IsNullOrEmpty(name)) - { - queryParams.Add("name", name); - } - if (partialNameMatch != null) - { - queryParams.Add("partialNameMatch", partialNameMatch.Value.ToString()); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - if (agentStatus != null) - { - queryParams.Add("agentStatus", agentStatus.Value.ToString()); - } - if (agentJobResult != null) - { - queryParams.Add("agentJobResult", agentJobResult.Value.ToString()); - } - if (!string.IsNullOrEmpty(continuationToken)) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (enabled != null) - { - queryParams.Add("enabled", enabled.Value.ToString()); - } - if (propertyFilters != null && propertyFilters.Any()) - { - queryParams.Add("propertyFilters", string.Join(",", propertyFilters)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("4.1-preview.1"), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - processResponse: GetPagedList); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// The cancellation token to cancel operation. - /// - public virtual Task> GetDeploymentTargetsAsyncWithContinuationToken( - Guid project, - int deploymentGroupId, - IEnumerable tags = null, - string name = null, - bool? partialNameMatch = null, - DeploymentTargetExpands? expand = null, - TaskAgentStatusFilter? agentStatus = null, - TaskAgentJobResultFilter? agentJobResult = null, - string continuationToken = null, - int? top = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken), - Boolean? enabled = null, - IEnumerable propertyFilters = null) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("2f0aa599-c121-4256-a5fd-ba370e0ae7b6"); - object routeValues = new { project = project, deploymentGroupId = deploymentGroupId }; - - List> queryParams = new List>(); - if (tags != null && tags.Any()) - { - queryParams.Add("tags", string.Join(",", tags)); - } - if (!string.IsNullOrEmpty(name)) - { - queryParams.Add("name", name); - } - if (partialNameMatch != null) - { - queryParams.Add("partialNameMatch", partialNameMatch.Value.ToString()); - } - if (expand != null) - { - queryParams.Add("$expand", expand.Value.ToString()); - } - if (agentStatus != null) - { - queryParams.Add("agentStatus", agentStatus.Value.ToString()); - } - if (agentJobResult != null) - { - queryParams.Add("agentJobResult", agentJobResult.Value.ToString()); - } - if (!string.IsNullOrEmpty(continuationToken)) - { - queryParams.Add("continuationToken", continuationToken); - } - if (top != null) - { - queryParams.Add("$top", top.Value.ToString(CultureInfo.InvariantCulture)); - } - if (enabled != null) - { - queryParams.Add("enabled", enabled.Value.ToString()); - } - if (propertyFilters != null && propertyFilters.Any()) - { - queryParams.Add("propertyFilters", string.Join(",", propertyFilters)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("4.1-preview.1"), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken, - processResponse: GetPagedList); - } - - protected async Task> GetPagedList(HttpResponseMessage responseMessage, CancellationToken cancellationToken) - { - var continuationToken = GetContinuationToken(responseMessage); - var list = await ReadContentAsAsync>(responseMessage, cancellationToken).ConfigureAwait(false); - return new PagedList(list, continuationToken); - } - - protected string GetContinuationToken(HttpResponseMessage responseMessage) - { - string continuationToken = null; - - IEnumerable headerValues = null; - if (responseMessage.Headers.TryGetValues("x-ms-continuationtoken", out headerValues)) - { - continuationToken = headerValues.FirstOrDefault(); - } - - return continuationToken; - } - protected Task SendAsync( HttpMethod method, Guid locationId, diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentHttpClientCompatBase.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentHttpClientCompatBase.cs index 5e5c50742..94d156735 100644 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentHttpClientCompatBase.cs +++ b/src/Sdk/DTWebApi/WebApi/TaskAgentHttpClientCompatBase.cs @@ -52,321 +52,5 @@ namespace GitHub.DistributedTask.WebApi : base(baseUrl, pipeline, disposeHandler) { } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteTaskGroupAsync( - string project, - Guid taskGroupId, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("4.0-preview.1"), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// The cancellation token to cancel operation. - public virtual async Task DeleteTaskGroupAsync( - Guid project, - Guid taskGroupId, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - HttpMethod httpMethod = new HttpMethod("DELETE"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - using (HttpResponseMessage response = await SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("4.0-preview.1"), - userState: userState, - cancellationToken: cancellationToken).ConfigureAwait(false)) - { - return; - } - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetTaskGroupsAsync( - string project, - Guid? taskGroupId = null, - bool? expanded = null, - Guid? taskIdFilter = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - if (expanded != null) - { - queryParams.Add("expanded", expanded.Value.ToString()); - } - if (taskIdFilter != null) - { - queryParams.Add("taskIdFilter", taskIdFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("4.0-preview.1"), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetTaskGroupsAsync( - Guid project, - Guid? taskGroupId = null, - bool? expanded = null, - Guid? taskIdFilter = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - if (expanded != null) - { - queryParams.Add("expanded", expanded.Value.ToString()); - } - if (taskIdFilter != null) - { - queryParams.Add("taskIdFilter", taskIdFilter.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("4.0-preview.1"), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID or project name - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetTaskGroupsAsync( - string project, - Guid? taskGroupId = null, - bool? expanded = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - if (expanded != null) - { - queryParams.Add("expanded", expanded.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("3.2-preview.1"), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] - /// - /// Project ID - /// - /// - /// - /// The cancellation token to cancel operation. - public virtual Task> GetTaskGroupsAsync( - Guid project, - Guid? taskGroupId = null, - bool? expanded = null, - object userState = null, - CancellationToken cancellationToken = default(CancellationToken)) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("6c08ffbf-dbf1-4f9a-94e5-a1cbd47005e7"); - object routeValues = new { project = project, taskGroupId = taskGroupId }; - - List> queryParams = new List>(); - if (expanded != null) - { - queryParams.Add("expanded", expanded.Value.ToString()); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion("3.2-preview.1"), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get information about an agent. - /// - /// The agent pool containing the agent - /// The agent ID to get information about - /// Whether to include the agent's capabilities in the response - /// Whether to include details about the agent's current work - /// Filter which custom properties will be returned - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never), Obsolete] - public virtual Task GetAgentAsync( - int poolId, - int agentId, - bool? includeCapabilities, - bool? includeAssignedRequest, - IEnumerable propertyFilters, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("e298ef32-5878-4cab-993c-043836571f42"); - object routeValues = new { poolId = poolId, agentId = agentId }; - - List> queryParams = new List>(); - if (includeCapabilities != null) - { - queryParams.Add("includeCapabilities", includeCapabilities.Value.ToString()); - } - if (includeAssignedRequest != null) - { - queryParams.Add("includeAssignedRequest", includeAssignedRequest.Value.ToString()); - } - if (propertyFilters != null && propertyFilters.Any()) - { - queryParams.Add("propertyFilters", string.Join(",", propertyFilters)); - } - - return SendAsync( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } - - /// - /// [Preview API] Get a list of agents. - /// - /// The agent pool containing the agents - /// Filter on agent name - /// Whether to include the agents' capabilities in the response - /// Whether to include details about the agents' current work - /// Filter which custom properties will be returned - /// Filter by demands the agents can satisfy - /// - /// The cancellation token to cancel operation. - [EditorBrowsable(EditorBrowsableState.Never), Obsolete] - public virtual Task> GetAgentsAsync( - int poolId, - string agentName, - bool? includeCapabilities, - bool? includeAssignedRequest, - IEnumerable propertyFilters, - IEnumerable demands, - object userState = null, - CancellationToken cancellationToken = default) - { - HttpMethod httpMethod = new HttpMethod("GET"); - Guid locationId = new Guid("e298ef32-5878-4cab-993c-043836571f42"); - object routeValues = new { poolId = poolId }; - - List> queryParams = new List>(); - if (agentName != null) - { - queryParams.Add("agentName", agentName); - } - if (includeCapabilities != null) - { - queryParams.Add("includeCapabilities", includeCapabilities.Value.ToString()); - } - if (includeAssignedRequest != null) - { - queryParams.Add("includeAssignedRequest", includeAssignedRequest.Value.ToString()); - } - if (propertyFilters != null && propertyFilters.Any()) - { - queryParams.Add("propertyFilters", string.Join(",", propertyFilters)); - } - if (demands != null && demands.Any()) - { - queryParams.Add("demands", string.Join(",", demands)); - } - - return SendAsync>( - httpMethod, - locationId, - routeValues: routeValues, - version: new ApiResourceVersion(5.1, 1), - queryParameters: queryParams, - userState: userState, - cancellationToken: cancellationToken); - } } } diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceDefinition.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceDefinition.cs deleted file mode 100644 index 9a4e5e595..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceDefinition.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskAgentPoolMaintenanceDefinition - { - internal TaskAgentPoolMaintenanceDefinition() - { - } - - private TaskAgentPoolMaintenanceDefinition(TaskAgentPoolMaintenanceDefinition maintenanceDefinitionToBeCloned) - { - this.Enabled = maintenanceDefinitionToBeCloned.Enabled; - this.JobTimeoutInMinutes = maintenanceDefinitionToBeCloned.JobTimeoutInMinutes; - this.MaxConcurrentAgentsPercentage = maintenanceDefinitionToBeCloned.MaxConcurrentAgentsPercentage; - - if (maintenanceDefinitionToBeCloned.Pool != null) - { - this.Pool = new TaskAgentPoolReference - { - Id = maintenanceDefinitionToBeCloned.Pool.Id, - Name = maintenanceDefinitionToBeCloned.Pool.Name, - Scope = maintenanceDefinitionToBeCloned.Pool.Scope, - PoolType = maintenanceDefinitionToBeCloned.Pool.PoolType - }; - } - - this.m_options = maintenanceDefinitionToBeCloned.Options.Clone(); - this.m_retentionPolicy = maintenanceDefinitionToBeCloned.RetentionPolicy.Clone(); - this.m_scheduleSetting = maintenanceDefinitionToBeCloned.ScheduleSetting.Clone(); - } - - /// - /// Id - /// - [DataMember] - public Int32 Id - { - get; - internal set; - } - - /// - /// Pool reference for the maintenance definition - /// - [DataMember(EmitDefaultValue = false)] - public TaskAgentPoolReference Pool - { - get; - set; - } - - /// - /// Enable maintenance - /// - [DataMember] - public Boolean Enabled - { - get; - set; - } - - /// - /// Maintenance job timeout per agent - /// - [DataMember] - public Int32 JobTimeoutInMinutes - { - get; - set; - } - - /// - /// Max percentage of agents within a pool running maintenance job at given time - /// - [DataMember] - public Int32 MaxConcurrentAgentsPercentage - { - get; - set; - } - - /// - /// Maintenance option for the definition - /// - public TaskAgentPoolMaintenanceOptions Options - { - get - { - if (m_options == null) - { - m_options = new TaskAgentPoolMaintenanceOptions() - { - WorkingDirectoryExpirationInDays = 0, - }; - } - - return m_options; - } - internal set - { - m_options = value; - } - } - - /// - /// The retention setting for the pool maintenance definition. - /// - public TaskAgentPoolMaintenanceRetentionPolicy RetentionPolicy - { - get - { - if (m_retentionPolicy == null) - { - m_retentionPolicy = new TaskAgentPoolMaintenanceRetentionPolicy() - { - NumberOfHistoryRecordsToKeep = 1, - }; - } - - return m_retentionPolicy; - } - internal set - { - m_retentionPolicy = value; - } - } - - /// - /// The schedule setting for the pool maintenance job. - /// - public TaskAgentPoolMaintenanceSchedule ScheduleSetting - { - get - { - if (m_scheduleSetting == null) - { - m_scheduleSetting = new TaskAgentPoolMaintenanceSchedule() - { - DaysToBuild = TaskAgentPoolMaintenanceScheduleDays.None, - }; - } - - return m_scheduleSetting; - } - internal set - { - m_scheduleSetting = value; - } - } - - public TaskAgentPoolMaintenanceDefinition Clone() - { - return new TaskAgentPoolMaintenanceDefinition(this); - } - - [DataMember(EmitDefaultValue = false, Name = "Options")] - public TaskAgentPoolMaintenanceOptions m_options; - - [DataMember(EmitDefaultValue = false, Name = "RetentionPolicy")] - private TaskAgentPoolMaintenanceRetentionPolicy m_retentionPolicy; - - [DataMember(EmitDefaultValue = false, Name = "ScheduleSetting")] - private TaskAgentPoolMaintenanceSchedule m_scheduleSetting; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJob.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJob.cs deleted file mode 100644 index 4d1f5647f..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJob.cs +++ /dev/null @@ -1,169 +0,0 @@ -using GitHub.Services.WebApi; -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskAgentPoolMaintenanceJob - { - internal TaskAgentPoolMaintenanceJob() - { - } - - /// - /// Id of the maintenance job - /// - [DataMember] - public Int32 JobId - { - get; - internal set; - } - - /// - /// Pool reference for the maintenance job - /// - [DataMember(EmitDefaultValue = false)] - public TaskAgentPoolReference Pool - { - get; - set; - } - - /// - /// Orchestration/Plan Id for the maintenance job - /// - [DataMember] - public Guid OrchestrationId - { - get; - internal set; - } - - /// - /// The maintenance definition for the maintenance job - /// - [DataMember] - public Int32 DefinitionId - { - get; - set; - } - - /// - /// Status of the maintenance job - /// - [DataMember] - public TaskAgentPoolMaintenanceJobStatus Status - { - get; - set; - } - - /// - /// The maintenance job result - /// - [DataMember(EmitDefaultValue = false)] - public TaskAgentPoolMaintenanceJobResult? Result - { - get; - internal set; - } - - /// - /// Time that the maintenance job was queued - /// - [DataMember(EmitDefaultValue = false)] - public DateTime? QueueTime - { - get; - internal set; - } - - /// - /// Time that the maintenance job was started - /// - [DataMember(EmitDefaultValue = false)] - public DateTime? StartTime - { - get; - internal set; - } - - /// - /// Time that the maintenance job was completed - /// - [DataMember(EmitDefaultValue = false)] - public DateTime? FinishTime - { - get; - internal set; - } - - /// - /// The identity that queued the maintenance job - /// - [DataMember(EmitDefaultValue = false)] - public IdentityRef RequestedBy - { - get; - internal set; - } - - /// - /// The total error counts during the maintenance job - /// - [DataMember] - public Int32 ErrorCount - { - get; - internal set; - } - - /// - /// The total warning counts during the maintenance job - /// - [DataMember] - public Int32 WarningCount - { - get; - internal set; - } - - /// - /// The log download url for the maintenance job - /// - [DataMember] - public String LogsDownloadUrl - { - get; - internal set; - } - - - /// - /// All agents that the maintenance job will run on - /// - public List TargetAgents - { - get - { - if (m_targetAgents == null) - { - m_targetAgents = new List(); - } - - return m_targetAgents; - } - internal set - { - m_targetAgents = value; - } - } - - [DataMember(EmitDefaultValue = false, Name = "TargetAgents")] - private List m_targetAgents; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobResult.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobResult.cs deleted file mode 100644 index 525947ba0..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobResult.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public enum TaskAgentPoolMaintenanceJobResult - { - [EnumMember] - Succeeded = 1, - - [EnumMember] - Failed = 2, - - [EnumMember] - Canceled = 4, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobStatus.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobStatus.cs deleted file mode 100644 index a8c594f7b..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobStatus.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public enum TaskAgentPoolMaintenanceJobStatus - { - [EnumMember] - InProgress = 1, - - [EnumMember] - Completed = 2, - - [EnumMember] - Cancelling = 4, - - [EnumMember] - Queued = 8, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobTargetAgent.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobTargetAgent.cs deleted file mode 100644 index e200ef5ec..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceJobTargetAgent.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskAgentPoolMaintenanceJobTargetAgent - { - internal TaskAgentPoolMaintenanceJobTargetAgent() - { - } - - [DataMember] - public Int32 JobId - { - get; - set; - } - - [DataMember] - public TaskAgentReference Agent - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TaskAgentPoolMaintenanceJobStatus? Status - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TaskAgentPoolMaintenanceJobResult? Result - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceOptions.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceOptions.cs deleted file mode 100644 index 332c32b3f..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceOptions.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class TaskAgentPoolMaintenanceOptions - { - internal TaskAgentPoolMaintenanceOptions() - { - } - - private TaskAgentPoolMaintenanceOptions(TaskAgentPoolMaintenanceOptions maintenanceOptionToBeCloned) - { - this.WorkingDirectoryExpirationInDays = maintenanceOptionToBeCloned.WorkingDirectoryExpirationInDays; - } - - /// - /// time to consider a System.DefaultWorkingDirectory is stale - /// - [DataMember] - public Int32 WorkingDirectoryExpirationInDays - { - get; - set; - } - - public TaskAgentPoolMaintenanceOptions Clone() - { - return new TaskAgentPoolMaintenanceOptions(this); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceRetentionPolicy.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceRetentionPolicy.cs deleted file mode 100644 index e5bb9d57a..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceRetentionPolicy.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class TaskAgentPoolMaintenanceRetentionPolicy - { - internal TaskAgentPoolMaintenanceRetentionPolicy() - { } - - private TaskAgentPoolMaintenanceRetentionPolicy(TaskAgentPoolMaintenanceRetentionPolicy maintenanceRetentionPolicyToBeCloned) - { - this.NumberOfHistoryRecordsToKeep = maintenanceRetentionPolicyToBeCloned.NumberOfHistoryRecordsToKeep; - } - - /// - /// Number of records to keep for maintenance job executed with this definition. - /// - [DataMember] - public Int32 NumberOfHistoryRecordsToKeep - { - get - { - return m_numberOfHistoryRecordsToKeep; - } - internal set - { - if (value < 1) - { - m_numberOfHistoryRecordsToKeep = 1; - } - else - { - m_numberOfHistoryRecordsToKeep = value; - } - } - } - - public TaskAgentPoolMaintenanceRetentionPolicy Clone() - { - return new TaskAgentPoolMaintenanceRetentionPolicy(this); - } - - private Int32 m_numberOfHistoryRecordsToKeep; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceSchedule.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceSchedule.cs deleted file mode 100644 index a931287ef..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceSchedule.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class TaskAgentPoolMaintenanceSchedule - { - internal TaskAgentPoolMaintenanceSchedule() - { - this.DaysToBuild = TaskAgentPoolMaintenanceScheduleDays.None; - } - - private TaskAgentPoolMaintenanceSchedule(TaskAgentPoolMaintenanceSchedule maintenanceScheduleToBeCloned) - { - this.ScheduleJobId = maintenanceScheduleToBeCloned.ScheduleJobId; - this.StartHours = maintenanceScheduleToBeCloned.StartHours; - this.StartMinutes = maintenanceScheduleToBeCloned.StartMinutes; - this.TimeZoneId = maintenanceScheduleToBeCloned.TimeZoneId; - this.DaysToBuild = maintenanceScheduleToBeCloned.DaysToBuild; - } - - /// - /// The Job Id of the Scheduled job that will queue the pool maintenance job. - /// - [DataMember] - public Guid ScheduleJobId { get; set; } - - /// - /// Time zone of the build schedule (string representation of the time zone id) - /// - [DataMember] - public String TimeZoneId { get; set; } - - /// - /// Local timezone hour to start - /// - [DataMember] - public Int32 StartHours { get; set; } - - /// - /// Local timezone minute to start - /// - [DataMember] - public Int32 StartMinutes { get; set; } - - /// - /// Days for a build (flags enum for days of the week) - /// - [DataMember] - public TaskAgentPoolMaintenanceScheduleDays DaysToBuild { get; set; } - - public TaskAgentPoolMaintenanceSchedule Clone() - { - return new TaskAgentPoolMaintenanceSchedule(this); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceScheduleDays.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceScheduleDays.cs deleted file mode 100644 index e96d34572..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentPoolMaintenanceScheduleDays.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public enum TaskAgentPoolMaintenanceScheduleDays - { - /// - /// Do not run. - /// - [EnumMember] - None = 0, - - /// - /// Run on Monday. - /// - [EnumMember] - Monday = 1, - - /// - /// Run on Tuesday. - /// - [EnumMember] - Tuesday = 2, - - /// - /// Run on Wednesday. - /// - [EnumMember] - Wednesday = 4, - - /// - /// Run on Thursday. - /// - [EnumMember] - Thursday = 8, - - /// - /// Run on Friday. - /// - [EnumMember] - Friday = 16, - - /// - /// Run on Saturday. - /// - [EnumMember] - Saturday = 32, - - /// - /// Run on Sunday. - /// - [EnumMember] - Sunday = 64, - - /// - /// Run on all days of the week. - /// - [EnumMember] - All = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentQueue.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentQueue.cs deleted file mode 100644 index 73dee04ee..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentQueue.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// An agent queue. - /// - [DataContract] - public class TaskAgentQueue - { - public TaskAgentQueue() - { - } - - private TaskAgentQueue(TaskAgentQueue queueToBeCloned) - { - this.Id = queueToBeCloned.Id; - this.ProjectId = queueToBeCloned.ProjectId; - this.Name = queueToBeCloned.Name; -#pragma warning disable 0618 - this.GroupScopeId = queueToBeCloned.GroupScopeId; - this.Provisioned = queueToBeCloned.Provisioned; -#pragma warning restore 0618 - if (queueToBeCloned.Pool != null) - { - this.Pool = queueToBeCloned.Pool.Clone(); - } - } - - /// - /// ID of the queue - /// - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - set; - } - - /// - /// Project ID - /// - [DataMember(EmitDefaultValue = false)] - public Guid ProjectId - { - get; - set; - } - - /// - /// Name of the queue - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Pool reference for this queue - /// - [DataMember(EmitDefaultValue = false)] - public TaskAgentPoolReference Pool - { - get; - set; - } - - #region Obsolete Properties - - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This property is no longer used and will be removed in a future version.", false)] - public Guid GroupScopeId - { - get; - set; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("This property is no longer used and will be removed in a future version.", false)] - public Boolean Provisioned - { - get; - set; - } - - #endregion - - public TaskAgentQueue Clone() - { - return new TaskAgentQueue(this); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskAgentQueueActionFilter.cs b/src/Sdk/DTWebApi/WebApi/TaskAgentQueueActionFilter.cs deleted file mode 100644 index 69f832336..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskAgentQueueActionFilter.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Filters queues based on whether the calling user has permission to use or manage the queue. - /// - [Flags] - [DataContract] - public enum TaskAgentQueueActionFilter - { - [EnumMember] - None = 0, - - [EnumMember] - Manage = 2, - - [EnumMember] - Use = 16, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskDefinition.cs b/src/Sdk/DTWebApi/WebApi/TaskDefinition.cs deleted file mode 100644 index 65c5a8288..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskDefinition.cs +++ /dev/null @@ -1,552 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Runtime.Serialization; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - [DebuggerDisplay("Id: {Id}, Name: {Name}, Version: {Version}")] - public class TaskDefinition - { - public TaskDefinition() - { - this.DefinitionType = TaskDefinitionType.Task; - } - - protected TaskDefinition(TaskDefinition taskDefinitionToClone) - { - if (taskDefinitionToClone.AgentExecution != null) - { - this.AgentExecution = taskDefinitionToClone.AgentExecution.Clone(); - } - - if (taskDefinitionToClone.PreJobExecution != null) - { - this.m_preJobExecution = new Dictionary(taskDefinitionToClone.m_preJobExecution); - } - - if (taskDefinitionToClone.Execution != null) - { - this.m_execution = new Dictionary(taskDefinitionToClone.m_execution); - } - - if (taskDefinitionToClone.PostJobExecution != null) - { - this.m_postJobExecution = new Dictionary(taskDefinitionToClone.m_postJobExecution); - } - - this.Author = taskDefinitionToClone.Author; - this.Category = taskDefinitionToClone.Category; - this.HelpMarkDown = taskDefinitionToClone.HelpMarkDown; - this.HelpUrl = taskDefinitionToClone.HelpUrl; - this.ContentsUploaded = taskDefinitionToClone.ContentsUploaded; - - if (taskDefinitionToClone.m_visibilities != null) - { - this.m_visibilities = new List(taskDefinitionToClone.m_visibilities); - } - - if (taskDefinitionToClone.m_runsOn != null) - { - this.m_runsOn = new List(taskDefinitionToClone.m_runsOn); - } - - if (this.m_runsOn == null) - { - this.m_runsOn = new List(TaskRunsOnConstants.DefaultValue); - } - - if (taskDefinitionToClone.m_demands != null) - { - this.m_demands = new List(taskDefinitionToClone.m_demands.Select(x => x.Clone())); - } - - this.Description = taskDefinitionToClone.Description; - this.FriendlyName = taskDefinitionToClone.FriendlyName; - this.HostType = taskDefinitionToClone.HostType; - this.IconUrl = taskDefinitionToClone.IconUrl; - this.Id = taskDefinitionToClone.Id; - - if (taskDefinitionToClone.m_inputs != null) - { - this.m_inputs = new List(taskDefinitionToClone.m_inputs.Select(x => x.Clone())); - } - - if (taskDefinitionToClone.m_satisfies != null) - { - this.m_satisfies = new List(taskDefinitionToClone.m_satisfies); - } - - if (taskDefinitionToClone.m_sourceDefinitions != null) - { - this.m_sourceDefinitions = new List(taskDefinitionToClone.m_sourceDefinitions.Select(x => x.Clone())); - } - - if (taskDefinitionToClone.m_dataSourceBindings != null) - { - this.m_dataSourceBindings = new List(taskDefinitionToClone.m_dataSourceBindings.Select(x => x.Clone())); - } - - if (taskDefinitionToClone.m_groups != null) - { - this.m_groups = new List(taskDefinitionToClone.m_groups.Select(x => x.Clone())); - } - - if (taskDefinitionToClone.m_outputVariables != null) - { - this.m_outputVariables = new List(taskDefinitionToClone.m_outputVariables.Select(x => x.Clone())); - } - - this.InstanceNameFormat = taskDefinitionToClone.InstanceNameFormat; - this.MinimumAgentVersion = taskDefinitionToClone.MinimumAgentVersion; - this.Name = taskDefinitionToClone.Name; - this.PackageLocation = taskDefinitionToClone.PackageLocation; - this.PackageType = taskDefinitionToClone.PackageType; - this.ServerOwned = taskDefinitionToClone.ServerOwned; - this.SourceLocation = taskDefinitionToClone.SourceLocation; - this.Version = taskDefinitionToClone.Version.Clone(); - this.ContributionIdentifier = taskDefinitionToClone.ContributionIdentifier; - this.ContributionVersion = taskDefinitionToClone.ContributionVersion; - this.Deprecated = taskDefinitionToClone.Deprecated; - this.Disabled = taskDefinitionToClone.Disabled; - this.DefinitionType = taskDefinitionToClone.DefinitionType; - this.ShowEnvironmentVariables = taskDefinitionToClone.ShowEnvironmentVariables; - this.Preview = taskDefinitionToClone.Preview; - this.ReleaseNotes = taskDefinitionToClone.ReleaseNotes; - - if (this.DefinitionType == null) - { - this.DefinitionType = TaskDefinitionType.Task; - } - } - - // - // Members to identify this task - // - [DataMember(EmitDefaultValue = false)] - public Guid Id - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TaskVersion Version - { - get; - set; - } - - [Obsolete("Ecosystem property is not currently supported.")] - [DataMember(EmitDefaultValue = false)] - public String Ecosystem - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean ServerOwned - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean ContentsUploaded - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String IconUrl - { - get; - set; - } - - // - // Location Information for acquisition - // - [DataMember(EmitDefaultValue = false)] - public String HostType - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String PackageType - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String PackageLocation - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String SourceLocation - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String MinimumAgentVersion - { - get; - set; - } - - // - // Helpful Metadata for discovery and designer - // - [DataMember(EmitDefaultValue = false)] - public String FriendlyName - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String Category - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String HelpMarkDown - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String HelpUrl - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String ReleaseNotes - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean Preview - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean Deprecated - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String ContributionIdentifier - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String ContributionVersion - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean Disabled - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String DefinitionType - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean ShowEnvironmentVariables - { - get; - set; - } - - public IList Visibility - { - get - { - if (m_visibilities == null) - { - m_visibilities = new List(); - } - return m_visibilities; - } - } - - public IList RunsOn - { - get - { - if (m_runsOn == null) - { - m_runsOn = new List(TaskRunsOnConstants.DefaultValue); - } - - return m_runsOn; - } - } - - [DataMember(EmitDefaultValue = false)] - public String Author { get; set; } - - [DataMember(EmitDefaultValue = false)] - public IList Demands - { - get - { - if (m_demands == null) - { - m_demands = new List(); - } - return m_demands; - } - } - - [DataMember(EmitDefaultValue = false)] - public IList Groups - { - get - { - if (m_groups == null) - { - m_groups = new List(); - } - return m_groups; - } - } - - [DataMember(EmitDefaultValue = false)] - public IList Inputs - { - get - { - if (m_inputs == null) - { - m_inputs = new List(); - } - return m_inputs; - } - } - - [DataMember(EmitDefaultValue = false)] - public IList Satisfies - { - get - { - if (m_satisfies == null) - { - m_satisfies = new List(); - } - return m_satisfies; - } - } - - [DataMember(EmitDefaultValue = false)] - public IList SourceDefinitions - { - get - { - if (m_sourceDefinitions == null) - { - m_sourceDefinitions = new List(); - } - return m_sourceDefinitions; - } - } - - [DataMember(EmitDefaultValue = false)] - public IList DataSourceBindings - { - get - { - if (m_dataSourceBindings == null) - { - m_dataSourceBindings = new List(); - } - return m_dataSourceBindings; - } - } - - [DataMember(EmitDefaultValue = false)] - public String InstanceNameFormat - { - get; - set; - } - - // - // Execution members - // - [DataMember(EmitDefaultValue = false)] - public IDictionary PreJobExecution - { - get - { - if (m_preJobExecution == null) - { - m_preJobExecution = new Dictionary(); - } - return m_preJobExecution; - } - } - - [DataMember(EmitDefaultValue = false)] - public IDictionary Execution - { - get - { - if (m_execution == null) - { - m_execution = new Dictionary(); - } - return m_execution; - } - } - - [DataMember(EmitDefaultValue = false)] - public IDictionary PostJobExecution - { - get - { - if (m_postJobExecution == null) - { - m_postJobExecution = new Dictionary(); - } - return m_postJobExecution; - } - } - - [DataMember(EmitDefaultValue = false)] - public TaskExecution AgentExecution - { - get; - set; - } - - public IList OutputVariables - { - get - { - if (m_outputVariables == null) - { - m_outputVariables = new List(); - } - return m_outputVariables; - } - } - - internal TaskDefinition Clone() - { - return new TaskDefinition(this); - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - SerializationHelper.Copy(ref m_serializedVisibilities, ref m_visibilities, true); - SerializationHelper.Copy(ref m_serializedRunsOn, ref m_runsOn, true); - RenameLegacyRunsOnValues(m_runsOn); - SerializationHelper.Copy(ref m_serializedOutputVariables, ref m_outputVariables, true); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - SerializationHelper.Copy(ref m_visibilities, ref m_serializedVisibilities); - RenameLegacyRunsOnValues(m_runsOn); - SerializationHelper.Copy(ref m_runsOn, ref m_serializedRunsOn); - SerializationHelper.Copy(ref m_outputVariables, ref m_serializedOutputVariables); - } - - [OnSerialized] - private void OnSerialized(StreamingContext context) - { - m_serializedVisibilities = null; - m_serializedRunsOn = null; - m_serializedOutputVariables = null; - } - - private static void RenameLegacyRunsOnValues(IList runsOn) - { - for (int i = 0; i < runsOn?.Count(); i++) - { - if (runsOn[i].Equals(TaskRunsOnConstants.RunsOnMachineGroup, StringComparison.OrdinalIgnoreCase)) - { - runsOn[i] = TaskRunsOnConstants.RunsOnDeploymentGroup; - } - } - } - - // - // Private - // - [DataMember(Name = "Visibility", EmitDefaultValue = false)] - private List m_serializedVisibilities; - - [DataMember(Name = "RunsOn", EmitDefaultValue = false)] - private List m_serializedRunsOn; - - [DataMember(Name = "OutputVariables", EmitDefaultValue = false)] - private List m_serializedOutputVariables; - - private Dictionary m_preJobExecution; - private Dictionary m_execution; - private Dictionary m_postJobExecution; - private List m_demands; - private List m_inputs; - private List m_satisfies; - private List m_sourceDefinitions; - private List m_dataSourceBindings; - private List m_groups; - private List m_outputVariables; - private List m_visibilities; - private List m_runsOn; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskDefinitionEndpoint.cs b/src/Sdk/DTWebApi/WebApi/TaskDefinitionEndpoint.cs deleted file mode 100644 index 7480da311..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskDefinitionEndpoint.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskDefinitionEndpoint - { - /// - /// The scope as understood by Connected Services. - /// Essentialy, a project-id for now. - /// - [DataMember] - public String Scope - { - get; - set; - } - - /// - /// URL to GET. - /// - [DataMember] - public String Url - { - get; - set; - } - - /// - /// An XPath/Json based selector to filter response returned by fetching - /// the endpoint Url. An XPath based selector must be prefixed with - /// the string "xpath:". A Json based selector must be prefixed with "jsonpath:". - /// - /// The following selector defines an XPath for extracting nodes named 'ServiceName'. - /// - /// endpoint.Selector = "xpath://ServiceName"; - /// - /// - /// - [DataMember] - public String Selector - { - get; - set; - } - - /// - /// An Json based keyselector to filter response returned by fetching - /// the endpoint Url.A Json based keyselector must be prefixed with "jsonpath:". - /// KeySelector can be used to specify the filter to get the keys for the values specified with Selector. - /// - /// The following keyselector defines an Json for extracting nodes named 'ServiceName'. - /// - /// endpoint.KeySelector = "jsonpath://ServiceName"; - /// - /// - /// - [DataMember] - public String KeySelector - { - get; - set; - } - - /// - /// An ID that identifies a service connection to be used for authenticating - /// endpoint requests. - /// - [DataMember] - public String ConnectionId - { - get; - set; - } - - /// - /// TaskId that this endpoint belongs to. - /// - [DataMember] - public String TaskId - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskDefinitionReference.cs b/src/Sdk/DTWebApi/WebApi/TaskDefinitionReference.cs deleted file mode 100644 index 28acbcba0..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskDefinitionReference.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskDefinitionReference - { - public TaskDefinitionReference() - { - // Default is Task - this.DefinitionType = TaskDefinitionType.Task; - } - - private TaskDefinitionReference(TaskDefinitionReference definitionReference) - { - this.Id = definitionReference.Id; - this.VersionSpec = definitionReference.VersionSpec; - - // If it is null, we set it to task - this.DefinitionType = definitionReference.DefinitionType ?? TaskDefinitionType.Task; - } - - /// - /// Gets or sets the unique identifier of task. - /// - [DataMember(IsRequired = true)] - public Guid Id { get; set; } - - /// - /// Gets or sets the version specification of task. - /// - [DataMember(IsRequired = true)] - public String VersionSpec { get; set; } - - /// - /// Gets or sets the definition type. Values can be 'task' or 'metaTask'. - /// - [DataMember(IsRequired = true)] - public String DefinitionType - { - get - { - return this.m_definitionType ?? (this.m_definitionType = TaskDefinitionType.Task); - } - - set - { - this.m_definitionType = value; - } - } - - public override bool Equals(object obj) - { - var toEqual = (TaskDefinitionReference)obj; - if (toEqual == null) - { - return false; - } - - return this.Id.Equals(toEqual.Id) && - (this.VersionSpec?.Equals(toEqual.VersionSpec) ?? this.VersionSpec == toEqual.VersionSpec) && - (this.DefinitionType?.Equals(toEqual.DefinitionType) ?? this.DefinitionType == toEqual.DefinitionType); - } - - public override int GetHashCode() - { - return this.ToString().GetHashCode(); - } - - internal TaskDefinitionReference Clone() - { - return new TaskDefinitionReference(this); - } - - private String m_definitionType; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskDefinitionType.cs b/src/Sdk/DTWebApi/WebApi/TaskDefinitionType.cs deleted file mode 100644 index 83bf7eaee..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskDefinitionType.cs +++ /dev/null @@ -1,12 +0,0 @@ - -using System; - -namespace GitHub.DistributedTask.WebApi -{ - public class TaskDefinitionType - { - public const String Task = "task"; - - public const String MetaTask = "metaTask"; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskExecution.cs b/src/Sdk/DTWebApi/WebApi/TaskExecution.cs deleted file mode 100644 index 32b02264c..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskExecution.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskExecution - { - public TaskExecution() - { - } - - private TaskExecution(TaskExecution taskExecutionToBeCloned) - { - if (taskExecutionToBeCloned.ExecTask != null) - { - this.ExecTask = taskExecutionToBeCloned.ExecTask.Clone(); - } - - if (taskExecutionToBeCloned.PlatformInstructions != null) - { - this.PlatformInstructions = new Dictionary>(taskExecutionToBeCloned.PlatformInstructions, StringComparer.OrdinalIgnoreCase); - } - } - - /// - /// The utility task to run. Specifying this means that this task definition is simply a meta task to call another task. - /// This is useful for tasks that call utility tasks like powershell and commandline - /// - [DataMember(Order = 10, EmitDefaultValue = false)] - public TaskReference ExecTask - { - get; - set; - } - - /// - /// If a task is going to run code, then this provides the type/script etc... information by platform. - /// For example, it might look like. - /// net45: { - /// typeName: "GitHub.Automation.Tasks.PowerShellTask", - /// assemblyName: "GitHub.Automation.Tasks.PowerShell.dll" - /// } - /// net20: { - /// typeName: "GitHub.Automation.Tasks.PowerShellTask", - /// assemblyName: "GitHub.Automation.Tasks.PowerShell.dll" - /// } - /// java: { - /// jar: "powershelltask.tasks.automation.teamfoundation.microsoft.com", - /// } - /// node: { - /// script: "powershellhost.js", - /// } - /// - [DataMember(Order = 20, EmitDefaultValue = false)] - public Dictionary> PlatformInstructions - { - get; - set; - } - - internal TaskExecution Clone() - { - return new TaskExecution(this); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskGroup.cs b/src/Sdk/DTWebApi/WebApi/TaskGroup.cs deleted file mode 100644 index 1d57777ea..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskGroup.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using System.Runtime.Serialization; -using System.Collections.Generic; -using System.Linq; - -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskGroup: TaskDefinition - { - /// - /// A task group lets you to encapsulate a sequence of tasks already defined in a build definition, a release definition or a task group into a single reusable task. - /// - public TaskGroup() - { - this.DefinitionType = TaskDefinitionType.MetaTask; - } - - private TaskGroup(TaskGroup definition) : base(definition) - { - this.DefinitionType = TaskDefinitionType.MetaTask; - - this.Owner = definition.Owner; - this.Revision = definition.Revision; - this.CreatedOn = definition.CreatedOn; - this.ModifiedOn = definition.ModifiedOn; - this.Comment = definition.Comment; - this.ParentDefinitionId = definition.ParentDefinitionId; - - if (definition.Tasks != null) - { - this.Tasks = new List(definition.Tasks.Select(x => x.Clone())); - } - - if (definition.CreatedBy != null) - { - this.CreatedBy = definition.CreatedBy.Clone(); - } - - if (definition.ModifiedBy != null) - { - this.ModifiedBy = definition.ModifiedBy.Clone(); - } - } - - public IList Tasks - { - get - { - if (m_tasks == null) - { - m_tasks = new List(); - } - - return m_tasks; - } - set - { - if (value == null) - { - m_tasks = new List(); - } - else - { - this.m_tasks = value; - } - } - } - - /// - /// Gets or sets the owner. - /// - [DataMember(EmitDefaultValue = false)] - public String Owner - { - get; - set; - } - - /// - /// Gets or sets revision. - /// - [DataMember] - public Int32 Revision - { - get; - set; - } - - /// - /// Gets or sets the identity who created. - /// - [DataMember] - public IdentityRef CreatedBy - { - get; - set; - } - - /// - /// Gets or sets date on which it got created. - /// - [DataMember] - public DateTime CreatedOn - { - get; - set; - } - - /// - /// Gets or sets the identity who modified. - /// - [DataMember] - public IdentityRef ModifiedBy - { - get; - set; - } - - /// - /// Gets or sets date on which it got modified. - /// - [DataMember] - public DateTime ModifiedOn - { - get; - set; - } - - /// - /// Gets or sets comment. - /// - [DataMember(EmitDefaultValue = false)] - public String Comment - { - get; - set; - } - - /// - /// Gets or sets parent task group Id. This is used while creating a draft task group. - /// - [DataMember(EmitDefaultValue = false)] - public Guid? ParentDefinitionId - { - get; - set; - } - - /// - /// Gets or sets as 'true' to indicate as deleted, 'false' otherwise. - /// - [DataMember(EmitDefaultValue = false)] - public bool Deleted - { - get; - set; - } - - internal new TaskGroup Clone() - { - return new TaskGroup(this); - } - - /// - /// Gets or sets the tasks. - /// - [DataMember(Name = "Tasks")] - private IList m_tasks; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskGroupCreateParameter.cs b/src/Sdk/DTWebApi/WebApi/TaskGroupCreateParameter.cs deleted file mode 100644 index 0ac49e6c8..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskGroupCreateParameter.cs +++ /dev/null @@ -1,140 +0,0 @@ -using System; -using System.Runtime.Serialization; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskGroupCreateParameter - { - /// - /// Sets name of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Name { get; set; } - - /// - /// Sets friendly name of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String FriendlyName { get; set; } - - /// - /// Sets author name of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Author { get; set; } - - /// - /// Sets description of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Description { get; set; } - - /// - /// Sets parent task group Id. This is used while creating a draft task group. - /// - [DataMember(EmitDefaultValue = false)] - public Guid? ParentDefinitionId { get; set; } - - /// - /// Sets url icon of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String IconUrl { get; set; } - - /// - /// Sets display name of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String InstanceNameFormat { get; set; } - - /// - /// Sets category of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Category { get; set; } - - /// - /// Sets version of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public TaskVersion Version { get; set; } - - public IList RunsOn - { - get - { - if (m_runsOn == null) - { - m_runsOn = new List(TaskRunsOnConstants.DefaultValue); - } - - return m_runsOn; - } - } - - public IList Tasks - { - get - { - if (m_tasks == null) - { - m_tasks = new List(); - } - - return m_tasks; - } - } - - public IList Inputs - { - get - { - if (m_inputs == null) - { - m_inputs = new List(); - } - return m_inputs; - } - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - SerializationHelper.Copy(ref m_serializedRunsOn, ref m_runsOn, true); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - SerializationHelper.Copy(ref m_runsOn, ref m_serializedRunsOn); - } - - [OnSerialized] - private void OnSerialized(StreamingContext context) - { - m_serializedRunsOn = null; - } - - /// - /// Sets RunsOn of the task group. Value can be 'Agent', 'Server' or 'DeploymentGroup'. - /// - [DataMember(Name = "RunsOn", EmitDefaultValue = false)] - private List m_serializedRunsOn; - - /// - /// Sets tasks for the task group. - /// - [DataMember(Name = "Tasks", EmitDefaultValue = false)] - private IList m_tasks; - - /// - /// Sets input for the task group. - /// - [DataMember(Name = "Inputs", EmitDefaultValue = false)] - private List m_inputs; - - private List m_runsOn; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskGroupDefinition.cs b/src/Sdk/DTWebApi/WebApi/TaskGroupDefinition.cs deleted file mode 100644 index 191ed3e0d..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskGroupDefinition.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskGroupDefinition - { - public TaskGroupDefinition() - { - IsExpanded = false; - } - - private TaskGroupDefinition(TaskGroupDefinition inputDefinitionToClone) - { - this.IsExpanded = inputDefinitionToClone.IsExpanded; - this.Name = inputDefinitionToClone.Name; - this.DisplayName = inputDefinitionToClone.DisplayName; - this.VisibleRule = inputDefinitionToClone.VisibleRule; - - if (inputDefinitionToClone.m_tags != null) - { - this.m_tags = new List(inputDefinitionToClone.m_tags); - } - } - - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String DisplayName - { - get; - set; - } - - [DataMember(EmitDefaultValue = true)] - public Boolean IsExpanded - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String VisibleRule - { - get; - set; - } - - public IList Tags - { - get - { - if (m_tags == null) - { - m_tags = new List(); - } - return m_tags; - } - } - - public TaskGroupDefinition Clone() - { - return new TaskGroupDefinition(this); - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - SerializationHelper.Copy(ref m_serializedTags, ref m_tags, true); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - SerializationHelper.Copy(ref m_tags, ref m_serializedTags); - } - - [OnSerialized] - private void OnSerialized(StreamingContext context) - { - m_serializedTags = null; - } - - [DataMember(Name = "Tags", EmitDefaultValue = false)] - private List m_serializedTags; - - private List m_tags; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskGroupExpands.cs b/src/Sdk/DTWebApi/WebApi/TaskGroupExpands.cs deleted file mode 100644 index b9868d577..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskGroupExpands.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace GitHub.DistributedTask.WebApi -{ - using System; - - [Flags] - public enum TaskGroupExpands - { - None = 0, - Tasks = 2, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskGroupQueryOrder.cs b/src/Sdk/DTWebApi/WebApi/TaskGroupQueryOrder.cs deleted file mode 100644 index c21840569..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskGroupQueryOrder.cs +++ /dev/null @@ -1,30 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// 2012-2023, All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace GitHub.DistributedTask.WebApi -{ - using System.Runtime.Serialization; - - /// - /// Specifies the desired ordering of taskGroups. - /// - [DataContract] - public enum TaskGroupQueryOrder - { - /// - /// Order by createdon ascending. - /// - [EnumMember] - CreatedOnAscending = 0, - - /// - /// Order by createdon descending. - /// - [EnumMember] - CreatedOnDescending = 1, - - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskGroupRevision.cs b/src/Sdk/DTWebApi/WebApi/TaskGroupRevision.cs deleted file mode 100644 index 7f13ec8c2..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskGroupRevision.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Runtime.Serialization; -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskGroupRevision - { - [DataMember] - public Guid TaskGroupId { get; set; } - - [DataMember] - public Int32 Revision { get; set; } - - [DataMember] - public Int32 MajorVersion { get; set; } - - [DataMember] - public IdentityRef ChangedBy { get; set; } - - [DataMember] - public DateTime ChangedDate { get; set; } - - [DataMember] - public AuditAction ChangeType { get; set; } - - [DataMember] - public Int32 FileId { get; set; } - - [DataMember] - public String Comment { get; set; } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskGroupStep.cs b/src/Sdk/DTWebApi/WebApi/TaskGroupStep.cs deleted file mode 100644 index e20fd2775..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskGroupStep.cs +++ /dev/null @@ -1,156 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Represents tasks in the task group. - /// - [DataContract] - public class TaskGroupStep - { - public TaskGroupStep() - { - } - - private TaskGroupStep(TaskGroupStep taskGroupStep) - { - this.DisplayName = taskGroupStep.DisplayName; - this.AlwaysRun = taskGroupStep.AlwaysRun; - this.ContinueOnError = taskGroupStep.ContinueOnError; - this.Enabled = taskGroupStep.Enabled; - this.TimeoutInMinutes = taskGroupStep.TimeoutInMinutes; - this.Inputs = new Dictionary(taskGroupStep.Inputs); - - if (taskGroupStep.m_environment != null) - { - foreach (var property in taskGroupStep.m_environment) - { - this.Environment[property.Key] = property.Value; - } - } - - this.Task = taskGroupStep.Task.Clone(); - } - - /// - /// Gets or sets the display name. - /// - [DataMember] - public String DisplayName - { - get - { - if (this.m_displayName == null) - { - this.m_displayName = String.Empty; - } - - return this.m_displayName; - } - set - { - this.m_displayName = value; - } - } - - /// - /// Gets or sets as 'true' to run the task always, 'false' otherwise. - /// - [DataMember] - public bool AlwaysRun { get; set; } - - /// - /// Gets or sets as 'true' to continue on error, 'false' otherwise. - /// - [DataMember] - public bool ContinueOnError { get; set; } - - /// - /// Gets or sets condition for the task. - /// - [DataMember(EmitDefaultValue = false)] - public String Condition { get; set; } - - /// - /// Gets or sets as task is enabled or not. - /// - [DataMember] - public bool Enabled { get; set; } - - /// - /// Gets or sets the maximum time, in minutes, that a task is allowed to execute on agent before being cancelled by server. A zero value indicates an infinite timeout. - /// - [DataMember] - public int TimeoutInMinutes { get; set; } - - /// - /// Gets or sets dictionary of inputs. - /// - [DataMember] - public IDictionary Inputs { get; set; } - - public IDictionary Environment - { - get - { - if (m_environment == null) - { - m_environment = new Dictionary(StringComparer.Ordinal); - } - return m_environment; - } - } - - /// - /// Gets dictionary of environment variables. - /// - [DataMember(Name = "Environment", EmitDefaultValue = false)] - private Dictionary m_environment; - - /// - /// Gets or sets the reference of the task. - /// - [DataMember] - public TaskDefinitionReference Task { get; set; } - - public static bool EqualsAndOldTaskInputsAreSubsetOfNewTaskInputs( - TaskGroupStep oldTaskGroupStep, - TaskGroupStep newTaskGroupStep) - { - if (!oldTaskGroupStep.DisplayName.Equals(newTaskGroupStep.DisplayName) - || oldTaskGroupStep.AlwaysRun != newTaskGroupStep.AlwaysRun - || oldTaskGroupStep.Enabled != newTaskGroupStep.Enabled - || oldTaskGroupStep.ContinueOnError != newTaskGroupStep.ContinueOnError - || !oldTaskGroupStep.Task.Equals(newTaskGroupStep.Task)) - { - return false; - } - - if (!(oldTaskGroupStep.Inputs != null && newTaskGroupStep.Inputs != null - && oldTaskGroupStep.Inputs.Keys.All(key => newTaskGroupStep.Inputs.ContainsKey(key) - && newTaskGroupStep.Inputs[key].Equals(oldTaskGroupStep.Inputs[key])))) - { - return false; - } - - if (!(oldTaskGroupStep.Environment != null - && oldTaskGroupStep.Environment.Keys.All(key => newTaskGroupStep.Environment.ContainsKey(key) - && newTaskGroupStep.Environment[key].Equals(oldTaskGroupStep.Environment[key])))) - { - return false; - } - - return true; - } - - internal TaskGroupStep Clone() - { - return new TaskGroupStep(this); - } - - private String m_displayName; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskGroupUpdateParameter.cs b/src/Sdk/DTWebApi/WebApi/TaskGroupUpdateParameter.cs deleted file mode 100644 index 0c9d7ea8a..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskGroupUpdateParameter.cs +++ /dev/null @@ -1,158 +0,0 @@ -using System; -using System.Runtime.Serialization; -using System.Collections.Generic; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskGroupUpdateParameter - { - /// - /// Sets the unique identifier of this field. - /// - [DataMember(EmitDefaultValue = false)] - public Guid Id { get; set; } - - /// - /// Sets name of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Name { get; set; } - - /// - /// Sets friendly name of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String FriendlyName { get; set; } - - /// - /// Sets author name of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Author { get; set; } - - /// - /// Sets description of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Description { get; set; } - - /// - /// Sets comment of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Comment { get; set; } - - /// - /// Sets revision of the task group. - /// - [DataMember] - public Int32 Revision { get; set; } - - /// - /// Gets or sets parent task group Id. This is used while creating a draft task group. - /// - [DataMember(EmitDefaultValue = false)] - public Guid? ParentDefinitionId { get; set; } - - /// - /// Sets url icon of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String IconUrl { get; set; } - - /// - /// Sets display name of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String InstanceNameFormat { get; set; } - - /// - /// Sets category of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public String Category { get; set; } - - /// - /// Sets version of the task group. - /// - [DataMember(EmitDefaultValue = false)] - public TaskVersion Version { get; set; } - - public IList Tasks - { - get - { - if (m_tasks == null) - { - m_tasks = new List(); - } - - return m_tasks; - } - } - - public IList Inputs - { - get - { - if (m_inputs == null) - { - m_inputs = new List(); - } - return m_inputs; - } - } - - public IList RunsOn - { - get - { - if (m_runsOn == null) - { - m_runsOn = new List(TaskRunsOnConstants.DefaultValue); - } - - return m_runsOn; - } - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - SerializationHelper.Copy(ref m_serializedRunsOn, ref m_runsOn, true); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - SerializationHelper.Copy(ref m_runsOn, ref m_serializedRunsOn); - } - - [OnSerialized] - private void OnSerialized(StreamingContext context) - { - m_serializedRunsOn = null; - } - - /// - /// Sets tasks for the task group. - /// - [DataMember(Name = "Tasks")] - private IList m_tasks; - - /// - /// Sets input for the task group. - /// - [DataMember(Name = "Inputs", EmitDefaultValue = false)] - private List m_inputs; - - /// - /// Sets RunsOn of the task group. Value can be 'Agent', 'Server' or 'DeploymentGroup'. - /// - [DataMember(Name = "RunsOn", EmitDefaultValue = false)] - private List m_serializedRunsOn; - - private List m_runsOn; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskHttpClient.cs b/src/Sdk/DTWebApi/WebApi/TaskHttpClient.cs index c0691ff6c..d700f19dc 100644 --- a/src/Sdk/DTWebApi/WebApi/TaskHttpClient.cs +++ b/src/Sdk/DTWebApi/WebApi/TaskHttpClient.cs @@ -128,20 +128,6 @@ namespace GitHub.DistributedTask.WebApi cancellationToken); } - public Task GetAgentRequestJobAsync( - Guid scopeIdentifier, - String planType, - String orchestrationId, - CancellationToken cancellationToken = default(CancellationToken), - Object userState = null) - { - return base.GetJobInstanceAsync(scopeIdentifier, - planType, - orchestrationId, - userState, - cancellationToken); - } - private readonly ApiResourceVersion m_currentApiVersion = new ApiResourceVersion(2.0, 1); } } diff --git a/src/Sdk/DTWebApi/WebApi/TaskHubLicenseDetails.cs b/src/Sdk/DTWebApi/WebApi/TaskHubLicenseDetails.cs deleted file mode 100644 index 33d637793..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskHubLicenseDetails.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class TaskHubLicenseDetails - { - public static readonly Int32 DefaultFreeLicenseCount = 0; - - [DataMember(Name = "FreeLicenseCount")] - public Int32 FreePrivateLicenseCount; - - [DataMember] - public Int32 FreeHostedLicenseCount; - - [DataMember] - public Int32 EnterpriseUsersCount; - - /// - /// Self-hosted licenses purchased from VSTS directly. - /// - [DataMember(Name = "PurchasedLicenseCount")] - public Int32 PurchasedPrivateLicenseCount; - - /// - /// Microsoft-hosted licenses purchased from VSTS directly. - /// - [DataMember] - public Int32 PurchasedHostedLicenseCount; - - [DataMember] - public Boolean HostedLicensesArePremium; - - /// - /// Microsoft-hosted licenses purchased from secondary marketplaces. - /// - public List MarketplacePurchasedHostedLicenses - { - get - { - if (m_marketplacePurchasedHostedLicenses == null) - { - m_marketplacePurchasedHostedLicenses = new List(); - } - return m_marketplacePurchasedHostedLicenses; - } - } - - [DataMember] - public Int32 TotalLicenseCount; - - [DataMember] - public Boolean HasLicenseCountEverUpdated; - - [DataMember] - public Int32 MsdnUsersCount; - - [DataMember] - public Int32 HostedAgentMinutesFreeCount; - - [DataMember] - public Int32 HostedAgentMinutesUsedCount; - - [DataMember] - public Boolean FailedToReachAllProviders; - - [DataMember] - public Int32 TotalPrivateLicenseCount; - - [DataMember] - public Int32 TotalHostedLicenseCount; - - [DataMember(Name = "MarketplacePurchasedHostedLicenses", EmitDefaultValue = false)] - private List m_marketplacePurchasedHostedLicenses; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskInputDefinition.cs b/src/Sdk/DTWebApi/WebApi/TaskInputDefinition.cs deleted file mode 100644 index 6d4c79cca..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskInputDefinition.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Runtime.Serialization; -using GitHub.Services.WebApi; -using CommonContracts = GitHub.DistributedTask.Common.Contracts; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskInputDefinition : CommonContracts.TaskInputDefinitionBase - { - public TaskInputDefinition() - : base() - { - } - - private TaskInputDefinition(TaskInputDefinition inputDefinitionToClone) - : base(inputDefinitionToClone) - { - } - - private TaskInputDefinition(TaskInputDefinition inputDefinitionToClone, ISecuredObject securedObject) - : base(inputDefinitionToClone, securedObject) - { - } - - public TaskInputDefinition Clone() - { - return new TaskInputDefinition(this); - } - - public override CommonContracts.TaskInputDefinitionBase Clone(ISecuredObject securedObject) - { - return base.Clone(securedObject); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskInputType.cs b/src/Sdk/DTWebApi/WebApi/TaskInputType.cs deleted file mode 100644 index 3d1227dd1..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskInputType.cs +++ /dev/null @@ -1,15 +0,0 @@ -using CommonContracts = GitHub.DistributedTask.Common.Contracts; -using System.Runtime.Serialization; -using System; - -namespace GitHub.DistributedTask.WebApi -{ - public static class TaskInputType - { - public const String String = CommonContracts.TaskInputType.String; - public const String Repository = CommonContracts.TaskInputType.Repository; - public const String Boolean = CommonContracts.TaskInputType.Boolean; - public const String KeyValue = CommonContracts.TaskInputType.KeyValue; - public const String FilePath = CommonContracts.TaskInputType.FilePath; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskInstance.cs b/src/Sdk/DTWebApi/WebApi/TaskInstance.cs deleted file mode 100644 index 884e81748..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskInstance.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class TaskInstance : TaskReference - { - public TaskInstance() - { - // Enabled defaults to true - this.Enabled = true; - } - - private TaskInstance(TaskInstance taskToBeCloned) - : base(taskToBeCloned) - { - this.InstanceId = taskToBeCloned.InstanceId; - this.DisplayName = taskToBeCloned.DisplayName; - this.Enabled = taskToBeCloned.Enabled; - this.Condition = taskToBeCloned.Condition; - this.ContinueOnError = taskToBeCloned.ContinueOnError; - this.AlwaysRun = taskToBeCloned.AlwaysRun; - this.TimeoutInMinutes = taskToBeCloned.TimeoutInMinutes; - this.RefName = taskToBeCloned.RefName; - - if (taskToBeCloned.m_environment != null) - { - m_environment = new Dictionary(taskToBeCloned.m_environment, StringComparer.Ordinal); - } - } - - [DataMember] - public Guid InstanceId - { - get; - set; - } - - [DataMember] - public String DisplayName - { - get; - set; - } - - [DataMember] - public Boolean Enabled - { - get; - set; - } - - [DataMember] - public String Condition - { - get; - set; - } - - [DataMember] - public Boolean ContinueOnError - { - get; - set; - } - - [DataMember] - public Boolean AlwaysRun - { - get; - set; - } - - [DataMember] - public int TimeoutInMinutes - { - get; - set; - } - - [DataMember] - public String RefName - { - get; - set; - } - - public IDictionary Environment - { - get - { - if (m_environment == null) - { - m_environment = new Dictionary(StringComparer.Ordinal); - } - return m_environment; - } - } - - public override TaskReference Clone() - { - return new TaskInstance(this); - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - SerializationHelper.Copy(ref m_serializedEnvironment, ref m_environment, StringComparer.Ordinal, true); - } - - [OnSerializing] - private void OnSerializing(StreamingContext context) - { - SerializationHelper.Copy(ref m_environment, ref m_serializedEnvironment); - } - - [OnSerialized] - private void OnSerialized(StreamingContext context) - { - m_serializedEnvironment = null; - } - - private IDictionary m_environment; - - [DataMember(EmitDefaultValue = false, Name = "Environment")] - private IDictionary m_serializedEnvironment; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationContainer.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationContainer.cs deleted file mode 100644 index ed97476e1..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationContainer.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class TaskOrchestrationContainer : TaskOrchestrationItem, IOrchestrationProcess - { - public TaskOrchestrationContainer() - : base(TaskOrchestrationItemType.Container) - { - ContinueOnError = true; - MaxConcurrency = Int32.MaxValue; - } - - [DataMember(EmitDefaultValue = false)] - public Boolean Parallel - { - get; - set; - } - - public List Children - { - get - { - if (m_children == null) - { - m_children = new List(); - } - - return m_children; - } - } - - [DataMember(EmitDefaultValue = false)] - public TaskOrchestrationContainer Rollback - { - get; - set; - } - - [DataMember(EmitDefaultValue = true)] - public Boolean ContinueOnError - { - get; - set; - } - - [DataMember(EmitDefaultValue = true)] - public Int32 MaxConcurrency - { - get; - set; - } - - /// - /// Get additional specifications for this container. - /// - /// - /// This provides an extensibility for consumers of DT SDK to pass additional data - /// to Orchestrations. Each Orchestration is free to interpret this data as appropriate. - /// - public IDictionary Data - { - get - { - if (m_data == null) - { - m_data = new Dictionary(); - } - - return m_data; - } - } - - OrchestrationProcessType IOrchestrationProcess.ProcessType - { - get - { - return OrchestrationProcessType.Container; - } - } - - public IEnumerable GetJobs() - { - var containerQueue = new Queue(); - containerQueue.Enqueue(this); - - while (containerQueue.Count > 0) - { - var currentContainer = containerQueue.Dequeue(); - foreach (var item in currentContainer.Children) - { - switch (item.ItemType) - { - case TaskOrchestrationItemType.Container: - containerQueue.Enqueue((TaskOrchestrationContainer)item); - break; - - case TaskOrchestrationItemType.Job: - yield return item as TaskOrchestrationJob; - break; - } - } - } - } - - [DataMember(Name = "Children")] - private List m_children; - - [DataMember(Name = "Data", EmitDefaultValue = false)] - private IDictionary m_data; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItem.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItem.cs deleted file mode 100644 index d271834ac..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItem.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Newtonsoft.Json; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - [KnownType(typeof(TaskOrchestrationContainer))] - [KnownType(typeof(TaskOrchestrationJob))] - [JsonConverter(typeof(TaskOrchestrationItemJsonConverter))] - public abstract class TaskOrchestrationItem - { - protected TaskOrchestrationItem(TaskOrchestrationItemType itemType) - { - this.ItemType = itemType; - } - - [DataMember] - public TaskOrchestrationItemType ItemType - { - get; - private set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItemJsonConverter.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItemJsonConverter.cs deleted file mode 100644 index f8ead8415..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItemJsonConverter.cs +++ /dev/null @@ -1,100 +0,0 @@ -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System; -using System.Reflection; - -namespace GitHub.DistributedTask.WebApi -{ - internal sealed class TaskOrchestrationItemJsonConverter : VssSecureJsonConverter - { - public override Boolean CanConvert(Type objectType) - { - return typeof(TaskOrchestrationItem).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - if (reader.TokenType != JsonToken.StartObject) - { - return null; - } - - var contract = serializer.ContractResolver.ResolveContract(objectType) as JsonObjectContract; - if (contract == null) - { - return existingValue; - } - - JsonProperty property = contract.Properties.GetClosestMatchProperty("ItemType"); - if (property == null) - { - return existingValue; - } - - JToken itemTypeValue; - TaskOrchestrationItemType itemType; - JObject value = JObject.Load(reader); - if (!value.TryGetValue(property.PropertyName, out itemTypeValue)) - { - return existingValue; - } - else - { - if (itemTypeValue.Type == JTokenType.Integer) - { - itemType = (TaskOrchestrationItemType)(Int32)itemTypeValue; - } - else if (itemTypeValue.Type != JTokenType.String || - !Enum.TryParse((String)itemTypeValue, true, out itemType)) - { - return existingValue; - } - } - - Object newValue = null; - switch (itemType) - { - case TaskOrchestrationItemType.Container: - newValue = new TaskOrchestrationContainer(); - break; - - case TaskOrchestrationItemType.Job: - newValue = new TaskOrchestrationJob(); - break; - } - - if (value != null) - { - using (JsonReader objectReader = value.CreateReader()) - { - serializer.Populate(objectReader, newValue); - } - } - - return newValue; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - // The virtual method returns false for CanWrite so this should never be invoked - throw new NotSupportedException(); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItemType.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItemType.cs deleted file mode 100644 index 51755c3a5..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationItemType.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public enum TaskOrchestrationItemType - { - [EnumMember] - Container, - - [EnumMember] - Job, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationJob.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationJob.cs deleted file mode 100644 index fc6787215..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationJob.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using GitHub.Services.WebApi; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public sealed class TaskOrchestrationJob : TaskOrchestrationItem - { - internal TaskOrchestrationJob() - : base(TaskOrchestrationItemType.Job) - { - this.ExecutionMode = JobExecutionModeTypes.Agent; - } - - public TaskOrchestrationJob( - Guid instanceId, - String name, - String refName, - string executionMode = JobExecutionModeTypes.Agent) - : base(TaskOrchestrationItemType.Job) - { - this.InstanceId = instanceId; - this.Name = name; - this.RefName = refName; - this.ExecutionMode = executionMode; - } - - private TaskOrchestrationJob(TaskOrchestrationJob jobToBeCloned) - : base(jobToBeCloned.ItemType) - { - this.InstanceId = jobToBeCloned.InstanceId; - this.Name = jobToBeCloned.Name; - this.RefName = jobToBeCloned.RefName; - this.ExecutionMode = jobToBeCloned.ExecutionMode; - this.ExecutionTimeout = jobToBeCloned.ExecutionTimeout; - - if (jobToBeCloned.ExecuteAs != null) - { - this.ExecuteAs = new IdentityRef - { - DisplayName = jobToBeCloned.ExecuteAs.DisplayName, - Id = jobToBeCloned.ExecuteAs.Id, - ImageUrl = jobToBeCloned.ExecuteAs.ImageUrl, - IsAadIdentity = jobToBeCloned.ExecuteAs.IsAadIdentity, - IsContainer = jobToBeCloned.ExecuteAs.IsContainer, - ProfileUrl = jobToBeCloned.ExecuteAs.ProfileUrl, - UniqueName = jobToBeCloned.ExecuteAs.UniqueName, - Url = jobToBeCloned.ExecuteAs.Url, - }; - } - - if (jobToBeCloned.m_demands != null) - { - m_demands = jobToBeCloned.Demands.Select(x => x.Clone()).ToList(); - } - - if (jobToBeCloned.m_variables != null) - { - m_variables = new Dictionary(jobToBeCloned.m_variables, StringComparer.OrdinalIgnoreCase); - } - - if (jobToBeCloned.m_tasks != null) - { - m_tasks = jobToBeCloned.m_tasks.Select(x => (TaskInstance)x.Clone()).ToList(); - } - } - - [DataMember] - public Guid InstanceId - { - get; - set; - } - - [DataMember] - public String Name - { - get; - set; - } - - [DataMember] - public String RefName - { - get; - set; - } - - [DataMember] - public string ExecutionMode - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public IdentityRef ExecuteAs - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TimeSpan? ExecutionTimeout - { - get; - set; - } - - public List Demands - { - get - { - if (m_demands == null) - { - m_demands = new List(); - } - - return m_demands; - } - } - - public IDictionary Variables - { - get - { - if (m_variables == null) - { - m_variables = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - - return m_variables; - } - } - - public List Tasks - { - get - { - if (m_tasks == null) - { - m_tasks = new List(); - } - - return m_tasks; - } - } - - public TaskOrchestrationJob Clone() - { - return new TaskOrchestrationJob(this); - } - - [DataMember(Name = "Demands", EmitDefaultValue = false)] - private List m_demands; - - [DataMember(Name = "Variables", EmitDefaultValue = false)] - private IDictionary m_variables; - - [DataMember(Name = "Tasks", EmitDefaultValue = false)] - private List m_tasks; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlan.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlan.cs deleted file mode 100644 index 11e1cd18f..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlan.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System; -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskOrchestrationPlan : TaskOrchestrationPlanReference - { - [DataMember(EmitDefaultValue = false)] - public DateTime? StartTime - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public DateTime? FinishTime - { - get; - set; - } - - [DataMember] - public TaskOrchestrationPlanState State - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TaskResult? Result - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public String ResultCode - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TimelineReference Timeline - { - get; - set; - } - - public PlanEnvironment Environment - { - get - { - return m_environment; - } - set - { - m_environment = value; - m_processEnvironment = value; - } - } - - public TaskOrchestrationContainer Implementation - { - get - { - return m_implementation; - } - set - { - m_process = value; - m_implementation = value; - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public IOrchestrationProcess Process - { - get - { - return m_process; - } - set - { - m_process = value; - m_implementation = value as TaskOrchestrationContainer; - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public IOrchestrationEnvironment ProcessEnvironment - { - get - { - return m_processEnvironment; - } - set - { - m_processEnvironment = value; - m_environment = value as PlanEnvironment; - } - } - - [DataMember(EmitDefaultValue = false)] - public Guid RequestedById - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public Guid RequestedForId - { - get; - set; - } - - internal PlanTemplateType TemplateType - { - get; - set; - } - - [DataMember(EmitDefaultValue = false)] - public TaskLogReference InitializationLog - { - get; - set; - } - - // Currently these members are not serialized on the wire since that would technically be an API break for - // the 1.0 version. While additive, existing clients wouldn't understand it and could blow up. Until this - // public model is finalized we will not send this data over the wire and will not revision the API. - private IOrchestrationProcess m_process; - private IOrchestrationEnvironment m_processEnvironment; - - [DataMember(Name = "Environment", EmitDefaultValue = false)] - private PlanEnvironment m_environment; - - [DataMember(Name = "Implementation", EmitDefaultValue = false)] - private TaskOrchestrationContainer m_implementation; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlanGroupsQueueMetrics.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlanGroupsQueueMetrics.cs deleted file mode 100644 index ddd426e8d..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlanGroupsQueueMetrics.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskOrchestrationPlanGroupsQueueMetrics - { - [DataMember] - public PlanGroupStatus Status - { - get; - set; - } - - [DataMember] - public Int32 Count - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlanReference.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlanReference.cs index 895580316..54b61e600 100644 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlanReference.cs +++ b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationPlanReference.cs @@ -62,13 +62,6 @@ namespace GitHub.DistributedTask.WebApi set; } - [IgnoreDataMember] - public OrchestrationProcessType ProcessType - { - get; - internal set; - } - [DataMember] public TaskOrchestrationOwner Definition { diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationQueuedPlan.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationQueuedPlan.cs deleted file mode 100644 index ee2ffeef2..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationQueuedPlan.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskOrchestrationQueuedPlan - { - [DataMember] - public Guid PlanId - { - get; - set; - } - - [DataMember] - public Guid ScopeIdentifier - { - get; - set; - } - - [DataMember] - public String PlanGroup - { - get; - set; - } - - [DataMember] - public Int32 QueuePosition - { - get; - set; - } - - [DataMember] - public Int32 PoolId - { - get; - set; - } - - [DataMember] - public DateTime QueueTime - { - get; - set; - } - - [DataMember] - public DateTime? AssignTime - { - get; - set; - } - - [DataMember] - public TaskOrchestrationOwner Definition - { - get; - set; - } - - [DataMember] - public TaskOrchestrationOwner Owner - { - get; - set; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationQueuedPlanGroup.cs b/src/Sdk/DTWebApi/WebApi/TaskOrchestrationQueuedPlanGroup.cs deleted file mode 100644 index fd5b57576..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskOrchestrationQueuedPlanGroup.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskOrchestrationQueuedPlanGroup - { - [DataMember] - public ProjectReference Project - { - get; - internal set; - } - - [DataMember] - public String PlanGroup - { - get; - internal set; - } - - [DataMember] - public Int32 QueuePosition - { - get; - internal set; - } - - [DataMember] - public List Plans - { - get - { - if (this._plans == null) - { - this._plans = new List(); - } - - return this._plans; - } - } - - [DataMember] - public TaskOrchestrationOwner Definition - { - get; - set; - } - - [DataMember] - public TaskOrchestrationOwner Owner - { - get; - set; - } - - private List _plans; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskRunsOnConstants.cs b/src/Sdk/DTWebApi/WebApi/TaskRunsOnConstants.cs deleted file mode 100644 index fdddf9e10..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskRunsOnConstants.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.WebApi -{ - [GenerateAllConstants] - public class TaskRunsOnConstants - { - public const string RunsOnAgent = "Agent"; - public const string RunsOnMachineGroup = "MachineGroup"; - public const string RunsOnDeploymentGroup = "DeploymentGroup"; - public const string RunsOnServer = "Server"; - - public static readonly List DefaultValue = new List { RunsOnAgent, RunsOnDeploymentGroup }; - - public static readonly List RunsOnAllTypes = new List - { - RunsOnAgent, - RunsOnDeploymentGroup, - RunsOnServer, - }; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskSourceDefinition.cs b/src/Sdk/DTWebApi/WebApi/TaskSourceDefinition.cs deleted file mode 100644 index 698c0bb08..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskSourceDefinition.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Runtime.Serialization; -using GitHub.Services.WebApi; -using CommonContracts = GitHub.DistributedTask.Common.Contracts; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskSourceDefinition : CommonContracts.TaskSourceDefinitionBase - { - public TaskSourceDefinition() - : base() - { - } - - private TaskSourceDefinition(TaskSourceDefinition inputDefinitionToClone) - : base(inputDefinitionToClone) - { - } - - private TaskSourceDefinition(TaskSourceDefinition inputDefinitionToClone, ISecuredObject securedObject) - : base(inputDefinitionToClone, securedObject) - { - } - - public TaskSourceDefinition Clone() - { - return new TaskSourceDefinition(this); - } - - public override CommonContracts.TaskSourceDefinitionBase Clone(ISecuredObject securedObject) - { - return new TaskSourceDefinition(this, securedObject); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskVersion.cs b/src/Sdk/DTWebApi/WebApi/TaskVersion.cs deleted file mode 100644 index b10d0a89a..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskVersion.cs +++ /dev/null @@ -1,182 +0,0 @@ -using GitHub.Services.Common; -using System; -using System.Globalization; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [DataContract] - public class TaskVersion : IComparable, IEquatable - { - public TaskVersion() - { - } - - public TaskVersion(String version) - { - Int32 major, minor, patch; - String semanticVersion; - - VersionParser.ParseVersion(version, out major, out minor, out patch, out semanticVersion); - Major = major; - Minor = minor; - Patch = patch; - - if (semanticVersion != null) - { - if (semanticVersion.Equals("test", StringComparison.OrdinalIgnoreCase)) - { - IsTest = true; - } - else - { - throw new ArgumentException("semVer"); - } - } - } - - private TaskVersion(TaskVersion taskVersionToClone) - { - this.IsTest = taskVersionToClone.IsTest; - this.Major = taskVersionToClone.Major; - this.Minor = taskVersionToClone.Minor; - this.Patch = taskVersionToClone.Patch; - } - - [DataMember] - public Int32 Major - { - get; - set; - } - - [DataMember] - public Int32 Minor - { - get; - set; - } - - [DataMember] - public Int32 Patch - { - get; - set; - } - - [DataMember] - public Boolean IsTest - { - get; - set; - } - - public TaskVersion Clone() - { - return new TaskVersion(this); - } - - public static implicit operator String(TaskVersion version) - { - return version.ToString(); - } - - public override String ToString() - { - String suffix = String.Empty; - if (IsTest) - { - suffix = "-test"; - } - - return String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}", Major, Minor, Patch, suffix); - } - - public override int GetHashCode() - { - return this.ToString().GetHashCode(); - } - - public Int32 CompareTo(TaskVersion other) - { - Int32 rc = Major.CompareTo(other.Major); - if (rc == 0) - { - rc = Minor.CompareTo(other.Minor); - if (rc == 0) - { - rc = Patch.CompareTo(other.Patch); - if (rc == 0 && this.IsTest != other.IsTest) - { - rc = this.IsTest ? -1 : 1; - } - } - } - - return rc; - } - - public Boolean Equals(TaskVersion other) - { - if (other is null) - { - return false; - } - - return this.CompareTo(other) == 0; - } - - public override bool Equals(object obj) - { - return Equals(obj as TaskVersion); - } - - public static Boolean operator ==(TaskVersion v1, TaskVersion v2) - { - if (v1 is null) - { - return v2 is null; - } - - return v1.Equals(v2); - } - - public static Boolean operator !=(TaskVersion v1, TaskVersion v2) - { - if (v1 is null) - { - return !(v2 is null); - } - - return !v1.Equals(v2); - } - - public static Boolean operator <(TaskVersion v1, TaskVersion v2) - { - ArgumentUtility.CheckForNull(v1, nameof(v1)); - ArgumentUtility.CheckForNull(v2, nameof(v2)); - return v1.CompareTo(v2) < 0; - } - - public static Boolean operator >(TaskVersion v1, TaskVersion v2) - { - ArgumentUtility.CheckForNull(v1, nameof(v1)); - ArgumentUtility.CheckForNull(v2, nameof(v2)); - return v1.CompareTo(v2) > 0; - } - - public static Boolean operator <=(TaskVersion v1, TaskVersion v2) - { - ArgumentUtility.CheckForNull(v1, nameof(v1)); - ArgumentUtility.CheckForNull(v2, nameof(v2)); - return v1.CompareTo(v2) <= 0; - } - - public static Boolean operator >=(TaskVersion v1, TaskVersion v2) - { - ArgumentUtility.CheckForNull(v1, nameof(v1)); - ArgumentUtility.CheckForNull(v2, nameof(v2)); - return v1.CompareTo(v2) >= 0; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/TaskVersionSpec.cs b/src/Sdk/DTWebApi/WebApi/TaskVersionSpec.cs deleted file mode 100644 index a8617d287..000000000 --- a/src/Sdk/DTWebApi/WebApi/TaskVersionSpec.cs +++ /dev/null @@ -1,239 +0,0 @@ -using GitHub.Services.Common; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; - -namespace GitHub.DistributedTask.WebApi -{ - public sealed class TaskVersionSpec - { - /// - /// Gets or sets the major version component. - /// - public Int32? Major - { - get; - set; - } - - /// - /// Gets or sets the minor version component. - /// - public Int32? Minor - { - get; - set; - } - - /// - /// Gets or sets the patch version component. - /// - public Int32? Patch - { - get; - set; - } - - /// - /// Gets or sets a value locking the semantic version to test. - /// - public Boolean IsTest - { - get; - set; - } - - /// - /// Provides a string representation of the version specification. - /// - /// A printable string representation of a version specification - public override String ToString() - { - StringBuilder sb = new StringBuilder(); - if (this.Major == null) - { - sb.Append("*"); - } - else - { - sb.Append(this.Major.Value); - if (this.Minor != null) - { - sb.AppendFormat(CultureInfo.InvariantCulture, ".{0}", this.Minor.Value); - if (this.Patch != null) - { - sb.AppendFormat(CultureInfo.InvariantCulture, ".{0}", this.Patch.Value); - } - else - { - sb.Append(".*"); - } - } - else - { - sb.Append(".*"); - } - } - - if (this.IsTest) - { - sb.Append("-test"); - } - - return sb.ToString(); - } - - /// - /// Provides an explicit conversion constructor for converting from a String. - /// - /// The version specification string - /// A version specification object - /// When the provided version string is not valid - public static explicit operator TaskVersionSpec(String version) - { - return Parse(version); - } - - /// - /// Finds the closest version match for the current specification. If no match can be found then a null - /// value is returned. - /// - /// The list of versions available for matching - /// The version which matches the specification if found; otherwise, null - public TaskVersion Match(IEnumerable versions) - { - ArgumentUtility.CheckForNull(versions, nameof(versions)); - - // Do not evaluate until the end so we only actually iterate the list a single time. Since LINQ returns - // lazy evaluators from the Where method, we can avoid multiple iterations by leaving the variable - // as IEnumerable and performing the iteration after all clauses have been concatenated. - var matchedVersions = versions.Where(x => x.IsTest == this.IsTest); - if (this.Major != null) - { - matchedVersions = matchedVersions.Where(x => x.Major == this.Major); - if (this.Minor != null) - { - matchedVersions = matchedVersions.Where(x => x.Minor == this.Minor); - if (this.Patch != null) - { - matchedVersions = matchedVersions.Where(x => x.Patch == this.Patch); - } - } - } - - return matchedVersions.OrderByDescending(x => x).FirstOrDefault(); - } - - public TaskDefinition Match(IEnumerable definitions) - { - ArgumentUtility.CheckForNull(definitions, nameof(definitions)); - - // Do not evaluate until the end so we only actually iterate the list a single time. Since LINQ returns - // lazy evaluators from the Where method, we can avoid multiple iterations by leaving the variable - // as IEnumerable and performing the iteration after all clauses have been concatenated. - var matchedDefinitions = definitions.Where(x => x.Version.IsTest == this.IsTest); - if (this.Major != null) - { - matchedDefinitions = matchedDefinitions.Where(x => x.Version.Major == this.Major); - if (this.Minor != null) - { - matchedDefinitions = matchedDefinitions.Where(x => x.Version.Minor == this.Minor); - if (this.Patch != null) - { - matchedDefinitions = matchedDefinitions.Where(x => x.Version.Patch == this.Patch); - } - } - } - - return matchedDefinitions.OrderByDescending(x => x.Version).FirstOrDefault(); - } - - public static TaskVersionSpec Parse(String version) - { - TaskVersionSpec versionSpec; - if (!TryParse(version, out versionSpec)) - { - throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The value {0} is not a valid version specification", version), "version"); - } - return versionSpec; - } - - public static Boolean TryParse( - String version, - out TaskVersionSpec versionSpec) - { - String[] versionComponents = version.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); - if (versionComponents.Length < 1 || versionComponents.Length > 3) - { - versionSpec = null; - return false; - } - - Int32? major = null; - Int32? minor = null; - Int32? patch = null; - Boolean isTest = false; - String lastComponent = versionComponents[versionComponents.Length - 1]; - if (lastComponent.EndsWith("-test", StringComparison.OrdinalIgnoreCase)) - { - isTest = true; - versionComponents[versionComponents.Length - 1] = lastComponent.Remove(lastComponent.Length - "-test".Length); - } - - if (versionComponents.Length == 1) - { - if (!TryParseVersionComponent(version, "major", versionComponents[0], true, out major)) - { - versionSpec = null; - return false; - } - } - else if (versionComponents.Length == 2) - { - if (!TryParseVersionComponent(version, "major", versionComponents[0], false, out major) || - !TryParseVersionComponent(version, "minor", versionComponents[1], true, out minor)) - { - versionSpec = null; - return false; - } - } - else - { - if (!TryParseVersionComponent(version, "major", versionComponents[0], false, out major) || - !TryParseVersionComponent(version, "minor", versionComponents[1], false, out minor) || - !TryParseVersionComponent(version, "patch", versionComponents[2], true, out patch)) - { - versionSpec = null; - return false; - } - } - - versionSpec = new TaskVersionSpec { Major = major, Minor = minor, Patch = patch, IsTest = isTest }; - return true; - } - - private static Boolean TryParseVersionComponent( - String version, - String name, - String value, - Boolean allowStar, - out Int32? versionValue) - { - versionValue = null; - - Int32 parsedVersion; - if (Int32.TryParse(value, out parsedVersion)) - { - versionValue = parsedVersion; - } - else if (!allowStar || value != "*") - { - return false; - } - - return true; - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/VariableGroup.cs b/src/Sdk/DTWebApi/WebApi/VariableGroup.cs deleted file mode 100644 index 8f6bb2f4a..000000000 --- a/src/Sdk/DTWebApi/WebApi/VariableGroup.cs +++ /dev/null @@ -1,244 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.Serialization; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// A variable group is a collection of related variables. - /// - [JsonConverter(typeof(VariableGroupJsonConverter))] - [DataContract] - public class VariableGroup - { - public VariableGroup() - { - } - - private VariableGroup(VariableGroup group) - { - this.Id = group.Id; - this.Type = group.Type; - this.Name = group.Name; - this.Description = group.Description; - this.ProviderData = group.ProviderData; - this.CreatedBy = group.CreatedBy; - this.CreatedOn = group.CreatedOn; - this.ModifiedBy = group.ModifiedBy; - this.ModifiedOn = group.ModifiedOn; - this.IsShared = group.IsShared; - this.Variables = group.Variables.ToDictionary(x => x.Key, x => x.Value.Clone()); - } - - /// - /// Gets or sets id of the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public Int32 Id - { - get; - set; - } - - /// - /// Gets or sets type of the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public String Type - { - get; - set; - } - - /// - /// Gets or sets name of the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Gets or sets description of the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - - /// - /// Gets or sets provider data. - /// - [DataMember(EmitDefaultValue = false)] - public VariableGroupProviderData ProviderData - { - get; - set; - } - - /// - /// Gets or sets the identity who created the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public IdentityRef CreatedBy - { - get; - set; - } - - /// - /// Gets or sets the time when variable group was created. - /// - [DataMember(EmitDefaultValue = false)] - public DateTime CreatedOn - { - get; - set; - } - - /// - /// Gets or sets the identity who modified the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public IdentityRef ModifiedBy - { - get; - set; - } - - /// - /// Gets or sets the time when variable group was modified - /// - [DataMember(EmitDefaultValue = false)] - public DateTime ModifiedOn - { - get; - set; - } - - /// - /// Indicates whether variable group is shared with other projects or not. - /// - [DataMember(EmitDefaultValue = true)] - public Boolean IsShared - { - get; - set; - } - - public IDictionary Variables - { - get - { - if (m_variables == null) - { - m_variables = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - - return m_variables; - } - set - { - if (value == null) - { - m_variables = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - else - { - m_variables = new Dictionary(value, StringComparer.OrdinalIgnoreCase); - } - } - } - - public VariableGroup Clone() - { - return new VariableGroup(this); - } - - /// - /// Gets or sets variables contained in the variable group. - /// - [DataMember(EmitDefaultValue = false, Name = "Variables")] - private Dictionary m_variables; - } - - internal sealed class VariableGroupJsonConverter : VssSecureJsonConverter - { - public override Boolean CanRead - { - get - { - return true; - } - } - - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Boolean CanConvert(Type objectType) - { - return typeof(VariableGroup).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - var variableGroupJsonObject = JObject.Load(reader); - var variablesJsonObject = variableGroupJsonObject.GetValue("Variables", StringComparison.OrdinalIgnoreCase); - var providerDataJsonObject = variableGroupJsonObject.GetValue("ProviderData", StringComparison.OrdinalIgnoreCase); - - String variablesJson = null; - if (variablesJsonObject != null) - { - variablesJson = variablesJsonObject.ToString(); - } - - String providerDataJson = null; - if (providerDataJsonObject != null) - { - providerDataJson = providerDataJsonObject.ToString(); - } - - VariableGroup variableGroup = new VariableGroup(); - using (var objectReader = variableGroupJsonObject.CreateReader()) - { - serializer.Populate(objectReader, variableGroup); - } - - if (String.IsNullOrEmpty(variableGroup.Type)) - { - // To handle backward compat with clients making api calls without type - variableGroup.Type = VariableGroupType.Vsts; - } - - variableGroup.PopulateVariablesAndProviderData(variablesJson, providerDataJson); - - return variableGroup; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/VariableGroupActionFilter.cs b/src/Sdk/DTWebApi/WebApi/VariableGroupActionFilter.cs deleted file mode 100644 index d5edb907e..000000000 --- a/src/Sdk/DTWebApi/WebApi/VariableGroupActionFilter.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - [Flags] - [DataContract] - public enum VariableGroupActionFilter - { - [EnumMember] - None = 0, - - [EnumMember] - Manage = 2, - - [EnumMember] - Use = 16, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/VariableGroupParameters.cs b/src/Sdk/DTWebApi/WebApi/VariableGroupParameters.cs deleted file mode 100644 index c455cdfe4..000000000 --- a/src/Sdk/DTWebApi/WebApi/VariableGroupParameters.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using GitHub.Services.WebApi; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace GitHub.DistributedTask.WebApi -{ - [JsonConverter(typeof(VariableGroupParametersJsonConverter))] - [DataContract] - public class VariableGroupParameters - { - /// - /// Sets type of the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public String Type - { - get; - set; - } - - /// - /// Sets name of the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public String Name - { - get; - set; - } - - /// - /// Sets description of the variable group. - /// - [DataMember(EmitDefaultValue = false)] - public String Description - { - get; - set; - } - - /// - /// Sets provider data. - /// - [DataMember(EmitDefaultValue = false)] - public VariableGroupProviderData ProviderData - { - get; - set; - } - - public IDictionary Variables - { - get - { - if (m_variables == null) - { - m_variables = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - - return m_variables; - } - set - { - if (value == null) - { - m_variables = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - else - { - m_variables = new Dictionary(value, StringComparer.OrdinalIgnoreCase); - } - } - } - - /// - /// Sets variables contained in the variable group. - /// - [DataMember(EmitDefaultValue = false, Name = "Variables")] - private Dictionary m_variables; - } - - internal sealed class VariableGroupParametersJsonConverter : VssSecureJsonConverter - { - public override Boolean CanRead - { - get - { - return true; - } - } - - public override Boolean CanWrite - { - get - { - return false; - } - } - - public override Boolean CanConvert(Type objectType) - { - return typeof(VariableGroupParameters).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); - } - - public override Object ReadJson( - JsonReader reader, - Type objectType, - Object existingValue, - JsonSerializer serializer) - { - var variableGroupJsonObject = JObject.Load(reader); - var variablesJsonObject = variableGroupJsonObject.GetValue("Variables", StringComparison.OrdinalIgnoreCase); - var providerDataJsonObject = variableGroupJsonObject.GetValue("ProviderData", StringComparison.OrdinalIgnoreCase); - - String variablesJson = null; - if (variablesJsonObject != null) - { - variablesJson = variablesJsonObject.ToString(); - } - - String providerDataJson = null; - if (providerDataJsonObject != null) - { - providerDataJson = providerDataJsonObject.ToString(); - } - - VariableGroupParameters variableGroupParameters = new VariableGroupParameters(); - using (var objectReader = variableGroupJsonObject.CreateReader()) - { - serializer.Populate(objectReader, variableGroupParameters); - } - - if (String.IsNullOrEmpty(variableGroupParameters.Type)) - { - // To handle backward compat with clients making api calls without type - variableGroupParameters.Type = VariableGroupType.Vsts; - } - - variableGroupParameters.PopulateVariablesAndProviderData(variablesJson, providerDataJson); - - return variableGroupParameters; - } - - public override void WriteJson( - JsonWriter writer, - Object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/Sdk/DTWebApi/WebApi/VariableGroupProviderData.cs b/src/Sdk/DTWebApi/WebApi/VariableGroupProviderData.cs deleted file mode 100644 index 1f90d1310..000000000 --- a/src/Sdk/DTWebApi/WebApi/VariableGroupProviderData.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace GitHub.DistributedTask.WebApi -{ - /// - /// Defines provider data of the variable group. - /// - [KnownType(typeof(AzureKeyVaultVariableGroupProviderData))] - [DataContract] - public class VariableGroupProviderData - { - } -} diff --git a/src/Sdk/DTWebApi/WebApi/VariableGroupQueryOrder.cs b/src/Sdk/DTWebApi/WebApi/VariableGroupQueryOrder.cs deleted file mode 100644 index e8736c18e..000000000 --- a/src/Sdk/DTWebApi/WebApi/VariableGroupQueryOrder.cs +++ /dev/null @@ -1,29 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// 2012-2023, All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace GitHub.DistributedTask.WebApi -{ - using System.Runtime.Serialization; - - /// - /// Specifies the desired ordering of variableGroups. - /// - [DataContract] - public enum VariableGroupQueryOrder - { - /// - /// Order by id ascending. - /// - [EnumMember] - IdAscending = 0, - - /// - /// Order by id descending. - /// - [EnumMember] - IdDescending = 1, - } -} diff --git a/src/Sdk/DTWebApi/WebApi/VariableGroupType.cs b/src/Sdk/DTWebApi/WebApi/VariableGroupType.cs deleted file mode 100644 index 8c7e5f40d..000000000 --- a/src/Sdk/DTWebApi/WebApi/VariableGroupType.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using GitHub.Services.Common; - -namespace GitHub.DistributedTask.WebApi -{ - [GenerateAllConstants] - public static class VariableGroupType - { - public const String Vsts = "Vsts"; - public const String AzureKeyVault = "AzureKeyVault"; - } -} diff --git a/src/Sdk/DTWebApi/WebApi/VariableGroupUtility.cs b/src/Sdk/DTWebApi/WebApi/VariableGroupUtility.cs index 1de79ddf8..78e195145 100644 --- a/src/Sdk/DTWebApi/WebApi/VariableGroupUtility.cs +++ b/src/Sdk/DTWebApi/WebApi/VariableGroupUtility.cs @@ -12,307 +12,7 @@ namespace GitHub.DistributedTask.WebApi { public static VariableValue Clone(this VariableValue value) { - if (keyVaultVariableType == value.GetType()) - { - return new AzureKeyVaultVariableValue((AzureKeyVaultVariableValue)value); - } - return new VariableValue(value); } - - public static void PopulateVariablesAndProviderData(this VariableGroup group, String variablesJson, String providerDataJson) - { - switch (group.Type) - { - case VariableGroupType.Vsts: - if (variablesJson != null) - { - group.Variables = JsonUtility.FromString>(variablesJson); - } - - if (providerDataJson != null) - { - group.ProviderData = JsonUtility.FromString(providerDataJson); - } - - break; - - case VariableGroupType.AzureKeyVault: - if (variablesJson != null) - { - var azureKeyVaultVariableValues = JsonUtility.FromString>(variablesJson); - if (azureKeyVaultVariableValues != null) - { - foreach (var azureKeyVaultVariableValue in azureKeyVaultVariableValues) - { - group.Variables[azureKeyVaultVariableValue.Key] = azureKeyVaultVariableValue.Value; - } - } - } - - if (providerDataJson != null) - { - group.ProviderData = JsonUtility.FromString(providerDataJson); - } - - break; - } - } - - public static void PopulateVariablesAndProviderData(this VariableGroupParameters variableGroupParameters, String variablesJson, String providerDataJson) - { - switch (variableGroupParameters.Type) - { - case VariableGroupType.Vsts: - if (variablesJson != null) - { - variableGroupParameters.Variables = JsonUtility.FromString>(variablesJson); - } - - if (providerDataJson != null) - { - variableGroupParameters.ProviderData = JsonUtility.FromString(providerDataJson); - } - - break; - - case VariableGroupType.AzureKeyVault: - if (variablesJson != null) - { - var azureKeyVaultVariableValues = JsonUtility.FromString>(variablesJson); - if (azureKeyVaultVariableValues != null) - { - foreach (var azureKeyVaultVariableValue in azureKeyVaultVariableValues) - { - variableGroupParameters.Variables[azureKeyVaultVariableValue.Key] = azureKeyVaultVariableValue.Value; - } - } - } - - if (providerDataJson != null) - { - variableGroupParameters.ProviderData = JsonUtility.FromString(providerDataJson); - } - - break; - } - } - - /// - /// Get list of cloned variable groups - /// - /// - /// - public static IList CloneVariableGroups(IList source) - { - var clonedVariableGroups = new List(); - if (source == null) - { - return clonedVariableGroups; - } - - foreach (var group in source) - { - if (group != null) - { - clonedVariableGroups.Add(group.Clone()); - } - } - - return clonedVariableGroups; - } - - /// - /// Replace secret values in group variables with null - /// - /// Variable groups to be cleared for secret variables - /// List of cleared variable groups - public static IList ClearSecrets(IList variableGroups) - { - var groups = new List(); - - if (variableGroups == null) - { - return groups; - } - - foreach (var group in variableGroups) - { - if (group != null) - { - var clearedGroup = group.Clone(); - - // Replacing secret variable's value with null - foreach (var variable in clearedGroup.Variables) - { - if (variable.Value != null && variable.Value.IsSecret) - { - variable.Value.Value = null; - } - } - - groups.Add(clearedGroup); - } - } - - return groups; - } - - /// - /// Replace all secrets in variables with null - /// - /// Variable set - /// Dictionary of variables - public static IDictionary ClearSecrets(IDictionary variables) - { - var dictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); - - if (variables == null) - { - return dictionary; - } - - foreach (var kvp in variables) - { - if (kvp.Value != null) - { - var clonedValue = kvp.Value.Clone(); - - if (kvp.Value.IsSecret) - { - clonedValue.Value = null; - } - - dictionary[kvp.Key] = clonedValue; - } - } - - return dictionary; - } - - /// - /// Check if any variable group has variable with secret value - /// - /// Variable groups to check if contains any secret variable with value. - /// Result - public static bool HasSecretWithValue(IList variableGroups) - { - if (variableGroups == null || variableGroups.Count == 0) - { - return false; - } - - foreach (var group in variableGroups) - { - if (group != null && HasSecretWithValue(group.Variables)) - { - return true; - } - } - - return false; - } - - /// - /// Check if Variables has any secret value - /// - /// Variable set to check for any secret value - /// - public static bool HasSecretWithValue(IDictionary variables) - { - if (variables == null || variables.Count == 0) - { - return false; - } - - return variables.Any(s => s.Value != null && - s.Value.IsSecret && - !String.IsNullOrEmpty(s.Value.Value)); - } - - /// - /// Check if any secret variable exists in variable group - /// - /// Variable groups to check if contains any secret variable - /// Result - public static bool HasSecret(IList variableGroups) - { - if (variableGroups == null || variableGroups.Count == 0) - { - return false; - } - - foreach (var group in variableGroups) - { - if (group != null && HasSecret(group.Variables)) - { - return true; - } - } - - return false; - } - - /// - /// Check if variable set contains any secret variable - /// - /// Variable set to be checked for secret variable - /// - public static bool HasSecret(IDictionary variables) - { - if (variables != null) - { - return variables.Any(v => v.Value != null && v.Value.IsSecret); - } - - return false; - } - - /// - /// Copies secrets from source variable groups to target variable groups - /// - /// Source variable groups - /// Target variable groups - /// - public static void FillSecrets( - IList sourceGroups, - IList targetGroups) - { - if (sourceGroups == null || sourceGroups.Count == 0) - { - return; - } - - if (targetGroups == null) - { - throw new ArgumentNullException("targetGroups"); - } - - foreach (var sourceGroup in sourceGroups) - { - var targetGroup = targetGroups.FirstOrDefault(group => group.Id == sourceGroup.Id); - - if (targetGroup != null) - { - if (sourceGroup.Variables == null || sourceGroup.Variables.Count == 0) - { - // nothing to fill - continue; - } - - if (targetGroup.Variables == null) - { - throw new ArgumentNullException(nameof(targetGroup.Variables)); - } - - foreach (var variable in sourceGroup.Variables.Where(x => x.Value.IsSecret)) - { - targetGroup.Variables[variable.Key] = variable.Value.Clone(); - } - } - } - } - - private static Type keyVaultVariableType = typeof(AzureKeyVaultVariableValue); } } diff --git a/src/Sdk/DTWebApi/WebApi/VariableValue.cs b/src/Sdk/DTWebApi/WebApi/VariableValue.cs index 99e1d8597..178590ceb 100644 --- a/src/Sdk/DTWebApi/WebApi/VariableValue.cs +++ b/src/Sdk/DTWebApi/WebApi/VariableValue.cs @@ -4,7 +4,6 @@ using System.Runtime.Serialization; namespace GitHub.DistributedTask.WebApi { [DataContract] - [KnownType(typeof(AzureKeyVaultVariableValue))] public class VariableValue { public VariableValue() diff --git a/src/Sdk/Resources/ContentResources.g.cs b/src/Sdk/Resources/ContentResources.g.cs deleted file mode 100644 index d9c4970c9..000000000 --- a/src/Sdk/Resources/ContentResources.g.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Globalization; - -namespace GitHub.Services.Content.Common -{ - public static class ContentResources - { - - public static string InvalidHexString(object arg0) - { - const string Format = @"Invalid hex string. The string value provided {0} is not a valid hex string."; - return string.Format(CultureInfo.CurrentCulture, Format, arg0); - } - - public static string ArtifactBillingException() - { - const string Format = @"Artifact cannot be uploaded because max quantity has been exceeded or the payment instrument is invalid."; - return Format; - } - } -} diff --git a/src/Test/L0/Listener/Configuration/ArgumentValidatorTestsL0.cs b/src/Test/L0/Listener/Configuration/ArgumentValidatorTestsL0.cs index c43ca9853..d2c50232d 100644 --- a/src/Test/L0/Listener/Configuration/ArgumentValidatorTestsL0.cs +++ b/src/Test/L0/Listener/Configuration/ArgumentValidatorTestsL0.cs @@ -25,7 +25,7 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration { using (TestHostContext hc = new TestHostContext(this)) { - Assert.True(Validators.AuthSchemeValidator("pat")); + Assert.True(Validators.AuthSchemeValidator("OAuth")); Assert.False(Validators.AuthSchemeValidator("Fail")); } } diff --git a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs index a4108cce8..533cc0459 100644 --- a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs +++ b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs @@ -44,7 +44,6 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration private string _expectedAuthType = "pat"; private string _expectedWorkFolder = "_work"; private int _expectedPoolId = 1; - private int _expectedDeploymentMachineId = 81; private RSACryptoServiceProvider rsa = null; private RunnerSettings _configMgrAgentSettings = new RunnerSettings(); @@ -68,7 +67,6 @@ namespace GitHub.Runner.Common.Tests.Listener.Configuration #endif var expectedAgent = new TaskAgent(_expectedAgentName) { Id = 1 }; - var expectedDeploymentMachine = new DeploymentMachine() { Agent = expectedAgent, Id = _expectedDeploymentMachineId }; expectedAgent.Authorization = new TaskAgentAuthorization { ClientId = Guid.NewGuid(), diff --git a/src/Test/L0/Listener/JobDispatcherL0.cs b/src/Test/L0/Listener/JobDispatcherL0.cs index 60955b6fb..5f774c174 100644 --- a/src/Test/L0/Listener/JobDispatcherL0.cs +++ b/src/Test/L0/Listener/JobDispatcherL0.cs @@ -32,11 +32,8 @@ namespace GitHub.Runner.Common.Tests.Listener { TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = null; - JobEnvironment environment = new JobEnvironment(); - List tasks = new List(); - Guid JobId = Guid.NewGuid(); - var jobRequest = new AgentJobRequestMessage(plan, timeline, JobId, "someJob", "someJob", environment, tasks); - var result = Pipelines.AgentJobRequestMessageUtil.Convert(jobRequest); + Guid jobId = Guid.NewGuid(); + var result = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, "someJob", "someJob", null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null); result.ContextData["github"] = new Pipelines.ContextData.DictionaryContextData(); return result; } diff --git a/src/Test/L0/Listener/RunnerL0.cs b/src/Test/L0/Listener/RunnerL0.cs index 0003ba5cd..418935644 100644 --- a/src/Test/L0/Listener/RunnerL0.cs +++ b/src/Test/L0/Listener/RunnerL0.cs @@ -40,15 +40,12 @@ namespace GitHub.Runner.Common.Tests.Listener _updater = new Mock(); } - private AgentJobRequestMessage CreateJobRequestMessage(string jobName) + private Pipelines.AgentJobRequestMessage CreateJobRequestMessage(string jobName) { TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = null; - JobEnvironment environment = new JobEnvironment(); - List tasks = new List(); - Guid JobId = Guid.NewGuid(); - var jobRequest = new AgentJobRequestMessage(plan, timeline, JobId, jobName, jobName, environment, tasks); - return jobRequest as AgentJobRequestMessage; + Guid jobId = Guid.NewGuid(); + return new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, "test", "test", null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null); } private JobCancelMessage CreateJobCancelMessage() diff --git a/src/Test/L0/ProcessInvokerL0.cs b/src/Test/L0/ProcessInvokerL0.cs index 735a35dc2..accf01a07 100644 --- a/src/Test/L0/ProcessInvokerL0.cs +++ b/src/Test/L0/ProcessInvokerL0.cs @@ -53,7 +53,7 @@ namespace GitHub.Runner.Common.Tests Assert.Equal(1, stdout.Count); Assert.Equal("From STDOUT 'ç'", stdout[0]); Assert.True(stderr.Count > 0); - Assert.True(stderr[0].Contains("From STDERR 'ç'")); + Assert.Contains("From STDERR 'ç'", stderr[0]); } } #endif diff --git a/src/Test/L0/Worker/ActionCommandManagerL0.cs b/src/Test/L0/Worker/ActionCommandManagerL0.cs index ac52bd8e8..f2e8d6755 100644 --- a/src/Test/L0/Worker/ActionCommandManagerL0.cs +++ b/src/Test/L0/Worker/ActionCommandManagerL0.cs @@ -203,12 +203,9 @@ namespace GitHub.Runner.Common.Tests.Worker // 1. Job request message (with ACTIONS_STEP_DEBUG = true) TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = new TimelineReference(); - JobEnvironment environment = new JobEnvironment(); - environment.SystemConnection = new ServiceEndpoint(); - List tasks = new List(); - Guid JobId = Guid.NewGuid(); + Guid jobId = Guid.NewGuid(); string jobName = "some job name"; - var jobRequest = Pipelines.AgentJobRequestMessageUtil.Convert(new AgentJobRequestMessage(plan, timeline, JobId, jobName, jobName, environment, tasks)); + var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, jobName, jobName, null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null); jobRequest.Resources.Repositories.Add(new Pipelines.RepositoryResource() { Alias = Pipelines.PipelineConstants.SelfAlias, diff --git a/src/Test/L0/Worker/ExecutionContextL0.cs b/src/Test/L0/Worker/ExecutionContextL0.cs index 0660c4a74..36dd8f57f 100644 --- a/src/Test/L0/Worker/ExecutionContextL0.cs +++ b/src/Test/L0/Worker/ExecutionContextL0.cs @@ -23,12 +23,9 @@ namespace GitHub.Runner.Common.Tests.Worker // Arrange: Create a job request message. TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = new TimelineReference(); - JobEnvironment environment = new JobEnvironment(); - environment.SystemConnection = new ServiceEndpoint(); - List tasks = new List(); - Guid JobId = Guid.NewGuid(); + Guid jobId = Guid.NewGuid(); string jobName = "some job name"; - var jobRequest = Pipelines.AgentJobRequestMessageUtil.Convert(new AgentJobRequestMessage(plan, timeline, JobId, jobName, jobName, environment, tasks)); + var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, jobName, jobName, null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null); jobRequest.Resources.Repositories.Add(new Pipelines.RepositoryResource() { Alias = Pipelines.PipelineConstants.SelfAlias, @@ -102,12 +99,9 @@ namespace GitHub.Runner.Common.Tests.Worker // Arrange: Create a job request message. TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = new TimelineReference(); - JobEnvironment environment = new JobEnvironment(); - environment.SystemConnection = new ServiceEndpoint(); - List tasks = new List(); - Guid JobId = Guid.NewGuid(); + Guid jobId = Guid.NewGuid(); string jobName = "some job name"; - var jobRequest = Pipelines.AgentJobRequestMessageUtil.Convert(new AgentJobRequestMessage(plan, timeline, JobId, jobName, jobName, environment, tasks)); + var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, jobName, jobName, null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null); jobRequest.Resources.Repositories.Add(new Pipelines.RepositoryResource() { Alias = Pipelines.PipelineConstants.SelfAlias, @@ -156,12 +150,9 @@ namespace GitHub.Runner.Common.Tests.Worker // Arrange: Create a job request message. TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = new TimelineReference(); - JobEnvironment environment = new JobEnvironment(); - environment.SystemConnection = new ServiceEndpoint(); - List tasks = new List(); - Guid JobId = Guid.NewGuid(); + Guid jobId = Guid.NewGuid(); string jobName = "some job name"; - var jobRequest = Pipelines.AgentJobRequestMessageUtil.Convert(new AgentJobRequestMessage(plan, timeline, JobId, jobName, jobName, environment, tasks)); + var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, jobName, jobName, null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null); jobRequest.Resources.Repositories.Add(new Pipelines.RepositoryResource() { Alias = Pipelines.PipelineConstants.SelfAlias, diff --git a/src/Test/L0/Worker/JobRunnerL0.cs b/src/Test/L0/Worker/JobRunnerL0.cs index b47faf0e3..9881868fb 100644 --- a/src/Test/L0/Worker/JobRunnerL0.cs +++ b/src/Test/L0/Worker/JobRunnerL0.cs @@ -64,22 +64,23 @@ namespace GitHub.Runner.Common.Tests.Worker TaskOrchestrationPlanReference plan = new TaskOrchestrationPlanReference(); TimelineReference timeline = new Timeline(Guid.NewGuid()); - JobEnvironment environment = new JobEnvironment(); - environment.Variables[Constants.Variables.System.Culture] = "en-US"; - environment.SystemConnection = new ServiceEndpoint() + Guid jobId = Guid.NewGuid(); + _message = new Pipelines.AgentJobRequestMessage(plan, timeline, jobId, testName, testName, null, null, null, new Dictionary(), new List(), new Pipelines.JobResources(), new Pipelines.ContextData.DictionaryContextData(), new Pipelines.WorkspaceOptions(), new List(), null); + _message.Variables[Constants.Variables.System.Culture] = "en-US"; + _message.Resources.Endpoints.Add(new ServiceEndpoint() { Name = WellKnownServiceEndpointNames.SystemVssConnection, Url = new Uri("https://test.visualstudio.com"), Authorization = new EndpointAuthorization() { Scheme = "Test", - } - }; - environment.SystemConnection.Authorization.Parameters["AccessToken"] = "token"; + Parameters = { + {"AccessToken", "token"} + } + }, + + }); - List tasks = new List(); - Guid JobId = Guid.NewGuid(); - _message = Pipelines.AgentJobRequestMessageUtil.Convert(new AgentJobRequestMessage(plan, timeline, JobId, testName, testName, environment, tasks)); _message.Resources.Repositories.Add(new Pipelines.RepositoryResource() { Alias = Pipelines.PipelineConstants.SelfAlias, diff --git a/src/Test/L0/Worker/WorkerL0.cs b/src/Test/L0/Worker/WorkerL0.cs index b84abb870..2129330ae 100644 --- a/src/Test/L0/Worker/WorkerL0.cs +++ b/src/Test/L0/Worker/WorkerL0.cs @@ -37,15 +37,15 @@ namespace GitHub.Runner.Common.Tests.Worker serviceEndpoint.Authorization.Parameters.Add("nullValue", null); resources.Endpoints.Add(serviceEndpoint); - List tasks = new List(); - tasks.Add(new Pipelines.TaskStep() + List actions = new List(); + actions.Add(new Pipelines.ActionStep() { Id = Guid.NewGuid(), - Reference = new Pipelines.TaskStepDefinitionReference() + Reference = new Pipelines.RepositoryPathReference() { - Id = Guid.NewGuid(), - Name = "TestTask", - Version = "1.0.0" + RepositoryType = "GitHub", + Name = "actions/test", + Ref = "v1" } }); Guid JobId = Guid.NewGuid(); @@ -69,7 +69,7 @@ namespace GitHub.Runner.Common.Tests.Worker new Pipelines.ContextData.DictionaryContextData() }, }; - var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, JobId, jobName, jobName, new StringToken(null, null, null, "ubuntu"), sidecarContainers, null, variables, new List(), resources, context, null, tasks, null); + var jobRequest = new Pipelines.AgentJobRequestMessage(plan, timeline, JobId, jobName, jobName, new StringToken(null, null, null, "ubuntu"), sidecarContainers, null, variables, new List(), resources, context, null, actions, null); return jobRequest; }