Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
110 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/replicatedhq/kots/kotsadm/pkg/logger" | ||
"github.com/replicatedhq/kots/kotsadm/pkg/store" | ||
) | ||
|
||
type GetClustersResponse struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func GetClusters(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Access-Control-Allow-Origin", "*") | ||
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization") | ||
|
||
if r.Method == "OPTIONS" { | ||
w.WriteHeader(http.StatusOK) | ||
return | ||
} | ||
|
||
if err := requireValidSession(w, r); err != nil { | ||
logger.Error(err) | ||
return | ||
} | ||
|
||
clusters, err := store.GetStore().ListClusters() | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(500) | ||
return | ||
} | ||
|
||
resp := []GetClustersResponse{} | ||
for idx, val := range clusters { | ||
resp = append(resp, GetClustersResponse{ | ||
ID: idx, | ||
Name: val, | ||
}) | ||
} | ||
|
||
JSON(w, 200, resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package s3pg | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/replicatedhq/kots/kotsadm/pkg/persistence" | ||
) | ||
|
||
func (s S3PGStore) ListClusters() (map[string]string, error) { | ||
db := persistence.MustGetPGSession() | ||
|
||
query := `select id, title from cluster` | ||
rows, err := db.Query(query) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to query clusters") | ||
} | ||
defer rows.Close() | ||
clusterIDs := map[string]string{} | ||
for rows.Next() { | ||
clusterID := "" | ||
name := "" | ||
if err := rows.Scan(&clusterID, &name); err != nil { | ||
return nil, errors.Wrap(err, "failed to scan row") | ||
} | ||
clusterIDs[clusterID] = name | ||
} | ||
|
||
return clusterIDs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.