github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/client/backups/mongoinfo.go (about)

     1  // Copyright 2017 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  	"gopkg.in/juju/names.v2"
     9  
    10  	"github.com/juju/juju/agent"
    11  	"github.com/juju/juju/mongo"
    12  )
    13  
    14  // TODO(axw) find a better way to pass the mongo info to the facade,
    15  // without necessarily making it available to all facades. This was
    16  // moved here so that we could remove the MongoConnectionInfo method
    17  // from State.
    18  func mongoInfo(dataDir, machineId string) (*mongo.MongoInfo, error) {
    19  	path := agent.ConfigPath(dataDir, names.NewMachineTag(machineId))
    20  	config, err := agent.ReadConfig(path)
    21  	if err != nil {
    22  		return nil, errors.Trace(err)
    23  	}
    24  	info, ok := config.MongoInfo()
    25  	if !ok {
    26  		return nil, errors.Errorf("no mongo info found in %q", path)
    27  	}
    28  	return info, nil
    29  }