// Pull pulls a plugin and computes the privileges required to install it. func (pm *Manager) Pull(name string, metaHeader http.Header, authConfig *types.AuthConfig) (types.PluginPrivileges, error) { ref, err := reference.ParseNamed(name) if err != nil { logrus.Debugf("error in reference.ParseNamed: %v", err) return nil, err } name = ref.String() if p, _ := pm.get(name); p != nil { logrus.Debugf("plugin already exists") return nil, fmt.Errorf("%s exists", name) } pluginID := stringid.GenerateNonCryptoID() if err := os.MkdirAll(filepath.Join(pm.libRoot, pluginID), 0755); err != nil { logrus.Debugf("error in MkdirAll: %v", err) return nil, err } pd, err := distribution.Pull(name, pm.registryService, metaHeader, authConfig) if err != nil { logrus.Debugf("error in distribution.Pull(): %v", err) return nil, err } if err := distribution.WritePullData(pd, filepath.Join(pm.libRoot, pluginID), true); err != nil { logrus.Debugf("error in distribution.WritePullData(): %v", err) return nil, err } p := pm.newPlugin(ref, pluginID) if err := pm.initPlugin(p); err != nil { return nil, err } pm.Lock() pm.plugins[pluginID] = p pm.nameToID[name] = pluginID pm.save() pm.Unlock() pm.pluginEventLogger(pluginID, name, "pull") return computePrivileges(&p.PluginObj.Manifest), nil }
// Pull pulls a plugin and computes the privileges required to install it. func (pm *Manager) Pull(name string, metaHeader http.Header, authConfig *types.AuthConfig) (types.PluginPrivileges, error) { ref, err := reference.ParseNamed(name) if err != nil { logrus.Debugf("error in reference.ParseNamed: %v", err) return nil, err } name = ref.String() if p, _ := pm.pluginStore.GetByName(name); p != nil { logrus.Debugf("plugin already exists") return nil, fmt.Errorf("%s exists", name) } pluginID := stringid.GenerateNonCryptoID() if err := os.MkdirAll(filepath.Join(pm.libRoot, pluginID), 0755); err != nil { logrus.Debugf("error in MkdirAll: %v", err) return nil, err } pd, err := distribution.Pull(name, pm.registryService, metaHeader, authConfig) if err != nil { logrus.Debugf("error in distribution.Pull(): %v", err) return nil, err } if err := distribution.WritePullData(pd, filepath.Join(pm.libRoot, pluginID), true); err != nil { logrus.Debugf("error in distribution.WritePullData(): %v", err) return nil, err } var tag string if ref, ok := ref.(reference.NamedTagged); ok { tag = ref.Tag() } p := v2.NewPlugin(ref.Name(), pluginID, pm.runRoot, tag) if err := p.InitPlugin(pm.libRoot); err != nil { return nil, err } pm.pluginStore.Add(p) pm.pluginEventLogger(pluginID, name, "pull") return p.ComputePrivileges(), nil }
func (pm *Manager) pull(name string, metaHeader http.Header, authConfig *types.AuthConfig) (reference.Named, distribution.PullData, error) { ref, err := distribution.GetRef(name) if err != nil { logrus.Debugf("error in distribution.GetRef: %v", err) return nil, nil, err } name = ref.String() if p, _ := pm.pluginStore.GetByName(name); p != nil { logrus.Debug("plugin already exists") return nil, nil, fmt.Errorf("%s exists", name) } pd, err := distribution.Pull(ref, pm.registryService, metaHeader, authConfig) if err != nil { logrus.Debugf("error in distribution.Pull(): %v", err) return nil, nil, err } return ref, pd, nil }
func (pm *Manager) pull(ref reference.Named, metaHeader http.Header, authConfig *types.AuthConfig, pluginID string) (types.PluginPrivileges, error) { pd, err := distribution.Pull(ref, pm.registryService, metaHeader, authConfig) if err != nil { logrus.Debugf("error in distribution.Pull(): %v", err) return nil, err } if err := distribution.WritePullData(pd, filepath.Join(pm.libRoot, pluginID), true); err != nil { logrus.Debugf("error in distribution.WritePullData(): %v", err) return nil, err } tag := distribution.GetTag(ref) p := v2.NewPlugin(ref.Name(), pluginID, pm.runRoot, pm.libRoot, tag) if err := p.InitPlugin(); err != nil { return nil, err } pm.pluginStore.Add(p) pm.pluginEventLogger(pluginID, ref.String(), "pull") return p.ComputePrivileges(), nil }