mirror of https://github.com/portainer/portainer
parent
19d4db13be
commit
914b46f813
@ -0,0 +1,19 @@
|
||||
package factory
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/portainer/portainer/api/http/proxy/factory/gitlab"
|
||||
)
|
||||
|
||||
func newGitlabProxy(uri string) (http.Handler, error) {
|
||||
url, err := url.Parse(uri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxy := newSingleHostReverseProxyWithHostHeader(url)
|
||||
proxy.Transport = gitlab.NewTransport()
|
||||
return proxy, nil
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package gitlab
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Transport struct {
|
||||
httpTransport *http.Transport
|
||||
}
|
||||
|
||||
// NewTransport returns a pointer to a new instance of Transport that implements the HTTP Transport
|
||||
// interface for proxying requests to the Gitlab API.
|
||||
func NewTransport() *Transport {
|
||||
return &Transport{
|
||||
httpTransport: &http.Transport{},
|
||||
}
|
||||
}
|
||||
|
||||
// RoundTrip is the implementation of the the http.RoundTripper interface
|
||||
func (transport *Transport) RoundTrip(request *http.Request) (*http.Response, error) {
|
||||
token := request.Header.Get("Private-Token")
|
||||
if token == "" {
|
||||
return nil, errors.New("no gitlab token provided")
|
||||
}
|
||||
|
||||
r, err := http.NewRequest(request.Method, request.URL.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.Header.Set("Private-Token", token)
|
||||
return transport.httpTransport.RoundTrip(r)
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type gitlabTransport struct {
|
||||
httpTransport *http.Transport
|
||||
}
|
||||
|
||||
func newGitlabProxy(uri string) (http.Handler, error) {
|
||||
url, err := url.Parse(uri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxy := newSingleHostReverseProxyWithHostHeader(url)
|
||||
proxy.Transport = &gitlabTransport{
|
||||
httpTransport: &http.Transport{},
|
||||
}
|
||||
|
||||
return proxy, nil
|
||||
}
|
||||
|
||||
func (transport *gitlabTransport) RoundTrip(request *http.Request) (*http.Response, error) {
|
||||
token := request.Header.Get("Private-Token")
|
||||
if token == "" {
|
||||
return nil, errors.New("No gitlab token provided")
|
||||
}
|
||||
r, err := http.NewRequest(request.Method, request.URL.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Header.Set("Private-Token", token)
|
||||
return transport.httpTransport.RoundTrip(r)
|
||||
}
|
Loading…
Reference in new issue