-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
94 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,69 @@ | ||
package standalone | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/viant/datly/gateway" | ||
"github.com/viant/datly/service/auth/jwt" | ||
) | ||
|
||
// Options represents standalone options | ||
type Options struct { | ||
ConfigURL string `short:"c" long:"cfg" description:"config URIPrefix"` | ||
Version bool `short:"v" long:"version" description:"Version"` | ||
ConfigURL string `short:"c" long:"cfg" description:"config URIPrefix"` | ||
Version bool `short:"v" long:"version" description:"Version"` | ||
config *Config | ||
auth gateway.Authorizer | ||
useSingleton *bool | ||
} | ||
|
||
func NewOptions(ctx context.Context, opts ...Option) (*Options, error) { | ||
options := &Options{} | ||
for _, opt := range opts { | ||
opt(options) | ||
} | ||
if options.config == nil { | ||
if options.ConfigURL == "" { | ||
return nil, fmt.Errorf("config url was empty") | ||
} | ||
ctx = context.Background() | ||
config, err := NewConfigFromURL(ctx, options.ConfigURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
options.config = config | ||
} | ||
var err error | ||
if options.config.Cognito != nil || options.config.JWTValidator != nil { | ||
if options.auth, err = jwt.Init(options.config.Config, nil); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return options, nil | ||
} | ||
|
||
// Option represents standalone option | ||
type Option func(*Options) | ||
|
||
func WithAuth(auth gateway.Authorizer) Option { | ||
return func(o *Options) { | ||
o.auth = auth | ||
} | ||
} | ||
|
||
func WithConfig(config *Config) Option { | ||
return func(o *Options) { | ||
o.config = config | ||
} | ||
} | ||
|
||
func WithUseSingleton(useSingleton *bool) Option { | ||
return func(o *Options) { | ||
o.useSingleton = useSingleton | ||
} | ||
} | ||
|
||
func WithConfigURL(configURL string) Option { | ||
return func(o *Options) { | ||
o.ConfigURL = configURL | ||
} | ||
} |
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