output result as json
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nathan Coad
2023-07-19 15:08:19 +10:00
parent db0b104a58
commit 5f6f116068

31
main.go
View File

@@ -2,12 +2,19 @@ package main
import (
"crypto/x509"
"encoding/json"
"flag"
"fmt"
auth "github.com/korylprince/go-ad-auth/v3"
)
type Output struct {
Server string
AuthSuccess bool
Error string
}
const WSDCCertPem = `
-----BEGIN CERTIFICATE-----
MIIJZzCCCE+gAwIBAgIKYQTouAAAAAAABzANBgkqhkiG9w0BAQsFADCBpzELMAkG
@@ -65,6 +72,8 @@ lS3ZUQcHCLtUbTw=
`
func main() {
var output Output
// Process command line arguments
server := flag.String("server", "ldap.example.com", "LDAP server to bind to")
baseDN := flag.String("baseDN", "OU=Users,DC=example,DC=com", "Base DN to use when attempting to bind to AD")
@@ -72,6 +81,8 @@ func main() {
password := flag.String("password", "pass", "Password to use when attempting to bind to AD")
flag.Parse()
output.Server = *server
// Get a copy of the system defined CA's
system, err := x509.SystemCertPool()
if err != nil {
@@ -97,13 +108,21 @@ func main() {
if err != nil {
//handle err
fmt.Println(err)
//fmt.Println("Error : %s", err)
output.Error = err.Error()
}
if !status {
//handle failed authentication
fmt.Println(err)
}
output.AuthSuccess = status
fmt.Println("success")
/*
if !status {
//handle failed authentication
fmt.Println("Authentication failed")
} else {
fmt.Println("success")
}
*/
b, _ := json.Marshal(output)
fmt.Println(string(b))
}