예제 #1
0
        public ServiceEndpoint CreateGenericEndpoint()
        {
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Get a service endpoint client instance
            VssConnection             connection     = Context.Connection;
            ServiceEndpointHttpClient endpointClient = connection.GetClient <ServiceEndpointHttpClient>();

            // Create a generic service endpoint
            ServiceEndpoint endpoint = endpointClient.CreateServiceEndpointAsync(project.Id, new ServiceEndpoint()
            {
                Name          = "MyNewServiceEndpoint",
                Type          = ServiceEndpointTypes.Generic,
                Url           = new Uri("https://myserver"),
                Authorization = new EndpointAuthorization()
                {
                    Scheme     = EndpointAuthorizationSchemes.UsernamePassword,
                    Parameters = new Dictionary <string, string>()
                    {
                        { "username", "myusername" },
                        { "password", "mysecretpassword" }
                    }
                }
            }).Result;

            Context.Log("Created endpoint: {0} {1} in {2}", endpoint.Id, endpoint.Name, project.Name);

            // Save new endpoint so it can be deleted later
            Context.SetValue <Guid>("$newServiceEndpointId", endpoint.Id);
            Context.SetValue <Guid>("$newServiceEndpointProjectId", project.Id);

            return(endpoint);
        }
예제 #2
0
        protected bool Connect(string PAT, string organisation)
        {
            var uriString = $"https://dev.azure.com/{organisation}";

            Console.Write($"Connecting to Azure DevOps REST API, {uriString} ...");
            try
            {
                _credentials     = new VssBasicCredential(string.Empty, PAT);
                _connection      = new VssConnection(new Uri(uriString), _credentials);
                _projectClient   = _connection.GetClient <ProjectHttpClient>();
                _buildClient     = _connection.GetClient <BuildHttpClient>();
                _releaseClient   = _connection.GetClient <ReleaseHttpClient>();
                _taskAgentClient = _connection.GetClient <TaskAgentHttpClient>();
                _extensionClient = _connection.GetClient <ExtensionManagementHttpClient>();
                _endpointClient  = _connection.GetClient <ServiceEndpointHttpClient>();
                _apiService      = new ApiService(PAT);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Console.WriteLine($"Unable to authenticate with Azure DevOps REST API :(");
                return(false);
            }
            Console.WriteLine($" connected :)");
            return(true);
        }
예제 #3
0
        private async Task <ServiceEndpointHttpClient> GetServiceEndpointClientAsync(CancellationToken cancellationToken)
        {
            if (cachedSeviceEndpointClient == null)
            {
                var connection = GetConnection();
                cachedSeviceEndpointClient = await connection.GetClientAsync <ServiceEndpointHttpClient>(cancellationToken);
            }

            return(cachedSeviceEndpointClient);
        }
예제 #4
0
        public void DeleteServiceEndpoint()
        {
            // Get ID of previously-created service endpoint
            Guid endpointId = Context.GetValue <Guid>("$newServiceEndpointId");
            Guid projectId  = Context.GetValue <Guid>("$newServiceEndpointProjectId");

            // Get a service endpoint client instance
            VssConnection             connection     = Context.Connection;
            ServiceEndpointHttpClient endpointClient = connection.GetClient <ServiceEndpointHttpClient>();

            try
            {
                endpointClient.DeleteServiceEndpointAsync(projectId, endpointId).SyncResult();

                Context.Log("Sucecssfully deleted endpoint {0} in {1}", endpointId, projectId);
            }
            catch (Exception ex)
            {
                Context.Log(ex.Message);
            }
        }
예제 #5
0
        public ServiceEndpoint CreateAzureRMEndpoint()
        {
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Get a service endpoint client instance
            VssConnection             connection     = Context.Connection;
            ServiceEndpointHttpClient endpointClient = connection.GetClient <ServiceEndpointHttpClient>();

            // Create a generic service endpoint
            ServiceEndpoint endpoint = endpointClient.CreateServiceEndpointAsync(project.Id, new ServiceEndpoint()
            {
                Name = "MyNewARMServiceEndpoint",
                Type = ServiceEndpointTypes.AzureRM,
                Url  = new Uri("https://management.azure.com/"),
                Data = new Dictionary <string, string>()
                {
                    { "subscriptionId", "1272a66f-e2e8-4e88-ab43-487409186c3f" },
                    { "subscriptionName", "subscriptionName" },
                    { "environment", "AzureCloud" },
                    { "scopeLevel", "Subscription" },
                    { "creationMode", "Manual" }
                },
                Authorization = new EndpointAuthorization()
                {
                    Scheme     = EndpointAuthorizationSchemes.ServicePrincipal,
                    Parameters = new Dictionary <string, string>()
                    {
                        { "tenantid", "1272a66f-e2e8-4e88-ab43-487409186c3f" },
                        { "serviceprincipalid", "1272a66f-e2e8-4e88-ab43-487409186c3f" },
                        { "authenticationType", "spnKey" },
                        { "serviceprincipalkey", "SomePassword" }
                    }
                }
            }).Result;

            Context.Log("Created endpoint: {0} {1} in {2}", endpoint.Id, endpoint.Name, project.Name);

            return(endpoint);
        }
예제 #6
0
        public IEnumerable <ServiceEndpoint> ListEndpoints()
        {
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Get a service endpoint client instance
            VssConnection             connection     = Context.Connection;
            ServiceEndpointHttpClient endpointClient = connection.GetClient <ServiceEndpointHttpClient>();

            // Get a list of all "generic" service endpoints in the specified project
            List <ServiceEndpoint> endpoints = endpointClient.GetServiceEndpointsAsync(
                project: project.Id,
                type: ServiceEndpointTypes.Generic).Result;

            // Show the endpoints
            Context.Log("Endpoints in project: {0}", project.Name);
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                Context.Log("- {0} {1}", endpoint.Id.ToString().PadLeft(6), endpoint.Name);
            }

            return(endpoints);
        }
예제 #7
0
        public IEnumerable <ServiceEndpointType> ListEndpointTypes()
        {
            // Get a service endpoint client instance
            VssConnection             connection     = Context.Connection;
            ServiceEndpointHttpClient endpointClient = connection.GetClient <ServiceEndpointHttpClient>();

            // Get a list of all available service endpoint types
            List <ServiceEndpointType> types = endpointClient.GetServiceEndpointTypesAsync().Result;

            // Show details about each type in the console
            foreach (ServiceEndpointType t in types)
            {
                Context.Log(t.Name);

                Context.Log("Inputs:");
                foreach (InputDescriptor input in t.InputDescriptors)
                {
                    Context.Log("- {0}", input.Id);
                }

                Context.Log("Schemes:");
                foreach (ServiceEndpointAuthenticationScheme scheme in t.AuthenticationSchemes)
                {
                    Context.Log("- {0}", scheme.Scheme);
                    Context.Log("  Inputs:");
                    foreach (InputDescriptor input in scheme.InputDescriptors)
                    {
                        Context.Log("  - {0}", input.Id);
                    }
                }

                Context.Log("================================");
            }

            return(types);
        }