-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38f6d5e
commit 3cca54a
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"crypto/x509" | ||
"flag" | ||
"io/ioutil" | ||
"time" | ||
|
||
"github.com/bmc-toolbox/bmclib/v2" | ||
"github.com/bmc-toolbox/bmclib/v2/providers" | ||
"github.com/bombsimon/logrusr/v2" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
user := flag.String("user", "", "Username to login with") | ||
pass := flag.String("password", "", "Username to login with") | ||
host := flag.String("host", "", "BMC hostname to connect to") | ||
withSecureTLS := flag.Bool("secure-tls", false, "Enable secure TLS") | ||
certPoolFile := flag.String("cert-pool", "", "Path to an file containing x509 CAs. An empty string uses the system CAs. Only takes effect when --secure-tls=true") | ||
flag.Parse() | ||
|
||
l := logrus.New() | ||
l.Level = logrus.DebugLevel | ||
logger := logrusr.New(l) | ||
|
||
if *host == "" || *user == "" || *pass == "" { | ||
l.Fatal("required host/user/pass parameters not defined") | ||
} | ||
|
||
clientOpts := []bmclib.Option{ | ||
bmclib.WithLogger(logger), | ||
bmclib.WithRedfishUseBasicAuth(true), | ||
} | ||
|
||
if *withSecureTLS { | ||
var pool *x509.CertPool | ||
if *certPoolFile != "" { | ||
pool = x509.NewCertPool() | ||
data, err := ioutil.ReadFile(*certPoolFile) | ||
if err != nil { | ||
l.Fatal(err) | ||
} | ||
pool.AppendCertsFromPEM(data) | ||
} | ||
// a nil pool uses the system certs | ||
clientOpts = append(clientOpts, bmclib.WithSecureTLS(pool)) | ||
} | ||
|
||
cl := bmclib.NewClient(*host, *user, *pass, clientOpts...) | ||
cl.Registry.Drivers = cl.Registry.Supports(providers.FeatureSELClear) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
defer cancel() | ||
|
||
err := cl.Open(ctx) | ||
if err != nil { | ||
l.WithError(err).Fatal(err, "BMC login failed") | ||
} | ||
defer cl.Close(ctx) | ||
|
||
err = cl.ClearSEL(ctx) | ||
if err != nil { | ||
l.WithError(err).Error() | ||
} | ||
l.Info("SEL cleared") | ||
} |