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

     1  package model
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/internal/uid"
     7  
     8  	"github.com/kyma-incubator/compass/components/director/pkg/pagination"
     9  )
    10  
    11  // ApplicationTemplate missing godoc
    12  type ApplicationTemplate struct {
    13  	ID                   string
    14  	Name                 string
    15  	Description          *string
    16  	ApplicationNamespace *string
    17  	ApplicationInputJSON string
    18  	Placeholders         []ApplicationTemplatePlaceholder
    19  	AccessLevel          ApplicationTemplateAccessLevel
    20  	Webhooks             []Webhook
    21  	Labels               map[string]interface{}
    22  }
    23  
    24  // ApplicationTemplatePage missing godoc
    25  type ApplicationTemplatePage struct {
    26  	Data       []*ApplicationTemplate
    27  	PageInfo   *pagination.Page
    28  	TotalCount int
    29  }
    30  
    31  // ApplicationTemplateInput missing godoc
    32  type ApplicationTemplateInput struct {
    33  	ID                   *string
    34  	Name                 string
    35  	Description          *string
    36  	ApplicationNamespace *string
    37  	ApplicationInputJSON string
    38  	Placeholders         []ApplicationTemplatePlaceholder
    39  	AccessLevel          ApplicationTemplateAccessLevel
    40  	Labels               map[string]interface{}
    41  	Webhooks             []*WebhookInput
    42  }
    43  
    44  // ApplicationTemplateAccessLevel missing godoc
    45  type ApplicationTemplateAccessLevel string
    46  
    47  // GlobalApplicationTemplateAccessLevel missing godoc
    48  const (
    49  	GlobalApplicationTemplateAccessLevel ApplicationTemplateAccessLevel = "GLOBAL"
    50  )
    51  
    52  // ApplicationFromTemplateInput missing godoc
    53  type ApplicationFromTemplateInput struct {
    54  	ID                  *string
    55  	TemplateName        string
    56  	Values              ApplicationFromTemplateInputValues
    57  	PlaceholdersPayload *string
    58  	Labels              map[string]interface{}
    59  }
    60  
    61  // ApplicationFromTemplateInputValues missing godoc
    62  type ApplicationFromTemplateInputValues []*ApplicationTemplateValueInput
    63  
    64  // FindPlaceholderValue missing godoc
    65  func (in ApplicationFromTemplateInputValues) FindPlaceholderValue(name string) (string, error) {
    66  	for _, value := range in {
    67  		if value.Placeholder == name {
    68  			return value.Value, nil
    69  		}
    70  	}
    71  	return "", fmt.Errorf("value for placeholder name '%s' not found", name)
    72  }
    73  
    74  // ApplicationTemplatePlaceholder missing godoc
    75  type ApplicationTemplatePlaceholder struct {
    76  	Name        string
    77  	Description *string
    78  	JSONPath    *string
    79  	Optional    *bool
    80  }
    81  
    82  // ApplicationTemplateValueInput missing godoc
    83  type ApplicationTemplateValueInput struct {
    84  	Placeholder string
    85  	Value       string
    86  }
    87  
    88  // ToApplicationTemplate missing godoc
    89  func (a *ApplicationTemplateInput) ToApplicationTemplate(id string) ApplicationTemplate {
    90  	if a == nil {
    91  		return ApplicationTemplate{}
    92  	}
    93  
    94  	uidService := uid.NewService()
    95  	webhooks := make([]Webhook, 0)
    96  	for _, webhookInput := range a.Webhooks {
    97  		webhook := webhookInput.ToWebhook(uidService.Generate(), id, ApplicationTemplateWebhookReference)
    98  		webhooks = append(webhooks, *webhook)
    99  	}
   100  
   101  	return ApplicationTemplate{
   102  		ID:                   id,
   103  		Name:                 a.Name,
   104  		Description:          a.Description,
   105  		ApplicationNamespace: a.ApplicationNamespace,
   106  		ApplicationInputJSON: a.ApplicationInputJSON,
   107  		Placeholders:         a.Placeholders,
   108  		AccessLevel:          a.AccessLevel,
   109  		Webhooks:             webhooks,
   110  	}
   111  }
   112  
   113  // ApplicationTemplateUpdateInput missing godoc
   114  type ApplicationTemplateUpdateInput struct {
   115  	Name                 string
   116  	Description          *string
   117  	ApplicationNamespace *string
   118  	ApplicationInputJSON string
   119  	Placeholders         []ApplicationTemplatePlaceholder
   120  	AccessLevel          ApplicationTemplateAccessLevel
   121  	Labels               map[string]interface{}
   122  	Webhooks             []*WebhookInput
   123  }
   124  
   125  // ToApplicationTemplate missing godoc
   126  func (a *ApplicationTemplateUpdateInput) ToApplicationTemplate(id string) ApplicationTemplate {
   127  	if a == nil {
   128  		return ApplicationTemplate{}
   129  	}
   130  
   131  	uidService := uid.NewService()
   132  	webhooks := make([]Webhook, 0)
   133  	for _, webhookInput := range a.Webhooks {
   134  		webhook := webhookInput.ToWebhook(uidService.Generate(), id, ApplicationTemplateWebhookReference)
   135  		webhooks = append(webhooks, *webhook)
   136  	}
   137  
   138  	return ApplicationTemplate{
   139  		ID:                   id,
   140  		Name:                 a.Name,
   141  		Description:          a.Description,
   142  		ApplicationNamespace: a.ApplicationNamespace,
   143  		ApplicationInputJSON: a.ApplicationInputJSON,
   144  		Placeholders:         a.Placeholders,
   145  		AccessLevel:          a.AccessLevel,
   146  		Labels:               a.Labels,
   147  		Webhooks:             webhooks,
   148  	}
   149  }