func getServicePrincipal(client ad.ServicePrincipalsClient) (ad.ServicePrincipal, error) { // TODO(axw) filter by Service Principal Name (SPN). // It works without that, but the response is noisy. result, err := client.List("") if err != nil { return ad.ServicePrincipal{}, errors.Annotate(err, "listing service principals") } for _, sp := range result.Value { if sp.ApplicationID == jujuApplicationId { return sp, nil } } return ad.ServicePrincipal{}, errors.NotFoundf("service principal") }