-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
config.go
80 lines (72 loc) · 2.4 KB
/
config.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
package junos
import (
"fmt"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)
// configProvider.
type configProvider struct {
junosFakeUpdateAlso bool
junosFakeDeleteAlso bool
junosPort int
junosCmdSleepShort int
junosCmdSleepLock int
junosSSHSleepClosed int
junosSSHTimeoutToEstab int
junosIP string
junosUserName string
junosPassword string
junosSSHKeyPEM string
junosSSHKeyFile string
junosKeyPass string
junosGroupIntDel string
junosFilePermission string
junosDebugNetconfLogPath string
junosFakeCreateSetFile string
junosSSHCiphers []string
}
// prepareSession : prepare information to connect to Junos Device and more.
func (c *configProvider) prepareSession() (*Session, diag.Diagnostics) {
sess := &Session{
junosIP: c.junosIP,
junosPort: c.junosPort,
junosUserName: c.junosUserName,
junosPassword: c.junosPassword,
junosSSHKeyPEM: c.junosSSHKeyPEM,
junosKeyPass: c.junosKeyPass,
junosGroupIntDel: c.junosGroupIntDel,
junosSleepLock: c.junosCmdSleepLock,
junosSleepShort: c.junosCmdSleepShort,
junosSleepSSHClosed: c.junosSSHSleepClosed,
junosSSHCiphers: c.junosSSHCiphers,
junosSSHTimeoutToEstab: c.junosSSHTimeoutToEstab,
junosFakeUpdateAlso: c.junosFakeUpdateAlso,
junosFakeDeleteAlso: c.junosFakeDeleteAlso,
}
// junosSSHKeyFile
sshKeyFile := c.junosSSHKeyFile
if err := replaceTildeToHomeDir(&sshKeyFile); err != nil {
return sess, diag.FromErr(err)
}
sess.junosSSHKeyFile = sshKeyFile
// junosFilePermission
filePermission, err := strconv.ParseInt(c.junosFilePermission, 8, 64)
if err != nil {
return sess, diag.FromErr(fmt.Errorf("failed to convert value from '%s' to int64: %w",
c.junosFilePermission, err))
}
sess.junosFilePermission = filePermission
// junosLogFile
junosLogFile := c.junosDebugNetconfLogPath
if err := replaceTildeToHomeDir(&junosLogFile); err != nil {
return sess, diag.FromErr(err)
}
sess.junosLogFile = junosLogFile
// junosFakeCreateSetFile
junosFakeCreateSetFile := c.junosFakeCreateSetFile
if err := replaceTildeToHomeDir(&junosFakeCreateSetFile); err != nil {
return sess, diag.FromErr(err)
}
sess.junosFakeCreateSetFile = junosFakeCreateSetFile
return sess, nil
}