Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVS-1433 Add credentials uri to the ServerConnection model #5660

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Core.UnitTests/Binding/ServerConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace SonarLint.VisualStudio.Core.UnitTests.Binding;
[TestClass]
public class ServerConnectionTests
{
private static readonly Uri Localhost = new Uri("http://localhost:5000");
private static readonly Uri Localhost = new("http://localhost:5000");
private const string Org = "myOrg";

[TestMethod]
public void Ctor_SonarCloud_NullOrganization_Throws()
{
Expand Down Expand Up @@ -66,6 +66,7 @@ public void Ctor_SonarCloud_SetsProperties()
sonarCloud.ServerUri.Should().Be(new Uri("https://sonarcloud.io"));
sonarCloud.Settings.Should().BeSameAs(serverConnectionSettings);
sonarCloud.Credentials.Should().BeSameAs(credentials);
sonarCloud.CredentialsUri.Should().Be(new Uri($"https://sonarcloud.io/organizations/{sonarCloud.OrganizationKey}"));
}

[TestMethod]
Expand Down Expand Up @@ -103,6 +104,7 @@ public void Ctor_SonarQube_SetsProperties()
sonarQube.ServerUri.Should().BeSameAs(Localhost);
sonarQube.Settings.Should().BeSameAs(serverConnectionSettings);
sonarQube.Credentials.Should().BeSameAs(credentials);
sonarQube.CredentialsUri.Should().BeSameAs(sonarQube.ServerUri);
}

[TestMethod]
Expand Down
18 changes: 13 additions & 5 deletions src/Core/Binding/ServerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public abstract class ServerConnection
public ICredentials Credentials { get; set; }

public abstract Uri ServerUri { get; }
public abstract Uri CredentialsUri { get; }

public static ServerConnection FromBoundSonarQubeProject(BoundSonarQubeProject boundProject) =>
boundProject switch
Expand All @@ -44,18 +45,25 @@ private ServerConnection(string id, ServerConnectionSettings settings = null, IC
Settings = settings ?? DefaultSettings;
Credentials = credentials;
}

public sealed class SonarCloud(string organizationKey, ServerConnectionSettings settings = null, ICredentials credentials = null)
: ServerConnection(organizationKey, settings, credentials)

public sealed class SonarCloud : ServerConnection
{
public string OrganizationKey { get; } = organizationKey;
public SonarCloud(string organizationKey, ServerConnectionSettings settings = null, ICredentials credentials = null) : base(organizationKey, settings, credentials)
{
OrganizationKey = organizationKey ?? throw new ArgumentNullException(nameof(organizationKey));
CredentialsUri = new Uri(ServerUri, $"organizations/{organizationKey}");
}

public string OrganizationKey { get; }

public override Uri ServerUri { get; } = new Uri("https://sonarcloud.io");
public override Uri ServerUri { get; } = new("https://sonarcloud.io");
public override Uri CredentialsUri { get; }
}

public sealed class SonarQube(Uri serverUri, ServerConnectionSettings settings = null, ICredentials credentials = null)
: ServerConnection(serverUri?.ToString(), settings, credentials)
{
public override Uri ServerUri { get; } = serverUri;
public override Uri CredentialsUri { get; } = serverUri;
}
}