- 15 Aug 2022
- 9 Minutes to read
- Print
- DarkLight
File Actions
- Updated on 15 Aug 2022
- 9 Minutes to read
- Print
- DarkLight
File Actions
addSMBFileACE
Add Access Control Entry (ACE) to a file/directory on an SMB/CIFS file system.
Property | Value | Description |
smbFilesystem* | expression, variable | the filesystem definition to use (must be SMB/CIFS filesystem) |
path* | text, expression, variable | the path of the target file or directory |
principal* | text, expression, variable | The user or group to which the ACE applies. For single-domain environments, this will be the sAMAAccountName. If you are referencing a user account that is on another trusted domain, use the objectSid of the user |
type* | choice (ALLOW, DENY), text, expression, variable | the ACE type |
mask* | choice (NONE, READ_ONLY, READ_EXECUTE, CHANGE, FULL), text, expression, variable | the permissions mask |
containerInherit* | boolean, expression, variable | the ACE will be inherited by directories |
objectInherit* | boolean, expression, variable | the ACE will by files |
inheritOnly* | boolean, expression, variable | the ACE does not apply to the current file/directory |
noPropagateInherit* | boolean, expression, variable | the ACE does not propagate inheritance |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
smbFS = defineRemoteFilesystem("smb", "smbtestserver", "/testdir")
result = addSMBFileACE(smbFS, "/testdir", "testuser", "ALLOW",
"CHANGE", true, true, false, false)
buildFilePath
Build a file path from a directory path, file name, and optional added extension.
Property | Value | Description |
parentPath* | text, expression, variable | the parent path of the file |
name* | text, expression, variable | the file name |
ext | text, expression, variable | the added extension |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
path = buildFilePath("/home/bsmith","students","csv")
clearSMBFileACE
Clear Access Control Entry (ACE) from a file/directory on an SMB/CIFS file system.
Property | Value | Description |
smbFilesystem* | expression, variable | the filesystem definition to use (must be SMB/CIFS filesystem) |
path* | text, expression, variable | the path of the target file or directory |
principal* | text, expression, variable | the User or Group to clear |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
smbFS = defineRemoteFilesystem("smb", "smbtestserver", "/testdir")
result = clearSMBFileACE(smbFS, "/testdir", "testuser")
copyFile
Copy a file or directory.
Property | Value | Description |
srcFilesystem | expression, variable | the source filesystem definition to use (default: dss server managed files) |
srcPath* | text, expression, variable | the path of the source file or directory |
destFilesystem | expression, variable | the destination filesystem definition to use (default: dss server managed files) |
destPath* | text, expression, variable | the path of the destination file or directory |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
srcfs = defineRemoteFilesystem("sftp","host1","user","password","/")
destfs = defineRemoteFilesystem("sftp","host2","user","password","/")
result = copyFile(srcfs,"etc/hosts",destfs,"etc/hosts")
createDirectory
Create a directory.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the directory |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
fs = defineRemoteFilesystem("sftp","host","user","password",
"/home/bsmith")
createDirectory(fs,"dir1")
defineRemoteFilesystem
Define a remote filesystem.
Property | Value | Description |
protocol* | choice (sftp, ftp, ftps, smb, s3), text, expression, variable | The remote access protocol |
host* | text, expression, variable | The remote host name, address, or s3 [<region-or-endpoint>:]<bucket-name> |
port | expression, variable | The remote port (default: depends on protocol) |
user | text, expression, variable | The remote username (default:none) |
password | password, string, expression, variable | The remote password (default:none) |
basePath* | text, expression, variable | The path to the base of the filesystem object or Record containing extra configuration properties to customize the connection |
extraProperties | expression, variable | Defined below as applicable |
Field | Value |
connectTimeout | S3/FTP/FTPS Connection Timeout (in milliseconds (ms)) |
dataTimeout | FTP/FTPS Data Timeout or S3 Request Timeout (ms) |
ftpsImplicitMode | Set to true to use implicit mode (default explicit) |
ftpsProtC | Set to true to use PROT C (default is P) |
ftpsProtS | Set to true to use PROT S (default is P) |
ftpsProtE | Set to true to use PROT E (default is P) |
ftpsTrustAll | Set to true to trust all TLS Certificates |
ftpsTrustSelfSigned | Set to true to trust a self-signed TLS Certificate from the defined host |
sftp.passPhrase | The passphrase for sftp.privateKey (required if sftp.privateKey is passphrase protected). |
sftp.privateKey | SSH private key as a String in OpenSSH/PEM format. |
sftp.publicKey | SSH public key as a String in OpenSSH/PEM format (required if the sftp.privateKey is in a format that does not include the public key). |
socketTimeout | S3/FTP/FTPS Socket Timeout or SFTP Timeout (ms) |
userDirIsRoot | true = basePath is relative to the user's home directory false= (default) basePath is relative to the root directory where home is the directory where the user is initially placed upon login and root directory corresponds to the path / which may be the actual root of the physical file system or may be a virtual root, depending on how the file server is configured. Applies only to ftp and sftp. |
Various Properties for JCIFS NG | Multiple properties for JCIFS NG are now supported in RapidIdentity. These properties can be used for troubleshooting, performance enhancements, etc. as needed. Note This is only applicable when protocol = smb |
Property | Value | Description |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
fs = defineRemoteFilesystem("sftp","host","user","password",
"/home/bsmith")
deleteFile
Delete a file or directory.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the file |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
fs = defineRemoteFilesystem("sftp","host","user","password",
"/home/bsmith")
fileExists = isFile(fs,"deleteme")
if(fileExists) {
deleteFile(fs,"deleteme")
} else {
log("There is no file to delete")
}
getFileExtension
Get the extension from a file name or file path.
Property | Value | Description |
path* | text, expression, variable | the path of the file |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
# should return "log"
ext = getFileExtension("apache.log")
getFileName
Get the name from a file path.
Property | Value | Description |
path* | text, expression, variable | the path of the file |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
# should return ".XAuthority"
ext = getFileName("/home/jdoe/.XAuthority")
getFileParentDirectory
Get the parent directory path from a file path
Property | Value | Description |
path* | text, expression, variable | the path of the file |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
# should return "/home/jdoe"
ext = getFileParentDirectory("/home/jdoe/.XAuthority")
getFileSize
Gets the file size in bytes.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the file |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
size = getFileSize("/tmp/temp.jpg")
getFileTimestamp
Get the file timestamp.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the file |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
fileTimestamp = getFileTimestamp("/tmp/temp.jpg")
isDirectory
Test if a path is a directory.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path to test |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
isDir = isDirectory("/tmp")
isFile
Test if a path is a file.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path to test |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
isFile = isFile("/tmp/temp.jpg")
listFiles
List the files in a directory.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the directory |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
logDirs = listFiles("log/jobs")
forEach(dir, logDirs) {
# process log directory
}
loadFileAsBytes
Load the contents of a file as byte array.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the file |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
image = loadFileAsBytes("images/test.jpg")
loadFileAsString
Load the contents of a file as a string.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the file |
encoding | text, expression, variable | The character encoding of the file. Defaults ISO-8859-1 |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
templateText = loadFileAsString("template/test.json")
template = parseJSON(templateText)
loadFileAsXML
Load the contents of a file as XML.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the file |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
soapTemplate = loadFileAsXML("template/soapEnvelope.xml")
moveFile
Move and/or rename a file or directory.
Property | Value | Description |
srcFilesystem | expression, variable | the source filesystem definition to use (default: dss server managed files) |
srcPath* | text, expression, variable | The path of the source file or directory. |
destFilesystem | expression, variable | the destination filesystem definition to use (default: dss server managed files) |
destPath* | text, expression, variable | the path of the destination file or directory |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
srcfs = defineRemoteFilesystem("sftp","host1","user","password","/")
destfs = defineRemoteFilesystem("sftp","host2","user","password","/")
result = moveFile(srcfs,"/home/jdoe/install.bin",destfs,
"/home/jdoe/install.bin")
saveToFile
Save to a file.
Property | Value | Description |
filesystem | expression, variable | the filesystem definition to use (default: dss server managed files) |
path* | text, expression, variable | the path of the file |
value* | text, expression, variable | value to save to the file |
encoding | text, expression, variable | the character encoding of the file (default: UTF8 for XML, ISO-8859-1 for string)(ignored if value is a byte array) |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
saveToFile("temp/hello.txt","hello")
setSMBFileACE
Set Access Control Entry (ACE) to a file/directory on an SMB/CIFS file system, replacing any existing ACE for the given principal.
Property | Value | Description |
smbFilesystem* | expression, variable | the filesystem definition to use (must be SMB/CIFS filesystem) |
path* | text, expression, variable | the path of the target file or directory |
principal* | text, expression, variable | the User or Group to which the ACE applies |
type* | choice (ALLOW, DENY), text, expression, variable | the ACE type |
mask* | choice (NONE, READ_ONLY, READ_EXECUTE, CHANGE, FULL), text, expression, variable | the permissions mask |
containerInherit* | boolean, expression, variable | the ACE will be inherited by directories |
objectInherit* | boolean, expression, variable | the ACE will be inherited by files |
inheritOnly* | boolean, expression, variable | the ACE does not apply to the current file/directory |
noPropagateInherit* | boolean, expression, variable | the ACE does not propagate inheritance |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
smbFS = defineRemoteFilesystem("smb", "smbtestserver", "/testdir")
result = setSMBFileACE(smbFS, "/testdir", "testuser", "ALLOW",
"CHANGE", true, true, false, false)
unzipFile
Extract the contents of a ZIP archive.
Property | Value | Description |
zipFilesystem | expression, variable | the filesystem definition to use for the destination zip file (default: dss server managed files) |
zipPath* | text, expression, variable | the path of the zip file |
destFilesystem | expression, variable | the destination filesystem definition to use (default: dss server managed files) |
destDir* | text, expression, variable | the path of the directory to receive the extracted files |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
result = unzipFile("log/jobs/test.zip", "log/jobs/test/")
zipFile
Create a ZIP archive from a file or directory.
Property | Value | Description |
srcFilesystem | expression, variable | the source filesystem definition to use (default: dss server managed files) |
srcPath* | text, expression, variable | the path or array of paths to the files or directories to add the the ZIP file |
zipFilesystem | expression, variable | the filesystem definition to use for the destination zip file (default: dss server managed files) |
zipPath* | text, expression, variable | the path of the zip file |
compressionLevel | expression, variable | the level of compression to use (0-9) |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
# Add an item to the directories array for each directory
relative to the root / var / opt / idauto / dss / files /
to process
directories = createArray()
appendArrayItem(directories, "log/jobs/")
appendArrayItem(directories, "log/run/")
# Set deleteFiles to true
if the log files should be deleted after archival
deleteFiles = true
# Set deleteArchivesAfter to the number of days you want to retain
log files
for.Set it to 0 to keep all Archives.
deleteArchivesAfter = 30
# Set myActionName to the scheduled job name of this action to
avoid archiving it.
myActionName = "archiveLogs"
# Set deleteMyLogs to true
if the logs
for this job should be deleted after running
deleteMyLogs = true
# Begin code
currentTime = now()
parseDate = splitString(currentTime, " ")
currentDate = parseDate[2] + "-" + parseDate[1] + "-" + parseDate[3]
forEach(directory, directories) {
dir = listFiles(directory)
forEach(entry, dir) {
# Process directories
isDir = isDirectory(entry)
if (isDir && (entry != directory + myActionName)) {
parsePath = splitString(entry, "/")
path = directory + parsePath[2]
files = listFiles(entry)
# Find unique filename
for archive
archiveFile = path + "-" + currentDate + ".zip"
fileExists = isFile(archiveFile)
counter = 0
while (fileExists) {
archiveFile = path + "-" + currentDate
+ "-" + counter + ".zip"
fileExists = isFile(archiveFile)
counter = counter + 1
}
log("Creating archive: " + archiveFile)
retVal = zipFile(files, archiveFile)
if (retVal && deleteFiles) {
log("Deleting log files from " + path)
deleteFile(path)
} else {
}
} else {
}
# Process archives
for deletion
isAFile = isFile(entry)
isArchive = stringEndsWith(entry, ".zip", true)
if (isAFile && (deleteArchivesAfter != 0) && isArchive) {
datetime = getFileTimestamp(entry)
parseDate2 = splitString(datetime, " ")
fileDate = parseDate2[2] + "-" + parseDate2[1] + "-"
+ parseDate2[3]
dateFormat = new java.text.SimpleDateFormat("dd-MMM-yyyy")
difference = Math.round((dateFormat.parse(currentDate).getTime()
- dateFormat.parse(fileDate).getTime()) / (3600000 * 24))
# log("File: " + entry + " - " + difference)
if ((difference > deleteArchivesAfter)) {
log("Deleting archive " + entry)
deleteFile(entry)
} else {
}
} else {
}
}
logDirExists = isDirectory(directory + myActionName)
if (deleteMyLogs && logDirExists) {
log("Deleting my log files from " + directory + myActionName)
deleteFile(directory + myActionName)
} else {}
}