org.openstack4j.openstack.OSFactory Java Examples

The following examples show how to use org.openstack4j.openstack.OSFactory. 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: SwiftStorageService.java    From front50 with Apache License 2.0 6 votes vote down vote up
public SwiftStorageService(
    String containerName,
    String identityEndpoint,
    String username,
    String password,
    String projectName,
    String domainName) {
  OSClient.OSClientV3 os =
      OSFactory.builderV3()
          .endpoint(identityEndpoint)
          .credentials(username, password, Identifier.byName(domainName))
          .scopeToProject(Identifier.byName(projectName), Identifier.byName(domainName))
          .authenticate();
  this.token = os.getToken();
  this.swift = os.objectStorage();
  this.containerName = containerName;
}
 
Example #2
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private Token createToken(KeystoneCredentialView osCredential) {
    if (osCredential == null) {
        throw new CredentialVerificationException("Empty credential");
    }
    if (osCredential.getScope() == null) {
        throw new CredentialVerificationException("Null scope not supported");
    }
    switch (osCredential.getScope()) {
        case CB_KEYSTONE_V3_DOMAIN_SCOPE:
            return OSFactory.builderV3().withConfig(config).endpoint(osCredential.getEndpoint())
                    .credentials(osCredential.getUserName(), osCredential.getPassword(), Identifier.byName(osCredential.getUserDomain()))
                    .scopeToDomain(Identifier.byName(osCredential.getDomainName()))
                    .authenticate()
                    .getToken();
        case CB_KEYSTONE_V3_PROJECT_SCOPE:
            return OSFactory.builderV3().withConfig(config).endpoint(osCredential.getEndpoint())
                    .credentials(osCredential.getUserName(), osCredential.getPassword(), Identifier.byName(osCredential.getUserDomain()))
                    .scopeToProject(Identifier.byName(osCredential.getProjectName()), Identifier.byName(osCredential.getProjectDomain()))
                    .authenticate()
                    .getToken();
        default:
            throw new CredentialVerificationException("Scope not supported: " + osCredential.getScope());
    }
}
 
Example #3
Source File: NovaV3Context.java    From karamel with Apache License 2.0 5 votes vote down vote up
public static IOSClientBuilder.V3 buildContext(NovaCredentials credentials) {
  Properties properties = new Properties();
  String[] parts = credentials.getAccountName().split(":");

  logger.info(String.format("Creds : %s", String.join(", ", parts)));
  logger.info(String.format("Creds : endpoint %s", credentials.getEndpoint()));
  logger.info(String.format("Creds : pass %s", credentials.getAccountPass()));

  IOSClientBuilder.V3 builder = OSFactory.builderV3()
              .endpoint(credentials.getEndpoint())
              .credentials(parts[2], credentials.getAccountPass(), Identifier.byName(parts[0]))
              .scopeToProject(Identifier.byName(parts[1]), Identifier.byName(parts[0]));
 
  return builder;
}
 
Example #4
Source File: NovaV3Context.java    From karamel with Apache License 2.0 5 votes vote down vote up
public void reauth()
    throws AuthenticationException {
    // Re auth if token expired
  if (this.token.getExpires().getTime() > new Date().getTime()) {
    this.authenticate(); 
  }
  this.os = OSFactory.clientFromToken(this.token);
}
 
Example #5
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    OSFactory.enableHttpLoggingFilter(debug);
    if (disableSSLVerification) {
        config.withSSLVerificationDisabled();
    }
}
 
Example #6
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public OSClient<?> createOSClient(AuthenticatedContext authenticatedContext) {
    String facing = authenticatedContext.getCloudCredential().getStringParameter(FACING);

    if (isV2Keystone(authenticatedContext)) {
        Access access = authenticatedContext.getParameter(Access.class);
        return OSFactory.clientFromAccess(access, Facing.value(facing));
    } else {
        Token token = authenticatedContext.getParameter(Token.class);
        return OSFactory.clientFromToken(token, Facing.value(facing));
    }
}
 
Example #7
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public OSClient<?> createOSClient(CloudCredential cloudCredential) {
    String facing = cloudCredential.getStringParameter(FACING);
    KeystoneCredentialView osCredential = createKeystoneCredential(cloudCredential);

    if (isV2Keystone(cloudCredential)) {
        Access access = createAccess(osCredential);
        return OSFactory.clientFromAccess(access, Facing.value(facing));
    } else {
        Token token = createToken(osCredential);
        return OSFactory.clientFromToken(token, Facing.value(facing));
    }
}
 
Example #8
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private Access createAccess(KeystoneCredentialView osCredential) {
    try {
        return OSFactory.builderV2().withConfig(config).endpoint(osCredential.getEndpoint())
                .credentials(osCredential.getUserName(), osCredential.getPassword())
                .tenantName(osCredential.getTenantName())
                .authenticate()
                .getAccess();
    } catch (AuthenticationException | ClientResponseException e) {
        LOGGER.info("Openstack authentication failed", e);
        throw new CredentialVerificationException("Authentication failed to openstack, message: " + e.getMessage(), e);
    }
}
 
Example #9
Source File: SwiftStorageService.java    From front50 with Apache License 2.0 4 votes vote down vote up
public ObjectStorageService getSwift() {
  if (token != null) {
    return OSFactory.clientFromToken(token).objectStorage();
  } else return this.swift;
}
 
Example #10
Source File: OpenStackClient.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public String getV2TenantId(AuthenticatedContext authenticatedContext) {
    KeystoneCredentialView osCredential = createKeystoneCredential(authenticatedContext);
    String facing = authenticatedContext.getCloudCredential().getStringParameter(FACING);
    Access access = authenticatedContext.getParameter(Access.class);
    return OSFactory.clientFromAccess(access, Facing.value(facing)).identity().tenants().getByName(osCredential.getTenantName()).getId();
}