Example #1
0
func (p *Pluginator) connect() error {
	defer trace.End(trace.Begin(""))
	var err error

	sessionconfig := &session.Config{
		Insecure: true,
	}
	sessionconfig.Service = p.tURL.String()

	p.Session = session.NewSession(sessionconfig)
	p.Session, err = p.Session.Connect(p.Context)
	if err != nil {
		return fmt.Errorf("failed to connect: %s", err)
	}

	p.Session.Populate(p.Context)

	em, err := object.GetExtensionManager(p.Session.Client.Client)
	if err != nil {
		return fmt.Errorf("failed to get extension manager: %s", err)
	}
	p.ExtensionManager = em

	p.connected = true
	return nil
}
Example #2
0
func (cmd *register) Run(ctx context.Context, f *flag.FlagSet) error {
	c, err := cmd.Client()
	if err != nil {
		return err
	}

	m, err := object.GetExtensionManager(c)
	if err != nil {
		return err
	}

	var e types.Extension
	e.Description = new(types.Description)

	if err = json.NewDecoder(os.Stdin).Decode(&e); err != nil {
		return err
	}

	e.LastHeartbeatTime = time.Now().UTC()

	if cmd.update {
		return m.Update(ctx, e)
	}

	return m.Register(ctx, e)
}
Example #3
0
func (cmd *setcert) Run(ctx context.Context, f *flag.FlagSet) error {
	c, err := cmd.Client()
	if err != nil {
		return err
	}

	m, err := object.GetExtensionManager(c)
	if err != nil {
		return err
	}

	if f.NArg() != 1 {
		return flag.ErrHelp
	}

	key := f.Arg(0)

	if cmd.cert == "-" {
		b, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			return err
		}
		cmd.cert = string(b)
	} else if cmd.cert == "+" {
		if err := cmd.create(key); err != nil {
			return fmt.Errorf("creating certificate: %s", err)
		}
		cmd.cert = cmd.encodedCert.String()
	}

	return m.SetCertificate(ctx, key, cmd.cert)
}
Example #4
0
func (cmd *register) Run(f *flag.FlagSet) error {
	ctx := context.TODO()

	c, err := cmd.Client()
	if err != nil {
		return err
	}

	m, err := object.GetExtensionManager(c)
	if err != nil {
		return err
	}

	b, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return err
	}

	var e types.Extension
	e.Description = new(types.Description)

	if err = json.Unmarshal(b, &e); err != nil {
		return err
	}

	e.LastHeartbeatTime = time.Now().UTC()

	if cmd.update {
		return m.Update(ctx, e)
	}

	return m.Register(ctx, e)
}
Example #5
0
func (cmd *unregister) Run(ctx context.Context, f *flag.FlagSet) error {
	c, err := cmd.Client()
	if err != nil {
		return err
	}

	m, err := object.GetExtensionManager(c)
	if err != nil {
		return err
	}

	for _, key := range f.Args() {
		if err = m.Unregister(ctx, key); err != nil {
			return err
		}
	}

	return nil
}
Example #6
0
func (cmd *info) Run(f *flag.FlagSet) error {
	ctx := context.TODO()

	c, err := cmd.Client()
	if err != nil {
		return err
	}

	m, err := object.GetExtensionManager(c)
	if err != nil {
		return err
	}

	list, err := m.List(ctx)
	if err != nil {
		return err
	}

	var res infoResult

	if f.NArg() == 0 {
		res.Extensions = list
	} else {
		exts := make(map[string]types.Extension)
		for _, e := range list {
			exts[e.Key] = e
		}

		for _, key := range f.Args() {
			if e, ok := exts[key]; ok {
				res.Extensions = append(res.Extensions, e)
			} else {
				return fmt.Errorf("extension %s not found", key)
			}
		}
	}

	return cmd.WriteResult(&res)
}