56 lines
1023 B
Go
56 lines
1023 B
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"git.loafle.net/overflow/overflow_probes/commons"
|
|
"git.loafle.net/overflow/overflow_probes/config"
|
|
)
|
|
|
|
type AuthHandler interface {
|
|
commons.Handler
|
|
}
|
|
|
|
func (a *auth) Serve() error {
|
|
if nil != config.CFG.Probe.Key || "" != *config.CFG.Probe.Key {
|
|
return nil
|
|
}
|
|
|
|
if nil != a.noAuthConfig.DenyDate {
|
|
return fmt.Errorf("Cannot start because this probe have been denied from overFlow[%s]", a.noAuthConfig.DenyDate.String())
|
|
}
|
|
|
|
var err error
|
|
if nil != a.noAuthConfig.TempKey && "" != *a.noAuthConfig.TempKey {
|
|
err = a.serveConnect(*a.noAuthConfig.TempKey)
|
|
} else {
|
|
err = a.serveRegistration()
|
|
}
|
|
if nil != err {
|
|
return err
|
|
}
|
|
|
|
err = nil
|
|
ListenLoop:
|
|
for {
|
|
select {
|
|
case <-a.ShutdownChan:
|
|
err = errors.New("Shutting down")
|
|
break ListenLoop
|
|
case <-a.acceptedChan:
|
|
break ListenLoop
|
|
case err = <-a.deniedChan:
|
|
break ListenLoop
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (a *auth) Shutdown(ctx context.Context) error {
|
|
a.ShutdownChan <- true
|
|
return nil
|
|
}
|