Commit 513a1854 authored by Michelle Noorali's avatar Michelle Noorali

Merge pull request #414 from michelleN/repo-cmds

feat(repo): add chart repo routes to manager
parents bc90e18b 61dd6644
......@@ -28,8 +28,8 @@ func init() {
addCommands(repoCommands())
}
var dmURL string = "http://localhost:8080"
var chartRepoPath string = "chart_repositories"
var dmURL = "http://localhost:8080"
var chartRepoPath = "chart_repositories"
func repoCommands() cli.Command {
return cli.Command{
......@@ -93,7 +93,7 @@ func addRepo(c *cli.Context) error {
}
client := client.NewClient(dmURL)
var dest string = ""
dest := ""
_, err := client.Post(chartRepoPath, nil, &dest)
if err != nil {
return err
......@@ -104,7 +104,7 @@ func addRepo(c *cli.Context) error {
func listRepos(c *cli.Context) error {
client := client.NewClient(dmURL)
var dest string = ""
dest := ""
_, err := client.Get(chartRepoPath, &dest)
if err != nil {
return err
......@@ -119,7 +119,7 @@ func removeRepo(c *cli.Context) error {
return errors.New("'helm repo remove' requires a repository as an argument")
}
client := client.NewClient(dmURL)
var dest string = ""
dest := ""
_, err := client.Delete(chartRepoPath, &dest)
if err != nil {
return err
......
......@@ -14,18 +14,38 @@ func registerChartRepoRoutes(c *router.Context, h *router.Handler) {
func listChartRepositoriesHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
handler := "manager: list chart repositories"
util.LogHandlerExitWithJSON(handler, w, "a repo here", http.StatusOK)
repos, err := c.Manager.ListChartRepos()
if err != nil {
return err
}
util.LogHandlerExitWithJSON(handler, w, repos, http.StatusOK)
return nil
}
func addChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
handler := "manager: add chart repository"
util.LogHandlerExitWithJSON(handler, w, "add a repo", http.StatusOK)
name, err := pos(w, r, 2)
if err != nil {
return err
}
err = c.Manager.AddChartRepo(name)
if err != nil {
return err
}
util.LogHandlerExitWithJSON(handler, w, "added", http.StatusOK)
return nil
}
func removeChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *router.Context) error {
handler := "manager: remove chart repository"
util.LogHandlerExitWithJSON(handler, w, "remove a repo", http.StatusOK)
name, err := pos(w, r, 2)
if err != nil {
return err
}
err = c.Manager.RemoveChartRepo(name)
if err != nil {
return err
}
util.LogHandlerExitWithJSON(handler, w, "removed", http.StatusOK)
return nil
}
package main
import (
"net/http"
"testing"
)
func TestListChartRepositories(t *testing.T) {
c := stubContext()
s := httpHarness(c, "GET /chart_repositories", listChartRepositoriesHandlerFunc)
defer s.Close()
res, err := http.Get(s.URL + "/chart_repositories")
if err != nil {
t.Errorf("Failed GET: %s", err)
} else if res.StatusCode != http.StatusOK {
t.Errorf("Expected status %d, got %d", http.StatusOK, res.StatusCode)
}
}
......@@ -3,16 +3,12 @@ package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"regexp"
"strings"
"testing"
"github.com/kubernetes/helm/cmd/manager/router"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/httputil"
"github.com/kubernetes/helm/pkg/registry"
)
func TestHealthz(t *testing.T) {
......@@ -21,13 +17,29 @@ func TestHealthz(t *testing.T) {
defer s.Close()
res, err := http.Get(s.URL)
if err != nil {
t.Fatalf("err on http get: %v", err)
}
body, err := ioutil.ReadAll(res.Body)
defer res.Body.Close()
if err != nil {
t.Fatalf("Failed to GET healthz: %s", err)
} else if res.StatusCode != 200 {
t.Fatalf("Unexpected status: %d", res.StatusCode)
}
// TODO: Get the body and check on the content type and the body.
expectedBody := "OK"
if bytes.Equal(body, []byte(expectedBody)) {
t.Fatalf("Expected response body: %s, Actual response body: %s",
expectedBody, string(body))
}
expectedContentType := "text/plain"
contentType := res.Header["Content-Type"][0]
if !strings.Contains(contentType, expectedContentType) {
t.Fatalf("Expected Content-Type to include %s", expectedContentType)
}
}
func TestCreateDeployments(t *testing.T) {
......@@ -48,99 +60,3 @@ func TestCreateDeployments(t *testing.T) {
t.Errorf("Expected status %d, got %d", http.StatusCreated, res.StatusCode)
}
}
// httpHarness is a simple test server fixture.
// Simple fixture for standing up a test server with a single route.
//
// You must Close() the returned server.
func httpHarness(c *router.Context, route string, fn router.HandlerFunc) *httptest.Server {
h := router.NewHandler(c)
h.Add(route, fn)
return httptest.NewServer(h)
}
// stubContext creates a stub of a Context object.
//
// This creates a stub context with the following properties:
// - Config is initialized to empty values
// - Encoder is initialized to httputil.DefaultEncoder
// - CredentialProvider is initialized to registry.InmemCredentialProvider
// - Manager is initialized to mockManager.
func stubContext() *router.Context {
return &router.Context{
Config: &router.Config{},
Manager: &mockManager{},
CredentialProvider: registry.NewInmemCredentialProvider(),
Encoder: httputil.DefaultEncoder,
}
}
type mockManager struct{}
func (m *mockManager) ListDeployments() ([]common.Deployment, error) {
return []common.Deployment{}, nil
}
func (m *mockManager) GetDeployment(name string) (*common.Deployment, error) {
return &common.Deployment{}, nil
}
func (m *mockManager) CreateDeployment(t *common.Template) (*common.Deployment, error) {
return &common.Deployment{}, nil
}
func (m *mockManager) DeleteDeployment(name string, forget bool) (*common.Deployment, error) {
return &common.Deployment{}, nil
}
func (m *mockManager) PutDeployment(name string, t *common.Template) (*common.Deployment, error) {
return &common.Deployment{}, nil
}
func (m *mockManager) ListManifests(deploymentName string) (map[string]*common.Manifest, error) {
return map[string]*common.Manifest{}, nil
}
func (m *mockManager) GetManifest(deploymentName string, manifest string) (*common.Manifest, error) {
return &common.Manifest{}, nil
}
func (m *mockManager) Expand(t *common.Template) (*common.Manifest, error) {
return &common.Manifest{}, nil
}
func (m *mockManager) ListTypes() ([]string, error) {
return []string{}, nil
}
func (m *mockManager) ListInstances(typeName string) ([]*common.TypeInstance, error) {
return []*common.TypeInstance{}, nil
}
func (m *mockManager) GetRegistryForType(typeName string) (string, error) {
return "", nil
}
func (m *mockManager) GetMetadataForType(typeName string) (string, error) {
return "", nil
}
func (m *mockManager) ListRegistries() ([]*common.Registry, error) {
return []*common.Registry{}, nil
}
func (m *mockManager) CreateRegistry(pr *common.Registry) error {
return nil
}
func (m *mockManager) GetRegistry(name string) (*common.Registry, error) {
return &common.Registry{}, nil
}
func (m *mockManager) DeleteRegistry(name string) error {
return nil
}
func (m *mockManager) ListRegistryTypes(registryName string, regex *regexp.Regexp) ([]registry.Type, error) {
return []registry.Type{}, nil
}
func (m *mockManager) GetDownloadURLs(registryName string, t registry.Type) ([]*url.URL, error) {
return []*url.URL{}, nil
}
func (m *mockManager) GetFile(registryName string, url string) (string, error) {
return "", nil
}
func (m *mockManager) CreateCredential(name string, c *common.RegistryCredential) error {
return nil
}
func (m *mockManager) GetCredential(name string) (*common.RegistryCredential, error) {
return &common.RegistryCredential{}, nil
}
......@@ -64,6 +64,11 @@ type Manager interface {
// Credentials
CreateCredential(name string, c *common.RegistryCredential) error
GetCredential(name string) (*common.RegistryCredential, error)
// Chart Repositories
ListChartRepos() ([]string, error)
AddChartRepo(name string) error
RemoveChartRepo(name string) error
}
type manager struct {
......@@ -72,6 +77,7 @@ type manager struct {
repository repository.Repository
registryProvider registry.RegistryProvider
service common.RegistryService
//TODO: add chart repo service
credentialProvider common.CredentialProvider
}
......@@ -81,6 +87,7 @@ func NewManager(expander Expander,
repository repository.Repository,
registryProvider registry.RegistryProvider,
service common.RegistryService,
//TODO: add chart repo service
credentialProvider common.CredentialProvider) Manager {
return &manager{expander, deployer, repository, registryProvider, service, credentialProvider}
}
......@@ -378,6 +385,24 @@ func (m *manager) ListRegistries() ([]*common.Registry, error) {
return m.service.List()
}
// ListChartRepos returns the list of chart repositories
func (m *manager) ListChartRepos() ([]string, error) {
//TODO: implement
return nil, nil
}
// AddChartRepo adds a chart repository to list of available chart repositories
func (m *manager) AddChartRepo(name string) error {
//TODO: implement
return nil
}
// RemoveChartRepo removes a chart repository to list of available chart repositories
func (m *manager) RemoveChartRepo(name string) error {
//TODO: implement
return nil
}
func (m *manager) CreateRegistry(pr *common.Registry) error {
return m.service.Create(pr)
}
......
package main
import (
"net/http/httptest"
"net/url"
"regexp"
"github.com/kubernetes/helm/cmd/manager/router"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/httputil"
"github.com/kubernetes/helm/pkg/registry"
)
// httpHarness is a simple test server fixture.
// Simple fixture for standing up a test server with a single route.
//
// You must Close() the returned server.
func httpHarness(c *router.Context, route string, fn router.HandlerFunc) *httptest.Server {
h := router.NewHandler(c)
h.Add(route, fn)
return httptest.NewServer(h)
}
// stubContext creates a stub of a Context object.
//
// This creates a stub context with the following properties:
// - Config is initialized to empty values
// - Encoder is initialized to httputil.DefaultEncoder
// - CredentialProvider is initialized to registry.InmemCredentialProvider
// - Manager is initialized to mockManager.
func stubContext() *router.Context {
return &router.Context{
Config: &router.Config{},
Manager: &mockManager{},
CredentialProvider: registry.NewInmemCredentialProvider(),
Encoder: httputil.DefaultEncoder,
}
}
type mockManager struct{}
func (m *mockManager) ListDeployments() ([]common.Deployment, error) {
return []common.Deployment{}, nil
}
func (m *mockManager) GetDeployment(name string) (*common.Deployment, error) {
return &common.Deployment{}, nil
}
func (m *mockManager) CreateDeployment(t *common.Template) (*common.Deployment, error) {
return &common.Deployment{}, nil
}
func (m *mockManager) DeleteDeployment(name string, forget bool) (*common.Deployment, error) {
return &common.Deployment{}, nil
}
func (m *mockManager) PutDeployment(name string, t *common.Template) (*common.Deployment, error) {
return &common.Deployment{}, nil
}
func (m *mockManager) ListManifests(deploymentName string) (map[string]*common.Manifest, error) {
return map[string]*common.Manifest{}, nil
}
func (m *mockManager) GetManifest(deploymentName string, manifest string) (*common.Manifest, error) {
return &common.Manifest{}, nil
}
func (m *mockManager) Expand(t *common.Template) (*common.Manifest, error) {
return &common.Manifest{}, nil
}
func (m *mockManager) ListTypes() ([]string, error) {
return []string{}, nil
}
func (m *mockManager) ListInstances(typeName string) ([]*common.TypeInstance, error) {
return []*common.TypeInstance{}, nil
}
func (m *mockManager) GetRegistryForType(typeName string) (string, error) {
return "", nil
}
func (m *mockManager) GetMetadataForType(typeName string) (string, error) {
return "", nil
}
func (m *mockManager) AddChartRepo(name string) error {
return nil
}
func (m *mockManager) ListChartRepos() ([]string, error) {
return []string{}, nil
}
func (m *mockManager) RemoveChartRepo(name string) error {
return nil
}
func (m *mockManager) ListRegistries() ([]*common.Registry, error) {
return []*common.Registry{}, nil
}
func (m *mockManager) CreateRegistry(pr *common.Registry) error {
return nil
}
func (m *mockManager) GetRegistry(name string) (*common.Registry, error) {
return &common.Registry{}, nil
}
func (m *mockManager) DeleteRegistry(name string) error {
return nil
}
func (m *mockManager) ListRegistryTypes(registryName string, regex *regexp.Regexp) ([]registry.Type, error) {
return []registry.Type{}, nil
}
func (m *mockManager) GetDownloadURLs(registryName string, t registry.Type) ([]*url.URL, error) {
return []*url.URL{}, nil
}
func (m *mockManager) GetFile(registryName string, url string) (string, error) {
return "", nil
}
func (m *mockManager) CreateCredential(name string, c *common.RegistryCredential) error {
return nil
}
func (m *mockManager) GetCredential(name string) (*common.RegistryCredential, error) {
return &common.RegistryCredential{}, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment