Skip to content

Commit

Permalink
Add support for Smart-1 Cloud + API key
Browse files Browse the repository at this point in the history
  • Loading branch information
chkp-royl committed Mar 15, 2023
1 parent 76db2a0 commit 058319f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Where:

[-m server-ip] (Optional): Management server ip address. Default value is 127.0.0.1.

[-u username] (Optional): Management administrator user name.

[-p password] (Optional): Management administrator password.

[--api-key] (Optional): Management administrator API key.

[--cloud-mgmt-id] (Optional): Smart-1 Cloud management UID.

[-d domain-name] (Optional): The name or uid of the Security Management Server domain.
When running the command on a Multi domain server the default domain is the "MDS".

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum ShowPackageConfiguration {
private static final String RULEBASE_FILE = "rulebase.txt";
/*Management server IP address*/
private static String server = ApiClient.LOCAL_SERVER_IP;
private static String cloudMgmtId = null;

/*Set the names of the tar and log files*/
private static final String tarName;
Expand All @@ -51,6 +52,7 @@ public enum ShowPackageConfiguration {
/*Login credentials*/
private static String username;
private static String password;
private static String apiKey;
private static String domain;
private static int port;
private static boolean userEnteredPort = false;
Expand Down Expand Up @@ -293,19 +295,23 @@ JSONObject createPayloadForLogin(boolean loginAsRoot){
JSONObject payload = new JSONObject();
String missing_arg;
if (!loginAsRoot) {
if (username != null && !username.isEmpty()) {
payload.put("user", username);
}
else{
String userName = readUserName();
payload.put("user", userName);
}
if (password != null && !password.isEmpty()) {
payload.put("password", password);
}
else{
char[] passwordFromConsole = readPassword();
payload.put("password", new String(passwordFromConsole));
if(apiKey != null && !apiKey.isEmpty()){
payload.put("api-key", apiKey);
}else{
if (username != null && !username.isEmpty()) {
payload.put("user", username);
}
else{
String userName = readUserName();
payload.put("user", userName);
}
if (password != null && !password.isEmpty()) {
payload.put("password", password);
}
else{
char[] passwordFromConsole = readPassword();
payload.put("password", new String(passwordFromConsole));
}
}
}
if(domain != null && !domain.isEmpty()){
Expand Down Expand Up @@ -546,6 +552,10 @@ public Boolean getDereferenceGroupMembers()

public boolean showRuleUidFlag() { return showEachRulesUid; }

public String getApiKey() { return apiKey; }

public String getCloudMgmtId() { return cloudMgmtId; }

/**
* This enum defines the known flags and the actions each of them does.
*/
Expand Down Expand Up @@ -653,6 +663,43 @@ String debugString()
return "password:(-p)=*****";
}
},
adminApiKey("--api-key") {
void runCommand(String value)
{
apiKey = value;
}

void flagToString()
{
System.out.println("\tManagement administrator API key.");
}

String value(){
return " API key";
}

String debugString()
{
return "API key:(--api-key)=*****";
}
},
mgmtCloudId("--cloud-mgmt-id") {
void runCommand(String value) { cloudMgmtId = value; }

void flagToString()
{
System.out.println("\tSmart-1 Cloud management UID.");
}

String value(){
return " Smart-1 Cloud management UID";
}

String debugString()
{
return "Smart-1 Cloud management UID:(--cloud-mgmt-id)=" + cloudMgmtId;
}
},
domainName("-d") {
void runCommand(String value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static void main(String[] args) {
/*Login to the Check Point Management server*/
if (!loginAsRoot) {
try {
loginResponse = client.login(configuration.getServer(), configuration.createPayloadForLogin(false));
loginResponse = client.login(configuration.getServer(), configuration.createPayloadForLogin(false), configuration.getCloudMgmtId());
}
catch (ApiClientException e) {
logoutReportAndExit("An error occurred while logging in to the server. Exception: "+ e.getMessage(), MessageType.SEVERE);
Expand Down Expand Up @@ -292,7 +292,7 @@ private static void handlePublishedSession(IndexView index)
private static boolean isLoginAsRoot(){

/*Check if the user entered use name and password*/
if (configuration.getUsername() != null && configuration.getPassword() != null){
if (configuration.getUsername() != null && configuration.getPassword() != null && configuration.getApiKey() != null){
return false;
}

Expand Down

0 comments on commit 058319f

Please sign in to comment.