diff --git a/broker/src/functional-test/groovy/com/swisscom/cloud/sb/broker/functional/MariaDBBackupRestoreFunctionalSpec.groovy b/broker/src/functional-test/groovy/com/swisscom/cloud/sb/broker/functional/MariaDBBackupRestoreFunctionalSpec.groovy index a7807f15a..2784b4efa 100644 --- a/broker/src/functional-test/groovy/com/swisscom/cloud/sb/broker/functional/MariaDBBackupRestoreFunctionalSpec.groovy +++ b/broker/src/functional-test/groovy/com/swisscom/cloud/sb/broker/functional/MariaDBBackupRestoreFunctionalSpec.groovy @@ -33,7 +33,7 @@ import spock.lang.IgnoreIf import spock.lang.Shared @Slf4j -@IgnoreIf({ !Boolean.valueOf(System.properties['com.swisscom.cloud.sb.broker.runMariaDBBackupRestoreFunctionalSpec']) }) +//@IgnoreIf({ !Boolean.valueOf(System.properties['com.swisscom.cloud.sb.broker.runMariaDBBackupRestoreFunctionalSpec']) }) class MariaDBBackupRestoreFunctionalSpec extends BaseFunctionalSpec { @Shared @@ -58,7 +58,7 @@ class MariaDBBackupRestoreFunctionalSpec extends BaseFunctionalSpec { serviceLifeCycler.createParameter('BACKUP_SCHEDULE_NAME', 'daily', serviceLifeCycler.plan) serviceLifeCycler.createParameter('BACKUP_POLICY_NAME', 'month', serviceLifeCycler.plan) serviceLifeCycler.createParameter('BACKUP_STORAGE_NAME', 'default', serviceLifeCycler.plan) - backupRestoreHelper = new BackupRestoreHelper(appBaseUrl, cfExtUser, cfExtPassword) + backupRestoreHelper = new BackupRestoreHelper(appBaseUrl, cfExtUser.username, cfExtUser.password) } @Autowired diff --git a/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldClient.groovy b/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldClient.groovy index cc0837a89..ad9e8d2cb 100644 --- a/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldClient.groovy +++ b/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldClient.groovy @@ -162,12 +162,16 @@ class ShieldClient { if (retention == null) { throw new RuntimeException("Retention ${shieldServiceConfig.retentionName} that is configured does not exist on shield") } - ScheduleDto schedule = buildClient().getScheduleByName(shieldServiceConfig.scheduleName) - if (schedule == null) { - throw new RuntimeException("Schedule ${shieldServiceConfig.scheduleName} that is configured does not exist on shield") + String schedule = shieldServiceConfig.scheduleName + if (buildClient().getAPIVersion() == 1) { + ScheduleDto scheduleDto = buildClient().getScheduleByName(shieldServiceConfig.scheduleName) + if (scheduleDto == null) { + throw new RuntimeException("Schedule ${shieldServiceConfig.scheduleName} that is configured does not exist on shield") + } + schedule = scheduleDto.uuid } - createOrUpdateJob(jobName, targetUuid, store.uuid, retention.uuid, schedule.uuid, paused) + createOrUpdateJob(jobName, targetUuid, store.uuid, retention.uuid, schedule, paused) } private String createOrUpdateTarget(ShieldTarget target, String targetName, String agent) { @@ -188,6 +192,6 @@ class ShieldClient { } private ShieldRestClient buildClient() { - shieldRestClientFactory.build(restTemplateBuilder.withSSLValidationDisabled().build(), shieldConfig.baseUrl, shieldConfig.apiKey) + shieldRestClientFactory.build(restTemplateBuilder.withSSLValidationDisabled().build(), shieldConfig) } } diff --git a/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldConfig.groovy b/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldConfig.groovy index 22076afaf..3a15c830a 100644 --- a/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldConfig.groovy +++ b/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldConfig.groovy @@ -27,4 +27,7 @@ class ShieldConfig implements Config { String jobPrefix String targetPrefix int maxRetryBackup + String defaultTenantName + String username + String password } diff --git a/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClient.groovy b/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClient.groovy index b8fadd041..ab2ac20e1 100644 --- a/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClient.groovy +++ b/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClient.groovy @@ -20,20 +20,48 @@ import com.swisscom.cloud.sb.broker.util.GsonFactory import groovy.json.JsonSlurper import groovy.util.logging.Slf4j import org.springframework.http.* +import org.springframework.web.client.HttpStatusCodeException import org.springframework.web.client.RestTemplate @Slf4j class ShieldRestClient { public static final String HEADER_API_KEY = 'X-Shield-Token' + public static final String HEADER_API_SESSION = 'X-Shield-Session' + private ShieldConfig config private RestTemplate restTemplate - private String baseUrl - private String apiKey + private int apiVersion = 1 - ShieldRestClient(RestTemplate restTemplate, String baseUrl, String apiKey) { + ShieldRestClient(RestTemplate restTemplate, ShieldConfig shieldConfig) { this.restTemplate = restTemplate - this.baseUrl = baseUrl - this.apiKey = apiKey + this.config = shieldConfig + this.apiVersion = getAPIVersion() + } + + int getAPIVersion() { + try { + this.apiVersion = 1 + def response = restTemplate.exchange(statusUrl(), HttpMethod.GET, configureRequestEntity(), String.class) + String version = new JsonSlurper().parseText(response.body).version + if (version != null && version[0..0].toInteger() == 1) return 1 + else { + this.apiVersion = 2 + response = restTemplate.exchange(infoUrl(), HttpMethod.GET, configureRequestEntity(), String.class) + if (new JsonSlurper().parseText(response.body).api == 2) return 2 + } + } catch (HttpStatusCodeException e) { + if (e.getStatusCode() == HttpStatus.NOT_FOUND) { + this.apiVersion = 2 + def response = restTemplate.exchange(infoUrl(), HttpMethod.GET, configureRequestEntity(), String.class) + if (new JsonSlurper().parseText(response.body).api == 2) return 2 + throw e + } + } + } + + String getTenantUuidByName(String name) { + def response = restTemplate.exchange(tenantsUrl() + "?limit=1&name=${name}", HttpMethod.GET, configureRequestEntity(), String.class) + return new JsonSlurper().parseText(response.body)[0].uuid } Object getStatus() { @@ -149,6 +177,9 @@ class ShieldRestClient { schedule : scheduleUuid, paused : paused] + if (apiVersion == 2) { + body = replaceRetentionWithPolicy(body, retentionUuid) + } def response = restTemplate.exchange(jobsUrl(), HttpMethod.POST, configureRequestEntity(body), String.class) new JsonSlurper().parseText(response.body).uuid } @@ -166,7 +197,9 @@ class ShieldRestClient { retention: retentionUuid, schedule : scheduleUuid, paused : paused] - + if (apiVersion == 2) { + body = replaceRetentionWithPolicy(body, retentionUuid) + } restTemplate.exchange(jobUrl(existingJob.uuid), HttpMethod.PUT, configureRequestEntity(body), (Class) null) existingJob.uuid } @@ -218,52 +251,89 @@ class ShieldRestClient { private HttpEntity configureRequestEntity(T t) { HttpHeaders headers = new HttpHeaders() headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE)) - headers.add(HEADER_API_KEY, apiKey) + apiVersion == 2 ? headers.add(HEADER_API_SESSION, getSession()) : headers.add(HEADER_API_KEY, config.apiKey) HttpEntity entity = t ? new HttpEntity(t, headers) : new HttpEntity(headers) return entity } + protected String getSession() { + HttpHeaders headers = new HttpHeaders() + headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE)) + def body = [username: config.username, + password: config.password] + HttpEntity> request = new HttpEntity>(body, headers) + ResponseEntity response = restTemplate.exchange(loginUrl(), HttpMethod.POST, request, String.class) + return response.getHeaders().getValuesAsList(HEADER_API_SESSION)[0] + } + protected String storesUrl() { - "${baseUrl()}/stores" + "${tenantBasedUrl()}/stores" } protected String retentionsUrl() { - "${baseUrl()}/retention" + apiVersion == 2 ? "${tenantBasedUrl()}/policies" : "${tenantBasedUrl()}/retention" } protected String schedulesUrl() { - "${baseUrl()}/schedules" + "${tenantBasedUrl()}/schedules" } protected String taskUrl(String uuid) { - "${baseUrl()}/task/${uuid}" + "${tenantBasedUrl()}/task/${uuid}" } protected String archiveUrl(String uuid) { - "${baseUrl()}/archive/${uuid}" + "${tenantBasedUrl()}/archive/${uuid}" } protected String targetsUrl() { - "${baseUrl()}/targets" + "${tenantBasedUrl()}/targets" } protected String targetUrl(String uuid) { - "${baseUrl()}/target/${uuid}" + "${tenantBasedUrl()}/target/${uuid}" } protected String jobsUrl() { - "${baseUrl()}/jobs" + "${tenantBasedUrl()}/jobs" } protected String jobUrl(String uuid) { - "${baseUrl()}/job/${uuid}" + "${tenantBasedUrl()}/job/${uuid}" } protected String statusUrl() { "${baseUrl()}/status" } + protected String infoUrl() { + "${baseUrl()}/info" + } + + protected String tenantsUrl() { + "${baseUrl()}/tenants" + } + + protected String loginUrl() { + "${baseUrl()}/auth/login" + } + + private String tenantBasedUrl() { + apiVersion == 2 ? "${baseUrl()}/tenants/${getTenantUuidByName(config.defaultTenantName)}" : baseUrl() + } + private String baseUrl() { - "${baseUrl}/v1" + "${config.baseUrl}/v${apiVersion}" + } + + private Map replaceRetentionWithPolicy(Map body, String retention) { + def iterator = body.entrySet().iterator() + while (iterator.hasNext()) { + if (iterator.next().key == "retention") { + iterator.remove() + } + } + body.put("policy", retention) + return body } } diff --git a/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientFactory.groovy b/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientFactory.groovy index 2b6b7500f..044d738ea 100644 --- a/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientFactory.groovy +++ b/broker/src/main/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientFactory.groovy @@ -22,8 +22,8 @@ import org.springframework.web.client.RestTemplate @Component @CompileStatic class ShieldRestClientFactory { - ShieldRestClient build(RestTemplate restTemplate, String baseUrl, String apiKey) { + ShieldRestClient build(RestTemplate restTemplate, ShieldConfig shieldConfig) { restTemplate.setErrorHandler(new ShieldRestResponseErrorHandler()) - new ShieldRestClient(restTemplate, baseUrl, apiKey) + new ShieldRestClient(restTemplate, shieldConfig) } } diff --git a/broker/src/main/resources/application.yml b/broker/src/main/resources/application.yml index 61be8efe2..2c49651f6 100644 --- a/broker/src/main/resources/application.yml +++ b/broker/src/main/resources/application.yml @@ -110,7 +110,7 @@ com.swisscom.cloud.sb.broker.service.mariadb: discoveryURL: "http://localhost:8080/v2/api-docs" com.swisscom.cloud.sb.broker.shield: - baseUrl: 'https://shield.service.consul:8002' + baseUrl: 'https://localhost:8443' apiKey: agent: '10.244.2.2:5444' jobPrefix: 'SB_CF_' @@ -119,6 +119,9 @@ com.swisscom.cloud.sb.broker.shield: retentionName: 'default' scheduleName: 'schedu' maxRetryBackup: 5 + defaultTenantName: tenant1 + username: admin + password: shield com.swisscom.cloud.sb.broker.service.openwhisk: openWhiskProtocol: diff --git a/broker/src/test/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientSpec.groovy b/broker/src/test/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientSpec.groovy index 65019907a..87c5dff28 100644 --- a/broker/src/test/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientSpec.groovy +++ b/broker/src/test/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientSpec.groovy @@ -35,9 +35,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat class ShieldRestClientSpec extends Specification { ShieldRestClient shieldRestClient MockRestServiceServer mockServer - - String baseUrl = "http://baseurl" - String apiKey = "apiKey" + ShieldConfig shieldConfig class DummyTarget implements ShieldTarget { @@ -54,16 +52,28 @@ class ShieldRestClientSpec extends Specification { def setup() { RestTemplate restTemplate = new RestTemplate() - mockServer = MockRestServiceServer.createServer(restTemplate) + MockRestServiceServer initMockServer = MockRestServiceServer.createServer(restTemplate) + shieldConfig = new ShieldConfig() + shieldConfig.baseUrl = "http://baseurl" + shieldConfig.username = "admin" + shieldConfig.password = "shield" + shieldConfig.defaultTenantName = "tenant1" + shieldConfig.apiKey = "apiKey" and: - shieldRestClient = new ShieldRestClientFactory().build(restTemplate, baseUrl, apiKey) + initMockServer.expect(requestTo(shieldConfig.baseUrl + "/v1/status")) + .andExpect(method(HttpMethod.GET)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) + .andExpect(content().contentType(APPLICATION_JSON_VALUE)) + .andRespond(withSuccess('{"version":"1.0"}', MediaType.APPLICATION_JSON)) + shieldRestClient = new ShieldRestClientFactory().build(restTemplate, shieldConfig) + mockServer = MockRestServiceServer.createServer(restTemplate) } def "get status"() { given: mockServer.expect(requestTo(shieldRestClient.statusUrl())) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('{"status":"status"}', MediaType.APPLICATION_JSON)) @@ -78,7 +88,7 @@ class ShieldRestClientSpec extends Specification { given: mockServer.expect(requestTo(shieldRestClient.storesUrl() + "?name=storeName")) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('[]', MediaType.APPLICATION_JSON)) @@ -92,7 +102,7 @@ class ShieldRestClientSpec extends Specification { given: mockServer.expect(requestTo(shieldRestClient.retentionsUrl() + "?name=retentionName")) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('[]', MediaType.APPLICATION_JSON)) @@ -106,7 +116,7 @@ class ShieldRestClientSpec extends Specification { given: mockServer.expect(requestTo(shieldRestClient.schedulesUrl() + "?name=scheduleName")) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('[]', MediaType.APPLICATION_JSON)) @@ -120,7 +130,7 @@ class ShieldRestClientSpec extends Specification { given: mockServer.expect(requestTo(shieldRestClient.targetsUrl() + "?name=targetName")) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('[]', MediaType.APPLICATION_JSON)) @@ -141,7 +151,7 @@ class ShieldRestClientSpec extends Specification { agent : agent]) mockServer.expect(requestTo(shieldRestClient.targetsUrl())) .andExpect(method(HttpMethod.POST)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andExpect(content().string(body)) .andRespond(withSuccess('{"uuid":"targetId"}', MediaType.APPLICATION_JSON)) @@ -165,7 +175,7 @@ class ShieldRestClientSpec extends Specification { agent : agent]) mockServer.expect(requestTo(shieldRestClient.targetUrl(targetDto.uuid))) .andExpect(method(HttpMethod.PUT)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andExpect(content().string(body)) .andRespond(withSuccess('', MediaType.APPLICATION_JSON)) @@ -182,7 +192,7 @@ class ShieldRestClientSpec extends Specification { String targetId = 'target-id' mockServer.expect(requestTo(shieldRestClient.targetUrl(targetId))) .andExpect(method(HttpMethod.DELETE)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('', MediaType.APPLICATION_JSON)) @@ -196,7 +206,7 @@ class ShieldRestClientSpec extends Specification { given: mockServer.expect(requestTo(shieldRestClient.jobsUrl() + "?name=jobName")) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('[]', MediaType.APPLICATION_JSON)) @@ -216,7 +226,7 @@ class ShieldRestClientSpec extends Specification { paused: false] mockServer.expect(requestTo(shieldRestClient.jobsUrl())) .andExpect(method(HttpMethod.POST)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andExpect(content().string(new ObjectMapper().writeValueAsString(job))) .andRespond(withSuccess('{"uuid": "job-uuid"}', MediaType.APPLICATION_JSON)) @@ -245,7 +255,7 @@ class ShieldRestClientSpec extends Specification { paused: false] mockServer.expect(requestTo(shieldRestClient.jobUrl(jobDto.uuid))) .andExpect(method(HttpMethod.PUT)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andExpect(content().string(new ObjectMapper().writeValueAsString(job))) .andRespond(withSuccess('', MediaType.APPLICATION_JSON)) @@ -267,7 +277,7 @@ class ShieldRestClientSpec extends Specification { String jobId = "job-id" mockServer.expect(requestTo(shieldRestClient.jobUrl(jobId) + "/run")) .andExpect(method(HttpMethod.POST)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('{"task_uuid":"1234"}', MediaType.APPLICATION_JSON)) @@ -283,7 +293,7 @@ class ShieldRestClientSpec extends Specification { String jobId = 'job-id' mockServer.expect(requestTo(shieldRestClient.jobUrl(jobId))) .andExpect(method(HttpMethod.DELETE)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('', MediaType.APPLICATION_JSON)) @@ -299,7 +309,7 @@ class ShieldRestClientSpec extends Specification { String taskId = "task-id" mockServer.expect(requestTo(shieldRestClient.taskUrl(taskId))) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('{"type": "backup", "status":"pending"}', MediaType.APPLICATION_JSON)) @@ -316,7 +326,7 @@ class ShieldRestClientSpec extends Specification { String archiveId = "archive-id" mockServer.expect(requestTo(shieldRestClient.archiveUrl(archiveId))) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('{"status":"valid"}', MediaType.APPLICATION_JSON)) @@ -332,7 +342,7 @@ class ShieldRestClientSpec extends Specification { String archiveId = "archive-id" mockServer.expect(requestTo(shieldRestClient.archiveUrl(archiveId) + "/restore")) .andExpect(method(HttpMethod.POST)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('{"task_uuid":"taskId"}', MediaType.APPLICATION_JSON)) @@ -348,7 +358,7 @@ class ShieldRestClientSpec extends Specification { String archiveId = 'archive-id' mockServer.expect(requestTo(shieldRestClient.archiveUrl(archiveId))) .andExpect(method(HttpMethod.DELETE)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withSuccess('', MediaType.APPLICATION_JSON)) @@ -363,7 +373,7 @@ class ShieldRestClientSpec extends Specification { String taskId = null mockServer.expect(requestTo(shieldRestClient.taskUrl(taskId))) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withStatus(HttpStatus.NOT_IMPLEMENTED)) @@ -379,7 +389,7 @@ class ShieldRestClientSpec extends Specification { String taskId = "" mockServer.expect(requestTo(shieldRestClient.taskUrl(taskId))) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withStatus(HttpStatus.NOT_IMPLEMENTED)) @@ -395,7 +405,7 @@ class ShieldRestClientSpec extends Specification { String archiveId = null mockServer.expect(requestTo(shieldRestClient.archiveUrl(archiveId))) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withStatus(HttpStatus.NOT_IMPLEMENTED)) @@ -411,7 +421,7 @@ class ShieldRestClientSpec extends Specification { String archiveId = "" mockServer.expect(requestTo(shieldRestClient.archiveUrl(archiveId))) .andExpect(method(HttpMethod.GET)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withStatus(HttpStatus.NOT_IMPLEMENTED)) @@ -427,7 +437,7 @@ class ShieldRestClientSpec extends Specification { String archiveId = null mockServer.expect(requestTo(shieldRestClient.archiveUrl(archiveId))) .andExpect(method(HttpMethod.DELETE)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withStatus(HttpStatus.NOT_IMPLEMENTED)) @@ -443,7 +453,7 @@ class ShieldRestClientSpec extends Specification { String archiveId = "" mockServer.expect(requestTo(shieldRestClient.archiveUrl(archiveId))) .andExpect(method(HttpMethod.DELETE)) - .andExpect(header(ShieldRestClient.HEADER_API_KEY, apiKey)) + .andExpect(header(ShieldRestClient.HEADER_API_KEY, shieldConfig.apiKey)) .andExpect(content().contentType(APPLICATION_JSON_VALUE)) .andRespond(withStatus(HttpStatus.NOT_IMPLEMENTED)) diff --git a/broker/src/test/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientTest.groovy b/broker/src/test/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientTest.groovy index 618ec644b..8d4737304 100644 --- a/broker/src/test/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientTest.groovy +++ b/broker/src/test/groovy/com/swisscom/cloud/sb/broker/backup/shield/ShieldRestClientTest.groovy @@ -26,14 +26,13 @@ class ShieldRestClientTest extends Specification { ShieldRestClient restClient void setup() { - restClient = new ShieldRestClient(new RestTemplateBuilder().withSSLValidationDisabled(), "https://localhost:18002", "averyhardkey") - } - - def "obtain status"() { - when: - def status = restClient.getStatus() - then: - status + ShieldConfig shieldConfig = new ShieldConfig() + shieldConfig.baseUrl = "https://localhost:8443" + shieldConfig.username = "admin" + shieldConfig.password = "shield" + shieldConfig.defaultTenantName = "tenant1" + shieldConfig.apiKey = "averyhardkey" + restClient = new ShieldRestClient(new RestTemplateBuilder().withSSLValidationDisabled().build(), shieldConfig) } def "get store by name"() { @@ -63,18 +62,4 @@ class ShieldRestClientTest extends Specification { then: retention == null } - - def "get schedule by name"() { - when: - def schedule = restClient.getScheduleByName("default") - then: - schedule - } - - def "get schedule by name not found"() { - when: - def schedule = restClient.getScheduleByName("notexisting") - then: - schedule == null - } }