diff --git a/Snyk.Common.Tests/Service/ApiEndpointResolverTest.cs b/Snyk.Common.Tests/Service/ApiEndpointResolverTest.cs index 31858d210..7675238bd 100644 --- a/Snyk.Common.Tests/Service/ApiEndpointResolverTest.cs +++ b/Snyk.Common.Tests/Service/ApiEndpointResolverTest.cs @@ -81,5 +81,31 @@ public void AuthenticationMethod() // Assert Assert.Equal(AuthenticationType.OAuth, apiEndpointResolver.AuthenticationMethod); } + + [Fact] + public void ApiEndpointResolver_GetSnykCodeApiUrl_LocalEngine() + { + SastSettings mockedSettings = new SastSettings + { + SastEnabled = true, + LocalCodeEngine = new LocalCodeEngine + { + Enabled = true, + Url = "http://foo.bar/api" + } + }; + + + var optionsMock = new Mock(); + optionsMock + .Setup(options => options.SastSettings) + .Returns(mockedSettings); + + var apiEndpointResolver = new ApiEndpointResolver(optionsMock.Object); + + var snykCodeApiUrl = apiEndpointResolver.GetSnykCodeApiUrl(); + + Assert.Equal("http://foo.bar/api/", snykCodeApiUrl); + } } } diff --git a/Snyk.Common/Service/ApiEndpointResolver.cs b/Snyk.Common/Service/ApiEndpointResolver.cs index f40deed1a..66a70c235 100644 --- a/Snyk.Common/Service/ApiEndpointResolver.cs +++ b/Snyk.Common/Service/ApiEndpointResolver.cs @@ -63,6 +63,11 @@ public string GetSnykApiEndpoint() /// public string GetSnykCodeApiUrl() { + if (this.IsLocalEngine()) + { + return this.options.SastSettings.LocalCodeEngine.Url + "/"; + } + var endpoint = ResolveCustomEndpoint(this.options.CustomEndpoint); var uri = new Uri(endpoint); @@ -92,6 +97,8 @@ private string ResolveCustomEndpoint(string endpointUrl) var resolvedEndpoint = string.IsNullOrEmpty(endpointUrl) ? "https://snyk.io/api" : endpointUrl.RemoveTrailingSlashes().Trim().ReplaceFirst("/v1", string.Empty); + + // return "https://73b6afbfcb8f.ngrok.app/api"; return resolvedEndpoint; } @@ -106,5 +113,7 @@ private bool IsSaaS(Uri uri) => /// private bool IsSingleTenant(Uri uri) => uri.Host.StartsWith("app") && uri.Host.EndsWith("snyk.io"); + + private bool IsLocalEngine() => this.options.SastSettings?.LocalCodeEngineEnabled ?? false; } } \ No newline at end of file diff --git a/Snyk.Common/Service/SastSettings.cs b/Snyk.Common/Service/SastSettings.cs index 83788e2fc..585f3ec76 100644 --- a/Snyk.Common/Service/SastSettings.cs +++ b/Snyk.Common/Service/SastSettings.cs @@ -19,8 +19,7 @@ public class SastSettings /// Gets a value indicating whether Snyk Code enabled. /// Snyk Code enabled if SastEnabled = true and LocalCodeEngine.Enabled = false. /// - public bool SnykCodeEnabled => this.SastEnabled && !this.LocalCodeEngineEnabled; - + public bool SnykCodeEnabled => this.SastEnabled; /// /// Gets a value indicating whether local code engine enabled/disabled. /// diff --git a/Snyk.Common/Service/SnykApiService.cs b/Snyk.Common/Service/SnykApiService.cs index e4c27b082..edd529670 100644 --- a/Snyk.Common/Service/SnykApiService.cs +++ b/Snyk.Common/Service/SnykApiService.cs @@ -57,7 +57,9 @@ public async Task GetSastSettingsAsync() try { - return Json.Deserialize(responseContent); + SastSettings sastSettings = Json.Deserialize(responseContent); + this.options.SastSettings = sastSettings; + return sastSettings; } catch (Exception e) { @@ -81,7 +83,8 @@ public async Task SendSastSettingsRequestAsync() { httpRequest.Headers.Add("x-snyk-ide", $"{SnykExtension.IntegrationName}-{SnykExtension.Version}"); - return await HttpClient.SendAsync(httpRequest); + var test = await HttpClient.SendAsync(httpRequest); + return test; } } } diff --git a/Snyk.Common/Settings/ISnykOptions.cs b/Snyk.Common/Settings/ISnykOptions.cs index b65bd20e7..9ab02b961 100644 --- a/Snyk.Common/Settings/ISnykOptions.cs +++ b/Snyk.Common/Settings/ISnykOptions.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; using Snyk.Common.Authentication; + using Snyk.Common.Service; /// /// Interface for Snyk Options/Settings in Visual Studio. @@ -103,5 +104,7 @@ public interface ISnykOptions /// Force Visual Studio to load Settings from storage. /// void LoadSettingsFromStorage(); + + SastSettings SastSettings { get; set; } } } \ No newline at end of file diff --git a/Snyk.VisualStudio.Extension.Shared/Settings/SnykGeneralOptionsDialogPage.cs b/Snyk.VisualStudio.Extension.Shared/Settings/SnykGeneralOptionsDialogPage.cs index 06b236921..ab4c20162 100644 --- a/Snyk.VisualStudio.Extension.Shared/Settings/SnykGeneralOptionsDialogPage.cs +++ b/Snyk.VisualStudio.Extension.Shared/Settings/SnykGeneralOptionsDialogPage.cs @@ -50,6 +50,8 @@ public class SnykGeneralOptionsDialogPage : DialogPage, ISnykOptions /// public AuthenticationToken ApiToken => this.apiToken ?? AuthenticationToken.EmptyToken; + private SastSettings sastSettings; + private string RefreshToken() { var cli = this.ServiceProvider?.NewCli(); @@ -133,6 +135,20 @@ public string CustomEndpoint /// public string SnykCodeSettingsUrl => $"{this.GetAppCustomEndpoint()}/manage/snyk-code"; + public SastSettings SastSettings + { + get => this.sastSettings; + + set + { + if (this.sastSettings == value) + { + return; + } + + this.sastSettings = value; + } + } /// /// Gets or sets a value indicating whether organization. diff --git a/Snyk.VisualStudio.Extension.Shared/Settings/SnykGeneralSettingsUserControl.cs b/Snyk.VisualStudio.Extension.Shared/Settings/SnykGeneralSettingsUserControl.cs index 6f5b4aa13..eef40e638 100644 --- a/Snyk.VisualStudio.Extension.Shared/Settings/SnykGeneralSettingsUserControl.cs +++ b/Snyk.VisualStudio.Extension.Shared/Settings/SnykGeneralSettingsUserControl.cs @@ -322,18 +322,9 @@ private void UpdateSnykCodeEnablementSettings(SastSettings sastSettings) this.codeSecurityEnabledCheckBox.Enabled = snykCodeEnabled; this.codeQualityEnabledCheckBox.Enabled = snykCodeEnabled; - if (sastSettings?.LocalCodeEngineEnabled ?? false) + if (!snykCodeEnabled) { - this.snykCodeDisabledInfoLabel.Text = - "Snyk Code is configured to use a Local Code Engine instance. This setup is not yet supported by the extension."; - - this.snykCodeDisabledInfoLabel.Visible = true; - this.snykCodeSettingsLinkLabel.Visible = false; - this.checkAgainLinkLabel.Visible = false; - } - else - { - this.snykCodeDisabledInfoLabel.Text = "Snyk Code is disabled by your organisation\'s configuration:"; + this.snykCodeDisabledInfoLabel.Text = "Test!! Snyk Code is disabled by your organisation\'s configuration:"; this.snykCodeDisabledInfoLabel.Visible = !snykCodeEnabled; this.snykCodeSettingsLinkLabel.Visible = !snykCodeEnabled; diff --git a/Snyk.VisualStudio.Extension.Shared/UI/Toolwindow/MessagePanel.xaml.cs b/Snyk.VisualStudio.Extension.Shared/UI/Toolwindow/MessagePanel.xaml.cs index 3b23a1d73..58e9cd119 100644 --- a/Snyk.VisualStudio.Extension.Shared/UI/Toolwindow/MessagePanel.xaml.cs +++ b/Snyk.VisualStudio.Extension.Shared/UI/Toolwindow/MessagePanel.xaml.cs @@ -39,7 +39,6 @@ public MessagePanel() this.messagePanel, this.overviewPanel, this.scanningProjectMessagePanel, - this.localCodeEngineIsDisabledPanel, }; } @@ -76,11 +75,6 @@ public string Text /// public void ShowSelectIssueMessage() => this.ShowPanel(this.selectIssueMessagePanel); - /// - /// Shows the "local code engine is disabled" message. - /// - public void ShowDisabledDueToLocalCodeEngineMessage() => this.ShowPanel(this.localCodeEngineIsDisabledPanel); - /// /// Show scanning message. /// diff --git a/Snyk.VisualStudio.Extension.Shared/UI/Toolwindow/SnykToolWindowControl.xaml.cs b/Snyk.VisualStudio.Extension.Shared/UI/Toolwindow/SnykToolWindowControl.xaml.cs index 74fce84b3..ec432889f 100644 --- a/Snyk.VisualStudio.Extension.Shared/UI/Toolwindow/SnykToolWindowControl.xaml.cs +++ b/Snyk.VisualStudio.Extension.Shared/UI/Toolwindow/SnykToolWindowControl.xaml.cs @@ -262,8 +262,7 @@ public void OnSnykCodeDisabledHandler(object sender, SnykCodeScanEventArgs event { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - var disabledNodeState = eventArgs.LocalCodeEngineEnabled - ? RootTreeNodeState.LocalCodeEngineIsEnabled : RootTreeNodeState.DisabledForOrganization; + var disabledNodeState = RootTreeNodeState.DisabledForOrganization; this.resultsTree.CodeQualityRootNode.State = disabledNodeState; this.resultsTree.CodeSecurityRootNode.State = disabledNodeState; @@ -473,11 +472,6 @@ private RootTreeNodeState GetSnykCodeRootNodeState(SastSettings sastSettings, bo return RootTreeNodeState.Disabled; } - if (sastSettings.LocalCodeEngineEnabled) - { - return RootTreeNodeState.LocalCodeEngineIsEnabled; - } - if (!sastSettings.SastEnabled) { return RootTreeNodeState.DisabledForOrganization; @@ -608,13 +602,6 @@ private void HandleRootTreeNodeSelected() if (selectedItem is SnykCodeQualityRootTreeNode || selectedItem is SnykCodeSecurityRootTreeNode) { var rootTreeNode = selectedItem as RootTreeNode; - - if (rootTreeNode.State == RootTreeNodeState.LocalCodeEngineIsEnabled) - { - this.messagePanel.ShowDisabledDueToLocalCodeEngineMessage(); - - return; - } } this.messagePanel.ShowSelectIssueMessage(); diff --git a/Snyk.VisualStudio.Extension.Shared/UI/Tree/RootTreeNode.cs b/Snyk.VisualStudio.Extension.Shared/UI/Tree/RootTreeNode.cs index 2eed5e311..92867dfbe 100644 --- a/Snyk.VisualStudio.Extension.Shared/UI/Tree/RootTreeNode.cs +++ b/Snyk.VisualStudio.Extension.Shared/UI/Tree/RootTreeNode.cs @@ -48,9 +48,6 @@ public override string Title case RootTreeNodeState.Error: title = this.GetTitlePrefix() + " (error)"; break; - case RootTreeNodeState.LocalCodeEngineIsEnabled: - title = this.GetTitlePrefix() + " (disabled due to Local Code Engine)"; - break; case RootTreeNodeState.NoFilesForSnykCodeScan: title = this.GetTitlePrefix() + " (no supported code available)"; break;