Search in sources :

Example 1 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyServiceTest method testCreate.

@Test
public void testCreate() {
    String appId = "someAppId";
    String secret = "someSecret";
    AccessKey entity = assembleAccessKey(appId, secret);
    AccessKey accessKey = accessKeyService.create(appId, entity);
    assertNotNull(accessKey);
}
Also used : AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyServiceTest method testCreateWithException.

@Test(expected = BadRequestException.class)
public void testCreateWithException() {
    String appId = "someAppId";
    String secret = "someSecret";
    int maxCount = 5;
    for (int i = 0; i <= maxCount; i++) {
        AccessKey entity = assembleAccessKey(appId, secret);
        accessKeyService.create(appId, entity);
    }
}
Also used : AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyService method update.

@Transactional
public AccessKey update(String appId, AccessKey entity) {
    long id = entity.getId();
    String operator = entity.getDataChangeLastModifiedBy();
    AccessKey accessKey = accessKeyRepository.findOneByAppIdAndId(appId, id);
    if (accessKey == null) {
        throw new BadRequestException("AccessKey not exist");
    }
    accessKey.setEnabled(entity.isEnabled());
    accessKey.setDataChangeLastModifiedBy(operator);
    accessKeyRepository.save(accessKey);
    auditService.audit(AccessKey.class.getSimpleName(), id, Audit.OP.UPDATE, operator);
    return accessKey;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyController method enable.

@PutMapping(value = "/apps/{appId}/accesskeys/{id}/enable")
public void enable(@PathVariable String appId, @PathVariable long id, String operator) {
    AccessKey entity = new AccessKey();
    entity.setId(id);
    entity.setEnabled(true);
    entity.setDataChangeLastModifiedBy(operator);
    accessKeyService.update(appId, entity);
}
Also used : AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 5 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyServiceWithCache method handleDeletedAccessKeys.

private void handleDeletedAccessKeys(Set<Long> deletedIds) {
    if (CollectionUtils.isEmpty(deletedIds)) {
        return;
    }
    for (Long deletedId : deletedIds) {
        AccessKey deleted = accessKeyIdCache.remove(deletedId);
        if (deleted == null) {
            continue;
        }
        accessKeyCache.remove(deleted.getAppId(), deleted);
        logger.info("Found AccessKey deleted, {}", deleted);
    }
}
Also used : AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey)

Aggregations

AccessKey (com.ctrip.framework.apollo.biz.entity.AccessKey)17 Test (org.junit.Test)5 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)4 Date (java.util.Date)4 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 Instant (java.time.Instant)1 List (java.util.List)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 Sql (org.springframework.test.context.jdbc.Sql)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1