Skip to content

Commit

Permalink
Docker example
Browse files Browse the repository at this point in the history
  • Loading branch information
dhcgn committed Feb 25, 2021
1 parent 2b572b0 commit b30a509
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions cmd/dockerdetector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,20 @@ func main() {
}

fmt.Println("Run in Docker:", isDocker)

if isDocker {
id, err := dockerdetector.CreateIDFromDocker()
if err != nil {
fmt.Println("Error:", err)
}
fmt.Println("Docker ID:", id)
}

if isDocker {
id, err := dockerdetector.CreateProtectedFromDockerID("My Salt")
if err != nil {
fmt.Println("Error:", err)
}
fmt.Println("Docker Protected ID:", id)
}
}
4 changes: 2 additions & 2 deletions dockerdetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func createProtectedIDFromDocker(salt string, file fs.File) (string, error) {
return protect(salt, id), nil
}

func protect(appID, key string) string {
func protect(salt, key string) string {
mac := hmac.New(sha256.New, []byte(key))
mac.Write([]byte(appID))
mac.Write([]byte(salt))
return hex.EncodeToString(mac.Sum(nil))
}

Expand Down

0 comments on commit b30a509

Please sign in to comment.