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

Add Azure implementation for util/di files

parent 005d9e3d
No related branches found
No related tags found
1 merge request!6Trusted ibm
package org.opendes.indexer.azure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class })
@Configuration
@ComponentScan({"org.opendes.core", "org.opendes.indexer"})
public class IndexerAzureApplication {
public static void main(String[] args) {
......
package org.opendes.indexer.azure.api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
public class Hello {
@GetMapping("/hello")
public String Default() {
return "Hello Azure Indexer!!!";
}
}
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opendes.indexer.azure.di;
import org.opendes.client.logging.DpsLog;
import org.opendes.client.logging.Log;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;
@Component
public class DpsLogFactory implements FactoryBean<DpsLog> {
@Override
public DpsLog getObject() throws Exception {
return new Log();
}
@Override
public Class<?> getObjectType() {
return DpsLog.class;
}
}
......@@ -3,37 +3,35 @@ package org.opendes.indexer.azure.di;
import org.opendes.client.cache.ICache;
import org.opendes.client.multitenancy.ITenantFactory;
import org.opendes.client.multitenancy.TenantInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.*;
@Component
public class TenantFactoryImpl implements ITenantFactory {
public static final String DefaultTenantName = "common";
private List<TenantInfo> tenants;
@Autowired
private CosmosDBTenantInfo db;
public TenantFactoryImpl()
{
TenantInfo ti = new TenantInfo();
ti.setName(DefaultTenantName);
this.tenants = new ArrayList<>();
this.tenants.add(ti);
}
private Map<String, TenantInfo> tenants;
public boolean exists(String tenantName)
{
return true;
if (this.tenants == null)
initTenants();
return this.tenants.containsKey(tenantName);
}
public TenantInfo getTenantInfo(String tenantName) {
// we are not checking tenantName yet, we have only 1 tenant
return this.tenants.get(0);
if (this.tenants == null)
initTenants();
return this.tenants.get(tenantName);
}
public Collection<TenantInfo> listTenantInfo() {
return this.tenants;
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)
......@@ -42,4 +40,18 @@ public class TenantFactoryImpl implements ITenantFactory {
}
public void flushCache() {}
private void initTenants() {
this.tenants = new HashMap<>();
db.findAll().forEach(doc -> {
TenantInfo ti = new TenantInfo();
String tenantName = doc.getId();
ti.setName(tenantName);
String complianceRuleSet = doc.getComplianceRuleSet();
ti.setComplianceRuleSet(complianceRuleSet);
this.tenants.put(tenantName, ti) ;
});
}
}
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opendes.indexer.azure.di;
import lombok.extern.java.Log;
import org.opendes.client.multitenancy.ITenantFactory;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Component;
@Log
@Component
public class TenantFactoryService extends AbstractFactoryBean<ITenantFactory> {
@Override
protected ITenantFactory createInstance() throws Exception {
return new TenantFactoryImpl();
}
@Override
public Class<?> getObjectType() {
return ITenantFactory.class;
}
}
\ No newline at end of file
package org.opendes.indexer.azure.di;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;
import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "TenantInfo") //collection name
public class TenantInfoDoc {
@PartitionKey
@Id
private String id;
private String complianceRuleSet;
}
interface CosmosDBTenantInfo extends DocumentDbRepository<TenantInfoDoc, String> {}
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opendes.indexer.azure.util;
import com.google.common.base.Strings;
import lombok.extern.java.Log;
import org.opendes.client.api.DpsHeaders;
import org.opendes.core.model.SlbHeaders;
import org.opendes.core.util.IHeadersInfo;
import org.opendes.core.util.Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
@Log
@Component
public class HeadersInfoAzureImpl implements IHeadersInfo {
@Autowired
private DpsHeaders headersMap;
private static final HashSet<String> FORBIDDEN_FROM_LOGGING = new HashSet<>();
static {
FORBIDDEN_FROM_LOGGING.add(DpsHeaders.AUTHORIZATION);
FORBIDDEN_FROM_LOGGING.add(DpsHeaders.ON_BEHALF_OF);
}
private static final HashSet<String> FORWARDED_HEADERS = new HashSet<>();
@Override
public DpsHeaders getHeaders() {
if (headersMap == null) {
log.info("Headers Map DpsHeaders is null");
// headersMap = this.getCoreServiceHeaders(httpHeaders.toSingleValueMap());
}
return headersMap;
}
@Override
public String getUser() {
return getHeaders().getUserEmail();
}
@Override
public String getPartitionId() {
return getHeaders().getPartitionIdWithFallbackToAccountId();
}
@Override
public String getPrimaryPartitionId() {
return getHeadersMap().get(SlbHeaders.PRIMARY_PARTITION_ID);
}
@Override
public Map<String, String> getHeadersMap() {
return getHeaders().getHeaders();
}
@Override
public DpsHeaders getCoreServiceHeaders(Map<String, String> input) {
Preconditions.checkNotNull(input, "input headers cannot be null");
DpsHeaders output = DpsHeaders.createFromMap(input);
output.addCorrelationIdIfMissing();
return output;
}
@Override
public String toString() {
return this.getHeadersMap().entrySet().stream().filter(map -> !FORBIDDEN_FROM_LOGGING.contains(map.getKey().toLowerCase())).map(Map.Entry::toString).collect(Collectors.joining(" | "));
}
}
\ No newline at end of file
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