Skip to content

Commit

Permalink
refactor: separate options model from page (#331)
Browse files Browse the repository at this point in the history
* refactor: separate options model from page

* fix: scrollbar in settings dialog

* fix: tests

* chore: update readme

* fix: attempt to only use nuget locked mode

* chore: remove redundant access modifiers
  • Loading branch information
ShawkyZ authored Dec 16, 2024
1 parent 066f218 commit 15b1b10
Show file tree
Hide file tree
Showing 23 changed files with 604 additions and 587 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ jobs:
with:
vs-version: '[17.0, )'

- name: Restore NuGet packages
run: nuget restore ${{ inputs.solution-file-path }}

- name: Build
run: |
msbuild ${{ inputs.solution-file-path }} /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m
msbuild ${{ inputs.solution-file-path }} /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /t:restore /p:RestoreLockedMode=true /v:m
shell: powershell

- name: Upload build artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security-scan-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Restore dependencies
run: dotnet restore /home/runner/work/snyk-visual-studio-plugin/snyk-visual-studio-plugin
run: dotnet restore /home/runner/work/snyk-visual-studio-plugin/snyk-visual-studio-plugin --locked-mode
- name: Run snyk monitor
uses: snyk/actions/dotnet@master
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ Continue by following the instructions in the other Visual Studio extension docs

For troubleshooting and known issues, see [Troubleshooting and known issues with Visual Studio extension](https://docs.snyk.io/scm-ide-and-ci-cd-integrations/snyk-ide-plugins-and-extensions/visual-studio-extension/troubleshooting-and-known-issues-with-visual-studio-extension).

If you need help, submit a request to [Snyk Support](https://support.snyk.io/hc/en-us/requests/new).
If you need help, submit a request to [Snyk Support](https://support.snyk.io).
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public async Task OnHasAuthenticated(JToken arg)
{
if (arg?["token"] == null)
{
await serviceProvider.Options.HandleFailedAuthentication("Authentication failed");
await serviceProvider.GeneralOptionsDialogPage.HandleFailedAuthentication("Authentication failed");
return;
}

Expand All @@ -134,7 +134,7 @@ public async Task OnHasAuthenticated(JToken arg)

serviceProvider.Options.ApiToken = new AuthenticationToken(serviceProvider.Options.AuthenticationMethod, token);

await serviceProvider.Options.HandleAuthenticationSuccess(token, apiUrl);
await serviceProvider.GeneralOptionsDialogPage.HandleAuthenticationSuccess(token, apiUrl);
serviceProvider.FeatureFlagService.RefreshAsync(SnykVSPackage.Instance.DisposalToken).FireAndForget();

if (serviceProvider.Options.AutoScan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public interface ISnykServiceProvider
/// Gets <see cref="ISnykOptions"/> (Settings) implementation instance.
/// </summary>
ISnykOptions Options { get; }
ISnykGeneralOptionsDialogPage GeneralOptionsDialogPage { get; }

/// <summary>
/// Gets Visual Studio Settiings Manager instance.
Expand Down
2 changes: 2 additions & 0 deletions Snyk.VisualStudio.Extension.2022/Service/SnykService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public SnykService(IAsyncServiceProvider serviceProvider, string vsVersion = "")
/// </summary>
public ISnykOptions Options => this.Package.Options;

public ISnykGeneralOptionsDialogPage GeneralOptionsDialogPage => this.Package.SnykGeneralOptionsDialogPage;

/// <summary>
/// Gets solution service.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public async Task<bool> IsFolderTrustedAsync()
try
{
this.serviceProvider.WorkspaceTrustService.AddFolderToTrusted(solutionFolderPath);
this.serviceProvider.Options.FireSettingsChangedEvent();
this.serviceProvider.Options.InvokeSettingsChangedEvent();
Logger.Information("Workspace folder was trusted: {SolutionFolderPath}", solutionFolderPath);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Snyk.VisualStudio.Extension.Service;
using System.Threading.Tasks;

namespace Snyk.VisualStudio.Extension.Settings;

public interface ISnykGeneralOptionsDialogPage
{
void Initialize(ISnykServiceProvider provider);
Task HandleAuthenticationSuccess(string token, string apiUrl);
Task HandleFailedAuthentication(string errorMessage);
void Authenticate();
}
34 changes: 12 additions & 22 deletions Snyk.VisualStudio.Extension.2022/Settings/ISnykOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Threading.Tasks;
using Snyk.VisualStudio.Extension.Authentication;
using Snyk.VisualStudio.Extension.Language;
using Snyk.VisualStudio.Extension.Service;

namespace Snyk.VisualStudio.Extension.Settings
{
Expand All @@ -12,7 +11,6 @@ namespace Snyk.VisualStudio.Extension.Settings
/// </summary>
public interface ISnykOptions
{
void Initialize(ISnykServiceProvider provider);
string Application { get; set; }
string ApplicationVersion { get; set; }
string IntegrationName { get; }
Expand All @@ -24,8 +22,8 @@ public interface ISnykOptions
bool AutoScan { get; set; }

bool ConsistentIgnoresEnabled { get; set; }
public bool OpenIssuesEnabled { get; set; }
public bool IgnoredIssuesEnabled { get; set; }
bool OpenIssuesEnabled { get; set; }
bool IgnoredIssuesEnabled { get; set; }

/// <summary>
/// Gets or sets a value indicating whether Snyk user API token.
Expand All @@ -35,7 +33,7 @@ public interface ISnykOptions
/// <summary>
/// Gets Value of Authentication Token Type.
/// </summary>
AuthenticationType AuthenticationMethod { get; }
AuthenticationType AuthenticationMethod { get; set; }

/// <summary>
/// Gets or sets a value indicating whether CLI custom endpoint parameter.
Expand All @@ -60,18 +58,18 @@ public interface ISnykOptions
/// <summary>
/// Gets a value indicating whether is Oss scan enabled.
/// </summary>
bool OssEnabled { get; }
bool IacEnabled { get; }
bool OssEnabled { get; set; }
bool IacEnabled { get; set; }

/// <summary>
/// Gets a value indicating whether is Oss scan enabled.
/// </summary>
bool SnykCodeSecurityEnabled { get; }
bool SnykCodeSecurityEnabled { get; set; }

/// <summary>
/// Gets a value indicating whether is Oss scan enabled.
/// </summary>
bool SnykCodeQualityEnabled { get; }
bool SnykCodeQualityEnabled { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the CLI should be automatically updated.
Expand All @@ -86,8 +84,8 @@ public interface ISnykOptions
string CliDownloadUrl { get; set; }
ISet<string> TrustedFolders { get; set; }

public bool EnableDeltaFindings { get; set; }
public List<FolderConfig> FolderConfigs { get; set; }
bool EnableDeltaFindings { get; set; }
List<FolderConfig> FolderConfigs { get; set; }

/// <summary>
/// Settings changed event.
Expand All @@ -108,18 +106,10 @@ public interface ISnykOptions
/// <returns><see cref="Task"/> representing the asynchronous operation.</returns>
Task<bool> IsScanAllProjectsAsync();

/// <summary>
/// Attempts to pull the token from the CLI config storage, and validates the token.
/// If the token is invalid, attempts to run the authentication command.
/// </summary>
/// <returns>Returns true if authenticated successfully, or if a valid token was loaded from storage.</returns>
void Authenticate();
public string CurrentCliVersion { get; set; }

string CurrentCliVersion { get; set; }
SastSettings SastSettings { get; set; }
bool AnalyticsPluginInstalledSent { get; set; }
Task HandleAuthenticationSuccess(string token, string apiUrl);
Task HandleFailedAuthentication(string errorMessage);
void FireSettingsChangedEvent();
void InvokeSettingsChangedEvent();
void SaveSettings();
}
}
Loading

0 comments on commit 15b1b10

Please sign in to comment.