Skip to content

Commit 83c3b84

Browse files
RevanthTanneeruravitejag
authored andcommitted
Bug Fixes for CLI Testing Round 1
1 parent 2987b21 commit 83c3b84

7 files changed

Lines changed: 127 additions & 44 deletions

File tree

cmd/add/domain/domain.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ func NewdomainCmd() *cobra.Command {
6060
}
6161

6262
func add(allDomains string, newDomain string) error {
63-
domain := allDomains + ";" + newDomain
63+
domain := ""
64+
if allDomains == "" {
65+
domain = newDomain
66+
} else {
67+
domain = allDomains + ";" + newDomain
68+
}
6469
err := api.UpdateDomain(domain)
6570
if err != nil {
6671
return err
6772
}
68-
fmt.Println("Your Domain " + newDomain + "is now whitelisted")
73+
fmt.Println("Your Domain " + newDomain + " is now whitelisted")
6974
return nil
7075
}

cmd/add/social/social.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ func add1(opts1 *socialProvider) error {
8484
var requestBody socialProviderList
8585
requestBody.Data = append(requestBody.Data, *opts1)
8686
body, _ := json.Marshal(requestBody)
87-
fmt.Println(string(body))
8887
var resultResp socialProviderList
8988
resp1, err := request.Rest(http.MethodPost, url1, nil, string(body))
9089
if err != nil {
@@ -99,7 +98,6 @@ func add1(opts1 *socialProvider) error {
9998
var requestBody2 socialProviderList2
10099
requestBody2.Data = append(requestBody2.Data, *opts2)
101100
body1, _ := json.Marshal(requestBody2)
102-
fmt.Println(string(body1))
103101

104102
var resultResp2 socialProviderList2
105103
resp, err1 := request.Rest(http.MethodPost, url2, nil, string(body1))

cmd/delete/domain/domain.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/MakeNowJust/heredoc"
99
"github.com/loginradius/lr-cli/api"
10-
1110
"github.com/loginradius/lr-cli/cmdutil"
1211

1312
"github.com/spf13/cobra"
@@ -40,6 +39,10 @@ func NewdomainCmd() *cobra.Command {
4039
return err
4140
}
4241
urls := strings.Split(p.Callbackurl, ";")
42+
if len(urls) == 1 {
43+
return &cmdutil.FlagError{Err: errors.New("Cannot delete the last domain")}
44+
45+
}
4346
for index, url := range urls {
4447
if url == opts.Domain {
4548
urls = append(urls[:index], urls[index+1:]...)

cmd/generateSott/generateSott.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ package generateSott
22

33
import (
44
"encoding/json"
5-
"errors"
65
"fmt"
76
"net/http"
87

98
"github.com/MakeNowJust/heredoc"
10-
"github.com/loginradius/lr-cli/cmdutil"
119
"github.com/loginradius/lr-cli/config"
1210
"github.com/loginradius/lr-cli/request"
1311

@@ -39,16 +37,19 @@ func NewgenerateSottCmd() *cobra.Command {
3937
Use: "generate-sott",
4038
Short: "generates sott",
4139
Long: `This commmand generates sott`,
42-
Example: heredoc.Doc(`$ lr generate sott`),
40+
Example: heredoc.Doc(`$ lr generate-sott -f <FromDate(mm/dd/yyyy)> -t <ToDate(mm/dd/yyyy)> -c <technology>`),
4341
RunE: func(cmd *cobra.Command, args []string) error {
44-
if opts.FromDate == "" {
45-
return &cmdutil.FlagError{Err: errors.New("`FromDate` is require argument")}
46-
}
47-
if opts.ToDate == "" {
48-
return &cmdutil.FlagError{Err: errors.New("`ToDate` is require argument")}
49-
}
50-
if opts.Technology == "" {
51-
return &cmdutil.FlagError{Err: errors.New("`technology` is require argument")}
42+
if opts.FromDate == "" || opts.ToDate == "" || opts.Technology == "" {
43+
if opts.FromDate == "" {
44+
fmt.Println("FromDate (mm/dd/yyyy) is a required argument")
45+
}
46+
if opts.ToDate == "" {
47+
fmt.Println("ToDate (mm/dd/yyyy) is a required argument")
48+
}
49+
if opts.Technology == "" {
50+
fmt.Println("technology is a required argument")
51+
}
52+
return nil
5253
}
5354
return generate(opts)
5455

@@ -81,7 +82,9 @@ func generate(opts *sott) error {
8182
return err
8283
}
8384
fmt.Println("sott generated successfully")
84-
fmt.Println("{AuthenticityToken, Comment, Sott, Technology}")
85-
fmt.Println(resultResp)
85+
fmt.Println("AunthenticityToken: " + resultResp.AuthenticityToken)
86+
fmt.Println("Comment: " + resultResp.Comment)
87+
fmt.Println("Sott: " + resultResp.Sott)
88+
fmt.Println("Technology: " + resultResp.Technology)
8689
return nil
8790
}

cmd/get/accountPassword/accountPassword.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func get(UID string) error {
5959
if err != nil {
6060
return err
6161
}
62-
fmt.Println("password hash for UID:" + UID + " is" + resultResp.PasswordHash)
62+
fmt.Println("password hash for UID:" + UID + " is " + resultResp.PasswordHash)
6363

6464
return nil
6565
}

cmd/get/social/social.go

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,33 @@ package social
33
import (
44
"encoding/json"
55
"fmt"
6-
76
"net/http"
87

8+
"github.com/loginradius/lr-cli/api"
99
"github.com/loginradius/lr-cli/config"
1010
"github.com/loginradius/lr-cli/request"
1111
"github.com/spf13/cobra"
1212
)
1313

14-
var fileName string
14+
var temp string
1515

1616
type socialProvider struct {
17-
Provider string `json:"Provider"`
17+
HtmlFileName string `json:"HtmlFileName"`
18+
Provider string `json:"Provider"`
19+
ProviderId int `json:"ProviderId"`
20+
ProviderKey string `json:"ProviderKey"`
21+
ProviderSecret string `json:"ProviderSecret"`
22+
Scope []string `json:"Scope"`
23+
Status bool `json:"Status"`
1824
}
1925

2026
type socialProviderList struct {
2127
Data []socialProvider `json:"Data"`
2228
}
2329

24-
var url string
30+
var Url string
31+
32+
var arr = [5]string{"Facebook", "Google", "Twitter", "LinkedIn", "GitHub"}
2533

2634
func NewsocialCmd() *cobra.Command {
2735

@@ -31,32 +39,96 @@ func NewsocialCmd() *cobra.Command {
3139
Long: `This commmand lists social providers`,
3240
Example: `$ lr get social`,
3341
RunE: func(cmd *cobra.Command, args []string) error {
34-
42+
fstatus, _ := cmd.Flags().GetBool("all")
43+
if fstatus {
44+
temp = "all"
45+
}
46+
fstatus1, _ := cmd.Flags().GetBool("active")
47+
if fstatus1 {
48+
temp = "active"
49+
}
50+
if !fstatus && !fstatus1 {
51+
fmt.Println("Please use atleast one of the flags 'lr get social --all' or 'lr get social --active'")
52+
return nil
53+
}
3554
return get()
3655

3756
},
3857
}
58+
fl := cmd.Flags()
59+
fl.BoolP("all", "a", false, "option to get all providers")
60+
fl.BoolP("active", "c", false, "option to get active providers")
3961

4062
return cmd
4163
}
4264

4365
func get() error {
66+
if temp == "all" {
67+
res, err := api.GetSites()
68+
if err != nil {
69+
return err
70+
}
71+
if res.Productplan.Name == "free" {
72+
for i := 0; i < 3; i++ {
73+
fmt.Println(i+1, arr[i])
74+
}
75+
return nil
76+
}
77+
if res.Productplan.Name == "developer" {
78+
for i := 0; i < len(arr); i++ {
79+
fmt.Println(i+1, arr[i])
80+
}
81+
return nil
82+
}
83+
}
84+
if temp == "active" {
85+
resultResp, err := GetActiveProviders()
86+
if err != nil {
87+
return err
88+
}
89+
if len(resultResp.Data) == 0 {
90+
fmt.Println("There is no social configuration")
91+
return nil
92+
}
93+
var num int
94+
for i := 0; i < len(resultResp.Data); i++ {
95+
fmt.Print(fmt.Sprint(i+1) + ".")
96+
fmt.Println(resultResp.Data[i].Provider)
97+
}
98+
// Taking input from user
99+
fmt.Print("Please select a number from 1 to " + fmt.Sprint(len(resultResp.Data)) + " :")
100+
fmt.Scanln(&num)
101+
for 1 > num || num > len(resultResp.Data) {
102+
fmt.Print("Please select a number from 1 to " + fmt.Sprint(len(resultResp.Data)) + " :")
103+
104+
fmt.Scanln(&num)
105+
}
106+
fmt.Println("HtmlFileName: " + resultResp.Data[num-1].HtmlFileName)
107+
fmt.Println("Provider: ", resultResp.Data[num-1].Provider)
108+
fmt.Println("ProviderId: ", resultResp.Data[num-1].ProviderId)
109+
fmt.Println("ProviderKey: ", resultResp.Data[num-1].ProviderKey)
110+
fmt.Println("ProviderSecret: ", resultResp.Data[num-1].ProviderSecret)
111+
fmt.Println("Scope: ", resultResp.Data[num-1].Scope)
112+
fmt.Println("Status: ", resultResp.Data[num-1].Status)
113+
}
114+
115+
return nil
116+
}
117+
118+
func GetActiveProviders() (*socialProviderList, error) {
44119
conf := config.GetInstance()
120+
Url = conf.AdminConsoleAPIDomain + "/platform-configuration/social-providers/options?"
45121

46-
url = conf.AdminConsoleAPIDomain + "/platform-configuration/social-providers/options?"
122+
var R1 socialProviderList
123+
resp, err := request.Rest(http.MethodGet, Url, nil, "")
47124

48-
var resultResp socialProviderList
49-
resp, err := request.Rest(http.MethodGet, url, nil, "")
50125
if err != nil {
51-
return err
126+
return nil, err
52127
}
53-
err = json.Unmarshal([]byte(resp), &resultResp)
128+
129+
err = json.Unmarshal(resp, &R1)
54130
if err != nil {
55-
return err
56-
}
57-
for i := 0; i < len(resultResp.Data); i++ {
58-
fmt.Print(fmt.Sprint(i+1) + ".")
59-
fmt.Println(resultResp.Data[i].Provider)
131+
return nil, err
60132
}
61-
return nil
133+
return &R1, nil
62134
}

cmd/set/email/email.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ func NewemailCmd() *cobra.Command {
2929
Use: "email",
3030
Short: "set email config",
3131
Long: `This commmand sets email config`,
32-
Example: `$ lr set email`,
32+
Example: `$ lr set email --link_expire <link_expire> --notif_count <notif_count> --notif_frequency <notif_frequency>`,
3333
RunE: func(cmd *cobra.Command, args []string) error {
3434

3535
if opts.EmailLinkExpire == 0 {
36-
return &cmdutil.FlagError{Err: errors.New("`email_link_expire` is require argument")}
36+
return &cmdutil.FlagError{Err: errors.New("`link_expire` is require argument")}
3737
}
3838

3939
if opts.EmailNotificationCount == 0 {
40-
return &cmdutil.FlagError{Err: errors.New("`email_notif_count` is require argument")}
40+
return &cmdutil.FlagError{Err: errors.New("`notif_count` is require argument")}
4141
}
4242

4343
if opts.EmailNotificationFrequency == 0 {
44-
return &cmdutil.FlagError{Err: errors.New("`email_notif_frequency` is require argument")}
44+
return &cmdutil.FlagError{Err: errors.New("`notif_frequency` is require argument")}
4545
}
4646
fmt.Printf(string(rune(opts.EmailLinkExpire)))
4747
return set(opts.EmailLinkExpire, opts.EmailNotificationCount, opts.EmailNotificationFrequency)
@@ -50,9 +50,9 @@ func NewemailCmd() *cobra.Command {
5050
}
5151
fl := cmd.Flags()
5252

53-
fl.IntVarP(&opts.EmailLinkExpire, "email_link_expire", "a", 0, "usage")
54-
fl.IntVarP(&opts.EmailNotificationCount, "email_notif_count", "b", 0, "usage")
55-
fl.IntVarP(&opts.EmailNotificationFrequency, "email_notif_frequency", "c", 0, "domain name")
53+
fl.IntVarP(&opts.EmailLinkExpire, "link_expire", "a", 0, "email link expire")
54+
fl.IntVarP(&opts.EmailNotificationCount, "notif_count", "b", 0, "number of email notifications")
55+
fl.IntVarP(&opts.EmailNotificationFrequency, "notif_frequency", "c", 0, "frequency of email notification")
5656

5757
return cmd
5858
}
@@ -77,7 +77,9 @@ func set(a int, b int, c int) error {
7777
if err != nil {
7878
return err
7979
}
80-
fmt.Printf("{EmailLinkExpire, EmailNotificationCount, EmailNotificationFrequency}\n")
81-
fmt.Println(resultResp)
80+
fmt.Println("successfully configured")
81+
fmt.Println("EmailLinkExpire: ", resultResp.EmailLinkExpire)
82+
fmt.Println("EmailNotificationCount: ", resultResp.EmailNotificationCount)
83+
fmt.Println("EmailNotificationFrequency: ", resultResp.EmailNotificationFrequency)
8284
return nil
8385
}

0 commit comments

Comments
 (0)