-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of user management
Signed-off-by: Radoslav Dimitrov <[email protected]>
- Loading branch information
Showing
22 changed files
with
1,924 additions
and
988 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,10 @@ endif | |
|
||
password-login: | ||
@echo "Setting up password login..." | ||
@$(CONTAINER) exec -it keycloak_container /opt/keycloak/bin/kcadm.sh create users -r stacklok -s username=testuser -s enabled=true | ||
@$(CONTAINER) exec -it keycloak_container /opt/keycloak/bin/kcadm.sh set-password -r stacklok --username testuser --new-password tester | ||
@$(CONTAINER) exec -it keycloak_container /opt/keycloak/bin/kcadm.sh create users -r stacklok -s username=testuser -s enabled=true -s [email protected] | ||
@$(CONTAINER) exec -it keycloak_container /opt/keycloak/bin/kcadm.sh set-password -r stacklok --username testuser --new-password tester | ||
|
||
password-login-2: | ||
@echo "Setting up password login..." | ||
@$(CONTAINER) exec -it keycloak_container /opt/keycloak/bin/kcadm.sh create users -r stacklok -s username=testuser2 -s enabled=true -s [email protected] | ||
@$(CONTAINER) exec -it keycloak_container /opt/keycloak/bin/kcadm.sh set-password -r stacklok --username testuser2 --new-password tester |
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,90 @@ | ||
// | ||
// Copyright 2023 Stacklok, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package invite provides the auth invite command for the minder CLI. | ||
package invite | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/stacklok/minder/cmd/cli/app" | ||
"github.com/stacklok/minder/internal/util" | ||
"github.com/stacklok/minder/internal/util/cli" | ||
"github.com/stacklok/minder/internal/util/cli/table" | ||
"github.com/stacklok/minder/internal/util/cli/table/layouts" | ||
minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" | ||
) | ||
|
||
// inviteGetCmd represents the list command | ||
var inviteGetCmd = &cobra.Command{ | ||
Hidden: true, // TODO: This hides the command, remove it once it's implemented | ||
Use: "get", | ||
Short: "Get info about pending invitations", | ||
Long: `Get shows additional information about a pending invitation`, | ||
RunE: cli.GRPCClientWrapRunE(inviteGetCommand), | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
// inviteGetCommand is the invite get subcommand | ||
func inviteGetCommand(ctx context.Context, cmd *cobra.Command, args []string, conn *grpc.ClientConn) error { | ||
client := minderv1.NewInviteServiceClient(conn) | ||
|
||
// No longer print usage on returned error, since we've parsed our inputs | ||
// See https://github.com/spf13/cobra/issues/340#issuecomment-374617413 | ||
cmd.SilenceUsage = true | ||
format := viper.GetString("output") | ||
|
||
res, err := client.GetInviteDetails(ctx, &minderv1.GetInviteDetailsRequest{ | ||
Code: args[0], | ||
}) | ||
if err != nil { | ||
return cli.MessageAndError("Error getting info for invitation", err) | ||
} | ||
|
||
switch format { | ||
case app.JSON: | ||
out, err := util.GetJsonFromProto(res) | ||
if err != nil { | ||
return cli.MessageAndError("Error getting json from proto", err) | ||
} | ||
cmd.Println(out) | ||
case app.YAML: | ||
out, err := util.GetYamlFromProto(res) | ||
if err != nil { | ||
return cli.MessageAndError("Error getting yaml from proto", err) | ||
} | ||
cmd.Println(out) | ||
case app.Table: | ||
t := table.New(table.Simple, layouts.Default, []string{"Sponsor", "Project", "Expires"}) | ||
t.AddRow(res.SponsorDisplay, res.ProjectDisplay, res.ExpiresAt.AsTime().Format(time.RFC3339)) | ||
t.Render() | ||
default: | ||
return fmt.Errorf("unsupported output format: %s", format) | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
inviteCmd.AddCommand(inviteGetCmd) | ||
inviteGetCmd.Flags().StringP("output", "o", app.Table, | ||
fmt.Sprintf("Output format (one of %s)", strings.Join(app.SupportedOutputFormats(), ","))) | ||
} |
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
Oops, something went wrong.