Skip to content

Commit

Permalink
Initial plan for kubeapps backend API which can be used by 3rd partie…
Browse files Browse the repository at this point in the history
…s. (#1347)

* Initial plan for kubeapps backend API which can be used by 3rd parties.

* Remove AuthGate and switch /api/v1/ for backend API
  • Loading branch information
absoludity authored Dec 11, 2019
1 parent f6cd36c commit 24e83ae
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
13 changes: 13 additions & 0 deletions chart/kubeapps/templates/kubeapps-frontend-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ data:
{{- end }}
}
# The route for the Kubeapps backend API is not prefixed.
location ~* /api/ {
rewrite /api/(.*) /backend/$1 break;
rewrite /api/ /backend break;
{{- if .Values.frontend.proxypassAccessTokenAsBearer }}
# Google Kubernetes Engine requires the access_token as the Bearer when talking to the k8s api server.
proxy_set_header Authorization "Bearer $http_x_forwarded_access_token";
{{- end }}
proxy_pass http://{{ template "kubeapps.tiller-proxy.fullname" . }}:{{ .Values.tillerProxy.service.port }};
}
location / {
# Add the Authorization header if exists
add_header Authorization $http_authorization;
Expand Down
34 changes: 34 additions & 0 deletions cmd/tiller-proxy/internal/handler/apprepos_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright (c) 2019 Bitnami
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package handler

import (
"net/http"

log "github.com/sirupsen/logrus"
)

// AppRepositories handles http requests for operating on app repositories
// in Kubeapps, without exposing implementation details to 3rd party integrations.
type AppRepositories struct{}

func (a *AppRepositories) Create(w http.ResponseWriter, req *http.Request) {
log.Printf("Creating AppRepository")
// TODO: Create AppRepository using the k8s client.
w.WriteHeader(http.StatusCreated)
w.Write([]byte("OK"))
}
36 changes: 36 additions & 0 deletions cmd/tiller-proxy/internal/handler/apprepos_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright (c) 2019 Bitnami
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package handler

import (
"net/http/httptest"
"strings"
"testing"
)

func TestAppRepositoryCreate(t *testing.T) {
handler := AppRepositories{}

req := httptest.NewRequest("POST", "https://foo.bar/backend/v1/apprepositories", strings.NewReader(""))

response := httptest.NewRecorder()
handler.Create(response, req)

if got, want := response.Code, 201; got != want {
t.Errorf("got: %d, want: %d", got, want)
}
}
9 changes: 9 additions & 0 deletions cmd/tiller-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ func main() {
negroni.Wrap(handlerutil.WithParams(h.DeleteRelease)),
))

// Backend routes unrelated to tiller-proxy functionality.
// TODO(mnelson): Once the helm3 support is complete and tiller-proxy is being removed,
// reconsider where these endpoints live.
appreposHandler := handler.AppRepositories{}
backendAPIv1 := r.PathPrefix("/backend/v1").Subrouter()
backendAPIv1.Methods("POST").Path("/apprepositories").Handler(negroni.New(
negroni.WrapFunc(appreposHandler.Create),
))

// Chartsvc reverse proxy
parsedChartsvcURL, err := url.Parse(chartsvcURL)
if err != nil {
Expand Down

0 comments on commit 24e83ae

Please sign in to comment.