Skip to content

Commit 646ea5b

Browse files
committed
Read config from github
1 parent edfb1e8 commit 646ea5b

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

scripts/golang/cmd/generate.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ var generateCmd = &cobra.Command{
2323
the Firewall public API and merges them together (including by removing schemas shared
2424
between the microservices).`,
2525
Run: func(cmd *cobra.Command, args []string) {
26-
configFile, err := cmd.Flags().GetString("config")
26+
configUrl, err := cmd.Flags().GetString("config")
2727
if err != nil {
28-
pterm.Error.Println("Failed to get config file path", err)
28+
pterm.Error.Println("Failed to get config URL", err)
2929
os.Exit(1)
3030
}
3131
outputFile, err := cmd.Flags().GetString("output")
@@ -34,8 +34,8 @@ var generateCmd = &cobra.Command{
3434
}
3535

3636
spinner, _ := pterm.DefaultSpinner.Start("Loading configuration file...")
37-
config := services.LoadConfig(configFile)
38-
spinner.Success(fmt.Sprintf("Configuration file loaded successfully: %s", configFile))
37+
config := services.LoadConfig(configUrl)
38+
spinner.Success(fmt.Sprintf("Configuration file loaded successfully: %s", configUrl))
3939

4040
serviceSpecs := make(map[string]*models.OpenAPI)
4141
for _, service := range config.Services {

scripts/golang/cmd/root.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ Copyright © 2025 Cisco Systems
44
package cmd
55

66
import (
7-
"fmt"
8-
"github.com/pterm/pterm"
9-
"os"
10-
"path/filepath"
11-
127
"github.com/spf13/cobra"
8+
"os"
139
)
1410

1511
// rootCmd represents the base command when called without any subcommands
@@ -29,10 +25,5 @@ func Execute() {
2925
}
3026

3127
func init() {
32-
homeDir, err := os.UserHomeDir()
33-
if err != nil {
34-
pterm.Error.Println("Failed to get home directory", err)
35-
}
36-
defaultConfigFilePath := filepath.Join(homeDir, ".cloud-fw-mgr-api-docs.config.yaml")
37-
rootCmd.PersistentFlags().StringP("config", "c", defaultConfigFilePath, fmt.Sprintf("config file (default is %s)", defaultConfigFilePath))
28+
rootCmd.PersistentFlags().StringP("config", "c", "https://github.com/cisco-lockhart/cdo-public-api-docs/blob/LH-89186-improve-api-doc-generation/cloud-fw-mgr-api-docs.config.yaml", "config URL")
3829
}

scripts/golang/services/config-reader.service.go

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
package services
22

33
import (
4+
"fmt"
45
"github.com/cisco-lockhart/fcm-api-docs-generator/models"
56
"gopkg.in/yaml.v3"
6-
"os"
7+
"io"
8+
"net/http"
79
)
810

9-
func LoadConfig(filename string) *models.Config {
11+
func LoadConfig(url string) *models.Config {
1012
// Load the configuration file
11-
data, err := os.ReadFile(filename)
13+
resp, err := http.Get(url)
14+
if err != nil {
15+
panic(err)
16+
}
17+
defer func(Body io.ReadCloser) {
18+
err := Body.Close()
19+
if err != nil {
20+
panic(err)
21+
}
22+
}(resp.Body)
23+
24+
// Check if the request was successful
25+
if resp.StatusCode != http.StatusOK {
26+
panic(fmt.Sprintf("failed to fetch URL: %s, status code: %d", url, resp.StatusCode))
27+
}
28+
29+
// Read the response body
30+
data, err := io.ReadAll(resp.Body)
1231
if err != nil {
1332
panic(err)
1433
}

0 commit comments

Comments
 (0)