Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cheynearista committed Mar 12, 2020
2 parents f5838f8 + 2bad72c commit 7944bce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
9 changes: 7 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ func (n *Node) GetSection(regex string, config string) (string, error) {
return config[blockStart:blockEnd], nil
}

// Config the node with the specified commands
// ConfigWithErr the node with the specified commands
//
// This method is used to send configuration commands to the node.
// It will takes a list of strings and prepend the necessary commands
// to put the session into config mode.
// to put the session into config mode. Returns error if issues arise.
func (n *Node) ConfigWithErr(commands ...string) error {
commands = append([]string{"configure terminal"}, commands...)
_, err := n.runCommands(commands, "json")
Expand All @@ -271,6 +271,11 @@ func (n *Node) ConfigWithErr(commands ...string) error {
return err
}

// Config the node with the specified commands
//
// This method is used to send configuration commands to the node.
// It will takes a list of strings and prepend the necessary commands
// to put the session into config mode.
func (n *Node) Config(commands ...string) bool {
err := n.ConfigWithErr(commands...)
return (err == nil)
Expand Down
20 changes: 11 additions & 9 deletions eapilib.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type EapiConnection struct {
host string
port int
path string
auth string
auth *url.Userinfo
timeOut uint32
}

Expand Down Expand Up @@ -96,21 +96,23 @@ func (conn *EapiConnection) Execute(commands []interface{},
// password (string): The password in clear text to use to authenticate
// the eAPI connection with
func (conn *EapiConnection) Authentication(username string, passwd string) {
auth := username + ":" + passwd
//data := []byte(auth)
//str := base64.StdEncoding.EncodeToString(data)
//str = strings.Replace(str,"\n","",-1)
str := strings.Replace(auth, "\n", "", -1)
conn.auth = url.PathEscape(str)
username = strings.Replace(username, "\n", "", -1)
passwd = strings.Replace(passwd, "\n", "", -1)
conn.auth = url.UserPassword(username, passwd)
}

// getURL helper method to prebuild url for http/s
func (conn *EapiConnection) getURL() string {
if conn == nil {
return ""
}
url := conn.transport + "://" + conn.auth + "@" + conn.host + ":" + strconv.Itoa(conn.port) + "/command-api"
return url
url := url.URL{
Scheme: conn.transport,
User: conn.auth,
Host: conn.host + ":" + strconv.Itoa(conn.port),
Path: "/command-api",
}
return url.String()
}

// Error returns the current error for Connection
Expand Down

0 comments on commit 7944bce

Please sign in to comment.