MCPcopy Create free account
hub / github.com/conforma/cli / startStubGitServer

Function startStubGitServer

acceptance/git/git.go:77–203  ·  view source on GitHub ↗

startStubGitServer launches a stub git server and exposes the port via NAT from the container

(ctx context.Context)

Source from the content-addressed store, hash-verified

75
76// startStubGitServer launches a stub git server and exposes the port via NAT from the container
77func startStubGitServer(ctx context.Context) (context.Context, error) {
78 var state *gitState
79 ctx, err := testenv.SetupState(ctx, &state)
80 if err != nil {
81 return ctx, err
82 }
83
84 if state.Up() {
85 return ctx, nil
86 }
87
88 // the directory on the host where we'll store the git repositories
89 repositories, err := os.MkdirTemp("", "git.*")
90 if err != nil {
91 return ctx, err
92 }
93
94 nginxConfDir := path.Join(repositories, "conf")
95 if err = os.Mkdir(nginxConfDir, 0o755); err != nil {
96 return ctx, err
97 }
98 if err = os.WriteFile(path.Join(nginxConfDir, "nginx.conf"), nginxConf, 0o400); err != nil {
99 return ctx, err
100 }
101
102 tlsDir := path.Join(repositories, "tls")
103 if err = os.Mkdir(tlsDir, 0o755); err != nil {
104 return ctx, err
105 }
106
107 if key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader); err != nil {
108 return ctx, err
109 } else if keyBytes, err := x509.MarshalECPrivateKey(key); err != nil {
110 return ctx, err
111 } else {
112 keyPem := pem.EncodeToMemory(&pem.Block{
113 Type: "EC PRIVATE KEY",
114 Bytes: keyBytes,
115 })
116
117 if err = os.WriteFile(path.Join(tlsDir, "server.key"), keyPem, 0o400); err != nil {
118 return ctx, err
119 }
120
121 serial, err := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
122 if err != nil {
123 return ctx, err
124 }
125
126 templ := x509.Certificate{
127 DNSNames: []string{"localhost"},
128 Subject: pkix.Name{CommonName: "localhost"},
129 SerialNumber: serial,
130 NotBefore: time.Now().Add(-24 * time.Hour),
131 NotAfter: time.Now().Add(24 * time.Hour),
132 KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
133 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
134 }

Callers

nothing calls this directly

Calls 6

UpMethod · 0.95
SetupStateFunction · 0.92
TestContainersRequestFunction · 0.92
LoggerForFunction · 0.92
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected