~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/juju/permission/model.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package permission
 
5
 
 
6
import (
 
7
        "github.com/juju/errors"
 
8
)
 
9
 
 
10
// ModelAccess defines the permission that a user has on a model.
 
11
type ModelAccess int
 
12
 
 
13
const (
 
14
        _ = iota
 
15
 
 
16
        // ModelReadAccess allows a user to read a model but not to change it.
 
17
        ModelReadAccess ModelAccess = iota
 
18
 
 
19
        // ModelWriteAccess allows a user write access to the model.
 
20
        ModelWriteAccess ModelAccess = iota
 
21
)
 
22
 
 
23
// ParseModelAccess parses a user-facing string representation of a model
 
24
// access permission into a logical representation.
 
25
func ParseModelAccess(access string) (ModelAccess, error) {
 
26
        var fail = ModelAccess(0)
 
27
        switch access {
 
28
        case "read":
 
29
                return ModelReadAccess, nil
 
30
        case "write":
 
31
                return ModelWriteAccess, nil
 
32
        default:
 
33
                return fail, errors.Errorf("invalid model access permission %q", access)
 
34
        }
 
35
}