2018-09-05 14:54:38 -04:00
|
|
|
package wclayer
|
|
|
|
|
|
|
|
import (
|
2020-05-09 11:16:54 -04:00
|
|
|
"context"
|
|
|
|
|
2020-01-06 12:15:00 -05:00
|
|
|
"github.com/Microsoft/go-winio/pkg/guid"
|
2018-09-05 14:54:38 -04:00
|
|
|
"github.com/Microsoft/hcsshim/internal/hcserror"
|
2020-05-09 11:16:54 -04:00
|
|
|
"github.com/Microsoft/hcsshim/internal/oc"
|
|
|
|
"go.opencensus.io/trace"
|
2018-09-05 14:54:38 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// NameToGuid converts the given string into a GUID using the algorithm in the
|
|
|
|
// Host Compute Service, ensuring GUIDs generated with the same string are common
|
|
|
|
// across all clients.
|
2020-05-09 11:16:54 -04:00
|
|
|
func NameToGuid(ctx context.Context, name string) (_ guid.GUID, err error) {
|
2019-02-28 13:16:30 -05:00
|
|
|
title := "hcsshim::NameToGuid"
|
2020-05-09 11:16:54 -04:00
|
|
|
ctx, span := trace.StartSpan(ctx, title)
|
|
|
|
defer span.End()
|
|
|
|
defer func() { oc.SetSpanStatus(span, err) }()
|
|
|
|
span.AddAttributes(trace.StringAttribute("name", name))
|
2018-09-05 14:54:38 -04:00
|
|
|
|
2020-05-09 11:16:54 -04:00
|
|
|
var id guid.GUID
|
2018-09-05 14:54:38 -04:00
|
|
|
err = nameToGuid(name, &id)
|
|
|
|
if err != nil {
|
2020-05-09 11:16:54 -04:00
|
|
|
return guid.GUID{}, hcserror.New(err, title+" - failed", "")
|
2018-09-05 14:54:38 -04:00
|
|
|
}
|
2020-05-09 11:16:54 -04:00
|
|
|
span.AddAttributes(trace.StringAttribute("guid", id.String()))
|
|
|
|
return id, nil
|
2018-09-05 14:54:38 -04:00
|
|
|
}
|