forked from PaloAltoNetworks/pango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.go
53 lines (44 loc) · 1.24 KB
/
connect.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
package pango
/*
Connect opens a connection to the PAN-OS client, then uses the "model" info
to return a pointer to either a Firewall or Panorama struct.
The Initialize function is invoked as part of this discovery, so there is no
need to Initialize() the Client connection prior to invoking this.
*/
func Connect(c Client) (interface{}, error) {
var err error
logg := c.Logging
c.Logging = LogQuiet
if err = c.Initialize(); err != nil {
return nil, err
}
model := c.SystemInfo["model"]
if model == "Panorama" || model[:2] == "M-" {
pano := &Panorama{Client: c}
pano.Logging = logg
if err = pano.Initialize(); err != nil {
return nil, err
}
return pano, nil
} else {
fw := &Firewall{Client: c}
fw.Logging = logg
if err = fw.Initialize(); err != nil {
return nil, err
}
return fw, nil
}
}
/*
ConnectUsing does Connect(), but takes in a filename that contains
fallback authentication credentials if they aren't specified.
The order of preference for auth / connection settings is:
* explicitly set
* environment variable (set chkenv to true to enable this)
* json file
*/
func ConnectUsing(c Client, filename string, chkenv bool) (interface{}, error) {
c.CheckEnvironment = chkenv
c.credsFile = filename
return Connect(c)
}