Exemplo n.º 1
0
// NewAgentAPI returns an object implementing the machine agent API
// with the given authorizer representing the currently logged in client.
func NewAgentAPI(st *state.State, auth common.Authorizer) (*AgentAPI, error) {
	if !auth.AuthMachineAgent() {
		return nil, common.ErrPerm
	}
	getCanChange := func() (common.AuthFunc, error) {
		// TODO(go1.1): method expression
		return func(tag string) bool {
			return auth.AuthOwner(tag)
		}, nil
	}
	return &AgentAPI{
		st:              st,
		auth:            auth,
		PasswordChanger: common.NewPasswordChanger(st, getCanChange),
	}, nil
}
Exemplo n.º 2
0
// NewMachinerAPI creates a new instance of the Machiner API.
func NewMachinerAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*MachinerAPI, error) {
	if !authorizer.AuthMachineAgent() {
		return nil, common.ErrPerm
	}
	getCanRead := func() (common.AuthFunc, error) {
		return func(tag string) bool {
			// TODO(go1.1): method expression
			return authorizer.AuthOwner(tag)
		}, nil
	}
	return &MachinerAPI{
		LifeGetter: common.NewLifeGetter(st, getCanRead),
		st:         st,
		resources:  resources,
		auth:       authorizer,
	}, nil
}