...
1
18
19 package faas_openfaas
20
21 import (
22 "crypto/md5"
23 "encoding/json"
24 "fmt"
25 "io"
26 )
27
28 type IdentifiableFunction struct {
29 Name string `json:"name,omitempty" bson:"name"`
30 Service string `json:"service,omitempty" bson:"service"`
31 Network string `json:"network,omitempty" bson:"network"`
32 Image string `json:"image,omitempty" bson:"image"`
33 EnvProcess string `json:"envProcess,omitempty" bson:"envProcess"`
34 EnvVars map[string]string `json:"envVars,omitempty" bson:"envVars"`
35 Constraints []string `json:"constraints,omitempty" bson:"constraints"`
36 Labels map[string]string `json:"labels,omitempty" bson:"labels"`
37 Annotations []string `json:"annotations,omitempty" bson:"annotations"`
38 Secrets []string `json:"secrets,omitempty" bson:"secrets"`
39 RegistryAuth string `json:"registryAuth,omitempty" bson:"registryAuth"`
40 Limits MachineResources `json:"limits,omitempty" bson:"limits"`
41 Requests MachineResources `json:"requests,omitempty" bson:"requests"`
42 }
43
44
45 func ComputeFunctionMD5(fn *Function) string {
46 idFn := IdentifiableFunction{
47 Name: fn.Name,
48 Service: fn.Service,
49 Network: fn.Network,
50 Image: fn.Image,
51 EnvProcess: fn.EnvProcess,
52 EnvVars: fn.EnvVars,
53 Constraints: fn.Constraints,
54 Labels: fn.Labels,
55 Annotations: fn.Annotations,
56 Secrets: fn.Secrets,
57 RegistryAuth: fn.RegistryAuth,
58 Limits: fn.Limits,
59 Requests: fn.Requests,
60 }
61
62 out, _ := json.Marshal(idFn)
63 jsonString := string(out)
64
65 h := md5.New()
66 io.WriteString(h, jsonString)
67 return fmt.Sprintf("%x", h.Sum(nil))
68 }
69
View as plain text