mirror of
https://github.com/actions/runner.git
synced 2025-12-18 00:07:08 +00:00
GitHub Actions Runner
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
[DataContract]
|
||||
public enum AadLoginPromptOption
|
||||
{
|
||||
/// <summary>
|
||||
/// Do not provide a prompt option
|
||||
/// </summary>
|
||||
[EnumMember]
|
||||
NoOption = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Force the user to login again.
|
||||
/// </summary>
|
||||
[EnumMember]
|
||||
Login = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[EnumMember]
|
||||
SelectAccount = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Force the user to login again.
|
||||
/// <remarks>
|
||||
/// Ignore current authentication state and force the user to authenticate again. This option should be used instead of Login.
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
[EnumMember]
|
||||
FreshLogin = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Force the user to login again with mfa.
|
||||
/// <remarks>
|
||||
/// Ignore current authentication state and force the user to authenticate again. This option should be used instead of Login, if MFA is required.
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
[EnumMember]
|
||||
FreshLoginWithMfa = 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Azure Management Group
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class AzureManagementGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// Azure management group name
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
[JsonProperty(PropertyName = "Name")]
|
||||
public String Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id of azure management group
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
[JsonProperty(PropertyName = "Id")]
|
||||
public String Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Display name of azure management group
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
[JsonProperty(PropertyName = "displayName")]
|
||||
public String DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id of tenant from which azure management group belogs
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public String TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Azure management group query result
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class AzureManagementGroupQueryResult
|
||||
{
|
||||
/// <summary>
|
||||
/// List of azure management groups
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
[JsonProperty("value")]
|
||||
public List<AzureManagementGroup> Value;
|
||||
|
||||
/// <summary>
|
||||
/// Error message in case of an exception
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string ErrorMessage;
|
||||
}
|
||||
}
|
||||
130
src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermission.cs
Normal file
130
src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/AzurePermission.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
[DataContract]
|
||||
public class AzureSubscriptionQueryResult
|
||||
{
|
||||
[DataMember]
|
||||
[JsonProperty("value")]
|
||||
public List<AzureSubscription> Value;
|
||||
|
||||
[DataMember]
|
||||
public string ErrorMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
public sealed class EndpointAuthorizationSchemes
|
||||
{
|
||||
public const String AzureStorage = "AzureStorage";
|
||||
public const String OAuth = "OAuth";
|
||||
public const String OAuth2 = "OAuth2";
|
||||
public const String OAuthWrap = "OAuthWrap";
|
||||
public const String Certificate = "Certificate";
|
||||
public const String UsernamePassword = "UsernamePassword";
|
||||
public const String Token = "Token";
|
||||
public const String PersonalAccessToken = "PersonalAccessToken";
|
||||
public const String ServicePrincipal = "ServicePrincipal";
|
||||
public const String None = "None";
|
||||
public const String Jwt = "JWT";
|
||||
public const String InstallationToken = "InstallationToken";
|
||||
}
|
||||
|
||||
public sealed class EndpointAuthorizationParameters
|
||||
{
|
||||
public const String Username = "Username";
|
||||
public const String Password = "Password";
|
||||
public const String Certificate = "Certificate";
|
||||
public const String AccessToken = "AccessToken";
|
||||
public const String ApiToken = "ApiToken";
|
||||
public const String RefreshToken = "RefreshToken";
|
||||
public const String ServicePrincipalId = "ServicePrincipalId";
|
||||
public const String ServicePrincipalKey = "ServicePrincipalKey";
|
||||
public const String TenantId = "TenantId";
|
||||
public const String RealmName = "RealmName";
|
||||
public const String IdToken = "IdToken";
|
||||
public const String Nonce = "nonce";
|
||||
public const String Scope = "Scope";
|
||||
public const String Role = "Role";
|
||||
public const String ServerCertThumbprint = "ServerCertThumbprint";
|
||||
public const String CompleteCallbackPayload = "CompleteCallbackPayload";
|
||||
public const String ClientMail = "ClientMail";
|
||||
public const String PrivateKey = "PrivateKey";
|
||||
public const String Issuer = "Issuer";
|
||||
public const String Audience = "Audience";
|
||||
public const String StorageAccountName = "StorageAccountName";
|
||||
public const String StorageAccessKey = "StorageAccessKey";
|
||||
public const String AccessTokenType = "AccessTokenType";
|
||||
public const String Signature = "Signature";
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public sealed class EndpointAuthorization
|
||||
{
|
||||
public EndpointAuthorization()
|
||||
{
|
||||
}
|
||||
|
||||
private EndpointAuthorization(EndpointAuthorization authorizationToClone)
|
||||
{
|
||||
this.Scheme = authorizationToClone.Scheme;
|
||||
if (authorizationToClone.m_parameters != null && authorizationToClone.m_parameters.Count > 0)
|
||||
{
|
||||
m_parameters = new Dictionary<String, String>(authorizationToClone.m_parameters, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the scheme used for service endpoint authentication.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public String Scheme
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IDictionary<String, String> Parameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_parameters == null)
|
||||
{
|
||||
m_parameters = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
return m_parameters;
|
||||
}
|
||||
}
|
||||
|
||||
public EndpointAuthorization Clone()
|
||||
{
|
||||
return new EndpointAuthorization(this);
|
||||
}
|
||||
|
||||
[OnDeserialized]
|
||||
private void OnDeserialized(StreamingContext context)
|
||||
{
|
||||
SerializationHelper.Copy(ref m_serializedParameters, ref m_parameters, StringComparer.OrdinalIgnoreCase, true);
|
||||
}
|
||||
|
||||
[OnSerializing]
|
||||
private void OnSerializing(StreamingContext context)
|
||||
{
|
||||
SerializationHelper.Copy(ref m_parameters, ref m_serializedParameters, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[OnSerialized]
|
||||
private void OnSerialized(StreamingContext context)
|
||||
{
|
||||
m_serializedParameters = null;
|
||||
}
|
||||
|
||||
private IDictionary<String, String> m_parameters;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the parameters for the selected authorization scheme.
|
||||
/// </summary>
|
||||
[DataMember(Name = "Parameters", EmitDefaultValue = false)]
|
||||
private IDictionary<String, String> m_serializedParameters;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
public static class SerializationHelper
|
||||
{
|
||||
public static void Copy<T>(
|
||||
ref List<T> source,
|
||||
ref List<T> target,
|
||||
Boolean clearSource = false)
|
||||
{
|
||||
if (source != null && source.Count > 0)
|
||||
{
|
||||
target = new List<T>(source);
|
||||
}
|
||||
|
||||
if (clearSource)
|
||||
{
|
||||
source = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Copy<T>(
|
||||
ref IList<T> source,
|
||||
ref ISet<T> target,
|
||||
IEqualityComparer<T> comparer,
|
||||
Boolean clearSource = false)
|
||||
{
|
||||
if (source != null && source.Count > 0)
|
||||
{
|
||||
target = new HashSet<T>(source, comparer);
|
||||
}
|
||||
|
||||
if (clearSource)
|
||||
{
|
||||
source = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Copy<T>(
|
||||
ref ISet<T> source,
|
||||
ref IList<T> target,
|
||||
Boolean clearSource = false)
|
||||
{
|
||||
if (source != null && source.Count > 0)
|
||||
{
|
||||
target = new List<T>(source);
|
||||
}
|
||||
|
||||
if (clearSource)
|
||||
{
|
||||
source = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Copy<TKey, TValue>(
|
||||
ref Dictionary<TKey, TValue> source,
|
||||
ref Dictionary<TKey, TValue> target,
|
||||
Boolean clearSource = false)
|
||||
{
|
||||
Copy(ref source, ref target, EqualityComparer<TKey>.Default, clearSource);
|
||||
}
|
||||
|
||||
public static void Copy<TKey, TValue>(
|
||||
ref IDictionary<TKey, TValue> source,
|
||||
ref IDictionary<TKey, TValue> target,
|
||||
Boolean clearSource = false)
|
||||
{
|
||||
Copy(ref source, ref target, EqualityComparer<TKey>.Default, clearSource);
|
||||
}
|
||||
|
||||
public static void Copy<TKey, TValue>(
|
||||
ref Dictionary<TKey, TValue> source,
|
||||
ref Dictionary<TKey, TValue> target,
|
||||
IEqualityComparer<TKey> comparer,
|
||||
Boolean clearSource = false)
|
||||
{
|
||||
if (source != null && source.Count > 0)
|
||||
{
|
||||
target = new Dictionary<TKey, TValue>(source, comparer);
|
||||
}
|
||||
|
||||
if (clearSource)
|
||||
{
|
||||
source = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Copy<TKey, TValue>(
|
||||
ref IDictionary<TKey, TValue> source,
|
||||
ref IDictionary<TKey, TValue> target,
|
||||
IEqualityComparer<TKey> comparer,
|
||||
Boolean clearSource = false)
|
||||
{
|
||||
if (source != null && source.Count > 0)
|
||||
{
|
||||
target = new Dictionary<TKey, TValue>(source, comparer);
|
||||
}
|
||||
|
||||
if (clearSource)
|
||||
{
|
||||
source = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
296
src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/ServiceEndpoint.cs
Normal file
296
src/Sdk/DTWebApi/WebApi/ServiceEndpointLegacy/ServiceEndpoint.cs
Normal file
@@ -0,0 +1,296 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using GitHub.Services.WebApi;
|
||||
using GitHub.Services.Common.Internal;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an endpoint which may be used by an orchestration job.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class ServiceEndpoint
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs an <c>ServiceEndpoint</c> instance with empty values.
|
||||
/// </summary>
|
||||
public ServiceEndpoint()
|
||||
{
|
||||
m_data = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
|
||||
IsReady = true;
|
||||
}
|
||||
|
||||
private ServiceEndpoint(ServiceEndpoint endpointToClone)
|
||||
{
|
||||
Id = endpointToClone.Id;
|
||||
Name = endpointToClone.Name;
|
||||
Type = endpointToClone.Type;
|
||||
Url = endpointToClone.Url;
|
||||
Description = endpointToClone.Description;
|
||||
GroupScopeId = endpointToClone.GroupScopeId;
|
||||
AdministratorsGroup = endpointToClone.AdministratorsGroup;
|
||||
ReadersGroup = endpointToClone.ReadersGroup;
|
||||
|
||||
if (endpointToClone.Authorization != null)
|
||||
{
|
||||
Authorization = endpointToClone.Authorization.Clone();
|
||||
}
|
||||
|
||||
if (endpointToClone.m_data != null)
|
||||
{
|
||||
m_data = new Dictionary<String, String>(endpointToClone.m_data, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ValidateServiceEndpoint(ServiceEndpoint endpoint, ref string message)
|
||||
{
|
||||
if (endpoint == null)
|
||||
{
|
||||
message = "endpoint: null";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (endpoint.Id == Guid.Empty)
|
||||
{
|
||||
message = CommonResources.EmptyGuidNotAllowed("endpoint.Id");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(endpoint.Name))
|
||||
{
|
||||
message = string.Format("{0}:{1}", CommonResources.EmptyStringNotAllowed(), "endpoint.Name");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (endpoint.Url == null)
|
||||
{
|
||||
message = "endpoint.Url: null";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(endpoint.Type))
|
||||
{
|
||||
message = string.Format("{0}:{1}", CommonResources.EmptyStringNotAllowed(), "endpoint.Type");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (endpoint.Authorization == null)
|
||||
{
|
||||
message = "endpoint.Authorization: null";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the identifier of this endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public Guid Id
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the friendly name of the endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public String Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public String Type
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the owner of the endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public String Owner
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the url of the endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public Uri Url
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the identity reference for the user who created the Service endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public IdentityRef CreatedBy
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the description of endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public string Description
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the authorization data for talking to the endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public EndpointAuthorization Authorization
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public Guid GroupScopeId
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the identity reference for the administrators group of the service endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public IdentityRef AdministratorsGroup
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the identity reference for the readers group of the service endpoint.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public IdentityRef ReadersGroup
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the custom data associated with this endpoint.
|
||||
/// </summary>
|
||||
public IDictionary<String, String> Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
m_data = new Dictionary<String, String>(value, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether service endpoint is shared with other projects or not.
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = true)]
|
||||
public Boolean IsShared
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// EndPoint state indictor
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = true)]
|
||||
[JsonConverter(typeof(EndpointIsReadyConverter<bool>))]
|
||||
public bool IsReady
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error message during creation/deletion of endpoint
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public JObject OperationStatus
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a deep clone of the <c>ServiceEndpoint</c> instance.
|
||||
/// </summary>
|
||||
/// <returns>A new <c>ServiceEndpoint</c> instance identical to the current instance</returns>
|
||||
public ServiceEndpoint Clone()
|
||||
{
|
||||
return new ServiceEndpoint(this);
|
||||
}
|
||||
|
||||
[DataMember(EmitDefaultValue = false, Name = "Data")]
|
||||
private Dictionary<String, String> m_data;
|
||||
}
|
||||
|
||||
internal class EndpointIsReadyConverter<T> : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
// we are converting every non-assignable thing to true
|
||||
return true;
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Boolean || reader.TokenType == JsonToken.Integer)
|
||||
{
|
||||
return serializer.Deserialize<T>(reader);
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.String)
|
||||
{
|
||||
var s = (string)reader.Value;
|
||||
|
||||
if (s.Equals("false", StringComparison.OrdinalIgnoreCase) || s.Equals("0", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue((bool)value ? true : false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
public static class ServiceEndpointTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Azure endpoint
|
||||
/// </summary>
|
||||
public const String Azure = "Azure";
|
||||
|
||||
/// <summary>
|
||||
/// Chef endpoint
|
||||
/// </summary>
|
||||
public const String Chef = "Chef";
|
||||
|
||||
/// Chef endpoint
|
||||
/// </summary>
|
||||
public const String ExternalTfs = "ExternalTfs";
|
||||
|
||||
/// <summary>
|
||||
/// Generic endpoint
|
||||
/// </summary>
|
||||
public const String Generic = "Generic";
|
||||
|
||||
/// <summary>
|
||||
/// GitHub endpoint
|
||||
/// </summary>
|
||||
public const String GitHub = "GitHub";
|
||||
|
||||
/// <summary>
|
||||
/// GitHub Enterprise endpoint
|
||||
/// </summary>
|
||||
public const String GitHubEnterprise = "GitHubEnterprise";
|
||||
|
||||
/// <summary>
|
||||
/// Bitbucket endpoint
|
||||
/// </summary>
|
||||
public const String Bitbucket = "Bitbucket";
|
||||
|
||||
/// <summary>
|
||||
/// SSH endpoint
|
||||
/// </summary>
|
||||
public const String SSH = "SSH";
|
||||
|
||||
/// <summary>
|
||||
/// Subversion endpoint
|
||||
/// </summary>
|
||||
public const String Subversion = "Subversion";
|
||||
|
||||
/// <summary>
|
||||
///Gcp endpoint
|
||||
/// </summary>
|
||||
public const String Gcp = "google-cloud";
|
||||
|
||||
/// <summary>
|
||||
/// Subversion endpoint
|
||||
/// </summary>
|
||||
public const String Jenkins = "Jenkins";
|
||||
|
||||
/// <summary>
|
||||
/// External Git repository
|
||||
/// </summary>
|
||||
public const String ExternalGit = "Git";
|
||||
|
||||
/// <summary>
|
||||
/// Azure RM endpoint
|
||||
/// </summary>
|
||||
public const String AzureRM = "AzureRM";
|
||||
|
||||
/// <summary>
|
||||
/// Azure Deployment Manager
|
||||
/// </summary>
|
||||
public const String AzureDeploymentManager = "AzureDeploymentManager";
|
||||
|
||||
/// <summary>
|
||||
/// Azure Service Fabric
|
||||
/// </summary>
|
||||
public const String AzureServiceFabric = "ServiceFabric";
|
||||
|
||||
/// <summary>
|
||||
/// Azure Service Fabric
|
||||
/// </summary>
|
||||
public const String Docker = "dockerregistry";
|
||||
|
||||
/// <summary>
|
||||
/// Jira
|
||||
/// </summary>
|
||||
public const String Jira = "Jira";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user