Skip to content

Commit

Permalink
chore: complete migration to mlog and drop logrus (#729)
Browse files Browse the repository at this point in the history
Signed-off-by: Monis Khan <[email protected]>
  • Loading branch information
enj committed Feb 4, 2023
1 parent bb7170f commit 48230a8
Show file tree
Hide file tree
Showing 27 changed files with 319 additions and 203 deletions.
5 changes: 0 additions & 5 deletions cmd/azwi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import (
"os"

"github.com/Azure/azure-workload-identity/pkg/cmd"

colorable "github.com/mattn/go-colorable"
log "github.com/sirupsen/logrus" // TODO mlog?
)

func main() {
log.SetFormatter(&log.TextFormatter{ForceColors: true})
log.SetOutput(colorable.NewColorableStdout())
if err := cmd.NewRootCmd().Execute(); err != nil {
os.Exit(1)
}
Expand Down
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ require (
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/mattn/go-colorable v0.1.13
github.com/microsoft/kiota/abstractions/go v0.0.0-20211202082735-099f3c37853a
github.com/microsoft/kiota/authentication/go/azure v0.0.0-20211201125630-3501743a5dc5
github.com/microsoft/kiota/serialization/go/json v0.0.0-20211112084539-17ac73ffdc7c
github.com/microsoftgraph/msgraph-beta-sdk-go v0.7.0
github.com/open-policy-agent/cert-controller v0.5.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2
github.com/sirupsen/logrus v1.8.2
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
go.opentelemetry.io/otel v0.20.0
Expand All @@ -35,13 +33,13 @@ require (
k8s.io/apimachinery v0.25.6
k8s.io/client-go v0.25.6
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
monis.app/mlog v0.0.2
monis.app/mlog v0.0.4
sigs.k8s.io/controller-runtime v0.13.1
)

require (
cloud.google.com/go v0.98.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.0
github.com/Azure/azure-sdk-for-go/sdk/internal v0.9.1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
Expand Down Expand Up @@ -76,10 +74,9 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/microsoft/kiota/http/go/nethttp v0.0.0-20211203130928-8449c9e67101 // indirect
github.com/microsoftgraph/msgraph-sdk-go-core v0.0.5 // indirect
github.com/microsoft/kiota/http/go/nethttp v0.0.0-20211203130928-8449c9e67101
github.com/microsoftgraph/msgraph-sdk-go-core v0.0.5
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
12 changes: 2 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,8 @@ github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
Expand Down Expand Up @@ -525,8 +521,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.2 h1:Na+MAUL+cI0P3CtS35fqYIYVL6uKkDYY7sptpCtHHlI=
github.com/sirupsen/logrus v1.8.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
Expand Down Expand Up @@ -807,8 +801,6 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down Expand Up @@ -1103,8 +1095,8 @@ k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 h1:MQ8BAZPZlWk3S9K4a9NCkI
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1/go.mod h1:C/N6wCaBHeBHkHUesQOQy2/MZqGgMAFPqGsGQLdbZBU=
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 h1:KTgPnR10d5zhztWptI952TNtt/4u5h3IzDXkdIMuo2Y=
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
monis.app/mlog v0.0.2 h1:zyEt5GsmLhTafXhwidtOFriIVVdejUNc44TzDn/OZc4=
monis.app/mlog v0.0.2/go.mod h1:LtOpnndFuRGqnLBwzBvpA1DaoKuud2/moLzYXIiNl1s=
monis.app/mlog v0.0.4 h1:YEzh5sguG4ApywaRWnBU+mGP6SA4WxOqiJ36u+KtoeE=
monis.app/mlog v0.0.4/go.mod h1:LtOpnndFuRGqnLBwzBvpA1DaoKuud2/moLzYXIiNl1s=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
58 changes: 31 additions & 27 deletions pkg/cloud/azureclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"regexp"
"time"

azidentity "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-06-01/subscriptions"
"github.com/Azure/go-autorest/autorest"
Expand All @@ -23,7 +24,7 @@ import (
msgraphbetasdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
"github.com/microsoftgraph/msgraph-beta-sdk-go/models/microsoft/graph"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"monis.app/mlog"
)

// ref: https://docs.microsoft.com/en-us/graph/migrate-azure-ad-graph-request-differences#basic-requests
Expand Down Expand Up @@ -66,7 +67,7 @@ type AzureClient struct {
}

// NewAzureClientWithCLI creates an AzureClient configured from Azure CLI 2.0 for local development scenarios.
func NewAzureClientWithCLI(env azure.Environment, subscriptionID, tenantID string) (*AzureClient, error) {
func NewAzureClientWithCLI(env azure.Environment, subscriptionID, tenantID string, client *http.Client) (*AzureClient, error) {
_, tenantID, err := getOAuthConfig(env, subscriptionID, tenantID)
if err != nil {
return nil, err
Expand All @@ -91,11 +92,11 @@ func NewAzureClientWithCLI(env azure.Environment, subscriptionID, tenantID strin
return nil, errors.Wrap(err, "failed to create authentication provider")
}

return getClient(env, subscriptionID, tenantID, autorest.NewBearerAuthorizer(&adalToken), auth)
return getClient(env, subscriptionID, tenantID, autorest.NewBearerAuthorizer(&adalToken), auth, client)
}

// NewAzureClientWithClientSecret returns an AzureClient via client_id and client_secret
func NewAzureClientWithClientSecret(env azure.Environment, subscriptionID, clientID, clientSecret, tenantID string) (*AzureClient, error) {
func NewAzureClientWithClientSecret(env azure.Environment, subscriptionID, clientID, clientSecret, tenantID string, client *http.Client) (*AzureClient, error) {
oauthConfig, tenantID, err := getOAuthConfig(env, subscriptionID, tenantID)
if err != nil {
return nil, err
Expand All @@ -106,7 +107,12 @@ func NewAzureClientWithClientSecret(env azure.Environment, subscriptionID, clien
return nil, err
}

cred, err := azidentity.NewClientSecretCredential(tenantID, clientID, clientSecret, nil)
cred, err := azidentity.NewClientSecretCredential(tenantID, clientID, clientSecret,
&azidentity.ClientSecretCredentialOptions{
ClientOptions: azcore.ClientOptions{
Transport: client,
},
})
if err != nil {
return nil, errors.Wrap(err, "failed to create credential")
}
Expand All @@ -115,11 +121,11 @@ func NewAzureClientWithClientSecret(env azure.Environment, subscriptionID, clien
return nil, errors.Wrap(err, "failed to create authentication provider")
}

return getClient(env, subscriptionID, tenantID, autorest.NewBearerAuthorizer(armSpt), auth)
return getClient(env, subscriptionID, tenantID, autorest.NewBearerAuthorizer(armSpt), auth, client)
}

// NewAzureClientWithClientCertificateFile returns an AzureClient via client_id and jwt certificate assertion
func NewAzureClientWithClientCertificateFile(env azure.Environment, subscriptionID, clientID, tenantID, certificatePath, privateKeyPath string) (*AzureClient, error) {
func NewAzureClientWithClientCertificateFile(env azure.Environment, subscriptionID, clientID, tenantID, certificatePath, privateKeyPath string, client *http.Client) (*AzureClient, error) {
certificateData, err := os.ReadFile(certificatePath)
if err != nil {
return nil, errors.Wrap(err, "Failed to read certificate")
Expand All @@ -140,27 +146,17 @@ func NewAzureClientWithClientCertificateFile(env azure.Environment, subscription
return nil, errors.Wrap(err, "Failed to parse rsa private key")
}

return NewAzureClientWithClientCertificate(env, subscriptionID, clientID, tenantID, certificate, privateKey)
return NewAzureClientWithClientCertificate(env, subscriptionID, clientID, tenantID, certificate, privateKey, client)
}

// NewAzureClientWithClientCertificate returns an AzureClient via client_id and jwt certificate assertion
func NewAzureClientWithClientCertificate(env azure.Environment, subscriptionID, clientID, tenantID string, certificate *x509.Certificate, privateKey *rsa.PrivateKey) (*AzureClient, error) {
func NewAzureClientWithClientCertificate(env azure.Environment, subscriptionID, clientID, tenantID string, certificate *x509.Certificate, privateKey *rsa.PrivateKey, client *http.Client) (*AzureClient, error) {
oauthConfig, tenantID, err := getOAuthConfig(env, subscriptionID, tenantID)
if err != nil {
return nil, err
}

return newAzureClientWithCertificate(env, oauthConfig, subscriptionID, clientID, tenantID, certificate, privateKey)
}

// NewAzureClientWithClientCertificateExternalTenant returns an AzureClient via client_id and jwt certificate assertion against a 3rd party tenant
func NewAzureClientWithClientCertificateExternalTenant(env azure.Environment, subscriptionID, tenantID, clientID string, certificate *x509.Certificate, privateKey *rsa.PrivateKey) (*AzureClient, error) {
oauthConfig, err := adal.NewOAuthConfig(env.ActiveDirectoryEndpoint, tenantID)
if err != nil {
return nil, err
}

return newAzureClientWithCertificate(env, oauthConfig, subscriptionID, clientID, tenantID, certificate, privateKey)
return newAzureClientWithCertificate(env, oauthConfig, subscriptionID, clientID, tenantID, certificate, privateKey, client)
}

func getOAuthConfig(env azure.Environment, subscriptionID, tenantID string) (*adal.OAuthConfig, string, error) {
Expand All @@ -172,7 +168,7 @@ func getOAuthConfig(env azure.Environment, subscriptionID, tenantID string) (*ad
return oauthConfig, tenantID, nil
}

func newAzureClientWithCertificate(env azure.Environment, oauthConfig *adal.OAuthConfig, subscriptionID, clientID, tenantID string, certificate *x509.Certificate, privateKey *rsa.PrivateKey) (*AzureClient, error) {
func newAzureClientWithCertificate(env azure.Environment, oauthConfig *adal.OAuthConfig, subscriptionID, clientID, tenantID string, certificate *x509.Certificate, privateKey *rsa.PrivateKey, client *http.Client) (*AzureClient, error) {
if certificate == nil {
return nil, errors.New("certificate should not be nil")
}
Expand All @@ -186,7 +182,12 @@ func newAzureClientWithCertificate(env azure.Environment, oauthConfig *adal.OAut
return nil, err
}

cred, err := azidentity.NewClientCertificateCredential(tenantID, clientID, []*x509.Certificate{certificate}, privateKey, nil)
cred, err := azidentity.NewClientCertificateCredential(tenantID, clientID, []*x509.Certificate{certificate}, privateKey,
&azidentity.ClientCertificateCredentialOptions{
ClientOptions: azcore.ClientOptions{
Transport: client,
},
})
if err != nil {
return nil, errors.Wrap(err, "failed to create credential")
}
Expand All @@ -195,11 +196,11 @@ func newAzureClientWithCertificate(env azure.Environment, oauthConfig *adal.OAut
return nil, errors.Wrap(err, "failed to create authentication provider")
}

return getClient(env, subscriptionID, tenantID, autorest.NewBearerAuthorizer(armSpt), auth)
return getClient(env, subscriptionID, tenantID, autorest.NewBearerAuthorizer(armSpt), auth, client)
}

func getClient(env azure.Environment, subscriptionID, tenantID string, armAuthorizer autorest.Authorizer, auth authentication.AuthenticationProvider) (*AzureClient, error) {
adapter, err := msgraphbetasdk.NewGraphRequestAdapter(auth)
func getClient(env azure.Environment, subscriptionID, tenantID string, armAuthorizer autorest.Authorizer, auth authentication.AuthenticationProvider, client *http.Client) (*AzureClient, error) {
adapter, err := msgraphbetasdk.NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient(auth, nil, nil, client)
if err != nil {
return nil, errors.Wrap(err, "failed to create request adapter")
}
Expand All @@ -217,6 +218,9 @@ func getClient(env azure.Environment, subscriptionID, tenantID string, armAuthor
azClient.roleAssignmentsClient.Authorizer = armAuthorizer
azClient.roleDefinitionsClient.Authorizer = armAuthorizer

azClient.roleAssignmentsClient.Sender = client
azClient.roleDefinitionsClient.Sender = client

return azClient, nil
}

Expand All @@ -228,7 +232,7 @@ func GetTenantID(resourceManagerEndpoint string, subscriptionID string) (string,
const hdrKey = "WWW-Authenticate"
c := subscriptions.NewClientWithBaseURI(resourceManagerEndpoint)

log.Debugf("Resolving tenantID for subscriptionID: %s", subscriptionID)
mlog.Debug("Resolving tenantID", "subscriptionID", subscriptionID)

// we expect this request to fail (err != nil), but we are only interested
// in headers, so surface the error if the Response is not present (i.e.
Expand Down
27 changes: 17 additions & 10 deletions pkg/cloud/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/microsoftgraph/msgraph-beta-sdk-go/models/microsoft/graph"
"github.com/microsoftgraph/msgraph-beta-sdk-go/serviceprincipals"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"monis.app/mlog"
)

var (
Expand All @@ -27,7 +27,7 @@ func (c *AzureClient) CreateServicePrincipal(ctx context.Context, appID string,
spPostOptions.Body.SetAppId(to.StringPtr(appID))
spPostOptions.Body.SetTags(tags)

log.Debugf("Creating service principal for application with id=%s", appID)
mlog.Debug("Creating service principal for application", "id", appID)
sp, err := c.graphServiceClient.ServicePrincipals().Post(spPostOptions)
if err != nil {
return nil, err
Expand All @@ -49,7 +49,7 @@ func (c *AzureClient) CreateApplication(ctx context.Context, displayName string)
}
appPostOptions.Body.SetDisplayName(to.StringPtr(displayName))

log.Debugf("Creating application with display name=%s", displayName)
mlog.Debug("Creating application", "displayName", displayName)
app, err := c.graphServiceClient.Applications().Post(appPostOptions)
if err != nil {
return nil, err
Expand All @@ -66,7 +66,7 @@ func (c *AzureClient) CreateApplication(ctx context.Context, displayName string)

// GetServicePrincipal gets a service principal by its display name.
func (c *AzureClient) GetServicePrincipal(ctx context.Context, displayName string) (*graph.ServicePrincipal, error) {
log.Debugf("Getting service principal with display name=%s", displayName)
mlog.Debug("Getting service principal", "displayName", displayName)

spGetOptions := &serviceprincipals.ServicePrincipalsRequestBuilderGetOptions{
Q: &serviceprincipals.ServicePrincipalsRequestBuilderGetQueryParameters{
Expand All @@ -93,7 +93,7 @@ func (c *AzureClient) GetServicePrincipal(ctx context.Context, displayName strin

// GetApplication gets an application by its display name.
func (c *AzureClient) GetApplication(ctx context.Context, displayName string) (*graph.Application, error) {
log.Debugf("Getting application with display name=%s", displayName)
mlog.Debug("Getting application", "displayName", displayName)

appGetOptions := &applications.ApplicationsRequestBuilderGetOptions{
Q: &applications.ApplicationsRequestBuilderGetQueryParameters{
Expand All @@ -120,19 +120,19 @@ func (c *AzureClient) GetApplication(ctx context.Context, displayName string) (*

// DeleteServicePrincipal deletes a service principal.
func (c *AzureClient) DeleteServicePrincipal(ctx context.Context, objectID string) error {
log.Debugf("Deleting service principal with object id=%s", objectID)
mlog.Debug("Deleting service principal", "objectID", objectID)
return c.graphServiceClient.ServicePrincipalsById(objectID).Delete(nil)
}

// DeleteApplication deletes an application.
func (c *AzureClient) DeleteApplication(ctx context.Context, objectID string) error {
log.Debugf("Deleting application with object id=%s", objectID)
mlog.Debug("Deleting application", "objectID", objectID)
return c.graphServiceClient.ApplicationsById(objectID).Delete(nil)
}

// AddFederatedCredential adds a federated credential to the cloud provider.
func (c *AzureClient) AddFederatedCredential(ctx context.Context, objectID string, fic *graph.FederatedIdentityCredential) error {
log.Debugf("Adding federated credential for objectID=%s", objectID)
mlog.Debug("Adding federated credential", "objectID", objectID)

ficPostOptions := &federatedidentitycredentials.FederatedIdentityCredentialsRequestBuilderPostOptions{
Body: fic,
Expand All @@ -153,7 +153,11 @@ func (c *AzureClient) AddFederatedCredential(ctx context.Context, objectID strin

// GetFederatedCredential gets a federated credential from the cloud provider.
func (c *AzureClient) GetFederatedCredential(ctx context.Context, objectID, issuer, subject string) (*graph.FederatedIdentityCredential, error) {
log.Debugf("Getting federated credential for objectID=%s, issuer=%s, subject=%s", objectID, issuer, subject)
mlog.Debug("Getting federated credential",
"objectID", objectID,
"issuer", issuer,
"subject", subject,
)

ficGetOptions := &federatedidentitycredentials.FederatedIdentityCredentialsRequestBuilderGetOptions{
Q: &federatedidentitycredentials.FederatedIdentityCredentialsRequestBuilderGetQueryParameters{
Expand Down Expand Up @@ -183,7 +187,10 @@ func (c *AzureClient) GetFederatedCredential(ctx context.Context, objectID, issu

// DeleteFederatedCredential deletes a federated credential from the cloud provider.
func (c *AzureClient) DeleteFederatedCredential(ctx context.Context, objectID, federatedCredentialID string) error {
log.Debugf("Deleting federated credential for objectID=%s, federatedCredentialID=%s", objectID, federatedCredentialID)
mlog.Debug("Deleting federated credential",
"objectID", objectID,
"federatedCredentialID", federatedCredentialID,
)
return c.graphServiceClient.ApplicationsById(objectID).FederatedIdentityCredentialsById(federatedCredentialID).Delete(nil)
}

Expand Down
Loading

0 comments on commit 48230a8

Please sign in to comment.