Skip to content

Commit cbae9ad

Browse files
committed
Initial Commit for LoginRadius CLI
0 parents  commit cbae9ad

43 files changed

Lines changed: 2884 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Binaries for programs and plugins
2+
.DS_Store
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
9+
# Test binary, build with `go test -c`
10+
*.test
11+
*.env
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
vendor/
16+
.idea/
17+
tmp/
18+
/bin
19+
/script/build
20+
21+
## Documentation
22+
manual/
23+
24+
#release
25+
dist/
26+

.goreleaser.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This is an example .goreleaser.yml file with some sane defaults.
2+
# Make sure to check the documentation at http://goreleaser.com
3+
before:
4+
hooks:
5+
# You may remove this if you don't use go modules.
6+
- go mod tidy
7+
project_name: lr
8+
builds:
9+
- <<: &build_defaults
10+
binary: lr
11+
main: ./app/lr
12+
id: macos
13+
goos: [darwin]
14+
goarch: [amd64]
15+
16+
- <<: *build_defaults
17+
id: linux
18+
goos: [linux]
19+
goarch: [386, arm, amd64, arm64]
20+
env:
21+
- CGO_ENABLED=0
22+
23+
- <<: *build_defaults
24+
id: windows
25+
goos: [windows]
26+
goarch: [386, amd64]
27+
28+
archives:
29+
- id: nix
30+
builds: [macos, linux]
31+
<<: &archive_defaults
32+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
33+
wrap_in_directory: true
34+
replacements:
35+
darwin: macOS
36+
format: tar.gz
37+
files:
38+
- LICENSE
39+
- id: windows
40+
builds: [windows]
41+
<<: *archive_defaults
42+
wrap_in_directory: false
43+
format: zip
44+
files:
45+
- LICENSE
46+
47+
checksum:
48+
name_template: 'checksums.txt'
49+
snapshot:
50+
name_template: "{{ .Tag }}-next"
51+
changelog:
52+
sort: asc
53+
brews:
54+
- folder: Formula
55+
homepage: https://github.com/loginradius/lr-cli
56+
description: "LoginRadius CLI to support LoginRadius API's and workflow!"
57+
tap:
58+
owner: loginradius
59+
name: homebrew-tap
60+
test:
61+
system "lr --help"

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 LoginRadius Inc.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# LoginRadius CLI
2+
3+
`lr` is LoginRadius on the command line. You can perform basic actions of your [LoginRadius Dashboard](https://dashboard.loginradius.com/dashboard) through command line. The actions includes **login, register, logout, email configuration, domain whitelisting etc**.
4+
5+
![](./cli_home.png)
6+
7+
# Documentation
8+
9+
[See the manual](https://www.loginradius.com/open-source/cli/manual) for more information related to the commands.
10+
# Installation
11+
## MacOS and Linux
12+
13+
`lr` is available via [Homebrew](https://brew.sh/) and as a downloadable binary from the [release page](https://github.com/loginradius/lr-cli/releases/latest).
14+
15+
## Other Platforms
16+
17+
Download packaged binaries from the [release page](https://github.com/loginradius/lr-cli/releases/latest).
18+
## Build from Source
19+
### Installation from source
20+
21+
0. Verify that you have Go 1.16+ installed
22+
23+
```sh
24+
$ go version
25+
```
26+
27+
If `go` is not installed, follow instructions on [the Go website](https://golang.org/doc/install).
28+
29+
1. Clone this repository
30+
31+
```sh
32+
$ git clone https://github.com/LoginRadius/lr-cli.git
33+
$ cd lr-cli
34+
```
35+
36+
2. Build and install
37+
#### Unix-like systems
38+
```sh
39+
# installs to '/usr/local' by default; sudo may be required
40+
$ make install
41+
42+
```
43+
#### Windows
44+
```sh
45+
# build the `bin\gh.exe` binary
46+
> go run script/build.go
47+
```
48+
49+
There is no install step available on Windows.
50+
51+
3. Run `lr --help` to check if it worked.
52+
53+
#### Windows
54+
Run `bin\lr --help` to check if it worked.
55+
56+
## License
57+
58+
For more information on licensing, please refer to [License](https://github.com/LoginRadius/lr-cli/blob/master/LICENSE)

app/gen-docs/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"github.com/loginradius/lr-cli/cmd/root"
5+
"github.com/loginradius/lr-cli/internal/docs"
6+
"log"
7+
)
8+
9+
func main() {
10+
rootCmd := root.NewRootCmd()
11+
rootCmd.InitDefaultHelpCmd()
12+
13+
err := docs.GenMarkdownTreeCustom(rootCmd, "manual")
14+
if err != nil {
15+
log.Fatal(err)
16+
}
17+
}

app/lr/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/loginradius/lr-cli/cmd"
4+
5+
func main() {
6+
cmd.Execute()
7+
}

cli_home.png

406 KB
Loading

cmd/add/add.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package add
2+
3+
import (
4+
"github.com/loginradius/lr-cli/cmd/add/domain"
5+
"github.com/loginradius/lr-cli/cmd/add/social"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func NewaddCmd() *cobra.Command {
10+
11+
cmd := &cobra.Command{
12+
Use: "add",
13+
Short: "add command",
14+
Long: `This commmand acts as a base command for add subcommands`,
15+
}
16+
17+
domainCmd := domain.NewdomainCmd()
18+
cmd.AddCommand(domainCmd)
19+
20+
socialCmd := social.NewsocialCmd()
21+
cmd.AddCommand(socialCmd)
22+
23+
return cmd
24+
}

cmd/add/domain/domain.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package domain
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"fmt"
7+
"net/http"
8+
"strings"
9+
10+
"github.com/MakeNowJust/heredoc"
11+
"github.com/loginradius/lr-cli/request"
12+
13+
"github.com/loginradius/lr-cli/cmdutil"
14+
"github.com/loginradius/lr-cli/config"
15+
16+
"github.com/spf13/cobra"
17+
)
18+
19+
var fileName string
20+
21+
type domainManagement struct {
22+
CallbackUrl string `json:"CallbackUrl"`
23+
}
24+
25+
type domain struct {
26+
Domain string `json:"domain"`
27+
}
28+
29+
type Result struct {
30+
CallbackUrl string `json:"CallbackUrl"`
31+
}
32+
33+
func NewdomainCmd() *cobra.Command {
34+
opts := &domain{}
35+
36+
cmd := &cobra.Command{
37+
Use: "domain",
38+
Short: "add doamin",
39+
Long: `This commmand adds domain`,
40+
Example: heredoc.Doc(`$ lr add domain --domain <domain>`),
41+
RunE: func(cmd *cobra.Command, args []string) error {
42+
if opts.Domain == "" {
43+
return &cmdutil.FlagError{Err: errors.New("`domain` is required argument")}
44+
}
45+
46+
var p, _ = get()
47+
fmt.Printf(p.CallbackUrl)
48+
s := strings.Split(p.CallbackUrl, ";")
49+
if len(s) < 3 {
50+
domain := p.CallbackUrl + ";" + opts.Domain
51+
52+
return add(domain)
53+
} else {
54+
return &cmdutil.FlagError{Err: errors.New("more than 3 domains cannot be added in free plan")}
55+
}
56+
57+
},
58+
}
59+
60+
fl := cmd.Flags()
61+
fl.StringVarP(&opts.Domain, "domain", "d", "", "domain name")
62+
63+
return cmd
64+
}
65+
66+
func get() (*domainManagement, error) {
67+
conf := config.GetInstance()
68+
var url string
69+
url = conf.AdminConsoleAPIDomain + "/deployment/sites?"
70+
71+
var resultResp *domainManagement
72+
resp, err := request.Rest(http.MethodGet, url, nil, "")
73+
err = json.Unmarshal(resp, &resultResp)
74+
if err != nil {
75+
return nil, err
76+
}
77+
78+
return resultResp, nil
79+
}
80+
81+
func add(domain string) error {
82+
var url string
83+
fmt.Printf("domain=%s", domain)
84+
body, _ := json.Marshal(map[string]string{
85+
"domain": "http://localhost",
86+
"production": domain,
87+
"staging": "",
88+
})
89+
conf := config.GetInstance()
90+
91+
url = conf.AdminConsoleAPIDomain + "/deployment/sites?"
92+
93+
var resultResp Result
94+
resp, err := request.Rest(http.MethodPost, url, nil, string(body))
95+
err = json.Unmarshal(resp, &resultResp)
96+
if err != nil {
97+
return err
98+
}
99+
fmt.Println(resultResp.CallbackUrl)
100+
return nil
101+
}

0 commit comments

Comments
 (0)