Exemple #1
0
        public virtual async Task EnsureUserEnterprise(EnterpriseArchitectClient entArch, EnterpriseManagerClient entMgr,
                                                       SecurityManagerClient secMgr, string parentEntLookup, string username)
        {
            if (State.UserEnterpriseLookup.IsNullOrEmpty())
            {
                var hostLookup = $"{parentEntLookup}|{username}";

                var getResp = await entMgr.ResolveHost(hostLookup, false);

                if (!getResp.Status || getResp.Model == null)
                {
                    var createResp = await entArch.CreateEnterprise(new CreateEnterpriseRequest()
                    {
                        Name        = username,
                        Description = username,
                        Host        = hostLookup
                    }, parentEntLookup, username);

                    if (createResp.Status)
                    {
                        State.UserEnterpriseLookup = createResp.Model.EnterpriseLookup;
                    }
                }
                else
                {
                    State.UserEnterpriseLookup = getResp.Model.EnterpriseLookup;
                }
            }

            if (State.UserEnterpriseLookup.IsNullOrEmpty())
            {
                throw new Exception("Unable to establish the user's enterprise, please try again.");
            }
        }
        public virtual async Task EnsureUserEnterprise(EnterpriseArchitectClient entArch, EnterpriseManagerClient entMgr,
                                                       SecurityManagerClient secMgr, string parentEntLookup, string username)
        {
            if (State.UserEnterpriseLookup.IsNullOrEmpty())
            {
                await DesignOutline.Instance.Retry()
                .SetActionAsync(async() =>
                {
                    try
                    {
                        var hostLookup = $"{parentEntLookup}|{username}";

                        log.LogInformation($"Ensuring user enterprise for {hostLookup}...");

                        var getResp = await entMgr.ResolveHost(hostLookup, false);

                        if (!getResp.Status || getResp.Model == null)
                        {
                            var createResp = await entArch.CreateEnterprise(new CreateEnterpriseRequest()
                            {
                                Name        = username,
                                Description = username,
                                Host        = hostLookup
                            }, parentEntLookup, username);

                            if (createResp.Status)
                            {
                                State.UserEnterpriseLookup = createResp.Model.EnterpriseLookup;
                            }
                        }
                        else
                        {
                            State.UserEnterpriseLookup = getResp.Model.EnterpriseLookup;
                        }

                        return(State.UserEnterpriseLookup.IsNullOrEmpty());
                    }
                    catch (Exception ex)
                    {
                        log.LogError(ex, "Failed ensuring user enterprise");

                        return(true);
                    }
                })
                .SetCycles(5)
                .SetThrottle(25)
                .SetThrottleScale(2)
                .Run();
            }

            if (State.UserEnterpriseLookup.IsNullOrEmpty())
            {
                throw new Exception("Unable to establish the user's enterprise, please try again.");
            }
        }
        public virtual async Task <Status> BootOrganizationEnvironment(EnterpriseArchitectClient entArch, EnterpriseManagerClient entMgr,
                                                                       DevOpsArchitectClient devOpsArch, string parentEntApiKey, string username)
        {
            var status = Status.Success;

            if (State.NewEnterpriseAPIKey.IsNullOrEmpty())
            {
                var entRes = await entArch.CreateEnterprise(new CreateEnterpriseRequest()
                {
                    Description = State.OrganizationDescription ?? State.OrganizationName,
                    Host        = State.Host,
                    Name        = State.OrganizationName
                }, parentEntApiKey, username);

                State.NewEnterpriseAPIKey = entRes.Model?.PrimaryAPIKey;

                status = entRes.Status;
            }

            if (status && !State.NewEnterpriseAPIKey.IsNullOrEmpty() && State.EnvironmentLookup.IsNullOrEmpty())
            {
                var envResp = await devOpsArch.EnsureEnvironment(new Personas.DevOps.EnsureEnvironmentRequest()
                {
                    EnvSettings        = State.EnvSettings,
                    OrganizationLookup = State.OrganizationLookup,
                }, State.NewEnterpriseAPIKey);

                State.EnvironmentLookup = envResp.Model?.Lookup;

                status = envResp.Status;
            }
            else if (!State.NewEnterpriseAPIKey.IsNullOrEmpty() && !State.EnvironmentLookup.IsNullOrEmpty())
            {
                await entMgr.SaveEnvironmentSettings(State.EnvSettings, State.NewEnterpriseAPIKey, State.EnvironmentLookup);
            }

            UpdateStatus(status);

            return(status);
        }
        public virtual async Task <NapkinIDESetupState> BootEnterprise()
        {
            logger.LogInformation("Booting Enterprise");

            await HasDevOpsOAuth();

            if (state.HasDevOpsOAuth)
            {
                if (state.NewEnterpriseAPIKey.IsNullOrEmpty())
                {
                    var entRes = await entArch.CreateEnterprise(new CreateEnterpriseRequest()
                    {
                        Description = state.OrganizationDescription,
                        Host        = state.Host,
                        Name        = state.OrganizationName
                    }, details.EnterpriseAPIKey, details.Username);

                    state.NewEnterpriseAPIKey = entRes.Model.PrimaryAPIKey;
                }

                if (!state.NewEnterpriseAPIKey.IsNullOrEmpty())
                {
                    var envResp = await devOpsArch.SetupEnvironment(new SetupEnvironmentRequest()
                    {
                        EnvSettings        = state.EnvSettings,
                        Template           = "fathym\\daf-iot-setup",
                        OrganizationLookup = state.OrganizationLookup
                    }, state.NewEnterpriseAPIKey, details.Username, devOpsEntApiKey : details.EnterpriseAPIKey);

                    state.EnvironmentLookup = envResp.Model?.Lookup;

                    state.EnterpriseBooted = envResp.Status;

                    // var doProj = await devOpsArch.EnsureDevOpsProject(state.NewEnterpriseAPIKey, details.Username, details.EnterpriseAPIKey);

                    // if (doProj.Status)
                    // {
                    //     var envResp = await devOpsArch.EnsureEnvironment(new EnsureEnvironmentRequest()
                    //     {
                    //         EnvSettings = state.EnvSettings,
                    //         OrganizationLookup = state.OrganizationLookup
                    //     }, state.NewEnterpriseAPIKey);

                    //     if (envResp.Status)
                    //     {
                    //         var env = envResp.Model;

                    //         var infraRepoResp = await devOpsArch.EnsureInfrastructureRepo(state.NewEnterpriseAPIKey, details.Username, env.Lookup, details.EnterpriseAPIKey, doProj.Model);

                    //         var lcuFeedResp = await devOpsArch.EnsureLCUFeed(new EnsureLCUFeedRequest()
                    //         {
                    //             EnvironmentLookup = env.Lookup
                    //         }, state.NewEnterpriseAPIKey, details.Username, details.EnterpriseAPIKey);

                    //         if (lcuFeedResp.Status)
                    //         {
                    //             var taskLibraryResp = await devOpsArch.EnsureTaskTlibrary(state.NewEnterpriseAPIKey, details.Username, env.Lookup, details.EnterpriseAPIKey, doProj.Model);

                    //             if (taskLibraryResp.Status)
                    //             {
                    //                 var buildReleaseResp = await devOpsArch.EnsureInfrastructureBuildAndRelease(state.NewEnterpriseAPIKey, details.Username, env.Lookup, details.EnterpriseAPIKey,
                    //                     doProj.Model);

                    //                 if (buildReleaseResp.Status)
                    //                 {
                    //                     var envInfra = await devOpsArch.SetEnvironmentInfrastructure(new SetEnvironmentInfrastructureRequest()
                    //                     {
                    //                         Template = "fathym\\daf-state-setup"
                    //                     }, state.NewEnterpriseAPIKey, env.Lookup, details.Username, details.EnterpriseAPIKey);

                    //                     state.EnterpriseBooted = envInfra.Status;
                    //                 }
                    //             }
                    //         }
                    //     }
                    // }
                }
            }

            return(state);
        }