本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.NewACName函数的典型用法代码示例。如果您正苦于以下问题:Golang NewACName函数的具体用法?Golang NewACName怎么用?Golang NewACName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewACName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteTrustedKeyPrefix
// DeleteTrustedKeyPrefix deletes the prefix trusted key identified by fingerprint.
func (ks *Keystore) DeleteTrustedKeyPrefix(prefix, fingerprint string) error {
acname, err := types.NewACName(prefix)
if err != nil {
return err
}
return os.Remove(path.Join(ks.LocalPrefixPath, acname.String(), fingerprint))
}
示例2: 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))
}
示例3: getAppName
// getAppName returns the app name to enter
// If one was supplied in the flags then it's simply returned
// If the PM contains a single app, that app's name is returned
// If the PM has multiple apps, the names are printed and an error is returned
func getAppName(p *pod) (*types.ACName, error) {
if flagAppName != "" {
return types.NewACName(flagAppName)
}
// figure out the app name, or show a list if multiple are present
b, err := ioutil.ReadFile(common.PodManifestPath(p.path()))
if err != nil {
return nil, fmt.Errorf("error reading pod manifest: %v", err)
}
m := schema.PodManifest{}
if err = m.UnmarshalJSON(b); err != nil {
return nil, fmt.Errorf("unable to load manifest: %v", err)
}
switch len(m.Apps) {
case 0:
return nil, fmt.Errorf("pod contains zero apps")
case 1:
return &m.Apps[0].Name, nil
default:
}
stderr("Pod contains multiple apps:")
for _, ra := range m.Apps {
stderr("\t%v", ra.Name)
}
return nil, fmt.Errorf("specify app using \"rkt enter --app= ...\"")
}
示例4: 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.ACName]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.ACName]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.NewACName(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
}
示例5: 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) {
acname, err := types.NewACName(prefix)
if err != nil {
return "", err
}
return storeTrustedKey(path.Join(ks.LocalPrefixPath, acname.String()), r)
}
示例6: mergeManifests
func mergeManifests(manifests []schema.ImageManifest) schema.ImageManifest {
// FIXME(iaguis) we take app layer's manifest as the final manifest for now
manifest := manifests[0]
manifest.Dependencies = nil
layerIndex := -1
for i, l := range manifest.Labels {
if l.Name.String() == "layer" {
layerIndex = i
}
}
if layerIndex != -1 {
manifest.Labels = append(manifest.Labels[:layerIndex], manifest.Labels[layerIndex+1:]...)
}
// this can't fail because the old name is legal
nameWithoutLayerID, _ := appctypes.NewACName(stripLayerID(manifest.Name.String()))
manifest.Name = *nameWithoutLayerID
// once the image is squashed, we don't need a pathWhitelist
manifest.PathWhitelist = nil
return manifest
}
示例7: MaskTrustedKeySystemPrefix
// MaskTrustedKeySystemPrefix masks the system prefix trusted key identified by fingerprint.
func (ks *Keystore) MaskTrustedKeySystemPrefix(prefix, fingerprint string) (string, error) {
acname, err := types.NewACName(prefix)
if err != nil {
return "", err
}
dst := path.Join(ks.LocalPrefixPath, acname.String(), fingerprint)
return dst, ioutil.WriteFile(dst, []byte(""), 0644)
}
示例8: loadKeyring
func (ks *Keystore) loadKeyring(prefix string) (openpgp.KeyRing, error) {
acname, err := types.NewACName(prefix)
if err != nil {
return nil, err
}
var keyring openpgp.EntityList
trustedKeys := make(map[string]*openpgp.Entity)
prefixRoot := strings.Split(acname.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, acname.String())},
{path.Join(ks.LocalPrefixPath, prefixRoot), path.Join(ks.LocalPrefixPath, acname.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
}
示例9: NewApp
func NewApp(name string, labels map[types.ACName]string) (*App, error) {
if labels == nil {
labels = make(map[types.ACName]string, 0)
}
acn, err := types.NewACName(name)
if err != nil {
return nil, err
}
return &App{
Name: *acn,
Labels: labels,
}, nil
}
示例10: checkSignature
func checkSignature(ks *Keystore, prefix string, signed, signature io.Reader) (*openpgp.Entity, error) {
acname, err := types.NewACName(prefix)
if err != nil {
return nil, err
}
keyring, err := ks.loadKeyring(acname.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 signatures found")
}
return entities, err
}
示例11: handleAppAnnotations
func handleAppAnnotations(w http.ResponseWriter, r *http.Request, pm *schema.PodManifest, im *schema.ImageManifest) {
defer r.Body.Close()
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
}
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
for _, annot := range mergeAppAnnotations(im, pm, an) {
fmt.Fprintln(w, string(annot.Name))
}
}
示例12: handleAppID
func handleAppID(w http.ResponseWriter, r *http.Request, pm *schema.PodManifest, im *schema.ImageManifest) {
defer r.Body.Close()
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
}
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
app := pm.Apps.Get(*an)
if app == nil {
// This is impossiple as we have already checked that
// the image manifest is not nil in the parent function.
panic("could not find app in manifest!")
}
w.Write([]byte(app.Image.ID.String()))
}
示例13: handlePodAnnotation
func handlePodAnnotation(w http.ResponseWriter, r *http.Request, pm *schema.PodManifest) {
defer r.Body.Close()
k, err := types.NewACName(mux.Vars(r)["name"])
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "Pod annotation is not a valid AC Name")
return
}
v, ok := pm.Annotations.Get(k.String())
if !ok {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "Pod annotation (%v) not found", k)
return
}
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte(v))
}
示例14: Set
func (al *appMount) Set(s string) error {
mount := schema.Mount{}
// this is intentionally made similar to types.VolumeFromString()
// TODO(iaguis) use MakeQueryString() when appc/spec#520 is merged
m, err := url.ParseQuery(strings.Replace(s, ",", "&", -1))
if err != nil {
return err
}
for key, val := range m {
if len(val) > 1 {
return fmt.Errorf("label %s with multiple values %q", key, val)
}
switch key {
case "volume":
mv, err := types.NewACName(val[0])
if err != nil {
return fmt.Errorf("invalid volume name %q in --mount flag %q: %v", val[0], s, err)
}
mount.Volume = *mv
case "target":
mount.Path = val[0]
default:
return fmt.Errorf("unknown mount parameter %q", key)
}
}
as := (*apps.Apps)(al)
if as.Count() == 0 {
as.Mounts = append(as.Mounts, mount)
} else {
app := as.Last()
app.Mounts = append(app.Mounts, mount)
}
return nil
}
示例15: Set
func (pl *portList) Set(s string) error {
parts := strings.SplitN(s, ":", 2)
if len(parts) != 2 {
return fmt.Errorf("%q is not in name:port format", s)
}
name, err := types.NewACName(parts[0])
if err != nil {
return fmt.Errorf("%q is not a valid port name: %v", parts[0], err)
}
port, err := strconv.ParseUint(parts[1], 10, 16)
if err != nil {
return fmt.Errorf("%q is not a valid port number", parts[1])
}
p := types.ExposedPort{
Name: *name,
HostPort: uint(port),
}
*pl = append(*pl, p)
return nil
}