Skip to content

Commit

Permalink
Final Changes
Browse files Browse the repository at this point in the history
- Added documentation
- Error handling
- Content-type additions
- Build changes
- General clean-up
- Version bump
  • Loading branch information
neil-mcglennon-sp committed May 1, 2024
1 parent 83cb3a6 commit 3c87ce2
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 269 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ replay_pid*
.DS_Store
/.idea
/.gradle
/bin
/build
/out
517 changes: 313 additions & 204 deletions README.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'sailpoint.cloud'
version '4.0.0-rc2'
version '4.0.0'

repositories {
mavenCentral()
Expand Down Expand Up @@ -34,7 +34,6 @@ jar {

dependencies {
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'org.jcommander:jcommander:1.83'
implementation 'org.apache.commons:commons-lang3:3.14.0'
implementation 'org.apache.commons:commons-collections4:4.5.0-M1'
implementation 'commons-io:commons-io:2.16.1'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sailpoint/service/SailPointService.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Session createSession() throws Exception {
if ( response.isSuccessful() )
session = response.body();
else
throw new Exception ( "Error obtaining session! " + response.code() + " " + response.message() );
throw new Exception ( "Error authenticating with credentials: " + response.code() + " " + response.message() );

} catch ( IOException e ) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Call<Session> getSession(
@Query( "client_id" ) String client_id,
@Query( "client_secret" ) String client_secret );

@Headers( "Content-Type: application/json" )
@GET( "beta/sources/")
Call<List<Source>> listSources(
@Query( QUERY_COUNT ) boolean count,
Expand All @@ -27,6 +28,7 @@ Call<List<Source>> listSources(
@Query( "filters" ) String filters,
@Query( "sorters" ) String sorters );

@Headers( "Content-Type: application/json" )
@GET( "beta/sources/{id}")
Call<Source> getSource(
@Path( "id" ) String id );
Expand Down
108 changes: 55 additions & 53 deletions src/main/java/sailpoint/utils/FileUploadUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static sailpoint.utils.FileUploadUtility.*;

@CommandLine.Command(
usageHelpAutoWidth = true,
name = "java -jar sailpoint-file-upload-utility.jar",
sortOptions = false,
headerHeading = "%nUsage:%n%n",
Expand All @@ -38,8 +39,8 @@ public class FileUploadUtility implements Callable<Integer> {
/**
* Metadata about the File Upload Utility
*/
public static final String ABOUT_DATE = "2024-04-29 11:07 CST";
public static final String ABOUT_VERSION = "4.0.0 RC 2";
public static final String ABOUT_DATE = "2024-05-01 9:00 CST";
public static final String ABOUT_VERSION = "4.0.0";
public static final String ABOUT_LINK = "https://developer.sailpoint.com/discuss/t/file-upload-utility/18181";

/**
Expand Down Expand Up @@ -146,6 +147,12 @@ public static void main( String[] args ) throws Exception {
} catch ( UnsupportedClassVersionError ue ) {

System.out.println( "Unsupported version of Java: Please upgrade to JDK 11 or higher." );
System.exit( 1 );

} catch ( RuntimeException rte ) {

System.out.println( rte.getMessage() );
System.exit( 1 );

} catch ( Exception e ) {

Expand All @@ -171,8 +178,20 @@ public Integer call() throws Exception {
logger.info( String.format("%1$-20s %2$-30s ", " Docs:", ABOUT_LINK ) );
logger.info( "------------------------------------------------------------------------------------------------------------" );

validateParameters();
/*
* Perform some basic validations of the parameters provided. Picocli already does validation of required parameters.
*/

if ( !StringUtils.startsWithIgnoreCase( url, "https://" ) )
throw new RuntimeException( "Usage: The provided --url parameter must begin with 'https://'" );

if ( !(StringUtils.endsWithIgnoreCase( url, ".api.identitynow.com" ) || StringUtils.endsWithIgnoreCase( url, ".api.identitynow-demo.com" ) ) )
throw new RuntimeException( "Usage: The provided --url parameter must be a valid API URL. Please see documentation around allowed URLs." );

/*
* Display configurations so that people can see how this is will run. Also, useful for troubleshooting.
* We do not want to display the client secret here for security reasons.
*/
logger.info( String.format("%1$-20s %2$-30s ", " URL:", url ) );
logger.info( String.format("%1$-20s %2$-30s ", " Client ID:", clientId ) );
logger.info( String.format("%1$-20s %2$-30s ", " Files:", StringUtils.join( files, ", \n" ) ) );
Expand All @@ -190,6 +209,9 @@ public Integer call() throws Exception {

Timer.start();

/*
* Create a SailPoint Service which will do all the API calls.
*/
this.sailPointService = new SailPointService.Builder()
.url( url )
.clientId( clientId )
Expand All @@ -202,8 +224,8 @@ public Integer call() throws Exception {
if ( proxyHost != null && proxyPort != -1 )
logger.debug( "Proxy enabled! Initializing proxy with settings: proxyHost[" + proxyHost + "], proxyPort[" + proxyPort + "]." );

/**
* Start processing files...
/*
* Check to make sure credentials are valid before we process files.
*/

logger.info( "Checking credentials..." );
Expand All @@ -213,10 +235,14 @@ public Integer call() throws Exception {
sailPointService.createSession();

} catch ( Exception e ) {
logger.error( "Error Logging into Identity Security Cloud. Check your credentials and try again. [" + e.getMessage() + "]" );
logger.error( "Error Logging into Identity Security Cloud. Please check your credentials and try again. [" + e.getMessage() + "]" );
System.exit(1);
}

/*
* Start processing files...
*/

if ( CollectionUtils.isNotEmpty( files ) ) {

for (File file : files ) {
Expand Down Expand Up @@ -267,32 +293,6 @@ public Integer call() throws Exception {
return 0;
}

/*
* This function validates the configuration parameters.
*/
private void validateParameters() {

if ( url == null ) {
logger.error( "Usage: You must specify a -url parameter." );
System.exit( 1 );
}

if ( !StringUtils.startsWithIgnoreCase( url, "https://" ) ) {
logger.error( "Usage: Your -url parameter must begin with 'https://'" );
System.exit( 1 );
}

if ( !(StringUtils.endsWithIgnoreCase( url, ".api.identitynow.com" ) || StringUtils.endsWithIgnoreCase( url, ".api.identitynow-demo.com" ) ) ) {
logger.error( "Usage: Your -url parameter must be a valid API URL. Please see documentation around allowed URLs." );
System.exit( 1 );
}

if ( clientId == null || clientSecret == null ) {
logger.info( "Usage: You must specify a SailPoint Personal Access Token Client ID or Secret. Review the documentation for further details." );
System.exit( 1 );
}
}

/*
* Helper Methods
*/
Expand Down Expand Up @@ -391,16 +391,17 @@ private Map<String, String> buildSourceReferenceMap() {

}

private String getSourceReferenceFromFile(File file) {

// First, look for the new-form Source ID in the file name
// This can be found on the Source object as "id": "2c918087701c40cf01701dfdf2c61e2a"
// and consists of 32 characters of any 0-9, a-f
//
// We'll parse the file name, and extract the new-form Source ID
// e.g., 2c918087701c40cf01701dfdf2c61e2a - Something.csv
// Would return "2c918087701c40cf01701dfdf2c61e2a"
private String getSourceReferenceFromFile( File file ) {

/*
* First, look for the new-form Source ID in the file name
* This can be found on the Source object as "id": "2c918087701c40cf01701dfdf2c61e2a"
* and consists of 32 characters of any 0-9, a-f
*
* We'll parse the file name, and extract the new-form Source ID
* e.g., 2c918087701c40cf01701dfdf2c61e2a - Something.csv
* Would return "2c918087701c40cf01701dfdf2c61e2a"
*/
Matcher newMatcher = Pattern
.compile("^(\\s)?([0-9a-f]{32})")
.matcher(file.getName());
Expand All @@ -415,17 +416,18 @@ private String getSourceReferenceFromFile(File file) {

}

// Second, look for the old-form Source ID in the file name
// This is mainly there for backwards compatibility purposes.
//
// This can be found on the Source object under "connectorAttributes"
// as "cloudExternalId": "184744"
// and consists of up to 10 characters of any number (0-9)
//
// We'll parse the file name, and extract the old-form Source ID
// e.g., 184744 - Something.csv
// Would return "184744"

/*
* Second, look for the old-form Source ID in the file name
* This is mainly there for backwards compatibility purposes.
*
* This can be found on the Source object under "connectorAttributes"
* as "cloudExternalId": "184744"
* and consists of up to 10 characters of any number (0-9)
*
* We'll parse the file name, and extract the old-form Source ID
* e.g., 184744 - Something.csv
* Would return "184744"
*/
Matcher oldMatcher = Pattern
.compile("^(\\s)?([0-9]{4,10})")
.matcher(file.getName());
Expand All @@ -446,7 +448,7 @@ private String getSourceReferenceFromFile(File file) {

/*
* At this point, the sourceReferenceMap is not null, and has already been initialized.
* Lets query what we have to see if we can resolve the oldSourceReference to the newSourceReference.
* Let's query what we have to see if we can resolve the oldSourceReference to the newSourceReference.
*/

if (this.sourceReferenceMap.containsKey(fileSourceId)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sailpoint/utils/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public Logger() {
this( false );
}

public Logger(boolean verbose) {
public Logger( boolean verbose ) {
super();
this.verbose = verbose;
}
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/sailpoint/utils/Reporter.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package sailpoint.utils;

import javax.swing.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Reporter {

enum MessageType {
SUCCESS,
ERROR,
SKIPPED
}

private List<String> errorMessages;
private List<String> skippedMessages;
private List<String> successMessages;
Expand Down

0 comments on commit 3c87ce2

Please sign in to comment.