-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
39 lines (31 loc) · 946 Bytes
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cli
import (
"net/url"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
)
type Handler struct {
Migration *MigrateHandler
}
func Remote(cmd *cobra.Command) string {
if endpoint := flagx.MustGetString(cmd, "endpoint"); endpoint != "" {
return strings.TrimRight(endpoint, "/")
} else if endpoint := os.Getenv("HYDRA_URL"); endpoint != "" {
return strings.TrimRight(endpoint, "/")
}
cmdx.Fatalf("To execute this command, the endpoint URL must point to the URL where ORY Hydra is located. To set the endpoint URL, use flag --endpoint or environment variable HYDRA_URL if an administrative command was used.")
return ""
}
func RemoteURI(cmd *cobra.Command) *url.URL {
endpoint, err := url.ParseRequestURI(Remote(cmd))
cmdx.Must(err, "Unable to parse remote url: %s", err)
return endpoint
}
func NewHandler() *Handler {
return &Handler{
Migration: newMigrateHandler(),
}
}