Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SetupAuth {
* @throws CredentialsInFileNotFoundException when no configuration is set or can be found
*/
public SetupAuth() throws CredentialsInFileNotFoundException {
this(new CoreConfiguration.Builder().build(), new EnvironmentVariables());
this(new CoreConfiguration(), new EnvironmentVariables());
}

/**
Expand All @@ -66,7 +66,7 @@ public SetupAuth(CoreConfiguration cfg) throws IOException, CredentialsInFileNot
protected SetupAuth(CoreConfiguration cfg, EnvironmentVariables environmentVariables)
throws CredentialsInFileNotFoundException {

this.cfg = cfg != null ? cfg : new CoreConfiguration.Builder().build();
this.cfg = cfg != null ? cfg : new CoreConfiguration();
this.env = environmentVariables != null ? environmentVariables : new EnvironmentVariables();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
import java.util.Map;

public class CoreConfiguration {
private final Map<String, String> defaultHeader;
private final String serviceAccountKey;
private final String serviceAccountKeyPath;
private final String privateKeyPath;
private final String privateKey;
private final String customEndpoint;
private final String credentialsFilePath;
private final String tokenCustomUrl;
private final Long tokenExpirationLeeway;

CoreConfiguration(Builder builder) {
this.defaultHeader = builder.defaultHeader;
this.serviceAccountKey = builder.serviceAccountKey;
this.serviceAccountKeyPath = builder.serviceAccountKeyPath;
this.privateKeyPath = builder.privateKeyPath;
this.privateKey = builder.privateKey;
this.customEndpoint = builder.customEndpoint;
this.credentialsFilePath = builder.credentialsFilePath;
this.tokenCustomUrl = builder.tokenCustomUrl;
this.tokenExpirationLeeway = builder.tokenExpirationLeeway;
}
private Map<String, String> defaultHeader;
private String serviceAccountKey;
private String serviceAccountKeyPath;
private String privateKeyPath;
private String privateKey;
private String customEndpoint;
private String credentialsFilePath;
private String tokenCustomUrl;
private Long tokenExpirationLeeway;

public CoreConfiguration() {}

public Map<String, String> getDefaultHeader() {
return defaultHeader;
Expand Down Expand Up @@ -61,64 +51,48 @@ public Long getTokenExpirationLeeway() {
return tokenExpirationLeeway;
}

public static class Builder {
private Map<String, String> defaultHeader;
private String serviceAccountKey;
private String serviceAccountKeyPath;
private String privateKeyPath;
private String privateKey;
private String customEndpoint;
private String credentialsFilePath;
private String tokenCustomUrl;
private Long tokenExpirationLeeway;

public Builder defaultHeader(Map<String, String> defaultHeader) {
this.defaultHeader = defaultHeader;
return this;
}

public Builder serviceAccountKey(String serviceAccountKey) {
this.serviceAccountKey = serviceAccountKey;
return this;
}

public Builder serviceAccountKeyPath(String serviceAccountKeyPath) {
this.serviceAccountKeyPath = serviceAccountKeyPath;
return this;
}

public Builder privateKeyPath(String privateKeyPath) {
this.privateKeyPath = privateKeyPath;
return this;
}

public Builder privateKey(String privateKey) {
this.privateKey = privateKey;
return this;
}

public Builder customEndpoint(String customEndpoint) {
this.customEndpoint = customEndpoint;
return this;
}

public Builder credentialsFilePath(String credentialsFilePath) {
this.credentialsFilePath = credentialsFilePath;
return this;
}

public Builder tokenCustomUrl(String tokenCustomUrl) {
this.tokenCustomUrl = tokenCustomUrl;
return this;
}

public Builder tokenExpirationLeeway(Long tokenExpirationLeeway) {
this.tokenExpirationLeeway = tokenExpirationLeeway;
return this;
}

public CoreConfiguration build() {
return new CoreConfiguration(this);
}
public CoreConfiguration defaultHeader(Map<String, String> defaultHeader) {
this.defaultHeader = defaultHeader;
return this;
}

public CoreConfiguration serviceAccountKey(String serviceAccountKey) {
this.serviceAccountKey = serviceAccountKey;
return this;
}

public CoreConfiguration serviceAccountKeyPath(String serviceAccountKeyPath) {
this.serviceAccountKeyPath = serviceAccountKeyPath;
return this;
}

public CoreConfiguration privateKeyPath(String privateKeyPath) {
this.privateKeyPath = privateKeyPath;
return this;
}

public CoreConfiguration privateKey(String privateKey) {
this.privateKey = privateKey;
return this;
}

public CoreConfiguration customEndpoint(String customEndpoint) {
this.customEndpoint = customEndpoint;
return this;
}

public CoreConfiguration credentialsFilePath(String credentialsFilePath) {
this.credentialsFilePath = credentialsFilePath;
return this;
}

public CoreConfiguration tokenCustomUrl(String tokenCustomUrl) {
this.tokenCustomUrl = tokenCustomUrl;
return this;
}

public CoreConfiguration tokenExpirationLeeway(Long tokenExpirationLeeway) {
this.tokenExpirationLeeway = tokenExpirationLeeway;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ void getAccessToken_response200_noException()
// Config
HttpUrl url = mockWebServer.url("/token");
CoreConfiguration cfg =
new CoreConfiguration.Builder()
.tokenCustomUrl(url.toString()) // Use mockWebServer
.build();
new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer

KeyFlowAuthenticator keyFlowAuthenticator = new KeyFlowAuthenticator(cfg, defaultSaKey);

Expand All @@ -143,9 +141,7 @@ void getAccessToken_expiredToken_noException()
// Config
HttpUrl url = mockWebServer.url("/token");
CoreConfiguration cfg =
new CoreConfiguration.Builder()
.tokenCustomUrl(url.toString()) // Use mockWebServer
.build();
new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer

KeyFlowAuthenticator keyFlowAuthenticator = new KeyFlowAuthenticator(cfg, defaultSaKey);
keyFlowAuthenticator.setToken(expiredKey);
Expand All @@ -162,9 +158,7 @@ void createAccessToken_response200WithEmptyBody_throwsException() {

// Config
CoreConfiguration cfg =
new CoreConfiguration.Builder()
.tokenCustomUrl(url.toString()) // Use mockWebServer
.build();
new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer

// Init keyFlowAuthenticator
KeyFlowAuthenticator keyFlowAuthenticator =
Expand All @@ -182,9 +176,7 @@ void createAccessToken_response400_throwsApiException() {

// Config
CoreConfiguration cfg =
new CoreConfiguration.Builder()
.tokenCustomUrl(url.toString()) // Use mockWebServer
.build();
new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer

// Init keyFlowAuthenticator
KeyFlowAuthenticator keyFlowAuthenticator =
Expand All @@ -206,9 +198,7 @@ void createAccessToken_response200WithValidResponse_noException()
// Config
HttpUrl url = mockWebServer.url("/token");
CoreConfiguration cfg =
new CoreConfiguration.Builder()
.tokenCustomUrl(url.toString()) // Use mockWebServer
.build();
new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer

// Init keyFlowAuthenticator
KeyFlowAuthenticator keyFlowAuthenticator = new KeyFlowAuthenticator(cfg, defaultSaKey);
Expand All @@ -229,9 +219,7 @@ void createAccessTokenWithRefreshToken_response200WithValidResponse_noException(
// Config
HttpUrl url = mockWebServer.url("/token");
CoreConfiguration cfg =
new CoreConfiguration.Builder()
.tokenCustomUrl(url.toString()) // Use mockWebServer
.build();
new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer

// Prepare keyFlowAuthenticator
KeyFlowAuthenticator keyFlowAuthenticator = new KeyFlowAuthenticator(cfg, defaultSaKey);
Expand All @@ -251,9 +239,7 @@ void createAccessTokenWithRefreshToken_response200WithEmptyBody_throwsException(

// Config
CoreConfiguration cfg =
new CoreConfiguration.Builder()
.tokenCustomUrl(url.toString()) // Use mockWebServer
.build();
new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer

// Prepare keyFlowAuthenticator
KeyFlowAuthenticator keyFlowAuthenticator =
Expand Down
Loading