Skip to content

Commit 90a523f

Browse files
author
Bill Miller
committed
Added sample project for deploying Redaction Rulesets using Gradle. Also included optional Gradle task for validating Redaction Rulesets anytime after deploying
1 parent 87e58fc commit 90a523f

File tree

12 files changed

+154
-0
lines changed

12 files changed

+154
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/bin
2+
.classpath
3+
.project
4+
/build
5+
.gradle
6+
.settings
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This project shows an example of how MarkLogic 9 Redaction Rulesets can be loaded into a schemas
2+
database from src/main/ml-schemas (the default path - this can be overridden via
3+
mlSchemasPath).
4+
5+
Note that in order for this to work, the content-database.json file must specify the schema
6+
database that it's associated with. And in most cases, you'll want your own schemas database - not the default Schemas one - so schemas-database.json can be used to create own with a name based on mlAppName.
7+
8+
Within each folder containing one or more Redaction Rulesets, you must provide a **collecitons.properties** and **permissions.properties** file.
9+
These files contain the definitions for the applicable collections to be applied to the rulesets as well as the document permissions.
10+
11+
***Note***: Rulesets must have a .json or .xml file extension.
12+
13+
See [Specifying collections and permissions](https://github.com/marklogic-community/ml-javaclient-util/wiki/Loading-files#specifying-collections-and-permissions) for information on how to appliy the collections and permission when the rulesets are loaded
14+
15+
See [Redacting Document Content](http://docs.marklogic.com/guide/app-dev/redaction) for more information on redacting content
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
// Needed for corb dependency: XCC
5+
maven { url "http://developer.marklogic.com/maven2/" }
6+
}
7+
dependencies {
8+
//Needed for CorbTask to dynamicaly generate properties from CORB Options class
9+
classpath 'com.marklogic:marklogic-corb:2.3.2'
10+
}
11+
}
12+
13+
plugins {
14+
id "com.marklogic.ml-gradle" version "3.0.0"
15+
}
16+
17+
repositories {
18+
jcenter()
19+
20+
// Needed for corb dependency: XCC
21+
maven { url "http://developer.marklogic.com/maven2/" }
22+
}
23+
24+
configurations {
25+
// This configuration captures the dependencies for running corb (Content Reprocessing in Bulk).
26+
// This is only needed if you want to run corb via Gradle tasks.
27+
// If you do, using com.marklogic.gradle.task.CorbTask is a useful starting point, as shown below.
28+
corb
29+
}
30+
31+
dependencies {
32+
// required to run CoRB2
33+
corb 'com.marklogic:marklogic-corb:2.3.2'
34+
// optional
35+
//corb 'org.jasypt:jasypt:1.9.2' // would be necessary to leverage JasyptDecrypter
36+
}
37+
38+
/*
39+
* ml-gradle adds an instance of com.marklogic.appdeployer.AppConfig to the Gradle project under the key "mlAppConfig".
40+
* This instance can be modified to affect the behavior of ml-gradle.
41+
*/
42+
ext {
43+
// mlAppConfig is an instance of com.marklogic.appdeployer.AppConfig
44+
mlAppConfig {
45+
// XCC URL for running corb task below and for creating triggers on pre-8.0-4 builds of MarkLogic
46+
contentXccUrl = "xcc://${mlUsername}:${mlPassword}@${mlHost}:${mlRestPort}"
47+
}
48+
}
49+
50+
/*
51+
* This optional task demonstrates validating redaction rules via a locally run CORB process.
52+
* To execute this task simply run it after you have successfully deployed the redaction rulesets (via mlAppDeploy or mlLoadSchemas).
53+
*/
54+
task validateRedactionRulesetsAdhoc(type: com.marklogic.gradle.task.CorbTask) {
55+
xccConnectionUri = contentXccUrl
56+
urisModule = "src/main/ml-modules/ext/redaction-ruleset-validation/corb/redaction-rules-uris.xqy|ADHOC"
57+
processModule = "src/main/ml-modules/ext/redaction-ruleset-validation/corb/validate-redaction-rules.xqy|ADHOC"
58+
59+
}
60+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mlHost=localhost
2+
mlAppName=redaction-project
3+
mlRestPort=8130
4+
mlUsername=admin
5+
mlPassword=admin
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"database-name": "%%DATABASE%%",
3+
"schema-database": "%%SCHEMAS_DATABASE%%"
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"database-name": "%%SCHEMAS_DATABASE%%"
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
xquery version "1.0-ml";
2+
3+
let $uris :=
4+
xdmp:invoke-function(
5+
function() { cts:uris((), (), cts:directory-query("/redactionRules/")) },
6+
<options xmlns="xdmp:eval">
7+
<database>{xdmp:database("redaction-project-schemas")}</database>
8+
</options>)
9+
10+
return (count($uris), $uris)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
xquery version "1.0-ml";
2+
import module namespace rdt = "http://marklogic.com/xdmp/redaction" at "/MarkLogic/redaction.xqy";
3+
4+
5+
declare variable $URI external;
6+
7+
let $collections :=
8+
xdmp:invoke-function(
9+
function() { xdmp:document-get-collections($URI) },
10+
<options xmlns="xdmp:eval">
11+
<database>{xdmp:database("redaction-project-schemas")}</database>
12+
</options>)
13+
14+
15+
return rdt:rule-validate(($collections))
16+
17+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Add one or more collecitons to add the ruleset to (comma separated)
2+
# Example: file.json=collection1,collection2
3+
4+
ssn.json=security-rules,pii-rules
5+
email.json=security-rules,email-rules
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"rule": {
3+
"description": "hide email addresses",
4+
"path": "//email",
5+
"method": {
6+
"function": "redact-email"
7+
},
8+
"options": {
9+
"pattern": "partial"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)