use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class MicroserviceVersionRule method printData.
private void printData(MicroserviceVersionRuleData data, int inputVersionCount, int inputInstanceCount) {
String latestVersion = data.latestVersion == null ? null : data.latestVersion.getVersion().getVersion();
if (data.getInstances().isEmpty()) {
LOGGER.info("update instances to be empty caused by version rule, appId={}, microserviceName={}, versionRule={}" + ", latestVersion={}, inputVersionCount={}, inputInstanceCount={}", appId, microserviceName, versionRule.getVersionRule(), latestVersion, inputVersionCount, inputInstanceCount);
return;
}
StringBuilder sb = new StringBuilder();
StringBuilderUtils.appendLine(sb, "update instances, appId=%s, microserviceName=%s, versionRule=%s" + ", latestVersion=%s, inputVersionCount=%s, inputInstanceCount=%s", appId, microserviceName, versionRule.getVersionRule(), latestVersion, inputVersionCount, inputInstanceCount);
int idx = 0;
for (MicroserviceInstance instance : data.getInstances().values()) {
MicroserviceVersion microserviceVersion = data.versions.get(instance.getServiceId());
Microservice microservice = microserviceVersion.getMicroservice();
Framework framework = microservice.getFramework();
String frameworkName = framework == null ? "unknown" : framework.getName();
String frameworkVersion = framework == null ? "unknown" : framework.getVersion();
StringBuilderUtils.appendLine(sb, " %d.instanceId=%s, status=%s, version=%s, endpoints=%s, environment=%s, framework.name=%s, framework.version=%s", idx, instance.getInstanceId(), instance.getStatus(), microserviceVersion.getVersion(), instance.getEndpoints(), microservice.getEnvironment(), frameworkName, frameworkVersion);
idx++;
}
LOGGER.info(StringBuilderUtils.deleteLast(sb, 1).toString());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestAuthHandlerBoot method testGenerateRSAKey.
@Test
public void testGenerateRSAKey() {
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
Microservice microservice = new Microservice();
microservice.setInstance(microserviceInstance);
AuthHandlerBoot authHandlerBoot = new AuthHandlerBoot();
BootEvent bootEvent = new BootEvent();
bootEvent.setEventType(BootListener.EventType.BEFORE_REGISTRY);
authHandlerBoot.onBootEvent(bootEvent);
Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPrivateKey());
Assert.assertNotNull(RSAKeypair4Auth.INSTANCE.getPublicKey());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestAccessController method testIsValidOfWhiteByServiceName.
@Test
public void testIsValidOfWhiteByServiceName() {
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
AccessController controller = new AccessController();
Microservice service = new Microservice();
service.setServiceName("trustCustomer");
Assert.assertTrue(controller.isAllowed(service));
service.setServiceName("nottrustCustomer");
Assert.assertTrue(!controller.isAllowed(service));
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "*trust");
service.setServiceName("Customer_trust");
Assert.assertTrue(controller.isAllowed(service));
service.setServiceName("Customer_trust_not");
Assert.assertTrue(!controller.isAllowed(service));
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust");
service.setServiceName("trust");
Assert.assertTrue(controller.isAllowed(service));
service.setServiceName("Customer_trust");
Assert.assertTrue(!controller.isAllowed(service));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestAccessController method testIsValidOfBlackByProperties.
@Test
public void testIsValidOfBlackByProperties() {
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "tag");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "test");
AccessController controller = new AccessController();
Microservice service = new Microservice();
Map<String, String> map = new HashMap<>();
map.put("tag", "test");
service.setProperties(map);
Assert.assertTrue(!controller.isAllowed(service));
map.put("tag", "testa");
service.setProperties(map);
Assert.assertTrue(controller.isAllowed(service));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestAccessController method testIsValidOfBlackAndWhiteByServiceName.
@Test
public void testIsValidOfBlackAndWhiteByServiceName() {
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "serviceName");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "*hacker");
AccessController controller = new AccessController();
Microservice service = new Microservice();
service.setServiceName("trustCustomer");
Assert.assertTrue(controller.isAllowed(service));
service.setServiceName("trustCustomerhacker");
Assert.assertTrue(!controller.isAllowed(service));
}
Aggregations