github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/fetchrequest.go (about) 1 package model 2 3 import ( 4 "time" 5 6 "github.com/kyma-incubator/compass/components/director/pkg/resource" 7 ) 8 9 // FetchRequest represents a request to fetch a specification resource from a remote system. 10 type FetchRequest struct { 11 ID string 12 URL string 13 Auth *Auth 14 Mode FetchMode 15 Filter *string 16 Status *FetchRequestStatus 17 ObjectType FetchRequestReferenceObjectType 18 ObjectID string 19 } 20 21 // FetchRequestReferenceObjectType represents the type of the object that the fetch request is referencing. 22 type FetchRequestReferenceObjectType string 23 24 const ( 25 // APISpecFetchRequestReference represents a fetch request for an API Specification. 26 APISpecFetchRequestReference FetchRequestReferenceObjectType = "APISpec" 27 // EventSpecFetchRequestReference represents a fetch request for an Event Specification. 28 EventSpecFetchRequestReference FetchRequestReferenceObjectType = "EventSpec" 29 // DocumentFetchRequestReference represents a fetch request for an Document Specification. 30 DocumentFetchRequestReference FetchRequestReferenceObjectType = "Document" 31 ) 32 33 // GetResourceType returns the resource type of the fetch request based on the referenced entity. 34 func (obj FetchRequestReferenceObjectType) GetResourceType() resource.Type { 35 switch obj { 36 case APISpecFetchRequestReference: 37 return resource.APISpecFetchRequest 38 case EventSpecFetchRequestReference: 39 return resource.EventSpecFetchRequest 40 case DocumentFetchRequestReference: 41 return resource.DocFetchRequest 42 } 43 return "" 44 } 45 46 // FetchRequestStatus is the status of an executed fetch request. 47 type FetchRequestStatus struct { 48 Condition FetchRequestStatusCondition 49 Message *string 50 Timestamp time.Time 51 } 52 53 // FetchMode is a legacy never delivered feature. 54 type FetchMode string 55 56 const ( 57 // FetchModeSingle is a legacy never delivered feature. 58 FetchModeSingle FetchMode = "SINGLE" 59 // FetchModeBundle is a legacy never delivered feature. 60 FetchModeBundle FetchMode = "BUNDLE" 61 // FetchModeIndex is a legacy never delivered feature. 62 FetchModeIndex FetchMode = "INDEX" 63 ) 64 65 // FetchRequestStatusCondition represents the condition of a fetch request. 66 type FetchRequestStatusCondition string 67 68 const ( 69 // FetchRequestStatusConditionInitial represents the initial state of a fetch request. 70 FetchRequestStatusConditionInitial FetchRequestStatusCondition = "INITIAL" 71 // FetchRequestStatusConditionSucceeded represents the state of a fetch request after it has been successfully executed. 72 FetchRequestStatusConditionSucceeded FetchRequestStatusCondition = "SUCCEEDED" 73 // FetchRequestStatusConditionFailed represents the state of a fetch request after it has failed. 74 FetchRequestStatusConditionFailed FetchRequestStatusCondition = "FAILED" 75 ) 76 77 // FetchRequestInput represents the input for creating a fetch request. 78 type FetchRequestInput struct { 79 URL string 80 Auth *AuthInput 81 Mode *FetchMode 82 Filter *string 83 } 84 85 // ToFetchRequest converts a FetchRequestInput to a FetchRequest. 86 func (f *FetchRequestInput) ToFetchRequest(timestamp time.Time, id string, objectType FetchRequestReferenceObjectType, objectID string) *FetchRequest { 87 if f == nil { 88 return nil 89 } 90 91 fetchMode := FetchModeSingle 92 if f.Mode != nil { 93 fetchMode = *f.Mode 94 } 95 96 return &FetchRequest{ 97 ID: id, 98 URL: f.URL, 99 Auth: f.Auth.ToAuth(), 100 Mode: fetchMode, 101 Filter: f.Filter, 102 Status: &FetchRequestStatus{ 103 Condition: FetchRequestStatusConditionInitial, 104 Timestamp: timestamp, 105 }, 106 ObjectType: objectType, 107 ObjectID: objectID, 108 } 109 }