Esempio n. 1
0
        public void ExecuteRibbonAction(IThreatModel threatModel, IActionDefinition action)
        {
            try
            {
                var connector = DevOpsManager.GetConnector(threatModel);

                switch (action.Name)
                {
                case "Connect":
                    var dialog = new DevOpsConnectionDialog();
                    if (connector == null)
                    {
                        var schemaManager = new DevOpsConfigPropertySchemaManager(threatModel);
                        dialog.Connection = schemaManager.ConnectionInfo;
                    }
                    else
                    {
                        dialog.Connector = connector;
                    }
                    if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        connector = dialog.Connector;
                        var project = dialog.ProjectName;
                        if (connector != null && !string.IsNullOrWhiteSpace(project))
                        {
                            connector.OpenProject(project);
                            DevOpsManager.Register(connector, threatModel);
                            ChangeDisconnectButtonStatus(connector, true);
                        }
                    }

                    break;

                case "Disconnect":
                    if (connector != null && MessageBox.Show(Form.ActiveForm,
                                                             "You are about to disconnect the current DevOps Connector.\nIf you proceed, all the links between the Threat Model and the DevOps system may be lost.\nAre you sure?",
                                                             "DevOps Disconnect", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                        DialogResult.Yes)
                    {
                        DevOpsManager.Unregister(threatModel);
                        ChangeDisconnectButtonStatus(null, false);
                    }
                    break;
                }
            }
            catch
            {
                ShowWarning?.Invoke("Connection failed.");
                throw;
            }
        }
Esempio n. 2
0
        public async void Process(IThreatModel model)
        {
            Connect.ChangeDisconnectButtonStatus(null, false);

            var schemaManager = new DevOpsConfigPropertySchemaManager(model);
            var connector     = schemaManager.GetDevOpsConnector(out var url, out var project);

            if (connector != null && !string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(project))
            {
                try
                {
                    var tokenManager = new SecretsManager();
                    var token        = tokenManager.GetSecret(url);
                    if (!string.IsNullOrWhiteSpace(token))
                    {
                        connector.Connect(url, token);
                        var projects = (await connector.GetProjectsAsync())?.ToArray();
                        if (projects?.Contains(project) ?? false)
                        {
                            if (connector.OpenProject(project))
                            {
                                DevOpsManager.Register(connector, model);
                                Connect.ChangeDisconnectButtonStatus(connector, true);

                                var configManager = new ExtensionConfigurationManager(model, this.GetExtensionId());
                                configManager.Apply();

                                await DevOpsManager.UpdateAsync(model);
                            }
                        }
                        else
                        {
                            connector.Disconnect();
                            ShowWarning?.Invoke(
                                "DevOps system cannot be automatically connected due to an internal error.");
                        }
                    }
                    else
                    {
                        ShowWarning?.Invoke(
                            "DevOps system cannot be automatically connected because no Personal Access Token has been found.");
                    }
                }
                catch (Exception exc)
                {
                    ShowWarning?.Invoke($@"DevOps system cannot be automatically connected due to the following error: {exc.Message}. Everything else should be unaffected.");
                }
            }
        }
Esempio n. 3
0
        public void Process([NotNull] IThreatModel model)
        {
            var schemaManager = new DevOpsConfigPropertySchemaManager(model);
            var connector     = schemaManager.GetDevOpsConnector(out var url, out var project);

            if (connector != null && !string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(project))
            {
                var projects = connector.Connect(url);
                if (projects.Contains(project))
                {
                    if (connector.OpenProject(project))
                    {
                        DevOpsManager.Register(connector, model);
                        Connect.ChangeDisconnectButtonStatus(connector, true);

                        var configManager = new ExtensionConfigurationManager(model, this.GetExtensionId());
                        configManager.Apply();
                    }
                }
            }
        }