Exemplo n.º 1
0
Arquivo: unit.go Projeto: imoapps/juju
// JoinedRelations returns the tags of the relations the unit has joined.
func (u *Unit) JoinedRelations() ([]names.RelationTag, error) {
	var results params.StringsResults
	args := params.Entities{
		Entities: []params.Entity{{Tag: u.tag.String()}},
	}
	err := u.st.facade.FacadeCall("JoinedRelations", args, &results)
	if err != nil {
		return nil, err
	}
	if len(results.Results) != 1 {
		return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
	}
	result := results.Results[0]
	if result.Error != nil {
		return nil, result.Error
	}
	var relTags []names.RelationTag
	for _, rel := range result.Result {
		tag, err := names.ParseRelationTag(rel)
		if err != nil {
			return nil, err
		}
		relTags = append(relTags, tag)
	}
	return relTags, nil
}
Exemplo n.º 2
0
func (s *relationSuite) TestParseRelationTag(c *gc.C) {
	for i, t := range parseRelationTagTests {
		c.Logf("test %d: %s", i, t.tag)
		got, err := names.ParseRelationTag(t.tag)
		if err != nil || t.err != nil {
			c.Check(err, gc.DeepEquals, t.err)
			continue
		}
		c.Check(got, gc.FitsTypeOf, t.expected)
		c.Check(got, gc.Equals, t.expected)
	}
}
Exemplo n.º 3
0
// Relation returns the existing relation with the given tag.
func (st *State) Relation(relationTag string) (*Relation, error) {
	rtag, err := names.ParseRelationTag(relationTag)
	if err != nil {
		return nil, err
	}
	result, err := st.relation(rtag, st.unitTag)
	if err != nil {
		return nil, err
	}
	return &Relation{
		id:   result.Id,
		tag:  rtag,
		life: result.Life,
		st:   st,
	}, nil
}
Exemplo n.º 4
0
func (u *UniterAPI) getRelationAndUnit(canAccess common.AuthFunc, relTag string, unitTag names.UnitTag) (*state.Relation, *state.Unit, error) {
	tag, err := names.ParseRelationTag(relTag)
	if err != nil {
		return nil, nil, common.ErrPerm
	}
	rel, err := u.st.KeyRelation(tag.Id())
	if errors.IsNotFound(err) {
		return nil, nil, common.ErrPerm
	} else if err != nil {
		return nil, nil, err
	}
	if !canAccess(unitTag) {
		return nil, nil, common.ErrPerm
	}
	unit, err := u.getUnit(unitTag)
	return rel, unit, err
}