-
Notifications
You must be signed in to change notification settings - Fork 0
/
portal_endpoints.go
71 lines (56 loc) · 1.93 KB
/
portal_endpoints.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cmd
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var portalEndpointsCmd = &cobra.Command{
Use: "endpoints",
Short: "Display the API Manager Developer Portal endpoints",
RunE: func(cmd *cobra.Command, args []string) error {
if err := doPortalEndpoints(); err != nil {
return err
}
return nil
},
}
func init() {
portalEndpointsCmd.Flags().StringVar(&portalCmdOpts.apimName, "apim", "", "API Manager instance")
portalEndpointsCmd.Flags().StringVar(&portalCmdOpts.resourceGroup, "rg", "", "Resource group containing the APIM instance")
portalEndpointsCmd.Flags().BoolVar(&portalCmdOpts.asJSON, "json", false, "Return results as JSON")
errPanic(portalEndpointsCmd.MarkFlagRequired("apim"))
errPanic(portalEndpointsCmd.MarkFlagRequired("rg"))
errPanic(viper.GetViper().BindPFlag("apim", portalEndpointsCmd.Flags().Lookup("apim")))
errPanic(viper.GetViper().BindPFlag("rg", portalEndpointsCmd.Flags().Lookup("rg")))
errPanic(viper.GetViper().BindPFlag("json", portalEndpointsCmd.Flags().Lookup("json")))
portalCmd.AddCommand(portalEndpointsCmd)
}
type endpointsInfo struct {
DevPortalBlobStorageURL string `json:"blob_storage_url"`
DevPortalURL string `json:"dev_portal_url"`
ApimMgmtURL string `json:"management_url"`
}
func doPortalEndpoints() error {
info, err := buildApimInfo(azureAPIVersion)
if err != nil {
return err
}
if viper.GetBool("json") {
ep := endpointsInfo{
DevPortalBlobStorageURL: info.devPortalBlobStorageURL,
DevPortalURL: info.devPortalURL,
ApimMgmtURL: info.apimMgmtURL,
}
b, err := json.MarshalIndent(ep, "", " ")
if err != nil {
return err
}
fmt.Println(string(b))
} else {
fmt.Printf("Developer portal URL: %s\n", info.devPortalURL)
fmt.Printf(" Management URL: %s\n", info.apimMgmtURL)
fmt.Printf(" Blob storage URL: %s\n", info.devPortalBlobStorageURL)
}
return nil
}