Fineract client builder tenant and username/password are made optional
This commit is contained in:
committed by
Arnold Gálovics
parent
b87d915dbc
commit
c2d5a735d6
@@ -141,6 +141,8 @@ import org.apache.fineract.client.services.UserGeneratedDocumentsApi;
|
|||||||
import org.apache.fineract.client.services.UsersApi;
|
import org.apache.fineract.client.services.UsersApi;
|
||||||
import org.apache.fineract.client.services.WorkingDaysApi;
|
import org.apache.fineract.client.services.WorkingDaysApi;
|
||||||
import org.apache.fineract.client.util.JSON.GsonCustomConverterFactory;
|
import org.apache.fineract.client.util.JSON.GsonCustomConverterFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
||||||
|
|
||||||
@@ -406,6 +408,8 @@ public final class FineractClient {
|
|||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(Builder.class);
|
||||||
|
|
||||||
private final JSON json = new JSON();
|
private final JSON json = new JSON();
|
||||||
private final OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
|
private final OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
|
||||||
private final Retrofit.Builder retrofitBuilder = new Retrofit.Builder().addConverterFactory(ScalarsConverterFactory.create())
|
private final Retrofit.Builder retrofitBuilder = new Retrofit.Builder().addConverterFactory(ScalarsConverterFactory.create())
|
||||||
@@ -488,14 +492,22 @@ public final class FineractClient {
|
|||||||
retrofitBuilder.baseUrl(has("baseURL", baseURL));
|
retrofitBuilder.baseUrl(has("baseURL", baseURL));
|
||||||
|
|
||||||
// Tenant
|
// Tenant
|
||||||
ApiKeyAuth tenantAuth = new ApiKeyAuth("header", "fineract-platform-tenantid");
|
if (tenant != null) {
|
||||||
tenantAuth.setApiKey(has("tenant", tenant));
|
ApiKeyAuth tenantAuth = new ApiKeyAuth("header", "fineract-platform-tenantid");
|
||||||
okBuilder.addInterceptor(tenantAuth);
|
tenantAuth.setApiKey(has("tenant", tenant));
|
||||||
|
okBuilder.addInterceptor(tenantAuth);
|
||||||
|
} else {
|
||||||
|
log.warn("Tenant hasn't been configured for the client");
|
||||||
|
}
|
||||||
|
|
||||||
// BASIC Auth
|
// BASIC Auth
|
||||||
HttpBasicAuth basicAuth = new HttpBasicAuth();
|
if (username != null && password != null) {
|
||||||
basicAuth.setCredentials(has("username", username), has("password", password));
|
HttpBasicAuth basicAuth = new HttpBasicAuth();
|
||||||
okBuilder.addInterceptor(basicAuth);
|
basicAuth.setCredentials(has("username", username), has("password", password));
|
||||||
|
okBuilder.addInterceptor(basicAuth);
|
||||||
|
} else {
|
||||||
|
log.warn("Username and password haven't been configured for the client");
|
||||||
|
}
|
||||||
|
|
||||||
OkHttpClient okHttpClient = okBuilder.build();
|
OkHttpClient okHttpClient = okBuilder.build();
|
||||||
retrofitBuilder.client(okHttpClient);
|
retrofitBuilder.client(okHttpClient);
|
||||||
|
|||||||
-6
@@ -44,11 +44,5 @@ public class FineractClientTechnicalTest {
|
|||||||
assertThrows(IllegalStateException.class, () -> {
|
assertThrows(IllegalStateException.class, () -> {
|
||||||
FineractClient.builder().build();
|
FineractClient.builder().build();
|
||||||
});
|
});
|
||||||
assertThrows(IllegalStateException.class, () -> {
|
|
||||||
FineractClient.builder().baseURL("https://server/").build();
|
|
||||||
});
|
|
||||||
assertThrows(IllegalStateException.class, () -> {
|
|
||||||
FineractClient.builder().baseURL("https://server/").tenant("default").build();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user