Example #1
0
        public async Task OnSubmitHandler()
        {
            if (!IsValidationEnabled)
            {
                return;
            }

            IsValid = editContext.Validate();
            if (IsValidatedAndValid)
            {
                try
                {
                    await OnTagSelectedEvent.InvokeAsync(Model);
                }
                catch (Exception ex)
                {
                    Logger.LogErrorCsro(ex);
                    await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
                }
                finally
                {
                    HideLoading();
                }
            }
        }
Example #2
0
        public async Task OnVmSelected(string value)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(value))
                {
                    return;
                }

                Model.VmName = value;
                LastVmStatus = "Loading...";
                ShowLoading();
                var status = await AzureSdkService.GetStatus(Model.SubcriptionId, Model.ResorceGroup, Model.VmName);

                if (status != null)
                {
                    LastVmStatus = status.DisplayStatus;
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorCsro(ex);
                await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
            }
            await InvokeAsync(() => HideLoading());
        }
Example #3
0
        async Task LoadRg(string subcriptionId)
        {
            try
            {
                if (subcriptionId.IsNullOrEmptyExt())
                {
                    return;
                }

                ClearSelection();

                var rgs = await ResourceGroupervice.GetResourceGroups(subcriptionId);

                if (rgs != null)
                {
                    ResourceGroups.AddRange(rgs.Select(a => a.Name));
                    StateHasChanged();
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorCsro(ex);
                await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
            }
        }
Example #4
0
        private async Task Load()
        {
            try
            {
                ShowLoading();

                //var mefull = await GraphClientService.GetCurrentGraphUserModel();
                //var upnFull = await GraphClientService.GetUserByUpnEmailGraphUserModel("*****@*****.**");
                ////var email = await GraphClientService.GetUserByUpnEmail("*****@*****.**");
                //var me = await GraphClientService.GetCurrentGraphUser();
                //var upn = await GraphClientService.GetUserByUpnEmail("*****@*****.**");

                if (OperationTypeTicket != OperatioType.Create)
                {
                    Model.Id = int.Parse(TicketId);
                    var server = await TicketDataService.GetItemByIdAsync(Model.Id);

                    if (server != null)
                    {
                        Model = server;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorCsro(ex);
                await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
            }
            HideLoading();
        }
Example #5
0
        //public Task OnOrganizationChanged(string value)
        //{
        //    if (value != null)
        //        Model.Organization = value;

        //    return Task.CompletedTask;
        //}

        //public Task OnProcessNameChanged(string value)
        //{
        //    if (value != null)
        //        Model.ProcessName = value;

        //    return Task.CompletedTask;
        //}

        public async Task OnValidSubmit(EditContext context)
        {
            ShowProcessing();
            var valid = context.Validate();

            if (valid)
            {
                try
                {
                    await Task.Delay(1 * 1000); // todo fix workaround

                    valid = context.Validate();

                    if (valid && OperationTypeTicket == OperatioType.Create)
                    {
                        Model.Status = AdoModels.Status.Submitted;
                        var added = await AdoProjectDataService.AddItemAsync(Model);

                        if (added != null)
                        {
                            Success = true;
                            Model   = added;
                        }
                    }
                    else if (valid && OperationTypeTicket == OperatioType.Edit)
                    {
                        var updated = await AdoProjectDataService.UpdateItemAsync(Model);

                        if (updated != null)
                        {
                            await CsroDialogService.ShowMessage("Success", $"Update Finished", "Refresh");
                            await Load();
                        }
                        else
                        {
                            var ok = await CsroDialogService.ShowWarning("Update Error", $"Conflic Detected, Please refresh and try again", "Refresh");

                            if (ok)
                            {
                                await Load();
                            }
                        }
                    }
                    StateHasChanged();
                }
                catch (Exception ex)
                {
                    Logger.LogErrorCsro(ex);
                    await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
                }
            }
            HideLoading();
        }
Example #6
0
        public async Task OnValidSubmit(EditContext context)
        {
            var valid = context.Validate();

            if (valid)
            {
                try
                {
                    ShowLoading();
                    if (OperationTypeTicket == OperatioType.Create)
                    {
                        var added = await TicketDataService.AddItemAsync(Model);

                        if (added != null)
                        {
                            await CsroDialogService.ShowMessage("Success", $"Ticket created.");

                            GoBack();
                        }
                    }
                    else if (OperationTypeTicket == OperatioType.Edit)
                    {
                        var updated = await TicketDataService.UpdateItemAsync(Model);

                        if (updated != null)
                        {
                            await Load();

                            await CsroDialogService.ShowMessage("Success", $"Ticket updated.");
                        }
                        else
                        {
                            var ok = await CsroDialogService.ShowWarning("Update Error", $"Conflic Detected, Please refresh and try again", "Refresh");

                            if (ok)
                            {
                                await Load();
                            }
                        }
                    }
                    StateHasChanged();
                }
                catch (Exception ex)
                {
                    Logger.LogErrorCsro(ex);
                    await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
                }
                HideLoading();
            }
        }
Example #7
0
        private async Task Load()
        {
            try
            {
                ShowLoading();
                Model ??= new DefaultTag();

                if (IsprivilegedMembersVisible)
                {
                    HashSet <string> members = new();
                    if (Model.privilegedMembers.IsNullOrEmptyExt())
                    {
                        var user = await GraphClientService.GetCurrentGraphUser();

                        if (user != null)
                        {
                            Model.privilegedMembers = user.AvailableUn;
                        }
                    }
                    if (Model.privilegedMembers.HasValueExt())
                    {
                        var spl = Model.privilegedMembers.Split(';');
                        foreach (var kv in spl)
                        {
                            if (kv.HasValueExt())
                            {
                                members.Add(kv);
                            }
                        }
                    }
                    Selectedmembers = members;
                }

                var tags = await SubcriptionService.GetDefualtTags(SubcriptionId);

                Tags = tags ?? new DefaultTags();
            }
            catch (Exception ex)
            {
                await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");

                Logger.LogErrorCsro(ex);
            }
            finally
            {
                HideLoading();
            }
        }
Example #8
0
 protected async override Task OnInitializedAsync()
 {
     //throw new Exception("test excpetion");
     try
     {
         ShowLoading();
         Tickets.Clear();
         Tickets = await TicketDataService.GetItemsAsync();
     }
     catch (Exception ex)
     {
         Logger.LogErrorCsro(ex);
         await CsroDialogService.ShowError("Error", ex?.Message);
     }
     HideLoading();
 }
Example #9
0
        public async Task SaveAsDraftAsync()
        {
            try
            {
                ShowLoading("Saving...");
                Model.Status = AdoModels.Status.Draft;
                var saved = await AdoProjectDataService.AddItemAsync(Model);

                if (saved != null)
                {
                    await CsroDialogService.ShowMessage("Success", $"Request was saved.");
                }

                //await Load();
            }
            catch (Exception ex)
            {
                Logger.LogErrorCsro(ex);
                await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
            }
            HideLoading();
        }
Example #10
0
        public async override Task LoadAsync()
        {
            try
            {
                ShowLoading();
                CanView = false;
                SettingModels.Clear();

                var auth = await AuthenticationStateProvider.GetAuthenticationStateAsync();

                if (auth != null && auth.User.Identity.IsAuthenticated)
                {
                    var isAdmin  = auth.User.IsInRole(Core.RolesCsro.Admin);
                    var isAdmin2 = await AuthCsroService.IsInRole(Core.RolesCsro.Admin);

                    if (auth.User.Identity.Name.Contains("supolik"))
                    {
                        ShowTestEmailComp = true;
                        isAdmin2          = false;
                    }

                    //if (auth.User.Identity.Name.Contains("supolik"))
                    if (isAdmin2)
                    {
                        //var all = await ServiceIssueDataService.GetItemsAsync();
                        ////var id = await ServiceIssueDataService.GetItemByIdAsync(1);
                        ////var trackid = await ServiceIssueDataService.GetByTrackingId("1VWB-V9G");

                        CanView = true;

                        var userAuth = await UserDataService.GetUserByUserName(auth.User.Identity.Name);

                        var azureAdOptions = Configuration.GetSection(nameof(AzureAd)).Get <AzureAd>();

                        string TokenCacheDbCs = Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.TokenCacheDb);
                        SettingModels.Add(new SettingModel {
                            Name = nameof(TokenCacheDbCs), Value = TokenCacheDbCs.ReplaceWithStars(), Type = "Config"
                        });

                        string ApiEndpoint = Configuration.GetValue <string>("ApiEndpoint");
                        SettingModels.Add(new SettingModel {
                            Name = nameof(ApiEndpoint), Value = ApiEndpoint, Type = "Config"
                        });

                        bool UseChainTokenCredential = Configuration.GetValue <bool>("UseChainTokenCredential");
                        SettingModels.Add(new SettingModel {
                            Name = nameof(UseChainTokenCredential), Value = UseChainTokenCredential.ToString(), Type = "Config"
                        });

                        var keyVaultConfig = Configuration.GetSection(nameof(KeyVaultConfig)).Get <KeyVaultConfig>();
                        Logger.LogInformation($"{nameof(KeyVaultConfig.UseKeyVault)} = {keyVaultConfig?.UseKeyVault}");

                        var readfromKV = true; //todo change for testing
                        //if (readfromKV)
                        if (keyVaultConfig != null && (readfromKV || keyVaultConfig.UseKeyVault))
                        {
                            Logger.LogInformation($"{nameof(KeyVaultConfig.KeyVaultName)} = {keyVaultConfig.KeyVaultName}");
                            string type         = "KeyVault-SecretClient";
                            int    replaceChars = 30;
                            ShowLoading(type);

                            var clientSecretCredential = new ClientSecretCredential(azureAdOptions.TenantId, azureAdOptions.ClientId, azureAdOptions.ClientSecret); //works
                            //var clientSecretCredential = new InteractiveBrowserCredential(); //forbiden
                            //var clientSecretCredential = new DefaultAzureCredential(); //forbiden
                            //var clientSecretCredential = new DefaultAzureCredential(true); //forbiden
                            //var clientSecretCredential = new ManagedIdentityCredential(); //forbiden
                            //var clientSecretCredential = new ManagedIdentityCredential(keyVaultConfig.AppServiceManagedIdentityId); //works, need to set access in portal

                            try
                            {
                                var client = new SecretClient(new Uri(keyVaultConfig.KeyVaultName), clientSecretCredential);

                                var secBund = await client.GetSecretAsync(keyVaultConfig.TokenCacheDbCsVaultKey);

                                if (secBund != null)
                                {
                                    SettingModels.Add(new SettingModel {
                                        Name = nameof(TokenCacheDbCs), Value = secBund.Value?.Value?.ReplaceWithStars(replaceChars), Type = type
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                //await CsroDialogService.ShowError($"Error in SecretClient {clientSecretCredential}", $"{ex.Message}");
                                SettingModels.Add(new SettingModel {
                                    Name = nameof(TokenCacheDbCs), Value = ex.Message, Type = type
                                });
                            }

                            try
                            {
                                type = "KeyVault-KeyVaultClient";
                                ShowLoading(type);
                                var keyVaultClient = new KeyVaultClient(
                                    async(authority, resource, scope) =>
                                {
                                    //var credential = new DefaultAzureCredential(false);
                                    var credential = clientSecretCredential;
                                    var token      = await credential.GetTokenAsync(
                                        new Azure.Core.TokenRequestContext(
                                            new[] { "https://vault.azure.net/.default" }));
                                    return(token.Token);
                                });
                                var val = await keyVaultClient.GetSecretAsync(keyVaultConfig.KeyVaultName, keyVaultConfig.TokenCacheDbCsVaultKey);

                                if (val != null)
                                {
                                    SettingModels.Add(new SettingModel {
                                        Name = nameof(TokenCacheDbCs), Value = val.Value?.ReplaceWithStars(replaceChars), Type = type
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                //await CsroDialogService.ShowError($"Error in KeyVaultClient {clientSecretCredential}", $"{ex.Message}");
                                SettingModels.Add(new SettingModel {
                                    Name = nameof(TokenCacheDbCs), Value = ex.Message, Type = type
                                });
                            }

                            try
                            {
                                type = "KeyVault-AzureServiceTokenProvider";
                                ShowLoading(type);
                                //SettingModels.Add(new SettingModel { Name = "UseKeyVault", Value = "", Type = "" });
                                //works
                                var azureServiceTokenProvider = new AzureServiceTokenProvider();
                                var keyVaultClient            = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));

                                var s2 = await keyVaultClient.GetSecretAsync(keyVaultConfig.KeyVaultName, keyVaultConfig.TokenCacheDbCsVaultKey);

                                SettingModels.Add(new SettingModel {
                                    Name = nameof(TokenCacheDbCs), Value = s2?.Value.ReplaceWithStars(replaceChars), Type = type
                                });
                            }
                            catch (Exception ex)
                            {
                                //await CsroDialogService.ShowError("Error in AzureServiceTokenProvider", $"{ex.Message}");
                                SettingModels.Add(new SettingModel {
                                    Name = nameof(TokenCacheDbCs), Value = ex.Message, Type = type
                                });
                            }
                        }

                        //AzureAd
                        var dic = DictionaryOfPropertiesFromInstance(azureAdOptions);
                        if (dic != null)
                        {
                            foreach (var item in dic)
                            {
                                var set = new SettingModel {
                                    Type = "AzureAd", Name = item.Key
                                };
                                //var val = item.Value.GetValue(item);    //common error, don't use
                                var val = item.Value.GetValue(azureAdOptions);
                                set.Value = val?.ToString().ReplaceWithStars();
                                SettingModels.Add(set);
                            }
                        }

                        //KeyVaultConfig
                        dic = null;
                        dic = DictionaryOfPropertiesFromInstance(keyVaultConfig);
                        if (dic != null)
                        {
                            foreach (var item in dic)
                            {
                                var set = new SettingModel {
                                    Type = "KeyVaultConfig", Name = item.Key
                                };
                                var val = item.Value.GetValue(keyVaultConfig);
                                if (val != null)
                                {
                                    set.Value = val?.ToString();
                                    SettingModels.Add(set);
                                }
                            }
                        }
                    }
                }
                else
                {
                    SignIn();
                }
            }
            catch (Exception ex)
            {
                HideLoading();
                await CsroDialogService.ShowError("Error", $"{ex.Message}");
            }
            finally
            {
                HideLoading();
            }
        }
Example #11
0
        public async Task OnValidSubmit(EditContext context)
        {
            var valid = context.Validate();

            if (valid)
            {
                try
                {
                    if (OperationTypeTicket == OperatioType.Create)
                    {
                        ShowLoading("Creating request");

                        var added = await VmTicketDataService.AddItemAsync(Model);

                        //var added = await VmTicketDataService.CreateVmTicketAndWaitForConfirmation(Model);
                        if (added != null)
                        {
                            Success = true;
                            Model   = added;

                            ShowLoading("Success, please wait");
                            StateHasChanged();
                            await Task.Delay(3 * 1000);

                            HideLoading();

                            NavigationManager.NavigateTo($"vm/restart/view/{Model.Id}");
                        }
                    }
                    else if (OperationTypeTicket == OperatioType.Edit)
                    {
                        ShowLoading("Updating request");

                        var updated = await VmTicketDataService.UpdateItemAsync(Model);

                        if (updated != null)
                        {
                            Success = true;
                            //throw new Exception("Fake Test exception");
                        }
                        else
                        {
                            var ok = await CsroDialogService.ShowWarning("Update Error", $"Conflic Detected, Please refresh and try again", "Refresh");

                            if (ok)
                            {
                                await LoadAsync();
                            }
                        }
                    }
                    StateHasChanged();
                }
                catch (Exception ex)
                {
                    Logger.LogErrorCsro(ex);
                    await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
                }
                finally
                {
                    HideLoading();
                }
            }
        }
Example #12
0
        public async override Task LoadAsync()
        {
            try
            {
                if (OperationTypeTicket != OperatioType.Create)
                {
                    ShowLoading();

                    Model.Id = int.Parse(TicketId);
                    var server = await VmTicketDataService.GetItemByIdAsync(Model.Id);
                    await LoadRg(server?.SubcriptionId);

                    if (server != null)
                    {
                        Model = server;
                        if (OperationTypeTicket == OperatioType.View)
                        {
                            #region Verify old Code
                            //if (Model.VmState == "Restart Started" || !string.Equals(Model.VmState, "VM running"))
                            //{
                            //    //need to create delay to update vm state after restart
                            //    LoadingMessage = $"Current state: {Model.VmState}";
                            //    StateHasChanged();

                            //    var running = await VmTicketDataService.VerifyRestartStatusCallback(Model, (status)=>
                            //    {
                            //        LoadingMessage = $"Current state: {status}";
                            //        StateHasChanged();
                            //    }).ConfigureAwait(false);
                            //    if (running)
                            //    {
                            //        Model = await VmTicketDataService.GetItemByIdAsync(Model.Id);
                            //    }
                            //}
                            #endregion
                        }
                    }
                }

                else
                {
                    ShowLoading();
                    Subscripions = await SubcriptionDataService.GetSubcriptions();

                    Subscripions = Subscripions ?? new List <IdName>();
#if DEBUG
                    if (Model.ExternalTicket == null)
                    {
                        Model.ExternalTicket = "Inc132666FakeTicket";
                    }
                    if (Subscripions?.Count == 1)
                    {
                        var id = Subscripions.First().Id;
                        Subscripions.Add(new IdName(id, $"fake-sub-prod"));
                        Subscripions.Add(new IdName(id, $"fake-sub-uat"));
                        Subscripions.Add(new IdName(id, $"fake-sub-dev"));
                        Subscripions.Add(new IdName(id, $"fake-sub-appdev"));
                        Subscripions.Add(new IdName(id, $"fake-sub-test"));
                    }
#endif
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorCsro(ex);
                await CsroDialogService.ShowError("Error", $"Detail error: {ex.Message}");
            }
            finally
            {
                HideLoading();
            }
        }