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

     1  package onetimetoken
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/internal/model"
     7  	"github.com/kyma-incubator/compass/components/director/pkg/graphql"
     8  )
     9  
    10  type converter struct {
    11  	legacyConnectorURL string
    12  }
    13  
    14  // NewConverter missing godoc
    15  func NewConverter(legacyConnectorURL string) *converter {
    16  	return &converter{legacyConnectorURL}
    17  }
    18  
    19  // ToGraphQLForRuntime missing godoc
    20  func (c converter) ToGraphQLForRuntime(model model.OneTimeToken) graphql.OneTimeTokenForRuntime {
    21  	return graphql.OneTimeTokenForRuntime{
    22  		TokenWithURL: graphql.TokenWithURL{
    23  			Token:        model.Token,
    24  			ConnectorURL: model.ConnectorURL,
    25  			Used:         model.Used,
    26  			ExpiresAt:    timeToTimestampPtr(model.ExpiresAt),
    27  			CreatedAt:    timeToTimestampPtr(model.CreatedAt),
    28  			UsedAt:       timeToTimestampPtr(model.UsedAt),
    29  			Type:         graphql.OneTimeTokenType(model.Type),
    30  		},
    31  	}
    32  }
    33  
    34  // ToGraphQLForApplication missing godoc
    35  func (c converter) ToGraphQLForApplication(model model.OneTimeToken) (graphql.OneTimeTokenForApplication, error) {
    36  	urlWithToken, err := legacyConnectorURLWithToken(c.legacyConnectorURL, model.Token)
    37  	if err != nil {
    38  		return graphql.OneTimeTokenForApplication{}, err
    39  	}
    40  
    41  	return graphql.OneTimeTokenForApplication{
    42  		TokenWithURL: graphql.TokenWithURL{
    43  			Token:          model.Token,
    44  			ConnectorURL:   model.ConnectorURL,
    45  			Used:           model.Used,
    46  			ExpiresAt:      timeToTimestampPtr(model.ExpiresAt),
    47  			CreatedAt:      timeToTimestampPtr(model.CreatedAt),
    48  			UsedAt:         timeToTimestampPtr(model.UsedAt),
    49  			Type:           graphql.OneTimeTokenType(model.Type),
    50  			ScenarioGroups: model.ScenarioGroups,
    51  		},
    52  		LegacyConnectorURL: urlWithToken,
    53  	}, nil
    54  }
    55  
    56  func timeToTimestampPtr(time time.Time) *graphql.Timestamp {
    57  	t := graphql.Timestamp(time)
    58  	return &t
    59  }