Skip to content

Commit

Permalink
solve log issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dgghinea committed Nov 20, 2023
1 parent c9354cf commit 5c06b62
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions pkg/subscription/credential/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,33 @@ func (p credentialProvisioner) Deprovision() provisioning.RequestStatus {
if credentialID == "" {
return rs.SetMessage("CredentialID cannot be empty").Failed()
}
p.logger.WithField("credentialID", credentialID).
log := p.logger.WithField("credentialID", credentialID).
WithField("consumerID", consumerID)
p.logger.Info("Started credential de-provisioning")
log.Info("Started credential de-provisioning")

switch credentialType {
case provisioning.APIKeyARD:
{
if err := p.client.DeleteAuthKey(ctx, consumerID, credentialID); err != nil {
return rs.SetMessage("API Key credential does not exist or it has already been deleted").Success()
}
p.logger.Info("API Key successful de-provision")
log.Info("API Key successful de-provision")
return rs.SetMessage("API Key successfully deleted.").Success()
}
case provisioning.BasicAuthARD:
{
if err := p.client.DeleteHttpBasic(ctx, consumerID, credentialID); err != nil {
return rs.SetMessage("Basic auth credential does not exist or it has already been deleted").Success()
}
p.logger.Info("Basic Auth successful de-provision")
log.Info("Basic Auth successful de-provision")
return rs.SetMessage("Basic auth credential successfully deleted.").Success()
}
case provisioning.OAuthSecretCRD:
{
if err := p.client.DeleteOauth2(ctx, consumerID, credentialID); err != nil {
return rs.SetMessage("OAuth2 credential does not exist or it has already been deleted").Success()
}
p.logger.Info("OAuth2 successful de-provision")
log.Info("OAuth2 successful de-provision")
return rs.SetMessage("OAuth2 credential successfully deleted.").Success()
}
}
Expand All @@ -100,8 +100,8 @@ func (p credentialProvisioner) Provision() (provisioning.RequestStatus, provisio
ctx := context.Background()
rs := provisioning.NewRequestStatusBuilder()
credentialType := p.request.GetCredentialType()
p.logger.WithField("consumerID", consumerID)
p.logger.Info("Started credential provisioning")
log := p.logger.WithField("consumerID", consumerID)
log.Info("Started credential provisioning")

switch credentialType {
case provisioning.APIKeyARD:
Expand All @@ -110,12 +110,12 @@ func (p credentialProvisioner) Provision() (provisioning.RequestStatus, provisio
ToKeyAuth()
resp, err := p.client.CreateAuthKey(ctx, consumerID, keyAuth)
if err != nil {
p.logger.Info("API key unsuccessful provisioning")
log.Info("API key unsuccessful provisioning")
return rs.SetMessage("Failed to create api-key credential").Failed(), nil
}
rs.AddProperty(common.AttrAppID, *resp.Consumer.ID)
rs.AddProperty(common.AttrCredentialID, *resp.ID)
p.logger.Info("API key successful provisioning")
log.Info("API key successful provisioning")
return rs.Success(), provisioning.NewCredentialBuilder().SetAPIKey(*resp.Key)
}
case provisioning.BasicAuthARD:
Expand All @@ -127,13 +127,13 @@ func (p credentialProvisioner) Provision() (provisioning.RequestStatus, provisio
ToBasicAuth()
resp, err := p.client.CreateHttpBasic(ctx, consumerID, basicAuth)
if err != nil {
p.logger.Info("Basic auth unsuccessful provisioning")
log.Info("Basic auth unsuccessful provisioning")
return rs.SetMessage("Failed to create basic auth credential").Failed(), nil
}
rs.AddProperty(common.AttrAppID, *resp.Consumer.ID)
rs.AddProperty(common.AttrCredentialID, *resp.ID)
rs.AddProperty(common.AttrCredUpdater, *resp.Username)
p.logger.Info("Basic auth successful provisioning")
log.Info("Basic auth successful provisioning")
return rs.Success(), provisioning.NewCredentialBuilder().SetHTTPBasic(user, pass)
}
case provisioning.OAuthSecretCRD:
Expand All @@ -144,13 +144,13 @@ func (p credentialProvisioner) Provision() (provisioning.RequestStatus, provisio
ToOauth2()
resp, err := p.client.CreateOauth2(ctx, consumerID, oauth2)
if err != nil {
p.logger.Info("Oauth2 unsuccessful provisioning")
log.Info("Oauth2 unsuccessful provisioning")
return rs.SetMessage("Failed to create oauth2 credential").Failed(), nil
}
rs.AddProperty(common.AttrAppID, *resp.Consumer.ID)
rs.AddProperty(common.AttrCredentialID, *resp.ID)
rs.AddProperty(common.AttrCredUpdater, *resp.ClientID)
p.logger.Info("OAuth2 successful provisioning")
log.Info("OAuth2 successful provisioning")
return rs.Success(), provisioning.NewCredentialBuilder().SetOAuthIDAndSecret(*resp.ClientID, *resp.ClientSecret)
}
}
Expand All @@ -173,53 +173,53 @@ func (p credentialProvisioner) Update() (provisioning.RequestStatus, provisionin
return rs.SetMessage("kongCredentialId cannot be empty").Failed(), nil
}

p.logger.WithField("credentialID", credentialID).
log := p.logger.WithField("credentialID", credentialID).
WithField("consumerID", consumerID)
p.logger.Info("Started credential update")
log.Info("Started credential update")

switch credentialType {
case provisioning.APIKeyARD:
{
if err := p.client.DeleteAuthKey(ctx, consumerID, credentialID); err != nil {
p.logger.WithError(err).Error("Could not delete api-key credential")
log.WithError(err).Error("Could not delete api-key credential")
return rs.SetMessage(fmt.Sprintf("Could not delete credential %s for consumer %s", consumerID, credentialID)).Failed(), nil
}
keyAuth := kongBuilder.WithAuthKey("").
ToKeyAuth()
resp, err := p.client.CreateAuthKey(ctx, consumerID, keyAuth)
if err != nil {
p.logger.WithError(err).Error("Could not create api-key credential")
log.WithError(err).Error("Could not create api-key credential")
return rs.SetMessage("Failed to create api-key credential").Failed(), nil
}
rs.AddProperty(common.AttrAppID, *resp.Consumer.ID)
rs.AddProperty(common.AttrCredentialID, *resp.ID)
p.logger.Info("API Key successful update")
log.Info("API Key successful update")
return rs.Success(), provisioning.NewCredentialBuilder().SetAPIKey(*resp.Key)
}
case provisioning.BasicAuthARD:
{
if err := p.client.DeleteHttpBasic(ctx, consumerID, credentialID); err != nil {
p.logger.WithError(err).Error("Could not delete basic auth credential")
log.WithError(err).Error("Could not delete basic auth credential")
return rs.SetMessage(fmt.Sprintf("Could not delete credential %s for consumer %s", consumerID, credentialID)).Failed(), nil
}
basicAuth := kongBuilder.WithUsername(key).
WithPassword("").
ToBasicAuth()
resp, err := p.client.CreateHttpBasic(ctx, consumerID, basicAuth)
if err != nil {
p.logger.WithError(err).Error("Could not create basic auth credential")
log.WithError(err).Error("Could not create basic auth credential")
return rs.SetMessage("Failed to create basic auth credential").Failed(), nil
}
rs.AddProperty(common.AttrAppID, *resp.Consumer.ID)
rs.AddProperty(common.AttrCredentialID, *resp.ID)
rs.AddProperty(common.AttrCredUpdater, *resp.Username)
p.logger.Info("Basic Auth successful update")
log.Info("Basic Auth successful update")
return rs.Success(), provisioning.NewCredentialBuilder().SetHTTPBasic(*resp.Username, *resp.Password)
}
case provisioning.OAuthSecretCRD:
{
if err := p.client.DeleteOauth2(ctx, consumerID, credentialID); err != nil {
p.logger.WithError(err).Error("Could not delete oauth2 credential")
log.WithError(err).Error("Could not delete oauth2 credential")
return rs.SetMessage(fmt.Sprintf("Could not delete credential %s for consumer %s", consumerID, credentialID)).Failed(), nil
}
oauth2 := kongBuilder.WithClientID(key).
Expand All @@ -228,13 +228,13 @@ func (p credentialProvisioner) Update() (provisioning.RequestStatus, provisionin
ToOauth2()
resp, err := p.client.CreateOauth2(ctx, consumerID, oauth2)
if err != nil {
p.logger.WithError(err).Error("Could not create oauth2 credential")
log.WithError(err).Error("Could not create oauth2 credential")
return rs.SetMessage("Failed to create oauth2 credential").Failed(), nil
}
rs.AddProperty(common.AttrAppID, *resp.Consumer.ID)
rs.AddProperty(common.AttrCredentialID, *resp.ID)
rs.AddProperty(common.AttrCredUpdater, *resp.ClientID)
p.logger.Info("Oauth2 successful update")
log.Info("Oauth2 successful update")
return rs.Success(), provisioning.NewCredentialBuilder().SetOAuthIDAndSecret(*resp.ClientID, *resp.ClientSecret)
}
}
Expand Down

0 comments on commit 5c06b62

Please sign in to comment.