org.springframework.credhub.support.CredentialSummary Java Examples
The following examples show how to use
org.springframework.credhub.support.CredentialSummary.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CredhubIntegrationTest.java From spring-cloud-config with Apache License 2.0 | 6 votes |
@Before public void setUp() { CredHubCredentialOperations credhubCredentialOperations = Mockito .mock(CredHubCredentialOperations.class); String expectedPath = "/myapp/master/default"; SimpleCredentialName togglesCredentialName = new SimpleCredentialName( expectedPath + "/toggles"); when(credhubCredentialOperations.findByPath(expectedPath)) .thenReturn(singletonList(new CredentialSummary(togglesCredentialName))); JsonCredential credentials = new JsonCredential(); credentials.put("key", "value"); when(credhubCredentialOperations.getByName( new SimpleCredentialName(expectedPath + "/toggles"), JsonCredential.class)) .thenReturn(new CredentialDetails<>("id1", togglesCredentialName, CredentialType.JSON, credentials)); when(this.credHubOperations.credentials()) .thenReturn(credhubCredentialOperations); }
Example #2
Source File: CredHubCredentialTemplateSummaryUnitTests.java From spring-credhub with Apache License 2.0 | 6 votes |
@Theory public void findByPath(@FromDataPoints("responses") ResponseEntity<CredentialSummaryData> expectedResponse) { given(this.restTemplate.getForEntity(CredHubCredentialTemplate.PATH_URL_QUERY, CredentialSummaryData.class, NAME.getName())).willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { this.credHubTemplate.findByPath(NAME.getName()); fail("Exception should have been thrown"); } catch (CredHubException ex) { assertThat(ex.getMessage()).contains(expectedResponse.getStatusCode().toString()); } } else { List<CredentialSummary> response = this.credHubTemplate.findByPath(NAME.getName()); assertResponseContainsExpectedCredentials(expectedResponse, response); } }
Example #3
Source File: CredHubCredentialTemplateSummaryUnitTests.java From spring-credhub with Apache License 2.0 | 6 votes |
@Theory public void findByName(@FromDataPoints("responses") ResponseEntity<CredentialSummaryData> expectedResponse) { given(this.restTemplate.getForEntity(CredHubCredentialTemplate.NAME_LIKE_URL_QUERY, CredentialSummaryData.class, NAME.getName())).willReturn(expectedResponse); if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) { try { this.credHubTemplate.findByName(NAME); fail("Exception should have been thrown"); } catch (CredHubException ex) { assertThat(ex.getMessage()).contains(expectedResponse.getStatusCode().toString()); } } else { List<CredentialSummary> response = this.credHubTemplate.findByName(NAME); assertResponseContainsExpectedCredentials(expectedResponse, response); } }
Example #4
Source File: ReactiveCredHubCredentialTemplate.java From spring-credhub with Apache License 2.0 | 5 votes |
@Override public Flux<CredentialSummary> findByName(final CredentialName name) { Assert.notNull(name, "credential name must not be null"); return this.credHubOperations.doWithWebClient((webClient) -> webClient.get() .uri(NAME_LIKE_URL_QUERY, name.getName()).retrieve() .onStatus(HttpStatus::isError, ExceptionUtils::buildError).bodyToMono(CredentialSummaryData.class) .flatMapMany((data) -> Flux.fromIterable(data.getCredentials()))); }
Example #5
Source File: CredhubEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
private void stubCredentials(String expectedPath, String name, String key, String value) { SimpleCredentialName credentialsName = new SimpleCredentialName( expectedPath + "/" + name); when(this.credhubCredentialOperations.findByPath(expectedPath)) .thenReturn(singletonList(new CredentialSummary(credentialsName))); JsonCredential credentials = new JsonCredential(); credentials.put(key, value); when(this.credhubCredentialOperations.getByName( new SimpleCredentialName(expectedPath + "/" + name), JsonCredential.class)) .thenReturn(new CredentialDetails<>("id1", credentialsName, CredentialType.JSON, credentials)); }
Example #6
Source File: ReactiveCredHubCredentialTemplate.java From spring-credhub with Apache License 2.0 | 5 votes |
@Override public Flux<CredentialSummary> findByPath(final String path) { Assert.notNull(path, "credential path must not be null"); return this.credHubOperations.doWithWebClient((webClient) -> webClient.get().uri(PATH_URL_QUERY, path) .retrieve().onStatus(HttpStatus::isError, ExceptionUtils::buildError) .bodyToMono(CredentialSummaryData.class) .flatMapMany((data) -> Flux.fromIterable(data.getCredentials()))); }
Example #7
Source File: CredHubCredentialTemplate.java From spring-credhub with Apache License 2.0 | 5 votes |
@Override public List<CredentialSummary> findByPath(final String path) { Assert.notNull(path, "credential path must not be null"); return this.credHubOperations.doWithRest((restOperations) -> { ResponseEntity<CredentialSummaryData> response = restOperations.getForEntity(PATH_URL_QUERY, CredentialSummaryData.class, path); ExceptionUtils.throwExceptionOnError(response); return response.getBody().getCredentials(); }); }
Example #8
Source File: CredHubCredentialTemplate.java From spring-credhub with Apache License 2.0 | 5 votes |
@Override public List<CredentialSummary> findByName(final CredentialName name) { Assert.notNull(name, "credential name must not be null"); return this.credHubOperations.doWithRest((restOperations) -> { ResponseEntity<CredentialSummaryData> response = restOperations.getForEntity(NAME_LIKE_URL_QUERY, CredentialSummaryData.class, name.getName()); ExceptionUtils.throwExceptionOnError(response); return response.getBody().getCredentials(); }); }
Example #9
Source File: CredHubDemoController.java From spring-credhub with Apache License 2.0 | 5 votes |
private void findCredentialsByPath(String path, Results results) { try { List<CredentialSummary> retrievedDetails = credentialOperations.findByPath(path); saveResults(results, "Successfully found credentials by path: ", retrievedDetails); } catch (Exception e) { saveResults(results, "Error finding credentials by path: ", e.getMessage()); } }
Example #10
Source File: CredHubDemoController.java From spring-credhub with Apache License 2.0 | 5 votes |
private void findCredentialsByName(CredentialName name, Results results) { try { List<CredentialSummary> retrievedDetails = credentialOperations.findByName(name); saveResults(results, "Successfully found credentials by name: ", retrievedDetails); } catch (Exception e) { saveResults(results, "Error finding credentials by name: ", e.getMessage()); } }
Example #11
Source File: CredentialIntegrationTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@Test public void writeCredential() { CredentialDetails<ValueCredential> written = this.credentials .write(ValueCredentialRequest.builder().name(CREDENTIAL_NAME).value(CREDENTIAL_VALUE).build()); assertThat(written.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(written.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); assertThat(written.getCredentialType()).isEqualTo(CredentialType.VALUE); assertThat(written.getId()).isNotNull(); CredentialDetails<ValueCredential> byId = this.credentials.getById(written.getId(), ValueCredential.class); assertThat(byId.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(byId.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); assertThat(byId.getCredentialType()).isEqualTo(CredentialType.VALUE); CredentialDetails<ValueCredential> byName = this.credentials.getByName(CREDENTIAL_NAME, ValueCredential.class); assertThat(byName.getName().getName()).isEqualTo(CREDENTIAL_NAME.getName()); assertThat(byName.getValue().getValue()).isEqualTo(CREDENTIAL_VALUE); assertThat(byName.getCredentialType()).isEqualTo(CredentialType.VALUE); List<CredentialSummary> foundByName = this.credentials.findByName(new SimpleCredentialName("/test")); assertThat(foundByName).hasSize(1); assertThat(foundByName).extracting("name").extracting("name").containsExactly(CREDENTIAL_NAME.getName()); List<CredentialSummary> foundByPath = this.credentials.findByPath("/spring-credhub/integration-test"); assertThat(foundByPath).hasSize(1); assertThat(foundByPath).extracting("name").extracting("name").containsExactly(CREDENTIAL_NAME.getName()); }
Example #12
Source File: CredentialIntegrationTests.java From spring-credhub with Apache License 2.0 | 5 votes |
@After public void tearDown() { deleteCredentialIfExists(CREDENTIAL_NAME); List<CredentialSummary> afterDelete = this.credentials.findByName(CREDENTIAL_NAME); assertThat(afterDelete).hasSize(0); }
Example #13
Source File: CredHubPersistingDeleteServiceInstanceBindingWorkflowTest.java From spring-cloud-app-broker with Apache License 2.0 | 4 votes |
@Test void deleteCredentialsFromCredHubWhenFound() { CredentialName credentialName = ServiceInstanceCredentialName.builder() .serviceBrokerName("test-app-name") .serviceOfferingName("foo-definition-id") .serviceBindingId("foo-binding-id") .credentialName("credentials-json") .build(); DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest .builder() .bindingId("foo-binding-id") .serviceInstanceId("foo-instance-id") .serviceDefinitionId("foo-definition-id") .build(); DeleteServiceInstanceBindingResponseBuilder responseBuilder = DeleteServiceInstanceBindingResponse.builder(); given(this.credHubOperations.credentials()) .willReturn(credHubCredentialOperations); given(this.credHubOperations.permissionsV2()) .willReturn(credHubPermissionV2Operations); given(this.credHubOperations.permissions()) .willReturn(credHubPermissionOperations); given(this.credHubCredentialOperations.findByName(credentialName)) .willReturn(Flux.fromIterable(Collections.singletonList(new CredentialSummary(credentialName)))); CredentialPermission credentialPermission = new CredentialPermission(credentialName, Permission.builder().app("app-id").operation(Operation.READ).build()); ReflectionTestUtils.setField(credentialPermission, "uuid", "permission-uuid"); given(this.credHubPermissionV2Operations.getPermissionsByPathAndActor(any(), any())) .willReturn(Mono.just(credentialPermission)); given(this.credHubPermissionV2Operations.deletePermission("permission-uuid")) .willReturn(Mono.empty()); Permission permission = Permission.builder().operation(Operation.READ).client("client-id").build(); given(this.credHubPermissionOperations.getPermissions(any())) .willReturn(Flux.just(permission)); given(this.credHubCredentialOperations.deleteByName(any())) .willReturn(Mono.empty()); StepVerifier .create(this.workflow.buildResponse(request, responseBuilder)) .expectNext(responseBuilder) .verifyComplete(); verify(this.credHubCredentialOperations, times(1)) .deleteByName(eq(credentialName)); verify(this.credHubPermissionV2Operations, times(1)) .getPermissionsByPathAndActor(eq(credentialName), eq(Actor.client("client-id"))); verify(this.credHubPermissionV2Operations, times(1)) .deletePermission(eq("permission-uuid")); verifyNoMoreInteractions(this.credHubCredentialOperations); verifyNoMoreInteractions(this.credHubPermissionOperations); verifyNoMoreInteractions(this.credHubPermissionV2Operations); }
Example #14
Source File: CredHubCredentialTemplateSummaryUnitTests.java From spring-credhub with Apache License 2.0 | 4 votes |
private void assertResponseContainsExpectedCredentials(ResponseEntity<CredentialSummaryData> expectedResponse, List<CredentialSummary> response) { assertThat(response).isNotNull(); assertThat(response.size()).isEqualTo(expectedResponse.getBody().getCredentials().size()); assertThat(response).contains(expectedResponse.getBody().getCredentials().get(0)); }
Example #15
Source File: CredhubEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 4 votes |
@Test public void shouldMergeWhenMoreThanOneCredentialsFound() { String expectedPath = "/my-application/production/mylabel"; SimpleCredentialName togglesCredentialName = new SimpleCredentialName( expectedPath + "/toggles"); SimpleCredentialName absCredentialName = new SimpleCredentialName( expectedPath + "/abs"); when(this.credhubCredentialOperations.findByPath(expectedPath)) .thenReturn(asList(new CredentialSummary(togglesCredentialName), new CredentialSummary(absCredentialName))); JsonCredential credentials = new JsonCredential(); credentials.put("key1", "value1"); when(this.credhubCredentialOperations.getByName(togglesCredentialName, JsonCredential.class)) .thenReturn(new CredentialDetails<>("id1", togglesCredentialName, CredentialType.JSON, credentials)); JsonCredential otherCredentials = new JsonCredential(); otherCredentials.put("key2", "value2"); when(this.credhubCredentialOperations.getByName(absCredentialName, JsonCredential.class)) .thenReturn(new CredentialDetails<>("id2", absCredentialName, CredentialType.JSON, otherCredentials)); Environment environment = this.credhubEnvironmentRepository .findOne("my-application", "production", "mylabel"); assertThat(environment.getName()).isEqualTo("my-application"); assertThat(environment.getProfiles()).containsExactly("production"); assertThat(environment.getLabel()).isEqualTo("mylabel"); assertThat(environment.getPropertySources().size()).isEqualTo(1); assertThat(environment.getPropertySources().get(0).getName()) .isEqualTo("credhub-my-application-production-mylabel"); HashMap<Object, Object> expectedValues = new HashMap<>(); expectedValues.put("key1", "value1"); expectedValues.put("key2", "value2"); assertThat(environment.getPropertySources().get(0).getSource()) .isEqualTo(expectedValues); }
Example #16
Source File: CredHubCredentialOperations.java From spring-credhub with Apache License 2.0 | 2 votes |
/** * Find a credential using a path. * @param path the path to the credential; must not be {@literal null} * @return a summary of the credential search results */ List<CredentialSummary> findByPath(String path);
Example #17
Source File: CredHubCredentialOperations.java From spring-credhub with Apache License 2.0 | 2 votes |
/** * Find a credential using a full or partial name. * @param name the name of the credential; must not be {@literal null} * @return a summary of the credential search results */ List<CredentialSummary> findByName(CredentialName name);
Example #18
Source File: ReactiveCredHubCredentialOperations.java From spring-credhub with Apache License 2.0 | 2 votes |
/** * Find a credential using a full or partial name. * @param name the name of the credential; must not be {@literal null} * @return a summary of the credential search results */ Flux<CredentialSummary> findByName(CredentialName name);
Example #19
Source File: ReactiveCredHubCredentialOperations.java From spring-credhub with Apache License 2.0 | 2 votes |
/** * Find a credential using a path. * @param path the path to the credential; must not be {@literal null} * @return a summary of the credential search results */ Flux<CredentialSummary> findByPath(String path);