Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Integrators and Integrators Config #5

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions june2024v2july2024/integrators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package june2024v2july2024

import (
"context"
"encoding/json"
"fmt"
"upgradationScript/june2024v2july2024/july2024"
"upgradationScript/june2024v2july2024/june2024v2"
"upgradationScript/logger"

"github.com/Khan/genqlient/graphql"
)

func performIntegratorsTransition(prodDgraphClient, expDgraphClient graphql.Client) error {

ctx := context.Background()

existingIntegrators, err := june2024v2.QueryExistingIntegrators(ctx, prodDgraphClient)
if err != nil {
return fmt.Errorf("performIntegratorsTransition: QueryExistingIntegrators: could'nt query old prod integrators to initiate transition error: %s", err.Error())
}

logger.Sl.Debugf("--------------Commencing scanned files transition iterations to complete %d -----------------", len(existingIntegrators.QueryIntegrator))

if len(existingIntegrators.QueryIntegrator) == 0 {
logger.Sl.Debugf("No Integrators Found while running performIntegratorsTransition")
}

integratorTypeGrouping := make(map[string]july2024.AddIntegratorInput)
for iter, eachIntegrator := range existingIntegrators.QueryIntegrator {
logger.Logger.Debug("---------------------------------------------")
logger.Sl.Debugf("existing integrators Iteration %d to begin", iter)

var existingIntegratorData map[string]string
if err := json.Unmarshal([]byte(eachIntegrator.Credentials.Data), &existingIntegratorData); err != nil {
logger.Sl.Errorf("error: performIntegratorsTransition: Unmarshal: %s for integrator type: %s", err.Error(), eachIntegrator.Type)
continue
}

var configValues []*july2024.IntegratorKeyValuesRef
for key, eachConfigData := range existingIntegratorData {
encrypt := IsEncryptionRequired(key)
configValues = append(configValues, &july2024.IntegratorKeyValuesRef{
Key: key,
Value: eachConfigData,
Encrypt: &encrypt,
})
}

configTemp := july2024.IntegratorConfigsRef{
Name: eachIntegrator.Name,
Configs: configValues,
}

if val, ok := integratorTypeGrouping[eachIntegrator.Type]; ok {

val.IntegratorConfigs = append(val.IntegratorConfigs, &configTemp)
integratorTypeGrouping[eachIntegrator.Type] = val

} else {

integratorTypeGrouping[eachIntegrator.Type] = july2024.AddIntegratorInput{
Organization: &july2024.OrganizationRef{
Id: eachIntegrator.Organization.Id,
},
Type: eachIntegrator.Type,
Category: eachIntegrator.Category,
Status: "disabled",
CreatedAt: eachIntegrator.CreatedAt,
UpdatedAt: eachIntegrator.UpdatedAt,
IntegratorConfigs: []*july2024.IntegratorConfigsRef{&configTemp},
}
}
logger.Sl.Debugf("existing integrators Iteration %d completed", iter)
}

var translatedIntegators []*july2024.AddIntegratorInput
for _, val := range integratorTypeGrouping {
translatedIntegators = append(translatedIntegators, &val)
}

logger.Sl.Debug("adding Integrators to the database")

if _, err := july2024.AddIntegrator(ctx, expDgraphClient, translatedIntegators); err != nil {
return fmt.Errorf("error: performIntegratorsTransition: AddIntegrator error: %s", err.Error())
}
logger.Sl.Debug("added Integrators to the database")

logger.Logger.Info("------------Integrators upgrade complete-------------------------")

return nil
}

func IsEncryptionRequired(configKey string) (isRequired bool) {

switch configKey {
case "token":
isRequired = true
case "password":
isRequired = true
case "awsAccessKey":
isRequired = true
case "awsSecretKey":
isRequired = true
case "key":
isRequired = true
default:
isRequired = false
}
return isRequired
}
6 changes: 6 additions & 0 deletions june2024v2july2024/july2024/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ mutation UpdateVulnScanState {
updateArtifactScanData(input: { set: { vulnScanState: "done" }, filter: { } }) {
numUids
}
}

mutation AddIntegrator($value: [AddIntegratorInput!]!) {
addIntegrator(input: $value) {
numUids
}
}
Loading