Skip to content

Commit

Permalink
Comments out prob processor
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed Oct 19, 2023
1 parent c876618 commit bd04204
Showing 1 changed file with 61 additions and 60 deletions.
121 changes: 61 additions & 60 deletions internal/handler/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,63 +74,64 @@ func processItemsDirectly(message mq.Message, h *Messaging) string {
return facts
}

func processProblemsDirectly(message mq.Message, h *Messaging) string {
var directProblems DirectProblems
json.Unmarshal(message.Body(), &directProblems)
err := json.Unmarshal(message.Body(), &directProblems)
if err != nil {
log.Println("Error unmarshaling JSON:", err)
return "exciting, unable to process direct problems"
}

// since its useful to allow int and string json definitions, we need to convert strings here to ints.
environmentId, err := strconv.Atoi(directProblems.EnvironmentId.String())
if err != nil {
log.Println("Error converting EnvironmentId to int:", err)
return "exciting, unable to process direct facts"
}

if h.EnableDebug {
log.Print("[DEBUG] problems", directProblems)
}

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

factSources := map[string]string{}

processedFacts := make([]lagoonclient.AddProblem, len(directProblems.Facts))
for i, fact := range directProblems.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: fact.Source,
Description: fact.Description,
KeyFact: false,
Type: lagoonclient.FactType(vartypeString),
Category: fact.Category,
}
factSources[fact.Source] = fact.Source
}

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", directProblems.ProjectName, directProblems.EnvironmentName, s)
}

facts, err := lagoonclient.AddFacts(context.TODO(), apiClient, processedFacts)
if err != nil {
log.Println(err)
}

return facts
}
//
//func processProblemsDirectly(message mq.Message, h *Messaging) string {
// var directProblems DirectProblems
// json.Unmarshal(message.Body(), &directProblems)
// err := json.Unmarshal(message.Body(), &directProblems)
// if err != nil {
// log.Println("Error unmarshaling JSON:", err)
// return "exciting, unable to process direct problems"
// }
//
// // since its useful to allow int and string json definitions, we need to convert strings here to ints.
// environmentId, err := strconv.Atoi(directProblems.EnvironmentId.String())
// if err != nil {
// log.Println("Error converting EnvironmentId to int:", err)
// return "exciting, unable to process direct facts"
// }
//
// if h.EnableDebug {
// log.Print("[DEBUG] problems", directProblems)
// }
//
// apiClient := graphql.NewClient(h.LagoonAPI.Endpoint, &http.Client{Transport: &authedTransport{wrapped: http.DefaultTransport, h: h}})
//
// factSources := map[string]string{}
//
// processedFacts := make([]lagoonclient.AddProblem, len(directProblems.Facts))
// for i, fact := range directProblems.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: fact.Source,
// Description: fact.Description,
// KeyFact: false,
// Type: lagoonclient.FactType(vartypeString),
// Category: fact.Category,
// }
// factSources[fact.Source] = fact.Source
// }
//
// 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", directProblems.ProjectName, directProblems.EnvironmentName, s)
// }
//
// facts, err := lagoonclient.AddFacts(context.TODO(), apiClient, processedFacts)
// if err != nil {
// log.Println(err)
// }
//
// return facts
//}

0 comments on commit bd04204

Please sign in to comment.