public Optional validateNamespace()

in src/main/java/org/apache/openwhisk/intellij/common/whisk/service/WhiskNamespaceService.java [45:65]


    public Optional<WhiskNamespace> validateNamespace(WhiskAuth whiskAuth) {
        String endpoint = whiskAuth.getApihost() + "/api/v1/namespaces";
        String authorization = whiskAuth.getBasicAuthHeader();
        try {
            String result = Request.Get(endpoint)
                    .setHeader(HttpHeaders.AUTHORIZATION, authorization)
                    .execute()
                    .returnContent()
                    .asString();

            String[] namespaces = JsonParserUtils.parseWhiskNamespace(result);
            if (namespaces.length > 0) {
                return Optional.of(new WhiskNamespace(whiskAuth.getAuth(), namespaces[0]));
            } else {
                return Optional.empty();
            }
        } catch (IOException e) {
            LOG.warn("Invalid namespace", e);
            return Optional.empty();
        }
    }