Skip to content

Commit

Permalink
Merge pull request #26 from dmartinol/23-browser-not-showing-latest-u…
Browse files Browse the repository at this point in the history
…rl-after-completion

Changed to POST method
  • Loading branch information
dmartinol authored Sep 27, 2022
2 parents 5b2f335 + 6cffad9 commit d5c07a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Go application to export the configuration of applications deployed in OpenShift
* Filter namespaces by configurable label(s)
* For each application (e.g., any `Deplopyment`, `DeploymentConfig` and `StatefulSet` in the matching namespaces), collect the image name and version and the resource configuration and usage (optional)
* Export configuration in configurable format (text or CSV)
* Run as a script or a REST service
* Run as a script or a REST service (`POST` to `/inventory` endpoint)
* Run as a standalone executable or in OpenShift containerized environment (REST service only)

Sample output in CSV format without the resource configuration and usage data:
Expand Down Expand Up @@ -83,8 +83,8 @@ go run main.go --help

The following are examples of requests performed using `curl`:
```bash
curl "http://localhost:8080/inventory"
curl "http://localhost:8080/inventory?content-type=CSV&ns-selector=mylabel=myvalue"
curl -X POST "http://localhost:8080/inventory"
curl -X POST "http://localhost:8080/inventory?content-type=CSV&ns-selector=mylabel=myvalue"
```

### Running the binary executable
Expand Down
10 changes: 7 additions & 3 deletions pkg/exporter/exporter_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ func (s *ExporterService) Run() {
router.Path("/inventory").Queries("content-type", "{content-type}").Queries("ns-selector", "{ns-selector}").Queries("output", "{output}").Queries("with-resources", "{with-resources}").HandlerFunc(s.inventoryHandler).Name("inventoryHandler")
router.Path("/inventory").HandlerFunc(s.inventoryHandler).Name("inventoryHandler")

url := fmt.Sprintf("0.0.0.0:%d", s.config.ServerPort())
host := "localhost"
if s.config.RunInContainer() {
host = "0.0.0.0"
}
url := fmt.Sprintf("%s:%d", host, s.config.ServerPort())
logger.Infof("Starting listener as %s", url)
if err := http.ListenAndServe(url, router); err != nil {
logger.Fatal(err)
Expand Down Expand Up @@ -57,10 +61,10 @@ func (s *ExporterService) inventoryHandler(rw http.ResponseWriter, req *http.Req
}

if req.URL.Path == "/inventory" {
if req.Method == "GET" {
if req.Method == "POST" {
s.inventory(&newConfig, rw)
} else {
http.Error(rw, fmt.Sprintf("Expect method GET at /, got %v", req.Method), http.StatusMethodNotAllowed)
http.Error(rw, fmt.Sprintf("Expect method POST at /, got %v", req.Method), http.StatusMethodNotAllowed)
}
} else {
http.Error(rw, fmt.Sprintf("Unmanaged path %s", req.URL.Path), http.StatusNotFound)
Expand Down

0 comments on commit d5c07a2

Please sign in to comment.