-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extract Authenticator and MFAProvider interfaces * Implement plugin loading * Add config example Signed-off-by: Knut Ahlers <knut@ahlers.me>
- Loading branch information
Showing
16 changed files
with
225 additions
and
127 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
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
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
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
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
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
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
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
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
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
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
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,58 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"plugin" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/Luzifer/nginx-sso/plugins" | ||
) | ||
|
||
func loadPlugins(pluginDir string) error { | ||
logger := log.WithField("plugin_dir", pluginDir) | ||
|
||
d, err := os.Stat(pluginDir) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
logger.Warn("Plugin directory not found, skipping") | ||
return nil | ||
} | ||
return errors.Wrap(err, "Could not stat plugin dir") | ||
} | ||
|
||
if !d.IsDir() { | ||
return errors.New("Plugin directory is not a directory") | ||
} | ||
|
||
return errors.Wrap(filepath.Walk(pluginDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !strings.HasSuffix(path, ".so") { | ||
// Ignore that file, is not a plugin | ||
return nil | ||
} | ||
|
||
p, err := plugin.Open(path) | ||
if err != nil { | ||
return errors.Wrapf(err, "Unable to load plugin %q", path) | ||
} | ||
|
||
f, err := p.Lookup("Register") | ||
if err != nil { | ||
return errors.Wrapf(err, "Unable to find register function in %q", path) | ||
} | ||
|
||
f.(func(plugins.RegisterAuthenticatorFunc, plugins.RegisterMFAProviderFunc))( | ||
registerAuthenticator, | ||
registerMFAProvider, | ||
) | ||
|
||
return nil | ||
}), "Unable to load plugins") | ||
} |
Oops, something went wrong.