Files
ucs-exporter/local/go-ucs/api/example_aaa_refresh_test.go
Nathan Coad 95a48a89a6
All checks were successful
continuous-integration/drone/push Build is passing
test build
2023-09-28 11:55:15 +10:00

52 lines
1.2 KiB
Go
Executable File

package api_test
import (
"context"
"crypto/tls"
"log"
"net/http"
"github.com/dnaeon/go-ucs/api"
)
func Example_aaaRefresh() {
// The following example shows how to refresh an existing session.
// Skip SSL certificate verification of remote endpoint.
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
httpClient := &http.Client{Transport: tr}
// Create a new Cisco UCS API client
config := api.Config{
Endpoint: "https://ucs01.example.org/",
Username: "admin",
Password: "password",
HttpClient: httpClient,
}
client, err := api.NewClient(config)
if err != nil {
log.Fatalf("Unable to create API client: %s", err)
}
ctx := context.Background()
// Authenticate to the remote API endpoint and obtain authentication cookie
log.Printf("Logging in to %s\n", config.Endpoint)
if _, err := client.AaaLogin(ctx); err != nil {
log.Fatalf("Unable to authenticate: %s", err)
}
defer client.AaaLogout(ctx)
log.Printf("Got authentication cookie: %s\n", client.Cookie)
log.Println("Refreshing session")
if _, err := client.AaaRefresh(ctx); err != nil {
log.Fatalf("Unable to refresh session: %s\n", err)
}
log.Printf("New authentication cookie is: %s\n", client.Cookie)
}