-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-generated Pull Request for feat/user-management #326
Changes from all commits
0559d27
4f89e60
9591bd1
e2b6240
8b5abad
1aa9092
c163639
a74664b
30dbba7
4002bea
e10792e
0f39e99
240723e
9f9d0e0
eed68e1
a785721
99dc342
f6550c2
6243700
3c60755
87295c5
a0bd1c9
ccf8e49
127a24d
91176c6
1cb837f
c1d6539
529f614
ed19bcf
27126f9
986ba5d
57caf9f
faaa442
ba40b9e
7ea292b
854449f
fb0766a
2aa36bd
a2c170c
ce6befd
3b8cae8
730359e
2401258
ccecf84
fa3d8d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ linters: | |
- bodyclose | ||
- bidichk | ||
- cyclop | ||
- depguard | ||
# - depguard | ||
- decorder | ||
- dogsled | ||
# - dupl | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/dictyBase/modware-import/internal/logger" | ||
logto "github.com/dictyBase/modware-import/internal/logto/cli" | ||
"github.com/dictyBase/modware-import/internal/registry" | ||
"github.com/jellydator/ttlcache/v3" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func main() { | ||
app := &cli.App{ | ||
Name: "logto", | ||
Usage: "A command line application for logto instance management", | ||
Before: setupCliLogger, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "endpoint", | ||
Usage: "endpoint of api server", | ||
Required: true, | ||
Aliases: []string{"e"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "app-secret", | ||
Usage: "logto application secret to access the api", | ||
Aliases: []string{"s"}, | ||
Required: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "app-id", | ||
Usage: "logto application identifier to access the api", | ||
Aliases: []string{"a"}, | ||
Required: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "api-resource", | ||
Usage: "logto api resource name", | ||
Aliases: []string{"r"}, | ||
Required: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "log-level", | ||
Usage: "Logging level, should be one of debug,warn,info or error", | ||
Value: "error", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "log-format", | ||
Usage: "Format of log, either of json or text", | ||
Value: "json", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "log-file", | ||
Usage: "log file for output in addition to stderr", | ||
}, | ||
}, | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "create-access-token", | ||
Usage: "Create a new logto access token", | ||
Action: logto.CreateAccessToken, | ||
}, | ||
{ | ||
Name: "import-user", | ||
Usage: "Import user from an input file", | ||
Action: logto.ImportUser, | ||
Before: setupTTLCache, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "input", | ||
Usage: "input csv file with users information", | ||
Aliases: []string{"i"}, | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func setupTTLCache(cltx *cli.Context) error { | ||
tcache := ttlcache.New[string, string]() | ||
registry.SetTTLCache(tcache) | ||
reader, err := os.Open(cltx.String("input")) | ||
if err != nil { | ||
return fmt.Errorf("error in reading file %s", err) | ||
} | ||
registry.SetReader("USER_INPUT", reader) | ||
return nil | ||
} | ||
|
||
func setupCliLogger(cltx *cli.Context) error { | ||
l, err := logger.NewCliLogger(cltx) | ||
if err != nil { | ||
return fmt.Errorf("error in getting a new logger %s", err) | ||
} | ||
registry.SetLogger(l) | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package stockcenter | |
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
loader "github.com/dictyBase/modware-import/internal/load/stockcenter" | ||
|
@@ -31,121 +32,6 @@ func setStrainPreRun(cmd *cobra.Command, args []string) error { | |
return nil | ||
} | ||
|
||
func setStrainInputReader() error { | ||
switch viper.GetString("input-source") { | ||
case FOLDER: | ||
ar, err := os.Open(viper.GetString("strain-annotator-input")) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"error in opening file %s %s", | ||
viper.GetString("strain-annotator-input"), | ||
err, | ||
) | ||
} | ||
pr, err := os.Open(viper.GetString("strain-pub-input")) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"error in opening file %s %s", | ||
viper.GetString("strain-pub-input"), | ||
err, | ||
) | ||
} | ||
gr, err := os.Open(viper.GetString("strain-gene-input")) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"error in opening file %s %s", | ||
viper.GetString("strain-gene-input"), | ||
err, | ||
) | ||
} | ||
sr, err := os.Open(viper.GetString("strain-input")) | ||
if err != nil { | ||
return fmt.Errorf("error in opening file %s %s", viper.GetString("strain-input"), err) | ||
} | ||
registry.SetReader(regsc.StrainAnnotatorReader, ar) | ||
registry.SetReader(regsc.StrainPubReader, pr) | ||
registry.SetReader(regsc.StrainGeneReader, gr) | ||
registry.SetReader(regsc.StrainReader, sr) | ||
case BUCKET: | ||
ar, err := registry.GetS3Client().GetObject( | ||
viper.GetString("s3-bucket"), | ||
fmt.Sprintf( | ||
"%s/%s", | ||
viper.GetString("s3-bucket-path"), | ||
viper.GetString("strain-annotator-input"), | ||
), | ||
minio.GetObjectOptions{}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"error in getting file %s from bucket %s %s", | ||
viper.GetString("strain-annotator-input"), | ||
viper.GetString("s3-bucket-path"), | ||
err, | ||
) | ||
} | ||
gr, err := registry.GetS3Client().GetObject( | ||
viper.GetString("s3-bucket"), | ||
fmt.Sprintf( | ||
"%s/%s", | ||
viper.GetString("s3-bucket-path"), | ||
viper.GetString("strain-gene-input"), | ||
), | ||
minio.GetObjectOptions{}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"error in getting file %s from bucket %s %s", | ||
viper.GetString("strain-gene-input"), | ||
viper.GetString("s3-bucket-path"), | ||
err, | ||
) | ||
} | ||
pr, err := registry.GetS3Client().GetObject( | ||
viper.GetString("s3-bucket"), | ||
fmt.Sprintf( | ||
"%s/%s", | ||
viper.GetString("s3-bucket-path"), | ||
viper.GetString("strain-pub-input"), | ||
), | ||
minio.GetObjectOptions{}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"error in getting file %s from bucket %s %s", | ||
viper.GetString("strain-pub-input"), | ||
viper.GetString("s3-bucket-path"), | ||
err, | ||
) | ||
} | ||
sr, err := registry.GetS3Client().GetObject( | ||
viper.GetString("s3-bucket"), | ||
fmt.Sprintf( | ||
"%s/%s", | ||
viper.GetString("s3-bucket-path"), | ||
viper.GetString("strain-input"), | ||
), | ||
minio.GetObjectOptions{}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"error in getting file %s from bucket %s %s", | ||
viper.GetString("strain-input"), | ||
viper.GetString("s3-bucket-path"), | ||
err, | ||
) | ||
} | ||
//registry.SetReader(regsc.STRAIN_ANNOTATOR_READER, ar) | ||
registry.SetReader(regsc.StrainAnnotatorReader, ar) | ||
registry.SetReader(regsc.StrainPubReader, pr) | ||
registry.SetReader(regsc.StrainGeneReader, gr) | ||
registry.SetReader(regsc.StrainReader, sr) | ||
default: | ||
return fmt.Errorf("error input source %s not supported", viper.GetString("input-source")) | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
StrainCmd.Flags().StringP( | ||
"strain-annotator-input", | ||
|
@@ -173,3 +59,97 @@ func init() { | |
) | ||
viper.BindPFlags(StrainCmd.Flags()) | ||
} | ||
|
||
func setStrainInputReader() error { | ||
switch viper.GetString("input-source") { | ||
case FOLDER: | ||
if err := openLocalFiles(); err != nil { | ||
return err | ||
} | ||
case BUCKET: | ||
if err := getS3Files(); err != nil { | ||
return err | ||
} | ||
default: | ||
return fmt.Errorf( | ||
"error input source %s not supported", | ||
viper.GetString("input-source"), | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func openLocalFiles() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. |
||
ar, err := openFile(viper.GetString("strain-annotator-input")) | ||
if err != nil { | ||
return err | ||
} | ||
pr, err := openFile(viper.GetString("strain-pub-input")) | ||
if err != nil { | ||
return err | ||
} | ||
gr, err := openFile(viper.GetString("strain-gene-input")) | ||
if err != nil { | ||
return err | ||
} | ||
sr, err := openFile(viper.GetString("strain-input")) | ||
if err != nil { | ||
return err | ||
} | ||
setRegistryReaders(ar, pr, gr, sr) | ||
return nil | ||
} | ||
|
||
func getS3Files() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. |
||
ar, err := getS3Object(viper.GetString("strain-annotator-input")) | ||
if err != nil { | ||
return err | ||
} | ||
pr, err := getS3Object(viper.GetString("strain-pub-input")) | ||
if err != nil { | ||
return err | ||
} | ||
gr, err := getS3Object(viper.GetString("strain-gene-input")) | ||
if err != nil { | ||
return err | ||
} | ||
sr, err := getS3Object(viper.GetString("strain-input")) | ||
if err != nil { | ||
return err | ||
} | ||
setRegistryReaders(ar, pr, gr, sr) | ||
return nil | ||
} | ||
|
||
func openFile(filePath string) (*os.File, error) { | ||
file, err := os.Open(filePath) | ||
if err != nil { | ||
return nil, fmt.Errorf("error in opening file %s %s", filePath, err) | ||
} | ||
return file, nil | ||
} | ||
|
||
func getS3Object(filePath string) (*minio.Object, error) { | ||
object, err := registry.GetS3Client().GetObject( | ||
viper.GetString("s3-bucket"), | ||
fmt.Sprintf("%s/%s", viper.GetString("s3-bucket-path"), filePath), | ||
minio.GetObjectOptions{}, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf( | ||
"error in getting file %s from bucket %s %s", | ||
filePath, | ||
viper.GetString("s3-bucket-path"), | ||
err, | ||
) | ||
} | ||
return object, nil | ||
} | ||
|
||
func setRegistryReaders(ar, pr, gr, sr io.Reader) { | ||
registry.SetReader(regsc.StrainAnnotatorReader, ar) | ||
registry.SetReader(regsc.StrainPubReader, pr) | ||
registry.SetReader(regsc.StrainGeneReader, gr) | ||
registry.SetReader(regsc.StrainReader, sr) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
openLocalFiles
has 5 return statements (exceeds 4 allowed).