func InitiateAzureOIDCFlow()

in pkg/providers/azure.go [35:84]


func InitiateAzureOIDCFlow(ctx context.Context, sc *SetUpCmd, s spinner.Spinner, gh GhClient, az AzClientInterface) error {
	log.Debug("Commencing github connection with azure...")

	s.Start()

	if err := sc.ValidateSetUpConfig(gh, az); err != nil {
		return err
	}

	if !az.AzAppExists(sc.AppName) {
		appId, err := az.CreateAzApp(sc.AppName)
		if err != nil {
			return err
		}
		sc.appId = appId
	}

	spObjId, err := az.CreateServicePrincipal(sc.appId)
	if err != nil {
		return err
	}
	sc.spObjectId = spObjId

	if err := sc.getAppObjectId(); err != nil {
		return err
	}

	if err := az.AssignSpRole(ctx, sc.SubscriptionID, sc.ResourceGroupName, sc.spObjectId, CONTRIBUTOR_ROLE_ID); err != nil {
		return err
	}

	if !sc.hasFederatedCredentials() {
		if err := sc.createFederatedCredentials(); err != nil {
			return err
		}
	}

	if err := sc.setAzClientId(); err != nil {
		return err
	}
	if err := sc.setAzSubscriptionId(); err != nil {
		return err
	}
	if err := sc.setAzTenantId(); err != nil {
		return err
	}

	log.Debug("Github connection with azure completed successfully!")
	return nil
}