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

     1  package model
     2  
     3  import (
     4  	"encoding/json"
     5  	"strconv"
     6  
     7  	"github.com/kyma-incubator/compass/components/director/pkg/str"
     8  
     9  	"github.com/kyma-incubator/compass/components/director/pkg/pagination"
    10  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
    11  )
    12  
    13  // Bundle missing godoc
    14  type Bundle struct {
    15  	ApplicationID                  *string
    16  	ApplicationTemplateVersionID   *string
    17  	Name                           string
    18  	Description                    *string
    19  	Version                        *string
    20  	ResourceHash                   *string
    21  	InstanceAuthRequestInputSchema *string
    22  	DefaultInstanceAuth            *Auth
    23  	OrdID                          *string
    24  	LocalTenantID                  *string
    25  	ShortDescription               *string
    26  	Links                          json.RawMessage
    27  	Labels                         json.RawMessage
    28  	CredentialExchangeStrategies   json.RawMessage
    29  	CorrelationIDs                 json.RawMessage
    30  	Tags                           json.RawMessage
    31  	DocumentationLabels            json.RawMessage
    32  	*BaseEntity
    33  }
    34  
    35  // GetType missing godoc
    36  func (*Bundle) GetType() resource.Type {
    37  	return resource.Bundle
    38  }
    39  
    40  // SetFromUpdateInput missing godoc
    41  func (bndl *Bundle) SetFromUpdateInput(update BundleUpdateInput, bndlHash uint64) {
    42  	var hash *string
    43  	if bndlHash != 0 {
    44  		hash = str.Ptr(strconv.FormatUint(bndlHash, 10))
    45  	}
    46  
    47  	bndl.Name = update.Name
    48  	bndl.Description = update.Description
    49  	bndl.Version = update.Version
    50  	bndl.ResourceHash = hash
    51  	bndl.InstanceAuthRequestInputSchema = update.InstanceAuthRequestInputSchema
    52  	bndl.DefaultInstanceAuth = update.DefaultInstanceAuth.ToAuth()
    53  	bndl.OrdID = update.OrdID
    54  	bndl.LocalTenantID = update.LocalTenantID
    55  	bndl.ShortDescription = update.ShortDescription
    56  	bndl.Links = update.Links
    57  	bndl.Labels = update.Labels
    58  	bndl.CredentialExchangeStrategies = update.CredentialExchangeStrategies
    59  	bndl.CorrelationIDs = update.CorrelationIDs
    60  	bndl.Tags = update.Tags
    61  	bndl.DocumentationLabels = update.DocumentationLabels
    62  }
    63  
    64  // BundleCreateInput missing godoc
    65  type BundleCreateInput struct {
    66  	Name                           string                  `json:"title"`
    67  	Description                    *string                 `json:"description"`
    68  	Version                        *string                 `json:"version" hash:"ignore"`
    69  	InstanceAuthRequestInputSchema *string                 `json:",omitempty"`
    70  	DefaultInstanceAuth            *AuthInput              `json:",omitempty"`
    71  	OrdID                          *string                 `json:"ordId"`
    72  	LocalTenantID                  *string                 `json:"localTenantId"`
    73  	ShortDescription               *string                 `json:"shortDescription"`
    74  	Links                          json.RawMessage         `json:"links"`
    75  	Labels                         json.RawMessage         `json:"labels"`
    76  	CredentialExchangeStrategies   json.RawMessage         `json:"credentialExchangeStrategies"`
    77  	APIDefinitions                 []*APIDefinitionInput   `json:",omitempty"`
    78  	APISpecs                       []*SpecInput            `json:",omitempty"`
    79  	EventDefinitions               []*EventDefinitionInput `json:",omitempty"`
    80  	EventSpecs                     []*SpecInput            `json:",omitempty"`
    81  	Documents                      []*DocumentInput        `json:",omitempty"`
    82  	CorrelationIDs                 json.RawMessage         `json:"correlationIds"`
    83  	Tags                           json.RawMessage         `json:"tags"`
    84  	DocumentationLabels            json.RawMessage         `json:"documentationLabels"`
    85  }
    86  
    87  // BundleUpdateInput missing godoc
    88  type BundleUpdateInput struct {
    89  	Name                           string
    90  	Description                    *string
    91  	Version                        *string
    92  	InstanceAuthRequestInputSchema *string
    93  	DefaultInstanceAuth            *AuthInput
    94  	OrdID                          *string
    95  	LocalTenantID                  *string
    96  	ShortDescription               *string
    97  	Links                          json.RawMessage
    98  	Labels                         json.RawMessage
    99  	CredentialExchangeStrategies   json.RawMessage
   100  	CorrelationIDs                 json.RawMessage
   101  	Tags                           json.RawMessage
   102  	DocumentationLabels            json.RawMessage
   103  }
   104  
   105  // BundlePage missing godoc
   106  type BundlePage struct {
   107  	Data       []*Bundle
   108  	PageInfo   *pagination.Page
   109  	TotalCount int
   110  }
   111  
   112  // IsPageable missing godoc
   113  func (BundlePage) IsPageable() {}
   114  
   115  // ToBundle missing godoc
   116  func (i *BundleCreateInput) ToBundle(id string, resourceType resource.Type, resourceID string, bndlHash uint64) *Bundle {
   117  	if i == nil {
   118  		return nil
   119  	}
   120  
   121  	var hash *string
   122  	if bndlHash != 0 {
   123  		hash = str.Ptr(strconv.FormatUint(bndlHash, 10))
   124  	}
   125  
   126  	bundle := &Bundle{
   127  		Name:                           i.Name,
   128  		Description:                    i.Description,
   129  		Version:                        i.Version,
   130  		ResourceHash:                   hash,
   131  		InstanceAuthRequestInputSchema: i.InstanceAuthRequestInputSchema,
   132  		DefaultInstanceAuth:            i.DefaultInstanceAuth.ToAuth(),
   133  		OrdID:                          i.OrdID,
   134  		LocalTenantID:                  i.LocalTenantID,
   135  		ShortDescription:               i.ShortDescription,
   136  		Links:                          i.Links,
   137  		Labels:                         i.Labels,
   138  		CredentialExchangeStrategies:   i.CredentialExchangeStrategies,
   139  		CorrelationIDs:                 i.CorrelationIDs,
   140  		Tags:                           i.Tags,
   141  		DocumentationLabels:            i.DocumentationLabels,
   142  		BaseEntity: &BaseEntity{
   143  			ID:    id,
   144  			Ready: true,
   145  		},
   146  	}
   147  
   148  	if resourceType.IsTenantIgnorable() {
   149  		bundle.ApplicationTemplateVersionID = &resourceID
   150  	} else if resourceType == resource.Application {
   151  		bundle.ApplicationID = &resourceID
   152  	}
   153  
   154  	return bundle
   155  }