Skip to content
Snippets Groups Projects
Commit 245face1 authored by helayoty's avatar helayoty
Browse files

Add serviceprincipalAppId property instead of tenantInfo object

parent ff69b244
No related branches found
No related tags found
1 merge request!6Trusted ibm
......@@ -15,29 +15,28 @@ import java.util.*;
@Component
@RequestScope
public class TenantFactoryImpl implements ITenantFactory {
@Autowired
private CosmosDBTenantInfo db;
private TenantInfo tenant;
private Map<String, TenantInfo> tenantsList = new HashMap<>();
private Map<String, TenantInfo> tenants;
public boolean exists(String tenantName)
{
if (this.tenant == null)
initTenants(tenantName);
return this.tenant.getName() == tenantName;
if (this.tenants == null)
initTenants();
return this.tenants.containsKey(tenantName);
}
public TenantInfo getTenantInfo(String tenantName) {
if (this.tenant == null)
initTenants(tenantName);
return this.tenant;
if (this.tenants == null)
initTenants();
return this.tenants.get(tenantName);
}
public Collection<TenantInfo> listTenantInfo() {
return this.tenantsList.values();
if (this.tenants == null)
initTenants();
return this.tenants.values();
}
public <V> ICache<String, V> createCache(String tenantName, String host, int port, int expireTimeSeconds, Class<V> classOfV)
......@@ -47,24 +46,16 @@ public class TenantFactoryImpl implements ITenantFactory {
public void flushCache() {}
private void initTenants(String id) {
Optional<TenantInfoDoc> tenantInfoDoc = db.findById(id);
if (!tenantInfoDoc.isPresent())
throw new AppException(HttpStatus.SC_NOT_FOUND, "TenantInfo not found in db", "");
this.tenant = new TenantInfo();
this.tenant.setId(tenantInfoDoc.get().getTenantInfo().getId());
this.tenant.setName(tenantInfoDoc.get().getTenantInfo().getName());
this.tenant.setServiceAccount(tenantInfoDoc.get().getTenantInfo().getServiceAccount());
this.tenant.setProjectId(tenantInfoDoc.get().getTenantInfo().getProjectId());
this.tenant.setDataPartitionId(tenantInfoDoc.get().getTenantInfo().getDataPartitionId());
this.tenant.setComplianceRuleSet(tenantInfoDoc.get().getTenantInfo().getComplianceRuleSet());
this.tenant.setCrmAccountIds(tenantInfoDoc.get().getTenantInfo().getCrmAccountIds());
this.tenantsList.putIfAbsent(tenant.getName(), tenant);
private void initTenants() {
this.tenants = new HashMap<>();
db.findAll().forEach(doc -> {
TenantInfo ti = new TenantInfo();
String tenantName = doc.getId();
ti.setName(tenantName);
//set serviceprincipalAppId in Azure side instead of ServiceAccount in Gcp
ti.setServiceAccount(doc.getServiceprincipalAppId());
this.tenants.put(tenantName, ti) ;
});
}
}
......@@ -17,8 +17,7 @@ public class TenantInfoDoc {
@PartitionKey
@Id
private String id;
private TenantInfo tenantInfo;
private String domain;
private String serviceprincipalAppId;
}
interface CosmosDBTenantInfo extends DocumentDbRepository<TenantInfoDoc, String> {}
package org.opendes.indexer.azure.di;
import lombok.extern.java.Log;
import org.opengroup.osdu.client.api.DpsHeaders;
import org.opengroup.osdu.client.multitenancy.ITenantFactory;
import org.opengroup.osdu.client.multitenancy.TenantInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@Log
@Component
@RequestScope
public class TenantInfoFactory extends AbstractFactoryBean<TenantInfo> {
@Autowired
private ITenantFactory tenantFactory;
@Autowired
private DpsHeaders headers;
@Override
protected TenantInfo createInstance() throws Exception {
String id = this.headers.getPartitionIdWithFallbackToAccountId();
return this.tenantFactory.getTenantInfo(id);
}
@Override
public Class<?> getObjectType() {
return TenantInfo.class;
}
}
package org.opendes.indexer.di;
import lombok.extern.java.Log;
import org.opengroup.osdu.client.api.DpsHeaders;
import org.opengroup.osdu.client.multitenancy.ITenantFactory;
import org.opengroup.osdu.client.multitenancy.TenantInfo;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment