~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/backups/shim.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2014 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package backups
 
5
 
 
6
import (
 
7
        "github.com/juju/errors"
 
8
        "github.com/juju/juju/apiserver/common"
 
9
        "github.com/juju/juju/apiserver/facade"
 
10
        "github.com/juju/juju/state"
 
11
)
 
12
 
 
13
// This file contains untested shims to let us wrap state in a sensible
 
14
// interface and avoid writing tests that depend on mongodb. If you were
 
15
// to change any part of it so that it were no longer *obviously* and
 
16
// *trivially* correct, you would be Doing It Wrong.
 
17
 
 
18
func init() {
 
19
        common.RegisterStandardFacade("Backups", 1, newAPI)
 
20
}
 
21
 
 
22
type stateShim struct {
 
23
        *state.State
 
24
}
 
25
 
 
26
// MachineSeries implements backups.Backend
 
27
func (s *stateShim) MachineSeries(id string) (string, error) {
 
28
        m, err := s.State.Machine(id)
 
29
        if err != nil {
 
30
                return "", errors.Trace(err)
 
31
        }
 
32
        return m.Series(), nil
 
33
}
 
34
 
 
35
func newAPI(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*API, error) {
 
36
        return NewAPI(&stateShim{st}, resources, authorizer)
 
37
}