To run the Core Function from the command line, run the following commands from this folder. For the parameter `chartMuseumUrl`, if it is not provided CAPIF Core will not do any Helm integration, i.e. try to start any Halm chart when publishing a service.
- ./capifcore [-port <port (default 8090)>] [-chartMuseumUrl <URL to ChartMuseum>] [-repoName <Helm repo name (default capifcore)>] [-loglevel <log level (default Info)>]
+ ./capifcore [-port <port (default 8090)>] [-secPort <Secure port (default 4433)>] [-chartMuseumUrl <URL to ChartMuseum>] [-repoName <Helm repo name (default capifcore)>] [-loglevel <log level (default Info)>] [-certPath <Path to certificate>] [-keyPath <Path to private key>]
To run CAPIF Core as a K8s pod together with ChartMuseum, start and stop scripts are provided. The pod configurations are provided in the `configs` folder. CAPIF Core is then available on port `31570`.
--- /dev/null
+-----BEGIN CERTIFICATE-----
+MIICMzCCAZygAwIBAgIRAI4ZifW8kkZA8erUGGlExBIwDQYJKoZIhvcNAQELBQAw
+EjEQMA4GA1UEChMHQWNtZSBDbzAgFw03MDAxMDEwMDAwMDBaGA8yMDg0MDEyOTE2
+MDAwMFowEjEQMA4GA1UEChMHQWNtZSBDbzCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
+gYkCgYEAvjU9/c+2dpoRRMnJPMh9eGAWA0cfg2h+AVotSVCqgJ+Hlr91BWCE0dDV
+nIlNGVXZSkxI4rRTI3DZi8wdEWNeiPBIQDbUpNDofCZ/AeAMfzhMb3cyMMZcZMG6
+Zx0aXvEdZhAmJjBUAT1+XrIAegLQvhN2g9awcaWVkuxoawG2HF0CAwEAAaOBhjCB
+gzAOBgNVHQ8BAf8EBAMCAqQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDwYDVR0TAQH/
+BAUwAwEB/zAdBgNVHQ4EFgQUuhJx8jwPJYB3Zg2Aaa4ZsVZ78v8wLAYDVR0RBCUw
+I4IJbG9jYWxob3N0hwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMA0GCSqGSIb3DQEB
+CwUAA4GBAKHALs8ifFaoVQw0GaCmIQt/yS9eWcssGGJHmAM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main() {
var port = flag.Int("port", 8090, "Port for CAPIF Core Function HTTP server")
+ var secPort = flag.Int("secPort", 4433, "Port for CAPIF Core Function HTTPS server")
flag.StringVar(&url, "chartMuseumUrl", "", "ChartMuseum URL")
flag.StringVar(&repoName, "repoName", "capifcore", "Repository name")
var logLevelStr = flag.String("loglevel", "Info", "Log level")
+ var certPath = flag.String("certPath", "certs/cert.pem", "Path for server certificate")
+ var keyPath = flag.String("keyPath", "certs/key.pem", "Path for server private key")
+
flag.Parse()
if loglevel, err := log.ParseLevel(*logLevelStr); err == nil {
}
go startWebServer(getEcho(), *port)
+ go startHttpsWebServer(getEcho(), *secPort, *certPath, *keyPath)
log.Info("Server started and listening on port: ", *port)
e.Logger.Fatal(e.Start(fmt.Sprintf("0.0.0.0:%d", port)))
}
+func startHttpsWebServer(e *echo.Echo, port int, certPath string, keyPath string) {
+ e.Logger.Fatal(e.StartTLS(fmt.Sprintf("0.0.0.0:%d", port), certPath, keyPath))
+}
+
func keepServerAlive() {
forever := make(chan int)
<-forever
}
func hello(c echo.Context) error {
- return c.String(http.StatusOK, "Hello, World!\n")
+ return c.String(http.StatusOK, "Hello, World!")
}
func getSwagger(c echo.Context) error {
package main
import (
+ "crypto/tls"
+ "fmt"
+ "io"
"net/http"
"testing"
+ "time"
"github.com/deepmap/oapi-codegen/pkg/testutil"
"github.com/getkin/kin-openapi/openapi3"
assert.Contains(t, *errorResponse.Cause, "Invalid API")
assert.Contains(t, *errorResponse.Cause, invalidApi)
}
+
+func TestHTTPSServer(t *testing.T) {
+ e = getEcho()
+ var port = 44333
+ go startHttpsWebServer(e, 44333, "certs/cert.pem", "certs/key.pem") //"certs/test/cert.pem", "certs/test/key.pem"
+
+ time.Sleep(100 * time.Millisecond)
+
+ tr := &http.Transport{
+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+ }
+
+ client := &http.Client{Transport: tr}
+ res, err := client.Get(fmt.Sprintf("https://localhost:%d", port))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ defer res.Body.Close()
+ assert.Equal(t, res.StatusCode, res.StatusCode)
+
+ body, err := io.ReadAll(res.Body)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ expected := []byte("Hello, World!")
+ assert.Equal(t, expected, body)
+}