Can reverse sha-ed job type
This commit is contained in:
parent
f2eacf41cf
commit
4e982b39f9
3 changed files with 64 additions and 21 deletions
41
jobs/jobs.go
Normal file
41
jobs/jobs.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package jobs
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Job struct {
|
||||
Image string
|
||||
Cmd []string
|
||||
DataMount bool
|
||||
}
|
||||
|
||||
var jobs = map[string]Job{
|
||||
"counter": {
|
||||
Image: "alpine",
|
||||
Cmd: []string{"sh", "-c", "touch /data/work_done; for i in `seq 10`; do echo $i; sleep 0.5; done"},
|
||||
DataMount: true,
|
||||
},
|
||||
}
|
||||
|
||||
var revJobs = map[string]string{}
|
||||
|
||||
func init() {
|
||||
for jobtype := range jobs {
|
||||
revJobs[fmt.Sprintf("%x", sha256.Sum224([]byte(jobtype)))] = jobtype
|
||||
}
|
||||
}
|
||||
|
||||
func GetJobType(hashJobType string) (jobtype string) {
|
||||
var ok bool
|
||||
if jobtype, ok = revJobs[hashJobType]; !ok {
|
||||
jobtype = ""
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func GetJob(jobtype string) (job Job) {
|
||||
return jobs[jobtype]
|
||||
}
|
||||
Reference in a new issue