Skip to content

Commit

Permalink
Add "all" into the allowed auth type
Browse files Browse the repository at this point in the history
  • Loading branch information
verdel committed Jan 11, 2019
1 parent 5004e55 commit b4aaf17
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ squid-auth-healthcheck --proxy-addr 127.0.0.1 --proxy-username [email protected] -
```
Application Options:
-u, --url= url to check for availability (required)
--auth-type= type of used proxy authentication mechanism. [ntlm, kerberos, no] (required)
--auth-type= type of used proxy authentication mechanism. [ntlm, kerberos, no, all] (required)
--proxy-addr= proxy server address (required)
--proxy-port= proxy server port (default: 3128) (default: 3128)
--proxy-username= proxy user login
Expand Down
35 changes: 24 additions & 11 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (

var opts struct {
URL []string `short:"u" long:"url" description:"url to check for availability (required)" required:"true"`
AuthType []string `long:"auth-type" description:"type of used proxy authentication mechanism. [ntlm, kerberos, no] (required)" required:"true"`
AuthType []string `long:"auth-type" description:"type of used proxy authentication mechanism. [ntlm, kerberos, no, all] (required)" required:"true"`
ProxyAddr string `long:"proxy-addr" description:"proxy server address (required)" required:"true"`
ProxyPort int `long:"proxy-port" description:"proxy server port (default: 3128)" default:"3128"`
ProxyUsername string `long:"proxy-username" description:"proxy user login"`
Expand All @@ -27,7 +27,7 @@ var opts struct {
StrictAuth bool `long:"strict-auth" description:"the check returns a positive result only if url are available with all auth method"`
Verbose bool `short:"v" long:"verbose" description:"output verbose healthcheck information"`
}
var allowAuthType = [3]string{"ntlm", "kerberos", "no"}
var allowAuthType = []string{"ntlm", "kerberos", "no", "all"}

func exitOK(verbose bool) {
if !verbose {
Expand Down Expand Up @@ -57,36 +57,49 @@ func main() {
os.Exit(1)
}

if len(opts.AuthType) > len(allowAuthType) {
var authType []string
if slice.StringInSlice("all", opts.AuthType) {
for _, v := range allowAuthType {
if v != "all" {
authType = append(authType, v)
}
}
} else {
for _, v := range opts.AuthType {
authType = append(authType, v)
}
}

if len(authType) > len(allowAuthType) {
fmt.Println("Too many authentication type")
os.Exit(1)
}

for _, item := range opts.AuthType {
if !slice.StringInSlice(item, opts.AuthType) {
for _, item := range authType {
if !slice.StringInSlice(item, allowAuthType) {
fmt.Printf("Authentication type %s is not allowed", item)
os.Exit(1)
}
}

var wg sync.WaitGroup

ch := make(chan checker.HealthResponse, len(opts.AuthType)*len(opts.URL))
wg.Add(len(opts.AuthType))
ch := make(chan checker.HealthResponse, len(authType)*len(opts.URL))
wg.Add(len(authType))

if slice.StringInSlice("ntlm", opts.AuthType) {
if slice.StringInSlice("ntlm", authType) {
var ntlm checker.Interface = checker.NewAuthNTLM(opts.ProxyAddr, opts.ProxyPort, opts.ProxyUsername, opts.ProxyPassword, opts.ConnectionTimeout)
go ntlm.Check(opts.URL, ch, &wg)
}
if slice.StringInSlice("kerberos", opts.AuthType) {
if slice.StringInSlice("kerberos", authType) {
kerberos, err := checker.NewAuthKerberos(opts.ProxyAddr, opts.ProxyPort, opts.ProxyUsername, opts.ProxyPassword, opts.ConnectionTimeout)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
go kerberos.Check(opts.URL, ch, &wg)
}
if slice.StringInSlice("no", opts.AuthType) {
if slice.StringInSlice("no", authType) {
var no checker.Interface = checker.NewAuthNo(opts.ProxyAddr, opts.ProxyPort, opts.ConnectionTimeout)
go no.Check(opts.URL, ch, &wg)
}
Expand All @@ -113,7 +126,7 @@ func main() {
}

if opts.StrictAuth {
if len(okAuthResult) < len(opts.AuthType) {
if len(okAuthResult) < len(authType) {
exitErr(opts.Verbose)
}
}
Expand Down

0 comments on commit b4aaf17

Please sign in to comment.