Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2020-01-29 14:47:52 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2020-01-29 14:47:52 +0300
commit2afc2463559e19ee40bcb0770ce49438adca0735 (patch)
tree3b8d8affae02aadcbd6a483c19bc1cf4037f7bda /internal/serving
parentc6a8765668f8566d4f5b2171f3d463ba497111df (diff)
Rename serverless cluster config to certs config
Diffstat (limited to 'internal/serving')
-rw-r--r--internal/serving/serverless/cluster.go20
-rw-r--r--internal/serving/serverless/serverless_test.go18
2 files changed, 19 insertions, 19 deletions
diff --git a/internal/serving/serverless/cluster.go b/internal/serving/serverless/cluster.go
index 3912fc73..b511f409 100644
--- a/internal/serving/serverless/cluster.go
+++ b/internal/serving/serverless/cluster.go
@@ -8,20 +8,20 @@ import (
// Cluster represent a Knative cluster that we want to proxy requests to
type Cluster struct {
Address string
- Hostname string
Port string
- Config *Config
+ Hostname string
+ Certs *ClusterCerts
}
-// Config holds configuration for a cluster, especially definition of
-// certificates we use to perform mTLS handshake
-type Config struct {
+// ClusterCerts holds definition of certificates we use to perform mTLS
+// handshake
+type ClusterCerts struct {
RootCerts *x509.CertPool
Certificate tls.Certificate
}
-// NewClusterConfig creates a new cluster configuration from cert / key pair
-func NewClusterConfig(clientCert, clientKey string) (*Config, error) {
+// NewClusterCerts creates a new cluster configuration from cert / key pair
+func NewClusterCerts(clientCert, clientKey string) (*ClusterCerts, error) {
cert, err := tls.X509KeyPair([]byte(clientCert), []byte(clientKey))
if err != nil {
return nil, err
@@ -30,14 +30,14 @@ func NewClusterConfig(clientCert, clientKey string) (*Config, error) {
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM([]byte(clientCert))
- return &Config{RootCerts: caCertPool, Certificate: cert}, nil
+ return &ClusterCerts{RootCerts: caCertPool, Certificate: cert}, nil
}
// TLSConfig builds a new tls.Config and returns a pointer to it
func (c Cluster) TLSConfig() *tls.Config {
return &tls.Config{
- Certificates: []tls.Certificate{c.Config.Certificate},
- RootCAs: c.Config.RootCerts,
+ Certificates: []tls.Certificate{c.Certs.Certificate},
+ RootCAs: c.Certs.RootCerts,
ServerName: c.Hostname,
}
}
diff --git a/internal/serving/serverless/serverless_test.go b/internal/serving/serverless/serverless_test.go
index 20e88d50..96627d7a 100644
--- a/internal/serving/serverless/serverless_test.go
+++ b/internal/serving/serverless/serverless_test.go
@@ -15,16 +15,16 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/internal/serving"
)
-func withTestCluster(t *testing.T, cert, key string, block func(*http.ServeMux, *url.URL, *Config)) {
+func withTestCluster(t *testing.T, cert, key string, block func(*http.ServeMux, *url.URL, *ClusterCerts)) {
mux := http.NewServeMux()
cluster := httptest.NewUnstartedServer(mux)
- config, err := NewClusterConfig(fixture.Certificate, fixture.Key)
+ certs, err := NewClusterCerts(fixture.Certificate, fixture.Key)
require.NoError(t, err)
cluster.TLS = &tls.Config{
- Certificates: []tls.Certificate{config.Certificate},
- RootCAs: config.RootCerts,
+ Certificates: []tls.Certificate{certs.Certificate},
+ RootCAs: certs.RootCerts,
}
cluster.StartTLS()
@@ -33,17 +33,17 @@ func withTestCluster(t *testing.T, cert, key string, block func(*http.ServeMux,
address, err := url.Parse(cluster.URL)
require.NoError(t, err)
- block(mux, address, config)
+ block(mux, address, certs)
}
func TestServeFileHTTP(t *testing.T) {
t.Run("when proxying simple request to a cluster", func(t *testing.T) {
- withTestCluster(t, fixture.Certificate, fixture.Key, func(mux *http.ServeMux, server *url.URL, config *Config) {
+ withTestCluster(t, fixture.Certificate, fixture.Key, func(mux *http.ServeMux, server *url.URL, certs *ClusterCerts) {
serverless := New(Cluster{
Hostname: "knative.gitlab-example.com",
Address: server.Hostname(),
Port: server.Port(),
- Config: config,
+ Certs: certs,
})
writer := httptest.NewRecorder()
@@ -66,12 +66,12 @@ func TestServeFileHTTP(t *testing.T) {
})
t.Run("when proxying request with invalid hostname", func(t *testing.T) {
- withTestCluster(t, fixture.Certificate, fixture.Key, func(mux *http.ServeMux, server *url.URL, config *Config) {
+ withTestCluster(t, fixture.Certificate, fixture.Key, func(mux *http.ServeMux, server *url.URL, certs *ClusterCerts) {
serverless := New(Cluster{
Hostname: "knative.invalid-gitlab-example.com",
Address: server.Hostname(),
Port: server.Port(),
- Config: config,
+ Certs: certs,
})
writer := httptest.NewRecorder()