github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/systemfetcher/director_client.go (about)

     1  package systemfetcher
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/kyma-incubator/compass/components/director/pkg/tenant"
     8  	gcli "github.com/machinebox/graphql"
     9  	"github.com/pkg/errors"
    10  )
    11  
    12  // Authenticator missing godoc
    13  type Authenticator interface {
    14  	GetAuthorization(ctx context.Context) (string, error)
    15  }
    16  
    17  // DirectorGraphClient missing godoc
    18  type DirectorGraphClient struct {
    19  	*gcli.Client
    20  	Authenticator Authenticator
    21  }
    22  
    23  // DeleteSystemAsync missing godoc
    24  func (d *DirectorGraphClient) DeleteSystemAsync(ctx context.Context, id, tenantID string) error {
    25  	gqlRequest := gcli.NewRequest(fmt.Sprintf(`mutation {
    26  			  unregisterApplication(
    27  				id: %q,
    28  				mode: ASYNC
    29  			  ) {
    30  				  id
    31  			    }
    32  			}`, id))
    33  	ctx = tenant.SaveToContext(ctx, tenantID)
    34  	token, err := d.Authenticator.GetAuthorization(ctx)
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	gqlRequest.Header.Set("Authorization", token)
    40  	gqlRequest.Header.Set("tenant", tenantID)
    41  
    42  	if err := d.Run(ctx, gqlRequest, nil); err != nil {
    43  		return errors.Wrapf(err, "while executing GraphQL call to delete a system with id %s", id)
    44  	}
    45  	return nil
    46  }