Skip to content
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

Merged
merged 45 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0559d27
fix(cli): update import path for the slices package
cybersiddhu Sep 12, 2023
4f89e60
feat(client.go): add client package with Client struct and AccessToke…
cybersiddhu Sep 12, 2023
9591bd1
feat(cli): add CreateAccessToken function to generate an access token
cybersiddhu Sep 12, 2023
e2b6240
feat(logto): add logto command line application for logto instance ma…
cybersiddhu Sep 12, 2023
8b5abad
chore(go.mod): add indirect dependency on github.com/Jeffail/gabs/v2 …
cybersiddhu Sep 13, 2023
1aa9092
refactor(client.go): add CreateUser method to Client struct to create…
cybersiddhu Sep 13, 2023
c163639
fix(client.go): add missing closing brace for AccessToken function
cybersiddhu Sep 13, 2023
a74664b
fix(client.go): remove duplicate code and fix error handling in Acces…
cybersiddhu Sep 13, 2023
30dbba7
feat(main.go): add "import-user" command to logto CLI tool for import…
cybersiddhu Sep 14, 2023
4002bea
refactor(client.go): rename accessTokenResp struct to AccessTokenResp…
cybersiddhu Sep 14, 2023
e10792e
feat(cli): add ImportUser function to handle user import functionality
cybersiddhu Sep 14, 2023
0f39e99
fix(cli): rename variable 'atoken' to 'aresp' for improved clarity an…
cybersiddhu Sep 14, 2023
240723e
chore(go.mod): add indirect dependency on github.com/jellydator/ttlca…
cybersiddhu Sep 14, 2023
9f9d0e0
feat(registry.go): add support for TTL cache in the registry
cybersiddhu Sep 14, 2023
eed68e1
feat(logto): add support for TTL cache in the logto command
cybersiddhu Sep 14, 2023
a785721
fix(main.go): change type of tcache variable from ttlcache.New[string…
cybersiddhu Sep 14, 2023
99dc342
refactor(cli/user.go): extract token retrieval logic into a separate …
cybersiddhu Sep 15, 2023
f6550c2
feat(main.go): add import-user command with input flag and before hoo…
cybersiddhu Sep 15, 2023
6243700
feat(client.go): implement CheckUser method to query the API for user…
cybersiddhu Sep 15, 2023
3c60755
fix(client.go): return user ID along with boolean result in CheckUser…
cybersiddhu Sep 15, 2023
87295c5
feat(client.go): add CheckUserWithUserName method to the Client struct
cybersiddhu Sep 17, 2023
a0bd1c9
refactor(client.go): remove unnecessary parameters from CheckUserWith…
cybersiddhu Sep 17, 2023
ccf8e49
refactor(client.go): rename 'Email' field to 'UserName' in APIUsersSe…
cybersiddhu Sep 17, 2023
127a24d
feat(cli/user.go): add functions to generate random numbers and strin…
cybersiddhu Sep 17, 2023
91176c6
feat(cli/user.go): add normalizeUserName function to remove special c…
cybersiddhu Sep 17, 2023
1cb837f
feat(cli/user.go): add support for importing users from a CSV file
cybersiddhu Sep 17, 2023
c1d6539
docs(cli/user.go): add documentation for FixedLenRandomInt, FixedLenR…
cybersiddhu Sep 17, 2023
529f614
chore(client.go): extract commonHeader function to improve code reusa…
cybersiddhu Oct 19, 2023
ed19bcf
refactor(client.go): simplify code by extracting common header settin…
cybersiddhu Oct 19, 2023
27126f9
feat(client.go): add APIUsersPatchCustomData struct to represent cust…
cybersiddhu Oct 19, 2023
986ba5d
feat(client.go): add function to add custom user information
cybersiddhu Oct 19, 2023
57caf9f
feat(client.go): add "Phone" field to APIUsersPatchCustomData struct
cybersiddhu Oct 19, 2023
faaa442
feat(user.go): add support for importing user custom data from CSV file
cybersiddhu Oct 19, 2023
ba40b9e
fix(client.go): fix the URL construction in AddCustomUserInformation …
cybersiddhu Oct 19, 2023
7ea292b
refactor(user.go): refactor ImportUser function to use a struct for C…
cybersiddhu Oct 19, 2023
854449f
chore(.gitignore): add 'logto' to the list of ignored files
cybersiddhu Oct 19, 2023
fb0766a
chore(.golangci.yml): comment out depguard linter
cybersiddhu Jan 31, 2024
2aa36bd
refactor(main.go): extract setupCliLogger and setupTTLCache functions…
cybersiddhu Feb 1, 2024
a2c170c
refactor(user.go): extract logic into separate functions for better r…
cybersiddhu Feb 1, 2024
ce6befd
refactor(strain.go): split LoadStrain function into smaller functions…
cybersiddhu Feb 1, 2024
3b8cae8
refactor(strain.go): extract repetitive code into separate functions …
cybersiddhu Feb 1, 2024
730359e
style(plasmid_inventory.go): improve readability by breaking long fun…
cybersiddhu Feb 1, 2024
2401258
refactor(plasmid.go): extract logic into smaller functions for better…
cybersiddhu Feb 2, 2024
ccecf84
refactor(strainsyn.go): split LoadStrainSynProp function into smaller…
cybersiddhu Feb 2, 2024
fa3d8d6
refactor(stockcenter.go): remove unused protobuf imports and replace …
cybersiddhu Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ linters:
- bodyclose
- bidichk
- cyclop
- depguard
# - depguard
- decorder
- dogsled
# - dupl
Expand Down
107 changes: 107 additions & 0 deletions cmd/logto/main.go
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
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ require (

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Jeffail/gabs/v2 v2.7.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
Expand Down Expand Up @@ -89,6 +90,7 @@ require (
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jellydator/ttlcache/v3 v3.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand Down Expand Up @@ -120,6 +122,7 @@ require (
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Gurpartap/logrus-stack v0.0.0-20170710170904-89c00d8a28f4 h1:vdT7QwBhJJEVNFMBNhRSFDRCB6O16T28VhvqRgqFyn8=
github.com/Gurpartap/logrus-stack v0.0.0-20170710170904-89c00d8a28f4/go.mod h1:SvXOG8ElV28oAiG9zv91SDe5+9PfIr7PPccpr8YyXNs=
github.com/Jeffail/gabs/v2 v2.7.0 h1:Y2edYaTcE8ZpRsR2AtmPu5xQdFDIthFG0jYhu5PY8kg=
github.com/Jeffail/gabs/v2 v2.7.0/go.mod h1:dp5ocw1FvBBQYssgHsG7I1WYsiLRtkUaB1FEtSwvNUw=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
Expand Down Expand Up @@ -254,6 +256,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jedib0t/go-pretty/v6 v6.4.6 h1:v6aG9h6Uby3IusSSEjHaZNXpHFhzqMmjXcPq1Rjl9Jw=
github.com/jedib0t/go-pretty/v6 v6.4.6/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs=
github.com/jellydator/ttlcache/v3 v3.1.0 h1:0gPFG0IHHP6xyUyXq+JaD8fwkDCqgqwohXNJBcYE71g=
github.com/jellydator/ttlcache/v3 v3.1.0/go.mod h1:hi7MGFdMAwZna5n2tuvh63DvFLzVKySzCVW6+0gA2n4=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
Expand Down
2 changes: 1 addition & 1 deletion internal/baserow/cli/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/dictyBase/modware-import/internal/baserow/client"
"github.com/dictyBase/modware-import/internal/collection"
"github.com/urfave/cli/v2"
"k8s.io/utils/strings/slices"
"golang.org/x/exp/slices"
)

type accessTokenProperties struct {
Expand Down
210 changes: 95 additions & 115 deletions internal/cli/stockcenter/strain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stockcenter

import (
"fmt"
"io"
"os"

loader "github.com/dictyBase/modware-import/internal/load/stockcenter"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Copy link

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).

Copy link

Choose a reason for hiding this comment

The 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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function getS3Files has 5 return statements (exceeds 4 allowed).

Copy link

Choose a reason for hiding this comment

The 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)
}
Loading
Loading