Skip to content

Commit

Permalink
Merge pull request #20 from slntopp/auth-type-on-login
Browse files Browse the repository at this point in the history
Auth type on login
  • Loading branch information
slntopp authored Sep 19, 2022
2 parents 22544e9 + 69ba5cc commit 72cd1a0
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 395 deletions.
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: daily
time: "06:00"
reviewers:
- slntopp
assignees:
- slntopp
- package-ecosystem: github-actions
directory: ".github/workflows/*"
schedule:
interval: daily
time: "06:00"
reviewers:
- slntopp
assignees:
- slntopp
4 changes: 2 additions & 2 deletions cmd/account/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand Down Expand Up @@ -38,7 +38,7 @@ var CreateCmd = &cobra.Command{
authType, _ := cmd.Flags().GetString("auth-type")
authData, _ := cmd.Flags().GetStringSlice("auth-data")
if strings.Join(authData, "") == "" {
return errors.New("Authorization Data wasn't given")
return errors.New("args: Authorization Data wasn't given")
}
credentials := accountspb.Credentials{
Type: (authType), Data: authData,
Expand Down
8 changes: 4 additions & 4 deletions cmd/billing/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand Down Expand Up @@ -103,12 +103,12 @@ var CreateTransactionCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
acc, _ := cmd.Flags().GetString("account")
if acc == "" {
return fmt.Errorf("Account is required")
return fmt.Errorf("args: Account is required")
}

total, _ := cmd.Flags().GetFloat64("total")
if total == 0 {
return fmt.Errorf("Total is required and must be not null")
return fmt.Errorf("args: Total is required and must be not null")
}

meta := make(map[string]*structpb.Value)
Expand All @@ -125,7 +125,7 @@ var CreateTransactionCmd = &cobra.Command{
re := regexp.MustCompile(`(?P<sign>^-?)(?P<num>\d+)(?P<mult>[smhdw]{1})`)
matches := re.FindStringSubmatch(delta)
if len(matches) == 0 {
return errors.New("Invalid delta format")
return errors.New("args: Invalid delta format")
}
multiplicators := map[string]int{
"s": 1,
Expand Down
12 changes: 7 additions & 5 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand All @@ -18,17 +18,18 @@ package cmd
import (
"encoding/json"
"fmt"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// contextCmd represents the context command
var contextCmd = &cobra.Command{
Use: "context",
Use: "context",
Aliases: []string{"ctx"},
Short: "Print current NoCloud CLI Context | Aliases: ctx",
Short: "Print current NoCloud CLI Context | Aliases: ctx",
RunE: func(cmd *cobra.Command, args []string) error {
data := make(map[string]interface{})
data["host"] = viper.Get("nocloud")
Expand All @@ -41,8 +42,9 @@ var contextCmd = &cobra.Command{
return nil
}

title := cases.Title(language.English)
for k, v := range data {
fmt.Printf("%s: %v\n", strings.Title(k), v)
fmt.Printf("%s: %v\n", title.String(k), v)
}

return nil
Expand Down
15 changes: 9 additions & 6 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand All @@ -27,6 +27,7 @@ import (
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

// loginCmd represents the login command
Expand All @@ -38,19 +39,20 @@ var loginCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
creds := credentials.NewTLS(&tls.Config{InsecureSkipVerify: true})
opt := grpc.WithTransportCredentials(creds)
insecure, _ := cmd.Flags().GetBool("insecure")
if insecure {
opt = grpc.WithInsecure()
_insecure, _ := cmd.Flags().GetBool("insecure")
if _insecure {
opt = grpc.WithTransportCredentials(insecure.NewCredentials())
}
conn, err := grpc.Dial(args[0], opt)
if err != nil {
return err
}

client := regpb.NewAccountsServiceClient(conn)
authType, _ := cmd.Flags().GetString("auth-type")
req := &pb.TokenRequest{
Auth: &pb.Credentials{
Type: "standard", Data: []string{args[1], args[2]},
Type: authType, Data: args[1:],
},
}
if rootClaim, _ := cmd.Flags().GetBool("root-claim"); rootClaim {
Expand All @@ -68,13 +70,14 @@ var loginCmd = &cobra.Command{

viper.Set("nocloud", args[0])
viper.Set("token", token)
viper.Set("insecure", insecure)
viper.Set("insecure", _insecure)
err = viper.WriteConfig()
return err
},
}

func init() {
loginCmd.Flags().String("auth-type", "standard", "Type of Credentials to be used")
loginCmd.Flags().Bool("print-token", false, "")
loginCmd.Flags().Bool("root-claim", true, "")
loginCmd.Flags().Bool("insecure", false, "Use WithInsecure instead of TLS")
Expand Down
6 changes: 3 additions & 3 deletions cmd/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand All @@ -23,7 +23,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"os"

tools "github.com/slntopp/nocloud-cli/pkg/tools"
"github.com/spf13/cobra"
Expand All @@ -43,7 +43,7 @@ var hashCmd = &cobra.Command{
var data []byte

if cert, err := cmd.Flags().GetString("cert"); err == nil && cert != "" {
r, err := ioutil.ReadFile(cert)
r, err := os.ReadFile(cert)
if err != nil {
return err
}
Expand Down
32 changes: 16 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ module github.com/slntopp/nocloud-cli
go 1.19

require (
github.com/jedib0t/go-pretty/v6 v6.2.4
github.com/jedib0t/go-pretty/v6 v6.3.8
github.com/manifoldco/promptui v0.9.0
github.com/slntopp/nocloud v0.0.15-r9
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.12.0
github.com/slntopp/nocloud v0.0.15-r19
github.com/slntopp/nocloud-cc v0.0.1-r2
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.13.0
golang.org/x/text v0.3.7
google.golang.org/grpc v1.49.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/slntopp/nocloud-cc v0.0.1-r1
github.com/spf13/afero v1.8.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/rivo/uniseg v0.4.2 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/sys v0.0.0-20220721230656-c6bc011c0c49 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220902135211-223410557253 // indirect
gopkg.in/ini.v1 v1.66.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
google.golang.org/genproto v0.0.0-20220919141832-68c03719ef51 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 72cd1a0

Please sign in to comment.