![JAR search and dependency download from the Maven repository](/logo.png)
com.hcl.appscan.cli.handlers.GetPresenceIds Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of appscan-cloud-cli Show documentation
Show all versions of appscan-cloud-cli Show documentation
Command line interface tool for interacting with HCL AppScan on Cloud or HCL AppScan 360°
The newest version!
/*
*
* Copyright 2023,2024 HCL America, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* /
*/
package com.hcl.appscan.cli.handlers;
import com.hcl.appscan.cli.auth.CloudAuthenticationHandler;
import com.hcl.appscan.sdk.presence.CloudPresenceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.concurrent.Callable;
import static picocli.CommandLine.*;
@Command(name = "getpresenceids" , sortOptions = false, mixinStandardHelpOptions = true , subcommands = {HelpCommand.class} ,
description ="Get list of presence id's from AppScan on Cloud"
)
public class GetPresenceIds implements Callable {
private static final Logger logger = LoggerFactory.getLogger(GetPresenceIds.class);
@Spec
Model.CommandSpec spec;
ResourceBundle messageBundle = ResourceBundle.getBundle("messages");
@Option(names = {"--key"}, description = "[Required] AppScan on Cloud API Key", required = true , order = 1)
private String key;
@Option(names = {"--secret"}, description = "[Required] AppScan on Cloud API Secret", required = true , order = 2)
private String secret;
@Option(names = {"--serviceUrl"}, description = "[Required] AppScan Service URL", required = false , order = 3)
private String serviceUrl;
@Override
public Integer call() {
try{
printPresenceIdList();
return 0;
}catch (Exception e){
return 2;
}
}
private void printPresenceIdList() throws Exception {
if(key.startsWith("local_")){
logger.error("This command is not applicable for AppScan 360° service.");
throw new IllegalArgumentException("This command is not applicable for AppScan 360° service.");
}
CloudAuthenticationHandler authHandler;
if(null!=serviceUrl){
authHandler = new CloudAuthenticationHandler(serviceUrl, false);
}else{
authHandler = new CloudAuthenticationHandler();
}
try {
authHandler.updateCredentials(key, secret);
} catch (Exception e) {
logger.error("Error in authenticating the request. Please check the credentials!");
throw e;
}
try {
Map presenceMap = getPresenceMap(authHandler);
System.out.println("Presence ID \t\t\t\t\t\t\tPresence Name");
System.out.println("---------------------------------------------------------------------------------");
for (Map.Entry, ?> entry : presenceMap.entrySet()) {
System.out.printf("%-15s\t-\t%s%n", entry.getKey(), entry.getValue());
}
} catch (Exception e) {
logger.error(e.getMessage());
throw e;
}
}
private static Map getPresenceMap(CloudAuthenticationHandler authHandler) throws Exception {
return new CloudPresenceProvider(authHandler).getPresences();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy