-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a global styles and add user sysAdmin elevate cmd
Signed-off-by: amands98 <amandeepsm.in@gmail.com>
- Loading branch information
Showing
11 changed files
with
289 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package user | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/user" | ||
"github.com/goharbor/harbor-cli/pkg/utils" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func UserDeleteCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete", | ||
Short: "delete user", | ||
Args: cobra.MaximumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var err error | ||
if len(args) > 0 { | ||
userId, _ := strconv.ParseInt(args[0], 10, 64) | ||
err = runDeleteUser(userId) | ||
|
||
} else { | ||
userId := utils.GetUserIdFromUser() | ||
err = runDeleteUser(userId) | ||
} | ||
|
||
if err != nil { | ||
log.Errorf("failed to delete user: %v", err) | ||
} | ||
|
||
}, | ||
} | ||
|
||
return cmd | ||
|
||
} | ||
|
||
func runDeleteUser(userId int64) error { | ||
credentialName := viper.GetString("current-credential-name") | ||
client := utils.GetClientByCredentialName(credentialName) | ||
ctx := context.Background() | ||
_, err := client.User.DeleteUser(ctx, &user.DeleteUserParams{UserID: userId}) | ||
if err != nil { | ||
return err | ||
} | ||
log.Info("user deleted successfully") | ||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package user | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/user" | ||
"github.com/goharbor/go-client/pkg/sdk/v2.0/models" | ||
"github.com/goharbor/harbor-cli/pkg/utils" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func ElevateUserCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "elevate", | ||
Short: "elevate user", | ||
Long: "elevate user to admin role", | ||
Args: cobra.MaximumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var err error | ||
var userId int64 | ||
if len(args) > 0 { | ||
userId, _ = strconv.ParseInt(args[0], 10, 64) | ||
|
||
} else { | ||
userId = utils.GetUserIdFromUser() | ||
} | ||
|
||
// Todo : Ask for the confirmation before elevating the user to admin role | ||
|
||
err = runElevateUser(userId) | ||
|
||
if err != nil { | ||
log.Errorf("failed to elevate user: %v", err) | ||
} | ||
|
||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runElevateUser(userId int64) error { | ||
credentialName := viper.GetString("current-credential-name") | ||
client := utils.GetClientByCredentialName(credentialName) | ||
ctx := context.Background() | ||
UserSysAdminFlag := &models.UserSysAdminFlag{ | ||
SysadminFlag: true, | ||
} | ||
_, err := client.User.SetUserSysAdmin(ctx, &user.SetUserSysAdminParams{UserID: userId, SysadminFlag: UserSysAdminFlag}) | ||
if err != nil { | ||
return err | ||
} | ||
log.Info("user elevated role to admin successfully") | ||
return nil | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package views | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/list" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
var ( | ||
TitleStyle = lipgloss.NewStyle().MarginLeft(2) | ||
ItemStyle = lipgloss.NewStyle().PaddingLeft(4) | ||
SelectedItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(lipgloss.Color("170")) | ||
PaginationStyle = list.DefaultStyles().PaginationStyle.PaddingLeft(4) | ||
HelpStyle = list.DefaultStyles().HelpStyle.PaddingLeft(4).PaddingBottom(1) | ||
) | ||
|
||
var BaseStyle = lipgloss.NewStyle(). | ||
BorderStyle(lipgloss.NormalBorder()).Padding(0, 1) |
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
Oops, something went wrong.