本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.NewACIdentifier函数的典型用法代码示例。如果您正苦于以下问题:Golang NewACIdentifier函数的具体用法?Golang NewACIdentifier怎么用?Golang NewACIdentifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewACIdentifier函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewAppFromString
// NewAppFromString takes a command line app parameter and returns a map of labels.
//
// Example app parameters:
// example.com/reduce-worker:1.0.0
// example.com/reduce-worker,channel=alpha,label=value
func NewAppFromString(app string) (*App, error) {
var (
name string
labels map[types.ACIdentifier]string
)
app = strings.Replace(app, ":", ",version=", -1)
app = "name=" + app
v, err := url.ParseQuery(strings.Replace(app, ",", "&", -1))
if err != nil {
return nil, err
}
labels = make(map[types.ACIdentifier]string, 0)
for key, val := range v {
if len(val) > 1 {
return nil, fmt.Errorf("label %s with multiple values %q", key, val)
}
if key == "name" {
name = val[0]
continue
}
labelName, err := types.NewACIdentifier(key)
if err != nil {
return nil, err
}
labels[*labelName] = val[0]
}
a, err := NewApp(name, labels)
if err != nil {
return nil, err
}
return a, nil
}
示例2: checkSignature
func checkSignature(ks *Keystore, prefix string, signed, signature io.ReadSeeker) (*openpgp.Entity, error) {
acidentifier, err := types.NewACIdentifier(prefix)
if err != nil {
return nil, err
}
keyring, err := ks.loadKeyring(acidentifier.String())
if err != nil {
return nil, fmt.Errorf("keystore: error loading keyring %v", err)
}
entities, err := openpgp.CheckArmoredDetachedSignature(keyring, signed, signature)
if err == io.EOF {
// When the signature is binary instead of armored, the error is io.EOF.
// Let's try with binary signatures as well
if _, err := signed.Seek(0, 0); err != nil {
return nil, fmt.Errorf("error seeking ACI file: %v", err)
}
if _, err := signature.Seek(0, 0); err != nil {
return nil, fmt.Errorf("error seeking signature file: %v", err)
}
entities, err = openpgp.CheckDetachedSignature(keyring, signed, signature)
}
if err == io.EOF {
// otherwise, the client failure is just "EOF", which is not helpful
return nil, fmt.Errorf("keystore: no valid signatures found in signature file")
}
return entities, err
}
示例3: StoreTrustedKeyPrefix
// StoreTrustedKeyPrefix stores the contents of public key r as a prefix trusted key.
func (ks *Keystore) StoreTrustedKeyPrefix(prefix string, r io.Reader) (string, error) {
acidentifier, err := types.NewACIdentifier(prefix)
if err != nil {
return "", err
}
return storeTrustedKey(path.Join(ks.LocalPrefixPath, acidentifier.String()), r)
}
示例4: DeleteTrustedKeyPrefix
// DeleteTrustedKeyPrefix deletes the prefix trusted key identified by fingerprint.
func (ks *Keystore) DeleteTrustedKeyPrefix(prefix, fingerprint string) error {
acidentifier, err := types.NewACIdentifier(prefix)
if err != nil {
return err
}
return os.Remove(path.Join(ks.LocalPrefixPath, acidentifier.String(), fingerprint))
}
示例5: handleAppAnnotation
func handleAppAnnotation(w http.ResponseWriter, r *http.Request, pm *schema.PodManifest, im *schema.ImageManifest) {
defer r.Body.Close()
n := mux.Vars(r)["name"]
k, err := types.NewACIdentifier(n)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "App annotation name %q is not a valid AC Identifier", n)
return
}
n = mux.Vars(r)["app"]
an, err := types.NewACName(n)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "App name %q is not a valid AC Name", n)
return
}
merged := mergeAppAnnotations(im, pm, an)
v, ok := merged.Get(k.String())
if !ok {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "App annotation %q not found", k)
return
}
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte(v))
}
示例6: isolatorStrFromString
func isolatorStrFromString(is string) (types.ACIdentifier, string, error) {
is = "name=" + is
v, err := url.ParseQuery(strings.Replace(is, ",", "&", -1))
if err != nil {
return "", "", err
}
var name string
var values []string
var acn *types.ACIdentifier
for key, val := range v {
if len(val) > 1 {
return "", "", fmt.Errorf("label %s with multiple values %q", key, val)
}
switch key {
case "name":
acn, err = types.NewACIdentifier(val[0])
if err != nil {
return "", "", err
}
name = val[0]
default:
// (TODO)yifan: Not support the default boolean yet.
values = append(values, fmt.Sprintf(`"%s": "%s"`, key, val[0]))
}
}
return *acn, getIsolatorStr(name, strings.Join(values, ", ")), nil
}
示例7: validatePodAnnotations
func validatePodAnnotations(metadataURL string, pm *schema.PodManifest) results {
r := results{}
var actualAnnots types.Annotations
annots, err := metadataGet(metadataURL, "/pod/annotations/")
if err != nil {
return append(r, err)
}
for _, key := range strings.Split(string(annots), "\n") {
if key == "" {
continue
}
val, err := metadataGet(metadataURL, "/pod/annotations/"+key)
if err != nil {
r = append(r, err)
}
name, err := types.NewACIdentifier(key)
if err != nil {
r = append(r, fmt.Errorf("invalid annotation name: %v", err))
continue
}
actualAnnots.Set(*name, string(val))
}
if !reflect.DeepEqual(actualAnnots, pm.Annotations) {
r = append(r, fmt.Errorf("pod annotations mismatch: %v vs %v", actualAnnots, pm.Annotations))
}
return r
}
示例8: NewAppFromString
// NewAppFromString takes a command line app parameter and returns a map of labels.
//
// Example app parameters:
// example.com/reduce-worker:1.0.0
// example.com/reduce-worker,channel=alpha,label=value
// example.com/reduce-worker:1.0.0,label=value
//
// As can be seen in above examples - colon, comma and equal sign have
// special meaning. If any of them has to be a part of a label's value
// then consider writing your own string to App parser.
func NewAppFromString(app string) (*App, error) {
var (
name string
labels map[types.ACIdentifier]string
)
preparedApp, err := prepareAppString(app)
if err != nil {
return nil, err
}
v, err := url.ParseQuery(preparedApp)
if err != nil {
return nil, err
}
labels = make(map[types.ACIdentifier]string, 0)
for key, val := range v {
if len(val) > 1 {
return nil, fmt.Errorf("label %s with multiple values %q", key, val)
}
if key == "name" {
name = val[0]
continue
}
labelName, err := types.NewACIdentifier(key)
if err != nil {
return nil, err
}
labels[*labelName] = val[0]
}
a, err := NewApp(name, labels)
if err != nil {
return nil, err
}
return a, nil
}
示例9: MaskTrustedKeySystemPrefix
// MaskTrustedKeySystemPrefix masks the system prefix trusted key identified by fingerprint.
func (ks *Keystore) MaskTrustedKeySystemPrefix(prefix, fingerprint string) (string, error) {
acidentifier, err := types.NewACIdentifier(prefix)
if err != nil {
return "", err
}
dst := path.Join(ks.LocalPrefixPath, acidentifier.String(), fingerprint)
return dst, ioutil.WriteFile(dst, []byte(""), 0644)
}
示例10: loadKeyring
func (ks *Keystore) loadKeyring(prefix string) (openpgp.KeyRing, error) {
acidentifier, err := types.NewACIdentifier(prefix)
if err != nil {
return nil, err
}
var keyring openpgp.EntityList
trustedKeys := make(map[string]*openpgp.Entity)
prefixRoot := strings.Split(acidentifier.String(), "/")[0]
paths := []struct {
root string
fullPath string
}{
{ks.SystemRootPath, ks.SystemRootPath},
{ks.LocalRootPath, ks.LocalRootPath},
{path.Join(ks.SystemPrefixPath, prefixRoot), path.Join(ks.SystemPrefixPath, acidentifier.String())},
{path.Join(ks.LocalPrefixPath, prefixRoot), path.Join(ks.LocalPrefixPath, acidentifier.String())},
}
for _, p := range paths {
err := filepath.Walk(p.root, func(path string, info os.FileInfo, err error) error {
if err != nil && !os.IsNotExist(err) {
return err
}
if info == nil {
return nil
}
if info.IsDir() {
switch {
case strings.HasPrefix(p.fullPath, path):
return nil
default:
return filepath.SkipDir
}
}
// Remove trust for default keys.
if info.Size() == 0 {
delete(trustedKeys, info.Name())
return nil
}
entity, err := entityFromFile(path)
if err != nil {
return err
}
trustedKeys[fingerprintToFilename(entity.PrimaryKey.Fingerprint)] = entity
return nil
})
if err != nil {
return nil, err
}
}
for _, v := range trustedKeys {
keyring = append(keyring, v)
}
return keyring, nil
}
示例11: GetImageName
func (custom *GoCustomizations) GetImageName() (*types.ACIdentifier, error) {
imageName := custom.Configuration.Project
if filepath.Base(imageName) == "..." {
imageName = filepath.Dir(imageName)
if custom.Configuration.UseBinary != "" {
imageName += "-" + custom.Configuration.UseBinary
}
}
return types.NewACIdentifier(strings.ToLower(imageName))
}
示例12: newLabel
func newLabel(name, value string) (*types.Label, error) {
acName, err := types.NewACIdentifier(name)
if err != nil {
return nil, err
}
return &types.Label{
Name: *acName,
Value: value,
}, nil
}
示例13: NewApp
func NewApp(name string, labels map[types.ACIdentifier]string) (*App, error) {
if labels == nil {
labels = make(map[types.ACIdentifier]string, 0)
}
acn, err := types.NewACIdentifier(name)
if err != nil {
return nil, err
}
return &App{
Name: *acn,
Labels: labels,
}, nil
}
示例14: checkSignature
func checkSignature(ks *Keystore, prefix string, signed, signature io.Reader) (*openpgp.Entity, error) {
acidentifier, err := types.NewACIdentifier(prefix)
if err != nil {
return nil, err
}
keyring, err := ks.loadKeyring(acidentifier.String())
if err != nil {
return nil, fmt.Errorf("keystore: error loading keyring %v", err)
}
entities, err := openpgp.CheckArmoredDetachedSignature(keyring, signed, signature)
if err == io.EOF {
// otherwise, the client failure is just "EOF", which is not helpful
return nil, fmt.Errorf("keystore: no valid signatures found in signature file")
}
return entities, err
}
示例15: validateAppAnnotations
func validateAppAnnotations(metadataURL string, pm *schema.PodManifest, app *schema.RuntimeApp, img *schema.ImageManifest) results {
r := results{}
// build a map of expected annotations by merging app.Annotations
// with PodManifest overrides
expectedAnnots := app.Annotations
a := pm.Apps.Get(app.Name)
if a == nil {
panic("could not find app in manifest!")
}
for _, annot := range a.Annotations {
expectedAnnots.Set(annot.Name, annot.Value)
}
var actualAnnots types.Annotations
annots, err := metadataGet(metadataURL, "/apps/"+string(app.Name)+"/annotations/")
if err != nil {
return append(r, err)
}
for _, key := range strings.Split(string(annots), "\n") {
if key == "" {
continue
}
val, err := metadataGet(metadataURL, "/apps/"+string(app.Name)+"/annotations/"+key)
if err != nil {
r = append(r, err)
}
lbl, err := types.NewACIdentifier(key)
if err != nil {
r = append(r, fmt.Errorf("invalid annotation name: %v", err))
continue
}
actualAnnots.Set(*lbl, string(val))
}
if !reflect.DeepEqual(actualAnnots, expectedAnnots) {
err := fmt.Errorf("%v annotations mismatch: %v vs %v", app.Name, actualAnnots, expectedAnnots)
r = append(r, err)
}
return r
}