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.database.IDbFactory; |
19
|
|
|
import com.strider.datadefender.database.metadata.TableMetaData.ColumnMetaData; |
20
|
|
|
import com.strider.datadefender.discoverer.DatabaseDiscoverer; |
21
|
|
|
|
22
|
|
|
import java.io.File; |
23
|
|
|
import java.util.List; |
24
|
|
|
import java.util.concurrent.Callable; |
25
|
|
|
|
26
|
|
|
import picocli.CommandLine.ArgGroup; |
27
|
|
|
import picocli.CommandLine.Command; |
28
|
|
|
import picocli.CommandLine.Model.CommandSpec; |
29
|
|
|
import picocli.CommandLine.Option; |
30
|
|
|
import picocli.CommandLine.ParentCommand; |
31
|
|
|
import picocli.CommandLine.Spec; |
32
|
|
|
|
33
|
|
|
import org.apache.commons.lang3.StringUtils; |
34
|
|
|
|
35
|
|
|
import lombok.extern.log4j.Log4j2; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* "discover" picocli subcommand, configures and executes the data discoverer. |
39
|
|
|
* |
40
|
|
|
* @author Zaahid Bateson |
41
|
|
|
*/ |
42
|
|
|
@Command( |
43
|
|
|
name = "data", |
44
|
|
|
version = "1.0", |
45
|
|
|
mixinStandardHelpOptions = true, |
46
|
|
|
description = "Run data discovery utility" |
47
|
|
|
) |
48
|
|
|
@Log4j2 |
49
|
|
|
public class DiscoverData implements Callable<Integer>, IRequirementCommand { |
50
|
|
|
|
51
|
|
|
@ArgGroup(exclusive = false, multiplicity = "1", heading = "Model discovery settings%n") |
52
|
|
|
private ModelDiscoveryConfig modelDiscoveryConfig; |
53
|
|
|
|
54
|
|
|
@ArgGroup(exclusive = false, multiplicity = "0..1", heading = "Database connection settings%n") |
55
|
|
|
private DbConfig dbConfig; |
56
|
|
|
|
57
|
|
|
@ParentCommand |
58
|
|
|
private Discover discover; |
59
|
|
|
|
60
|
|
|
@Spec |
61
|
|
|
private CommandSpec spec; |
62
|
|
|
|
63
|
|
|
private List<ColumnMetaData> results; |
64
|
|
|
|
65
|
|
|
@Option(names = { "-o", "--output" }, description = "Generate a requirements xml file and write it out to the specified file") |
66
|
|
|
public void setOutputFile(File f) { |
67
|
|
|
discover.setOutputFile(f); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
@Override |
71
|
|
|
public Integer call() throws Exception { |
72
|
|
|
|
73
|
|
|
if (dbConfig == null) { |
74
|
|
|
dbConfig = discover.getDbConfig(); |
75
|
|
|
} else { |
76
|
|
|
discover.setDbConfig(dbConfig); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
System.out.println(""); |
80
|
|
|
System.out.println("Starting data discovery"); |
81
|
|
|
log.warn("Discovery writes personal data to log files."); |
82
|
|
|
|
83
|
|
|
log.info("Datasource URL: {}, vendor: {}, schema: {}", dbConfig.getUrl(), dbConfig.getVendor(), dbConfig.getSchema()); |
84
|
|
|
log.info("Username: {}, Password provided: {}", dbConfig.getUsername(), (StringUtils.isNotBlank(dbConfig.getPassword()) ? "yes" : "no")); |
85
|
|
|
log.info("Probability threshold: {}", modelDiscoveryConfig.getProbabilityThreshold()); |
86
|
|
|
log.info("Calculate score: {}", (modelDiscoveryConfig.getCalculateScore()) ? "yes" : "no"); |
87
|
|
|
log.info("Threshold count: {}", modelDiscoveryConfig.getThresholdCount()); |
88
|
|
|
log.info("Threshold high-risk count: {}", modelDiscoveryConfig.getThresholdHighRisk()); |
89
|
|
|
log.info("Limit: {}", modelDiscoveryConfig.getLimit()); |
90
|
|
|
log.info("Built-in models: {}", StringUtils.join(modelDiscoveryConfig.getModels(), ", ")); |
91
|
|
|
log.info("Custom models: {}", StringUtils.join(modelDiscoveryConfig.getFileModels(), ", ")); |
92
|
|
|
log.info("Custom token model: {}", modelDiscoveryConfig.getTokenModel()); |
93
|
|
|
log.info("Extensions: {}", StringUtils.join(modelDiscoveryConfig.getExtensions(), ", ")); |
94
|
|
|
|
95
|
|
|
IDbFactory factory = IDbFactory.get(dbConfig); |
96
|
|
|
DatabaseDiscoverer dd = new DatabaseDiscoverer(modelDiscoveryConfig, factory); |
97
|
|
|
results = dd.discover(); |
98
|
|
|
|
99
|
|
|
discover.afterSubcommand(); |
100
|
|
|
return 0; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
@Override |
104
|
|
|
public List<ColumnMetaData> getColumnMetaData() { |
105
|
|
|
return results; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|