Ejemplo n.º 1
0
        public async Task ExecuteAsync(OctoContext context)
        {
            var json    = await new StreamReader(context.Request.Body).ReadToEndAsync();
            var request = JsonConvert.DeserializeObject <JObject>(json);

            var baseUrl  = request.GetValue("BaseUrl").ToString();
            var username = request.GetValue("Username").ToString();
            // If password here is null, it could be that they're clicking the test connectivity button after saving
            // the configuration as we won't have the value of the password on client side, so we need to retrieve it
            // from the database
            var password = string.IsNullOrEmpty(request.GetValue("Password").ToString())
                ? configurationStore.GetJiraPassword()
                : request.GetValue("Password").ToString();

            if (string.IsNullOrEmpty(baseUrl) || string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                context.Response.AsOctopusJson(ConnectivityCheckResponse.Failure(
                                                   string.IsNullOrEmpty(baseUrl) ? "Please provide a value for Jira Base Url." : null,
                                                   string.IsNullOrEmpty(username) ? "Please provide a value for Jira Username." : null,
                                                   string.IsNullOrEmpty(password) ? "Please provide a value for Jira Password." : null));
                return;
            }

            var jiraRestClient          = new JiraRestClient(baseUrl, username, password, log);
            var connectivityCheckResult = jiraRestClient.GetServerInfo().Result;

            context.Response.AsOctopusJson(connectivityCheckResult);
        }
Ejemplo n.º 2
0
 public void FillCountries()
 {
     using (var context = new OctoContext())
     {
         context.Countries.Add(new Country {
             Name = "Armenia"
         });
         context.SaveChanges();
     }
 }
        public async Task ExecuteAsync(OctoContext context)
        {
            var json    = await new StreamReader(context.Request.Body).ReadToEndAsync();
            var request = JsonConvert.DeserializeObject <JObject>(json);
            var baseUrl = request.GetValue("BaseUrl").ToString();

            var username = installationIdProvider.GetInstallationId().ToString();
            // If password here is null, it could be that they're clicking the test connectivity button after saving
            // the configuration as we won't have the value of the password on client side, so we need to retrieve it
            // from the database
            var password = string.IsNullOrEmpty(request.GetValue("Password").ToString()) ? configurationStore.GetConnectAppPassword() : request.GetValue("Password").ToString();

            if (string.IsNullOrEmpty(baseUrl) || string.IsNullOrEmpty(password))
            {
                context.Response.AsOctopusJson(ConnectivityCheckResponse.Failure(
                                                   string.IsNullOrEmpty(baseUrl) ? "Please provide a value for Jira Base Url." : null,
                                                   string.IsNullOrEmpty(password) ? "Please provide a value for Jira Connect App Password." : null)
                                               );
                return;
            }

            var token = connectAppClient.GetAuthTokenFromConnectApp(username, password);

            if (token is null)
            {
                context.Response.AsOctopusJson(ConnectivityCheckResponse.Failure("Failed to get authentication token from Jira Connect App."));
                return;
            }

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var connectivityCheckPayload =
                    JsonConvert.SerializeObject(new JiraConnectAppConnectivityCheckRequest {
                    BaseHostUrl = baseUrl, OctopusInstallationId = username
                });
                var result = await client.PostAsync(
                    $"{configurationStore.GetConnectAppUrl()}/relay/connectivitycheck",
                    new StringContent(connectivityCheckPayload, Encoding.UTF8, "application/json"));

                if (!result.IsSuccessStatusCode)
                {
                    context.Response.AsOctopusJson(ConnectivityCheckResponse.Failure(result.StatusCode == HttpStatusCode.NotFound
                        ? $"Failed to find an installation for Jira host {configurationStore.GetBaseUrl()}. Please ensure you have installed the Octopus Deploy for Jira plugin from the [Atlassian Marketplace](https://marketplace.atlassian.com/apps/1220376/octopus-deploy-for-jira). [Learn more](https://g.octopushq.com/JiraIssueTracker)."
                        : $"Failed to check connectivity to Jira. Response code: {result.StatusCode}, Message: {result.Content.ReadAsStringAsync().GetAwaiter().GetResult()}")
                                                   );
                    return;
                }

                context.Response.AsOctopusJson(ConnectivityCheckResponse.Success);
            }
        }
Ejemplo n.º 4
0
        public void InitializeSalutations()
        {
            using (var context = new OctoContext())
            {
                var account = new Account
                {
                    Name      = "Second account",
                    CountryId = 1
                };

                context.Accounts.Add(account);
                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        public void GetByFilterTest()
        {
            using (var context = new OctoContext())
            {
                var repo = new AccountRepository(context);

                var filter = new AccountFilter
                {
                    Id = 1
                };

                var items = repo.GetByFilterAsync(filter).GetAwaiter().GetResult();
            }
        }
Ejemplo n.º 6
0
        public Task ExecuteAsync(OctoContext context)
        {
            var name = context.Request.Query["partialName"];

            if (string.IsNullOrWhiteSpace(name))
            {
                context.Response.BadRequest("Please provide the name of a user to search for");
                return(Task.FromResult(0));
            }

            using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)))
            {
                context.Response.AsOctopusJson(userSearch.Search(name, cts.Token));
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 7
0
        public void Initialize()
        {
            var context = new OctoContext();

            _contactRepository = new ContactRepository(context);
        }