private void createOrSelectTemplateHint() throws Exception {
   if (cloudbreakClient.credentialEndpoint().getPublics().isEmpty()) {
     context.setHint(Hints.ADD_BLUEPRINT);
   } else {
     context.setHint(Hints.SELECT_BLUEPRINT);
   }
 }
 @Override
 public boolean getAllPossibleValues(
     List<Completion> completions,
     Class<?> targetType,
     String existingData,
     String optionContext,
     MethodTarget target) {
   try {
     return getAllPossibleValues(
         completions, context.getAvailabilityZonesByPlatform(context.getActiveCloudPlatform()));
   } catch (Exception e) {
     return false;
   }
 }
 @Override
 public boolean getAllPossibleValues(
     List<Completion> completions,
     Class<?> targetType,
     String existingData,
     String optionContext,
     MethodTarget target) {
   try {
     return getAllPossibleValues(completions, context.getActiveHostGroups());
   } catch (Exception e) {
     return false;
   }
 }
 @Override
 public boolean getAllPossibleValues(
     List<Completion> completions,
     Class<?> targetType,
     String existingData,
     String optionContext,
     MethodTarget target) {
   try {
     return getAllPossibleValues(completions, context.getVolumeTypesByPlatform("GCP"));
   } catch (Exception e) {
     return false;
   }
 }
  @CliCommand(value = "credential select", help = "Select the credential by its id or name")
  public String selectCredential(
      @CliOption(key = "id", mandatory = false, help = "Id of the credential") String id,
      @CliOption(key = "name", mandatory = false, help = "Name of the credential") String name) {
    try {

      if (id != null) {
        if (cloudbreakClient.credentialEndpoint().get(Long.valueOf(id)) != null) {
          context.setCredential(id);
          createOrSelectTemplateHint();
          return "Credential selected, id: " + id;
        }
      } else if (name != null) {
        CredentialResponse aPublic = cloudbreakClient.credentialEndpoint().getPublic(name);
        context.setCredential(aPublic.getId().toString());
        createOrSelectTemplateHint();
        return "Credential selected, name: " + name;
      }
      return "No credential specified (select a credential by --id or --name)";
    } catch (Exception ex) {
      throw exceptionTransformer.transformToRuntimeException(ex);
    }
  }
 @CliAvailabilityIndicator(value = "credential select")
 public boolean isCredentialSelectCommandAvailable() throws Exception {
   return context.isCredentialAccessible();
 }
  @CliCommand(value = "credential create --AZURE", help = "Create a new AZURE credential")
  public String createAzureRmCredential(
      @CliOption(key = "name", mandatory = true, help = "Name of the credential") String name,
      @CliOption(
              key = "subscriptionId",
              mandatory = true,
              help = "subscriptionId of the credential")
          String subscriptionId,
      @CliOption(key = "tenantId", mandatory = true, help = "tenantId of the credential")
          String tenantId,
      @CliOption(key = "appId", mandatory = true, help = "appId of the credential") String appId,
      @CliOption(key = "password", mandatory = true, help = "password of the credential")
          String password,
      @CliOption(key = "sshKeyPath", mandatory = false, help = "sshKeyPath of the template")
          File sshKeyPath,
      @CliOption(key = "sshKeyUrl", mandatory = false, help = "sshKeyUrl of the template")
          String sshKeyUrl,
      @CliOption(
              key = "sshKeyString",
              mandatory = false,
              help = "Raw data of a public SSH key file")
          String sshKeyString,
      @CliOption(
              key = "publicInAccount",
              mandatory = false,
              help = "flags if the credential is public in the account")
          Boolean publicInAccount,
      @CliOption(key = "description", mandatory = false, help = "Description of the credential")
          String description,
      @CliOption(
              key = "topologyId",
              mandatory = false,
              help = "Id of a topology the credential belongs to")
          Long topologyId) {
    if ((sshKeyPath == null)
        && (sshKeyUrl == null || sshKeyUrl.isEmpty())
        && sshKeyString == null) {
      return "An SSH public key must be specified either with --sshKeyPath or --sshKeyUrl or --sshKeyString";
    }
    String sshKey;
    if (sshKeyPath != null) {
      try {
        sshKey = IOUtils.toString(new FileReader(new File(sshKeyPath.getPath())));
      } catch (IOException ex) {
        throw exceptionTransformer.transformToRuntimeException(FILE_NOT_FOUND);
      }
    } else if (sshKeyUrl != null) {
      try {
        sshKey = readUrl(sshKeyUrl);
      } catch (IOException ex) {
        throw exceptionTransformer.transformToRuntimeException(URL_NOT_FOUND);
      }
    } else {
      sshKey = sshKeyString;
    }
    try {
      String cloudPlatform = "AZURE_RM";
      CredentialRequest credentialRequest = new CredentialRequest();
      credentialRequest.setName(name);
      credentialRequest.setDescription(description);
      credentialRequest.setCloudPlatform(cloudPlatform);
      credentialRequest.setPublicKey(sshKey);

      Map<String, Object> parameters = new HashMap<>();
      parameters.put("subscriptionId", subscriptionId);
      parameters.put("secretKey", password);
      parameters.put("tenantId", tenantId);
      parameters.put("accessKey", appId);

      credentialRequest.setParameters(parameters);
      if (topologyId != null) {
        checkTopologyForResource(
            cloudbreakClient.topologyEndpoint().getPublics(), topologyId, cloudPlatform);
      }
      credentialRequest.setTopologyId(topologyId);

      IdJson id;
      publicInAccount = publicInAccount == null ? false : publicInAccount;
      if (publicInAccount) {
        id = cloudbreakClient.credentialEndpoint().postPublic(credentialRequest);
      } else {
        id = cloudbreakClient.credentialEndpoint().postPrivate(credentialRequest);
      }
      context.setCredential(id.getId().toString());
      createOrSelectTemplateHint();
      return "Credential created, id: " + id.getId().toString();
    } catch (Exception ex) {
      throw exceptionTransformer.transformToRuntimeException(ex);
    }
  }
  @CliCommand(value = "credential create --OPENSTACK", help = "Create a new OPENSTACK credential")
  public String createOpenStackCredential(
      @CliOption(key = "name", mandatory = true, help = "Name of the credential") String name,
      @CliOption(key = "userName", mandatory = true, help = "Username of the credential")
          String userName,
      @CliOption(key = "password", mandatory = true, help = "password of the credential")
          String password,
      @CliOption(key = "endPoint", mandatory = true, help = "endPoint of the credential")
          String endPoint,
      @CliOption(
              key = "tenantName",
              mandatory = false,
              help = "tenantName of the credential for cb-keystone-v2")
          String tenantName,
      @CliOption(
              key = "userDomain",
              mandatory = false,
              help = "userDomain of the credential for cb-keystone-v3*")
          String userDomain,
      @CliOption(
              key = "keystoneAuthScope",
              mandatory = false,
              help = "keystoneAuthScope of the credential for cb-keystone-v3*")
          String keystoneAuthScope,
      @CliOption(
              key = "domainName",
              mandatory = false,
              help = "domainName of the credential for cb-keystone-v3-default-scope")
          String domainName,
      @CliOption(
              key = "projectDomainName",
              mandatory = false,
              help = "projectDomainName of the credential for cb-keystone-v3-project-scope")
          String projectDomainName,
      @CliOption(
              key = "projectName",
              mandatory = false,
              help = "projectName of the credential for cb-keystone-v3-project-scope")
          String projectName,
      @CliOption(key = "sshKeyPath", mandatory = false, help = "path of a public SSH key file")
          File sshKeyPath,
      @CliOption(key = "sshKeyUrl", mandatory = false, help = "URL of a public SSH key file")
          String sshKeyUrl,
      @CliOption(
              key = "sshKeyString",
              mandatory = false,
              help = "Raw data of a public SSH key file")
          String sshKeyString,
      @CliOption(key = "description", mandatory = false, help = "Description of the credential")
          String description,
      @CliOption(
              key = "publicInAccount",
              mandatory = false,
              help = "flags if the credential is public in the account")
          Boolean publicInAccount,
      @CliOption(
              key = "topologyId",
              mandatory = false,
              help = "Id of a topology the credential belongs to")
          Long topologyId) {
    if ((sshKeyPath == null)
        && (sshKeyUrl == null || sshKeyUrl.isEmpty())
        && sshKeyString == null) {
      return "An SSH public key must be specified either with --sshKeyPath or --sshKeyUrl or --sshKeyString";
    }
    String selector = null;
    String keyStoneVersion = null;
    if (tenantName != null) {
      selector = "cb-keystone-v2";
      keyStoneVersion = "cb-keystone-v2";
    }
    if (userDomain != null && keystoneAuthScope != null) {
      if (domainName != null) {
        selector = "cb-keystone-v3-domain-scope";
      } else if (projectDomainName != null && projectName != null) {
        selector = "cb-keystone-v3-project-scope";
      } else {
        selector = "cb-keystone-v3-default-scope";
      }
      keyStoneVersion = "cb-keystone-v3";
    }
    if (selector == null || keyStoneVersion == null) {
      return "Selector not found for specified parameters.";
    }
    String sshKey;
    if (sshKeyPath != null) {
      try {
        sshKey = IOUtils.toString(new FileReader(new File(sshKeyPath.getPath())));
      } catch (IOException ex) {
        throw exceptionTransformer.transformToRuntimeException(FILE_NOT_FOUND);
      }
    } else if (sshKeyUrl != null) {
      try {
        sshKey = readUrl(sshKeyUrl);
      } catch (IOException ex) {
        throw exceptionTransformer.transformToRuntimeException(URL_NOT_FOUND);
      }
    } else {
      sshKey = sshKeyString;
    }

    try {
      String cloudPlatform = "OPENSTACK";
      CredentialRequest credentialRequest = new CredentialRequest();
      credentialRequest.setName(name);
      credentialRequest.setDescription(description);
      credentialRequest.setCloudPlatform(cloudPlatform);
      credentialRequest.setPublicKey(sshKey);

      Map<String, Object> parameters = new HashMap<>();
      parameters.put("userName", userName);
      parameters.put("password", password);
      parameters.put("endpoint", endPoint);
      parameters.put("keystoneVersion", keyStoneVersion);
      parameters.put("selector", selector);
      parameters.put("tenantName", tenantName);
      parameters.put("userDomain", userDomain);
      parameters.put("keystoneAuthScope", keystoneAuthScope);
      parameters.put("domainName", domainName);
      parameters.put("projectDomainName", projectDomainName);
      parameters.put("projectName", projectName);

      credentialRequest.setParameters(parameters);
      if (topologyId != null) {
        checkTopologyForResource(
            cloudbreakClient.topologyEndpoint().getPublics(), topologyId, cloudPlatform);
      }
      credentialRequest.setTopologyId(topologyId);

      IdJson idJson;
      publicInAccount = publicInAccount == null ? false : publicInAccount;
      if (publicInAccount) {
        idJson = cloudbreakClient.credentialEndpoint().postPublic(credentialRequest);
      } else {
        idJson = cloudbreakClient.credentialEndpoint().postPrivate(credentialRequest);
      }
      context.setCredential(idJson.getId().toString());
      createOrSelectTemplateHint();
      return "Credential created, id: " + idJson.getId().toString();
    } catch (Exception ex) {
      throw exceptionTransformer.transformToRuntimeException(ex);
    }
  }