github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/maas/errors.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package maas
     5  
     6  import (
     7  	"github.com/juju/gomaasapi"
     8  
     9  	"github.com/juju/juju/provider/common"
    10  )
    11  
    12  // IsAuthorisationFailure determines if the given error has an authorisation failure.
    13  func IsAuthorisationFailure(err error) bool {
    14  	// This should cover most cases.
    15  	if gomaasapi.IsPermissionError(err) {
    16  		return true
    17  	}
    18  
    19  	// This should cover exceptional circumstances.
    20  	if maasErr, ok := err.(gomaasapi.ServerError); ok {
    21  		return common.AuthorisationFailureStatusCodes.Contains(maasErr.StatusCode)
    22  	}
    23  	return false
    24  }