github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/application/validate.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package application
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  	"github.com/juju/errors"
     9  	"github.com/juju/gnuflag"
    10  	"github.com/juju/juju/core/lxdprofile"
    11  
    12  	"gopkg.in/macaroon-bakery.v2-unstable/httpbakery"
    13  )
    14  
    15  // ValidateLXDProfileCharm implements the DeployStep interface.
    16  type ValidateLXDProfileCharm struct{}
    17  
    18  // SetFlags implements DeployStep.
    19  func (r *ValidateLXDProfileCharm) SetFlags(f *gnuflag.FlagSet) {
    20  }
    21  
    22  // SetPlanURL implements DeployStep.
    23  func (r *ValidateLXDProfileCharm) SetPlanURL(planURL string) {
    24  	// noop
    25  }
    26  
    27  // RunPre obtains authorization to deploy this charm. The authorization, if received is not
    28  // sent to the controller, rather it is kept as an attribute on RegisterMeteredCharm.
    29  func (r *ValidateLXDProfileCharm) RunPre(api DeployStepAPI, bakeryClient *httpbakery.Client, ctx *cmd.Context, deployInfo DeploymentInfo) error {
    30  	// if the charm info is not empty, we should use that to validate the
    31  	// lxd profile.
    32  	if charmInfo := deployInfo.CharmInfo; charmInfo != nil {
    33  		if err := lxdprofile.ValidateCharmInfoLXDProfile(charmInfo); err != nil {
    34  			// The force flag was provided, but we should let the user know that
    35  			// this could deliver some unexpected results.
    36  			if deployInfo.Force {
    37  				logger.Debugf("force option used to override validation error %v", err)
    38  				return nil
    39  			}
    40  			return errors.Trace(err)
    41  		}
    42  	}
    43  	return nil
    44  }
    45  
    46  // RunPost sends credentials obtained during the call to RunPre to the controller.
    47  func (r *ValidateLXDProfileCharm) RunPost(api DeployStepAPI, bakeryClient *httpbakery.Client, ctx *cmd.Context, deployInfo DeploymentInfo, prevErr error) error {
    48  	return nil
    49  }