use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class SshCommandTaskServiceTest method createAuth.
private static String createAuth(BaseModelTest test, String username, String privateKey) throws Throwable {
AuthCredentialsServiceState startState = new AuthCredentialsServiceState();
startState.userEmail = username;
startState.privateKey = privateKey;
AuthCredentialsServiceState returnState = test.postServiceSynchronously(AuthCredentialsService.FACTORY_LINK, startState, AuthCredentialsServiceState.class);
return returnState.documentSelfLink;
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class SessionUtil method retrieveExternalToken.
public static DeferredResult<AuthCredentialsServiceState> retrieveExternalToken(Service service, AuthorizationContext ctx) {
return service.sendWithDeferredResult(Operation.createGet(buildSessionURI(service, ctx)), SessionState.class).thenApply(sessionState -> {
AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
creds.privateKey = sessionState.externalToken;
return creds;
});
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class AzureStorageEnumerationAdapterService method getLocalStorageAccountDescriptions.
/**
* Query all storage descriptions for the cluster filtered by the received set of storage
* account Ids
*/
private void getLocalStorageAccountDescriptions(StorageEnumContext context, StorageEnumStages next) {
if (context.storageAccountsToUpdateCreate.isEmpty()) {
context.subStage = StorageEnumStages.CREATE_STORAGE_DESCRIPTIONS;
handleSubStage(context);
return;
}
context.storageDescriptions.clear();
Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(StorageDescription.class);
Query.Builder instanceIdFilterParentQuery = Query.Builder.create(Occurance.MUST_OCCUR);
for (Map.Entry<String, StorageAccount> account : context.storageAccountsToUpdateCreate.entrySet()) {
Query instanceIdFilter = Query.Builder.create(Occurance.SHOULD_OCCUR).addFieldClause(StorageDescription.FIELD_NAME_ID, canonizeId(account.getValue().id)).build();
instanceIdFilterParentQuery.addClause(instanceIdFilter);
}
qBuilder.addClause(instanceIdFilterParentQuery.build());
QueryByPages<StorageDescription> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), StorageDescription.class, context.parentCompute.tenantLinks, null, /* endpointLink */
context.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
queryLocalStates.collectDocuments(Collectors.toList()).whenComplete((sds, ex) -> {
if (ex != null) {
handleError(context, ex);
return;
}
logFine(() -> String.format("Found %d matching storage descriptions for Azure" + " storage accounts", sds.size()));
List<DeferredResult<AuthCredentialsServiceState>> results = sds.stream().map(sd -> {
context.storageDescriptions.put(sd.id, sd);
// populate connectionStrings
if (!context.storageConnectionStrings.containsKey(sd.id)) {
return loadStorageAuth(context, sd);
} else {
return DeferredResult.<AuthCredentialsServiceState>completed(null);
}
}).collect(Collectors.toList());
DeferredResult.allOf(results).whenComplete((creds, e) -> {
if (e != null) {
logWarning(() -> String.format("Failed to get storage description" + " credentials: %s", e.getMessage()));
}
context.subStage = next;
handleSubStage(context);
});
});
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class AzureInstanceService method getChildAuth.
private void getChildAuth(AzureInstanceContext ctx, AzureInstanceStage next) {
if (ctx.child.description.authCredentialsLink == null) {
AuthCredentialsServiceState auth = new AuthCredentialsServiceState();
auth.userEmail = AzureConstants.DEFAULT_ADMIN_USER;
auth.privateKey = AzureConstants.DEFAULT_ADMIN_PASSWORD;
ctx.childAuth = auth;
handleAllocation(ctx, next);
return;
}
String childAuthLink = ctx.child.description.authCredentialsLink;
Consumer<Operation> onSuccess = (op) -> {
ctx.childAuth = op.getBody(AuthCredentialsServiceState.class);
handleAllocation(ctx, next);
};
AdapterUtils.getServiceState(this, createInventoryUri(getHost(), childAuthLink), onSuccess, getFailureConsumer(ctx));
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class AzureTestUtil method createDefaultStorageAccountDescription.
public static StorageDescription createDefaultStorageAccountDescription(VerificationHost host, String storageAccountName, ComputeState computeHost, EndpointState endpointState) throws Throwable {
AuthCredentialsServiceState auth = new AuthCredentialsServiceState();
auth.customProperties = new HashMap<>();
auth.customProperties.put(AZURE_STORAGE_ACCOUNT_KEY1, randomString(15));
auth.customProperties.put(AZURE_STORAGE_ACCOUNT_KEY2, randomString(15));
auth = TestUtils.doPost(host, auth, AuthCredentialsServiceState.class, UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK));
String authLink = UriUtils.buildUriPath(AuthCredentialsService.FACTORY_LINK, auth.documentSelfLink);
// Create a storage description
StorageDescription storageDesc = new StorageDescription();
storageDesc.id = "testStorAcct-" + randomString(4);
storageDesc.name = storageAccountName;
storageDesc.regionId = AZURE_RESOURCE_GROUP_LOCATION;
storageDesc.computeHostLink = computeHost.documentSelfLink;
storageDesc.authCredentialsLink = authLink;
storageDesc.resourcePoolLink = computeHost.resourcePoolLink;
storageDesc.tenantLinks = endpointState.tenantLinks;
storageDesc.endpointLink = endpointState.documentSelfLink;
storageDesc.endpointLinks = new HashSet<>();
storageDesc.endpointLinks.add(endpointState.documentSelfLink);
storageDesc.customProperties = new HashMap<>();
storageDesc.customProperties.put(AZURE_STORAGE_TYPE, AZURE_STORAGE_ACCOUNTS);
return TestUtils.doPost(host, storageDesc, StorageDescription.class, UriUtils.buildUri(host, StorageDescriptionService.FACTORY_LINK));
}
Aggregations