Skip to content

Commit

Permalink
SLVS-1433 Add credentials uri to the ServerConnection model (#5660)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriela-trutan-sonarsource authored Sep 3, 2024
1 parent 09c0e6a commit b546045
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
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;
}
}

0 comments on commit b546045

Please sign in to comment.