github.com/Azure/aad-pod-identity@v1.8.17/pkg/cloudprovider/identity.go (about)

     1  package cloudprovider
     2  
     3  import (
     4  	"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
     5  )
     6  
     7  // IdentityHolder represents a resource that contains an Identity object
     8  // This is used to be able to generically intract with multiple resource types (e.g. VirtualMachine and VirtualMachineScaleSet)
     9  // which each contain an identity.
    10  type IdentityHolder interface {
    11  	IdentityInfo() IdentityInfo
    12  	ResetIdentity() IdentityInfo
    13  }
    14  
    15  // IdentityInfo is used to interact with different implementations of Azure compute identities.
    16  // This is needed because different Azure resource types (e.g. VirtualMachine and VirtualMachineScaleSet)
    17  // have different identity types.
    18  // This abstracts those differences.
    19  type IdentityInfo interface {
    20  	GetUserIdentityList() []string
    21  	SetUserIdentities(map[string]bool) bool
    22  	RemoveUserIdentity(string) bool
    23  }
    24  
    25  // getUpdatedResourceIdentityType returns the new resource identity type
    26  // to be set on the VM/VMSS based on current type
    27  func getUpdatedResourceIdentityType(identityType compute.ResourceIdentityType) compute.ResourceIdentityType {
    28  	switch identityType {
    29  	case "", compute.ResourceIdentityTypeNone, compute.ResourceIdentityTypeUserAssigned:
    30  		return compute.ResourceIdentityTypeUserAssigned
    31  	case compute.ResourceIdentityTypeSystemAssigned, compute.ResourceIdentityTypeSystemAssignedUserAssigned:
    32  		return compute.ResourceIdentityTypeSystemAssignedUserAssigned
    33  	default:
    34  		return compute.ResourceIdentityTypeNone
    35  	}
    36  }