Can reverse sha-ed job type

This commit is contained in:
nemunaire 2021-07-31 17:35:29 +02:00
commit 4e982b39f9
3 changed files with 64 additions and 21 deletions

41
jobs/jobs.go Normal file
View 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]
}