aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/core/auth/options.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-12-08 21:15:06 +0100
committerMichael Muré <batolettre@gmail.com>2019-12-08 21:28:27 +0100
commitb92adfcb5f79f2b32c3dafb0fc3e7f1b753b6197 (patch)
tree69202c4021b10f3ab7b7f5ebf229d501e95c4786 /bridge/core/auth/options.go
parent981a4a848b1329da1a73270e27633911f9298bb1 (diff)
downloadgit-bug-b92adfcb5f79f2b32c3dafb0fc3e7f1b753b6197.tar.gz
bridge: huge refactor to accept multiple kind of credentials
Diffstat (limited to 'bridge/core/auth/options.go')
-rw-r--r--bridge/core/auth/options.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/bridge/core/auth/options.go b/bridge/core/auth/options.go
new file mode 100644
index 00000000..7bcda68e
--- /dev/null
+++ b/bridge/core/auth/options.go
@@ -0,0 +1,62 @@
+package auth
+
+import (
+ "github.com/MichaelMure/git-bug/entity"
+ "github.com/MichaelMure/git-bug/identity"
+)
+
+type options struct {
+ target string
+ userId entity.Id
+ kind CredentialKind
+}
+
+type Option func(opts *options)
+
+func matcher(opts []Option) *options {
+ result := &options{}
+ for _, opt := range opts {
+ opt(result)
+ }
+ return result
+}
+
+func (opts *options) Match(cred Credential) bool {
+ if opts.target != "" && cred.Target() != opts.target {
+ return false
+ }
+
+ if opts.userId != "" && cred.UserId() != opts.userId {
+ return false
+ }
+
+ if opts.kind != "" && cred.Kind() != opts.kind {
+ return false
+ }
+
+ return true
+}
+
+func WithTarget(target string) Option {
+ return func(opts *options) {
+ opts.target = target
+ }
+}
+
+func WithUser(user identity.Interface) Option {
+ return func(opts *options) {
+ opts.userId = user.Id()
+ }
+}
+
+func WithUserId(userId entity.Id) Option {
+ return func(opts *options) {
+ opts.userId = userId
+ }
+}
+
+func WithKind(kind CredentialKind) Option {
+ return func(opts *options) {
+ opts.kind = kind
+ }
+}