Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
corteza
corteza-server
Commits
5be1b607
Commit
5be1b607
authored
6 years ago
by
Denis Arh
Browse files
Options
Download
Email Patches
Plain Diff
Add 'users jwt <email>' command
Command generates valid JWT for that user
parent
980b6d58
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
2 deletions
+35
-2
cmd/system-cli/main.go
cmd/system-cli/main.go
+1
-1
system/cli/cli.go
system/cli/cli.go
+1
-1
system/cli/users.go
system/cli/users.go
+33
-0
No files found.
cmd/system-cli/main.go
View file @
5be1b607
...
...
@@ -23,5 +23,5 @@ func main() {
log
.
Fatalf
(
"Error initializing system: %+v"
,
err
)
}
cli
.
Run
(
ctx
)
cli
.
StartCLI
(
ctx
)
}
This diff is collapsed.
Click to expand it.
system/cli/cli.go
View file @
5be1b607
...
...
@@ -11,7 +11,7 @@ import (
"github.com/crusttech/crust/system/internal/repository"
)
func
Run
(
ctx
context
.
Context
)
{
func
StartCLI
(
ctx
context
.
Context
)
{
var
(
db
=
repository
.
DB
(
ctx
)
settingsService
=
settings
.
NewService
(
settings
.
NewRepository
(
db
,
"sys_settings"
))
...
...
This diff is collapsed.
Click to expand it.
system/cli/users.go
View file @
5be1b607
...
...
@@ -3,12 +3,14 @@ package cli
import
(
"context"
"fmt"
"strconv"
"syscall"
"github.com/spf13/cobra"
"github.com/titpetric/factory"
"golang.org/x/crypto/ssh/terminal"
"github.com/crusttech/crust/internal/auth"
"github.com/crusttech/crust/system/internal/repository"
"github.com/crusttech/crust/system/internal/service"
"github.com/crusttech/crust/system/types"
...
...
@@ -127,10 +129,41 @@ func usersCmd(ctx context.Context, db *factory.DB) *cobra.Command {
},
}
jwtCmd
:=
&
cobra
.
Command
{
Use
:
"jwt [email-or-id]"
,
Short
:
"Generates new JWT for a user"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
var
(
userRepo
=
repository
.
User
(
ctx
,
db
)
// authSvc = service.Auth(ctx)
user
*
types
.
User
err
error
ID
uint64
userStr
=
args
[
0
]
)
if
user
,
err
=
userRepo
.
FindByEmail
(
userStr
);
err
!=
nil
&&
err
!=
repository
.
ErrUserNotFound
{
exit
(
cmd
,
err
)
}
else
if
user
==
nil
||
user
.
ID
==
0
{
if
ID
,
err
=
strconv
.
ParseUint
(
userStr
,
10
,
64
);
err
!=
nil
{
exit
(
cmd
,
err
)
}
else
if
user
,
err
=
userRepo
.
FindByID
(
ID
);
err
!=
nil
{
exit
(
cmd
,
err
)
}
}
cmd
.
Println
(
auth
.
DefaultJwtHandler
.
Encode
(
user
))
},
}
cmd
.
AddCommand
(
listCmd
,
addCmd
,
pwdCmd
,
jwtCmd
,
)
return
cmd
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment