Example #1
0
func (e *GetExecutor) Execute(t *Task) (err error) {
	e.reply.Container = containers.Get(e.arg.ContainerID)
	if e.reply.Container == nil {
		e.reply.Status = StatusError
		err = errors.New("Unknown Container.")
	} else {
		e.reply.Status = StatusOk
	}
	return
}
func (e *ContainerMaintenanceExecutor) Execute(t *Task) error {
	if e.arg.ContainerID == "" {
		return errors.New("Please specify a container id.")
	}
	cont := containers.Get(e.arg.ContainerID)
	if cont == nil {
		e.reply.Status = StatusError
		return errors.New("Unknown Container.")
	}
	if err := containers.SetMaintenance(cont, e.arg.Maintenance); err != nil {
		e.reply.Status = StatusError
		return err
	}
	e.reply.Status = StatusOk
	return nil
}
Example #3
0
func (e *DeauthorizeSSHExecutor) Execute(t *Task) error {
	if e.arg.ContainerID == "" {
		return errors.New("Please specify a container id.")
	}
	if e.arg.User == "" {
		return errors.New("Please specify a user.")
	}
	cont := containers.Get(e.arg.ContainerID)
	if cont == nil {
		e.reply.Status = StatusError
		return errors.New("Unknown Container.")
	}
	if err := containers.DeauthorizeSSHUser(cont, e.arg.User); err != nil {
		e.reply.Status = StatusError
		return err
	}
	e.reply.Status = StatusOk
	return nil
}
Example #4
0
func (e *AuthorizeSSHExecutor) Execute(t *Task) error {
	if e.arg.PublicKey == "" {
		return errors.New("Please specify an SSH public key.")
	}
	if e.arg.ContainerID == "" {
		return errors.New("Please specify a container id.")
	}
	if e.arg.User == "" {
		return errors.New("Please specify a user.")
	}
	cont := containers.Get(e.arg.ContainerID)
	if cont == nil {
		e.reply.Status = StatusError
		return errors.New("Unknown Container.")
	}
	if err := containers.AuthorizeSSHUser(cont, e.arg.User, e.arg.PublicKey); err != nil {
		e.reply.Status = StatusError
		return err
	}
	t.Log("[RPC][AuthorizeSSH] authorized %d", cont.SSHPort)
	e.reply.Port = cont.SSHPort
	e.reply.Status = StatusOk
	return nil
}