Clean up docs and refactor createhandler

**What**
- Add a description for the secret key to the api swagger spec.
- Remove optional examples from the secret management guide.
- Update the ApiKeyProtected README to point at the new guide.
- Refactor the `makeSpec` function to accept the already assembled secrets
array because this should be easier to unit test.

Signed-off-by: Lucas Roesler <lucas.roesler@gmail.com>
This commit is contained in:
Lucas Roesler
2017-10-17 11:33:31 +02:00
committed by Alex Ellis
parent 5dce1deb21
commit 35f0e9e657
4 changed files with 21 additions and 79 deletions

View File

@ -53,7 +53,7 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
options.EncodedRegistryAuth = auth
}
spec, err := makeSpec(c, &request, maxRestarts, restartDelay)
secrets, err := makeSecretsArray(c, request.Secrets)
if err != nil {
log.Println(err)
w.WriteHeader(http.StatusBadRequest)
@ -61,6 +61,8 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
return
}
spec := makeSpec(&request, maxRestarts, restartDelay, secrets)
response, err := c.ServiceCreate(context.Background(), spec, options)
if err != nil {
log.Println("Error creating service:", err)
@ -72,8 +74,7 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
}
}
func makeSpec(c *client.Client, request *requests.CreateFunctionRequest, maxRestarts uint64, restartDelay time.Duration) (swarm.ServiceSpec, error) {
linuxOnlyConstraints := []string{"node.platform.os == linux"}
func makeSpec(request *requests.CreateFunctionRequest, maxRestarts uint64, restartDelay time.Duration, secrets []*swarm.SecretReference) swarm.ServiceSpec {
constraints := []string{}
if request.Constraints != nil && len(request.Constraints) > 0 {
@ -101,11 +102,6 @@ func makeSpec(c *client.Client, request *requests.CreateFunctionRequest, maxRest
},
}
secrets, err := makeSecretsArray(c, request.Secrets)
if err != nil {
return swarm.ServiceSpec{}, err
}
spec := swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: request.Service,
@ -142,7 +138,7 @@ func makeSpec(c *client.Client, request *requests.CreateFunctionRequest, maxRest
spec.TaskTemplate.ContainerSpec.Env = env
}
return spec, nil
return spec
}
func buildEnv(envProcess string, envVars map[string]string) []string {