Skip to content

Commit

Permalink
Merge pull request #26 from uselagoon/hotfix/fix_source_write
Browse files Browse the repository at this point in the history
Adds direct.facts service logic and support
  • Loading branch information
CGoodwin90 authored Jun 23, 2023
2 parents b1a7259 + 3b378f3 commit 4b7e4c3
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions internal/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type DirectFact struct {
Type string `json:"type"`
Category string `json:"category"`
Service string `json:"service"`
Source string `json:"source"`
}

type DirectFacts struct {
Expand All @@ -95,7 +96,6 @@ type DirectFacts struct {
Facts []DirectFact `json:"facts"`
Type string `json:"type"`
InsightsType string `json:"insightsType"`
Source string `json:"source"`
}

type InsightsData struct {
Expand Down Expand Up @@ -448,25 +448,36 @@ func processItemsDirectly(message mq.Message, h *Messaging) string {

apiClient := graphql.NewClient(h.LagoonAPI.Endpoint, &http.Client{Transport: &authedTransport{wrapped: http.DefaultTransport, h: h}})

factSources := map[string]string{}

processedFacts := make([]lagoonclient.AddFactInput, len(directFacts.Facts))
for i, fact := range directFacts.Facts {

vartypeString := FactTypeText
if fact.Type == FactTypeText || fact.Type == FactTypeSemver || fact.Type == FactTypeUrl {
vartypeString = fact.Type
}

processedFacts[i] = lagoonclient.AddFactInput{
Environment: environmentId,
Name: fact.Name,
Value: fact.Value,
Source: directFacts.Source,
Source: fact.Source,
Description: fact.Description,
KeyFact: false,
Type: lagoonclient.FactType(FactTypeText),
Type: lagoonclient.FactType(vartypeString),
Category: fact.Category,
}
factSources[fact.Source] = fact.Source
}

_, err = lagoonclient.DeleteFactsFromSource(context.TODO(), apiClient, environmentId, directFacts.Source)
if err != nil {
log.Println(err)
for _, s := range factSources {
_, err = lagoonclient.DeleteFactsFromSource(context.TODO(), apiClient, environmentId, s)
if err != nil {
log.Println(err)
}
log.Printf("Deleted facts on '%v:%v' for source %v", directFacts.ProjectName, directFacts.EnvironmentName, s)
}
log.Printf("Deleted facts on '%v:%v' for source %v", directFacts.ProjectName, directFacts.EnvironmentName, directFacts.Source)

facts, err := lagoonclient.AddFacts(context.TODO(), apiClient, processedFacts)
if err != nil {
Expand Down

0 comments on commit 4b7e4c3

Please sign in to comment.