forked from bippio/go-impala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumerateDB.go
executable file
·81 lines (66 loc) · 1.67 KB
/
enumerateDB.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
// Simple program to list databases and the tables
import (
"context"
"fmt"
"log"
impala "github.com/bippio/go-impala"
)
func main() {
host := "<impala host>"
port := 21000
opts := impala.DefaultOptions
// enable LDAP authentication:
opts.UseLDAP = true
opts.Username = "<ldap username>"
opts.Password = "<ldap password>"
// enable TLS
opts.UseTLS = true
opts.CACertPath = "/path/to/cacert"
con, err := impala.Connect(host, port, &opts)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
var rows impala.RowSet
// get all databases for the connection object
query := fmt.Sprintf("SHOW DATABASES")
rows, err = con.Query(ctx, query)
if err != nil {
log.Fatal("error in retrieving databases: ", err)
}
databases := make([]string, 0) // databases will contain all the DBs to enumerate later
for rows.Next(ctx) {
row := make(map[string]interface{})
err = rows.MapScan(row)
if err != nil {
log.Println(err)
continue
}
if db, ok := row["name"].(string); ok {
databases = append(databases, db)
}
}
log.Println("List of Databases", databases)
for _, d := range databases {
q := "SHOW TABLES IN " + d
rows, err = con.Query(ctx, q)
if err != nil {
log.Printf("error in querying database %s: %s", d, err.Error())
continue
}
tables := make([]string, 0) // databases will contain all the DBs to enumerate later
for rows.Next(ctx) {
row := make(map[string]interface{})
err = rows.MapScan(row)
if err != nil {
log.Println(err)
continue
}
if tab, ok := row["name"].(string); ok {
tables = append(tables, tab)
}
}
log.Printf("List of Tables in Database %s: %v\n", d, tables)
}
}