1
|
|
|
/* |
2
|
|
|
* Copyright 2014, Armenak Grigoryan, and individual contributors as indicated |
3
|
|
|
* by the @authors tag. See the copyright.txt in the distribution for a |
4
|
|
|
* full listing of individual contributors. |
5
|
|
|
* |
6
|
|
|
* This is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU Lesser General Public License as |
8
|
|
|
* published by the Free Software Foundation; either version 2.1 of |
9
|
|
|
* the License, or (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This software is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14
|
|
|
* Lesser General Public License for more details. |
15
|
|
|
*/ |
16
|
|
|
package com.strider.datadefender; |
17
|
|
|
|
18
|
|
|
import com.strider.datadefender.discoverer.FileDiscoverer; |
19
|
|
|
import java.io.File; |
20
|
|
|
import java.util.List; |
21
|
|
|
import java.util.concurrent.Callable; |
22
|
|
|
|
23
|
|
|
import picocli.CommandLine.ArgGroup; |
24
|
|
|
import picocli.CommandLine.Command; |
25
|
|
|
import picocli.CommandLine.Option; |
26
|
|
|
import picocli.CommandLine.ParentCommand; |
27
|
|
|
|
28
|
|
|
import lombok.extern.log4j.Log4j2; |
29
|
|
|
import org.apache.commons.lang3.StringUtils; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* "discover" picocli subcommand, configures and executes the data discoverer. |
34
|
|
|
* |
35
|
|
|
* @author Zaahid Bateson |
36
|
|
|
*/ |
37
|
|
|
@Command( |
38
|
|
|
name = "files", |
39
|
|
|
version = "1.0", |
40
|
|
|
mixinStandardHelpOptions = true, |
41
|
|
|
description = "Run file discovery utility" |
42
|
|
|
) |
43
|
|
|
@Log4j2 |
44
|
|
|
public class DiscoverFiles implements Callable<Integer> { |
45
|
|
|
|
46
|
|
|
@ArgGroup(exclusive = false, multiplicity = "1", heading = "Model discovery settings%n") |
47
|
|
|
private ModelDiscoveryConfig modelDiscoveryConfig; |
48
|
|
|
|
49
|
|
|
@Option(names = { "-d", "--directory" }, description = "Adds a directory to list of directories to be scanned", required = true) |
50
|
|
|
private List<File> directories; |
51
|
|
|
|
52
|
|
|
@Option(names = { "-x", "--exclude-extension" }, description = "Adds an extension to exclude from data discovery") |
53
|
|
|
private List<String> excludeExtensions; |
54
|
|
|
|
55
|
|
|
@ParentCommand |
56
|
|
|
private Discover discover; |
57
|
|
|
|
58
|
|
|
@Override |
59
|
|
|
public Integer call() throws Exception { |
60
|
|
|
System.out.println(""); |
61
|
|
|
System.out.println("Starting file discovery"); |
62
|
|
|
log.warn("Discovery writes personal data to log files."); |
63
|
|
|
|
64
|
|
|
log.info("Probability threshold: {}", modelDiscoveryConfig.getProbabilityThreshold()); |
65
|
|
|
log.info("Calculate score: {}", (modelDiscoveryConfig.getCalculateScore()) ? "yes" : "no"); |
66
|
|
|
log.info("Threshold count: {}", modelDiscoveryConfig.getThresholdCount()); |
67
|
|
|
log.info("Threshold high-risk count: {}", modelDiscoveryConfig.getThresholdHighRisk()); |
68
|
|
|
log.info("Limit: {}", modelDiscoveryConfig.getLimit()); |
69
|
|
|
log.info("Built-in models: {}", StringUtils.join(modelDiscoveryConfig.getModels(), ", ")); |
70
|
|
|
log.info("Custom models: {}", StringUtils.join(modelDiscoveryConfig.getFileModels(), ", ")); |
71
|
|
|
log.info("Custom token model: {}", modelDiscoveryConfig.getTokenModel()); |
72
|
|
|
log.info("Extensions: {}", StringUtils.join(modelDiscoveryConfig.getExtensions(), ", ")); |
73
|
|
|
log.info("Directories: {}", StringUtils.join(directories, ", ")); |
74
|
|
|
log.info("File types not considered for analysis: {}", excludeExtensions); |
75
|
|
|
|
76
|
|
|
FileDiscoverer fd = new FileDiscoverer(modelDiscoveryConfig, directories, excludeExtensions); |
77
|
|
|
fd.discover(); |
78
|
|
|
|
79
|
|
|
return 0; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|