/// <summary>
        /// Debug info
        /// </summary>
        /// <returns>The debug info you want</returns>
        public IActionResult Debug()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Debug info");
            stringBuilder.AppendLine("App token is: " + _sourceControl.GetAppToken());
            stringBuilder.AppendLine("App token id is " + _sourceControl.GetAppTokenId());
            stringBuilder.AppendLine("UserName from service: " + _giteaApi.GetUserNameFromUI().Result);
            return(Content(stringBuilder.ToString()));
        }
Example #2
0
 /// <inheritdoc/>
 public string GetAppToken()
 {
     try
     {
         return(_decoratedService.GetAppToken());
     }
     catch (Exception ex)
     {
         LogError(ex, "GetAppToken");
         throw;
     }
 }
Example #3
0
        public IActionResult CreateService(string org)
        {
            AltinnStudioViewModel model = new AltinnStudioViewModel();
            string token = _sourceControl.GetAppToken();

            if (string.IsNullOrEmpty(token))
            {
                model.MissingAppToken = true;
            }

            return(View(model));
        }
Example #4
0
        /// <summary>
        /// clone a repository.
        /// </summary>
        /// <param name="org">Unique identifier of the organisation responsible for the app.</param>
        /// <param name="app">Application identifier which is unique within an organisation.</param>
        /// <returns>The home app token page or the clone page.</returns>
        public IActionResult Clone(string org, string app)
        {
            AltinnStudioViewModel model = new AltinnStudioViewModel();
            string token = _sourceControl.GetAppToken();

            if (!string.IsNullOrEmpty(token))
            {
                _sourceControl.CloneRemoteRepository(org, app);
            }
            else
            {
                return(Redirect("/Home/AppToken"));
            }

            return(RedirectToAction("Index", new { org, app }));
        }
        public async Task <JsonResult> StartDeployment(string org, string service, string edition)
        {
            if (_configuration["AccessTokenDevOps"] == null)
            {
                ViewBag.ServiceUnavailable = true;
                return(Json(new
                {
                    Success = false,
                    Message = "Deployment unavailable"
                }));
            }
            string credentials = _configuration["AccessTokenDevOps"];

            string result = string.Empty;

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
                    object buildContent = new {
                        definition = new {
                            id = 12
                        },
                        parameters = $"{{\"SERVICE_ORG\":\"{org}\",\"SERVICE_REPO\":\"{service}\",\"SERVICE_TOKEN\":\"{_sourceControl.GetAppToken()}\",\"system.debug\":\"false\"}}\""
                    };

                    string        buildjson   = JsonConvert.SerializeObject(buildContent);
                    StringContent httpContent = new StringContent(buildjson, Encoding.UTF8, "application/json");
                    using (HttpResponseMessage response = await client.PostAsync("https://dev.azure.com/brreg/altinn-studio/_apis/build/builds?api-version=5.0-preview.4", httpContent))
                    {
                        response.EnsureSuccessStatusCode();
                        BuildModel responseBody = await response.Content.ReadAsAsync <BuildModel>();

                        result = responseBody.Id;
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Success = true,
                    Message = "Deployment failed " + ex
                }));
            }

            return(Json(new
            {
                Success = true,
                BuildId = result,
                Message = "Deployment status: " + result
            }));
        }