Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(220)

Side by Side Diff: state/service.go

Issue 6551044: state: check unit/service name validity
Patch Set: state: check unit/service name validity Created 12 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « juju/conn_test.go ('k') | state/service_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package state 1 package state
2 2
3 import ( 3 import (
4 "errors" 4 "errors"
5 "fmt" 5 "fmt"
6 "labix.org/v2/mgo" 6 "labix.org/v2/mgo"
7 "labix.org/v2/mgo/txn" 7 "labix.org/v2/mgo/txn"
8 "launchpad.net/juju-core/charm" 8 "launchpad.net/juju-core/charm"
9 "launchpad.net/juju-core/trivial" 9 "launchpad.net/juju-core/trivial"
10 "strconv" 10 "strconv"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 274 }
275 err := s.st.units.Find(sel).One(udoc) 275 err := s.st.units.Find(sel).One(udoc)
276 if err != nil { 276 if err != nil {
277 return nil, err 277 return nil, err
278 } 278 }
279 return udoc, nil 279 return udoc, nil
280 } 280 }
281 281
282 // Unit returns the service's unit with name. 282 // Unit returns the service's unit with name.
283 func (s *Service) Unit(name string) (*Unit, error) { 283 func (s *Service) Unit(name string) (*Unit, error) {
284 if !IsUnitName(name) {
285 return nil, fmt.Errorf("%q is not a valid unit name", name)
286 }
284 udoc, err := s.unitDoc(name) 287 udoc, err := s.unitDoc(name)
285 if err != nil { 288 if err != nil {
286 return nil, fmt.Errorf("cannot get unit %q from service %q: %v", name, s.doc.Name, err) 289 return nil, fmt.Errorf("cannot get unit %q from service %q: %v", name, s.doc.Name, err)
287 } 290 }
288 return newUnit(s.st, udoc), nil 291 return newUnit(s.st, udoc), nil
289 } 292 }
290 293
291 // AllUnits returns all units of the service. 294 // AllUnits returns all units of the service.
292 func (s *Service) AllUnits() (units []*Unit, err error) { 295 func (s *Service) AllUnits() (units []*Unit, err error) {
293 docs := []unitDoc{} 296 docs := []unitDoc{}
(...skipping 22 matching lines...) Expand all
316 } 319 }
317 320
318 // Config returns the configuration node for the service. 321 // Config returns the configuration node for the service.
319 func (s *Service) Config() (config *ConfigNode, err error) { 322 func (s *Service) Config() (config *ConfigNode, err error) {
320 config, err = readConfigNode(s.st, "s/"+s.Name()) 323 config, err = readConfigNode(s.st, "s/"+s.Name())
321 if err != nil { 324 if err != nil {
322 return nil, fmt.Errorf("cannot get configuration of service %q: %v", s, err) 325 return nil, fmt.Errorf("cannot get configuration of service %q: %v", s, err)
323 } 326 }
324 return config, nil 327 return config, nil
325 } 328 }
OLDNEW
« no previous file with comments | « juju/conn_test.go ('k') | state/service_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b