예제 #1
0
 private Map<String, ConfigEntry> getConfig(String url) throws IOException, UnauthorizedException {
   HttpResponse response =
       restClient.execute(HttpMethod.GET, config.resolveURL(url), config.getAccessToken());
   List<ConfigEntry> responseObject =
       ObjectResponse.fromJsonBody(response, new TypeToken<List<ConfigEntry>>() {})
           .getResponseObject();
   Map<String, ConfigEntry> config = Maps.newHashMap();
   for (ConfigEntry configEntry : responseObject) {
     config.put(configEntry.getName(), configEntry);
   }
   return config;
 }
예제 #2
0
파일: CLIConfig.java 프로젝트: ngopina/cdap
 public void setNamespace(Id.Namespace namespace) {
   ConnectionConfig connectionConfig =
       ConnectionConfig.builder(clientConfig.getConnectionConfig())
           .setNamespace(namespace)
           .build();
   this.setConnectionConfig(connectionConfig);
 }
예제 #3
0
파일: CLIConfig.java 프로젝트: ngopina/cdap
  private AccessToken getNewAccessToken(
      ConnectionConfig connectionInfo, PrintStream output, boolean debug) throws IOException {

    AuthenticationClient authenticationClient = getAuthenticationClient(connectionInfo);

    Properties properties = new Properties();
    properties.put(
        BasicAuthenticationClient.VERIFY_SSL_CERT_PROP_NAME,
        String.valueOf(clientConfig.isVerifySSLCert()));

    // obtain new access token via manual user input
    output.printf(
        "Authentication is enabled in the CDAP instance: %s.\n", connectionInfo.getHostname());
    ConsoleReader reader = new ConsoleReader();
    for (Credential credential : authenticationClient.getRequiredCredentials()) {
      String prompt = "Please, specify " + credential.getDescription() + "> ";
      String credentialValue;
      if (credential.isSecret()) {
        credentialValue = reader.readLine(prompt, '*');
      } else {
        credentialValue = reader.readLine(prompt);
      }
      properties.put(credential.getName(), credentialValue);
    }

    authenticationClient.configure(properties);
    AccessToken accessToken = authenticationClient.getAccessToken();

    if (accessToken != null) {
      if (saveAccessToken(accessToken, connectionInfo.getHostname()) && debug) {
        output.printf(
            "Saved access token to %s\n",
            getAccessTokenFile(connectionInfo.getHostname()).getAbsolutePath());
      }
    }

    return accessToken;
  }
예제 #4
0
 public Version getVersion() throws IOException, UnauthorizedException {
   HttpResponse response =
       restClient.execute(HttpMethod.GET, config.resolveURL("version"), config.getAccessToken());
   return ObjectResponse.fromJsonBody(response, Version.class).getResponseObject();
 }
예제 #5
0
 public void ping() throws IOException, UnauthorizedException {
   restClient.execute(HttpMethod.GET, config.resolveURLNoVersion("ping"), config.getAccessToken());
 }
예제 #6
0
파일: CLIConfig.java 프로젝트: ngopina/cdap
 public CLIConfig() {
   this(ClientConfig.builder().build(), System.out, new AltStyleTableRenderer());
 }
예제 #7
0
파일: CLIConfig.java 프로젝트: ngopina/cdap
 public void updateAccessToken(PrintStream output) throws IOException {
   AccessToken newAccessToken =
       getNewAccessToken(clientConfig.getConnectionConfig(), output, false);
   clientConfig.setAccessToken(newAccessToken);
 }
예제 #8
0
파일: CLIConfig.java 프로젝트: ngopina/cdap
 public void setConnectionConfig(@Nullable ConnectionConfig connectionConfig) {
   clientConfig.setConnectionConfig(connectionConfig);
   notifyConnectionChanged();
 }
예제 #9
0
파일: CLIConfig.java 프로젝트: ngopina/cdap
 public Id.Namespace getCurrentNamespace() {
   return clientConfig.getNamespace();
 }