All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aeontronix.enhancedmule.tools.cli.UserInfoCmd Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha4
Show newest version
/*
 * Copyright (c) Aeontronix 2023
 */

package com.aeontronix.enhancedmule.tools.cli;

import com.aeontronix.commons.io.IOUtils;
import com.aeontronix.enhancedmule.tools.anypoint.User;
import com.aeontronix.enhancedmule.tools.util.HttpException;
import com.aeontronix.restclient.RESTClientHost;
import com.aeontronix.restclient.RESTResponse;
import org.slf4j.Logger;
import picocli.CommandLine;

import java.util.concurrent.Callable;

import static org.slf4j.LoggerFactory.getLogger;

@CommandLine.Command(name = "userinfo", description = "Retrieve user info from server")
public class UserInfoCmd extends AbstractCommand implements Callable {
    private static final Logger logger = getLogger(UserInfoCmd.class);

    @Override
    public Integer call() throws Exception {
        final User user;
        try {
            final RESTClientHost anypointRestClient = getCli().createEMClient().getLegacyAnypointClient().getAnypointRestClient();
            try (RESTResponse response = anypointRestClient.get("/accounts/api/me").execute()) {
                logger.info("Anypoint User Info: " + IOUtils.toString(response.getContentStream()));
            }
        } catch (HttpException e) {
            if (e.getStatusCode() == 401) {
                logger.info("Authentication failed");
            }
        }
        return 0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy