diff --git a/litmus-portal/graphql-server/go.mod b/litmus-portal/graphql-server/go.mod index ef52a4219..e022d8469 100644 --- a/litmus-portal/graphql-server/go.mod +++ b/litmus-portal/graphql-server/go.mod @@ -19,7 +19,7 @@ require ( github.com/tidwall/sjson v1.1.1 github.com/vektah/gqlparser/v2 v2.0.1 go.mongodb.org/mongo-driver v1.3.5 - golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect diff --git a/litmus-portal/graphql-server/graph/generated/generated.go b/litmus-portal/graphql-server/graph/generated/generated.go index 4f5167db8..908bc0207 100644 --- a/litmus-portal/graphql-server/graph/generated/generated.go +++ b/litmus-portal/graphql-server/graph/generated/generated.go @@ -168,33 +168,54 @@ type ComplexityRoot struct { DeclineInvitation func(childComplexity int, member model.MemberInput) int DeleteChaosWorkflow func(childComplexity int, workflowid string) int DeleteClusterReg func(childComplexity int, clusterID string) int + DeleteMyHub func(childComplexity int, hubID string) int + GeneraterSSHKey func(childComplexity int) int NewClusterEvent func(childComplexity int, clusterEvent model.ClusterEventInput) int PodLog func(childComplexity int, log model.PodLog) int RemoveInvitation func(childComplexity int, member model.MemberInput) int + SaveMyHub func(childComplexity int, myhubInput model.CreateMyHub, projectID string) int SendInvitation func(childComplexity int, member model.MemberInput) int - SyncHub func(childComplexity int, projectID string, hubName string) int + SyncHub func(childComplexity int, id string) int UpdateChaosWorkflow func(childComplexity int, input *model.ChaosWorkFlowInput) int + UpdateMyHub func(childComplexity int, myhubInput model.UpdateMyHub, projectID string) int UpdateUser func(childComplexity int, user model.UpdateUserInput) int UserClusterReg func(childComplexity int, clusterInput model.ClusterInput) int } MyHub struct { - CreatedAt func(childComplexity int) int - HubName func(childComplexity int) int - ID func(childComplexity int) int - ProjectID func(childComplexity int) int - RepoBranch func(childComplexity int) int - RepoURL func(childComplexity int) int - UpdatedAt func(childComplexity int) int + AuthType func(childComplexity int) int + CreatedAt func(childComplexity int) int + HubName func(childComplexity int) int + ID func(childComplexity int) int + IsPrivate func(childComplexity int) int + IsRemoved func(childComplexity int) int + LastSyncedAt func(childComplexity int) int + Password func(childComplexity int) int + ProjectID func(childComplexity int) int + RepoBranch func(childComplexity int) int + RepoURL func(childComplexity int) int + SSHPrivateKey func(childComplexity int) int + Token func(childComplexity int) int + UpdatedAt func(childComplexity int) int + UserName func(childComplexity int) int } MyHubStatus struct { - HubName func(childComplexity int) int - ID func(childComplexity int) int - IsAvailable func(childComplexity int) int - RepoBranch func(childComplexity int) int - RepoURL func(childComplexity int) int - TotalExp func(childComplexity int) int + AuthType func(childComplexity int) int + HubName func(childComplexity int) int + ID func(childComplexity int) int + IsAvailable func(childComplexity int) int + IsPrivate func(childComplexity int) int + IsRemoved func(childComplexity int) int + LastSyncedAt func(childComplexity int) int + Password func(childComplexity int) int + RepoBranch func(childComplexity int) int + RepoURL func(childComplexity int) int + SSHPrivateKey func(childComplexity int) int + SSHPublicKey func(childComplexity int) int + Token func(childComplexity int) int + TotalExp func(childComplexity int) int + UserName func(childComplexity int) int } PackageInformation struct { @@ -237,6 +258,11 @@ type ComplexityRoot struct { Users func(childComplexity int) int } + SSHKey struct { + PrivateKey func(childComplexity int) int + PublicKey func(childComplexity int) int + } + ScheduledWorkflows struct { ClusterID func(childComplexity int) int ClusterName func(childComplexity int) int @@ -354,9 +380,13 @@ type MutationResolver interface { ChaosWorkflowRun(ctx context.Context, workflowData model.WorkflowRunInput) (string, error) PodLog(ctx context.Context, log model.PodLog) (string, error) AddMyHub(ctx context.Context, myhubInput model.CreateMyHub, projectID string) (*model.MyHub, error) - SyncHub(ctx context.Context, projectID string, hubName string) ([]*model.MyHubStatus, error) + SaveMyHub(ctx context.Context, myhubInput model.CreateMyHub, projectID string) (*model.MyHub, error) + SyncHub(ctx context.Context, id string) ([]*model.MyHubStatus, error) UpdateChaosWorkflow(ctx context.Context, input *model.ChaosWorkFlowInput) (*model.ChaosWorkFlowResponse, error) DeleteClusterReg(ctx context.Context, clusterID string) (string, error) + GeneraterSSHKey(ctx context.Context) (*model.SSHKey, error) + UpdateMyHub(ctx context.Context, myhubInput model.UpdateMyHub, projectID string) (*model.MyHub, error) + DeleteMyHub(ctx context.Context, hubID string) (bool, error) } type QueryResolver interface { GetWorkFlowRuns(ctx context.Context, projectID string) ([]*model.WorkflowRun, error) @@ -984,6 +1014,25 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.DeleteClusterReg(childComplexity, args["cluster_id"].(string)), true + case "Mutation.deleteMyHub": + if e.complexity.Mutation.DeleteMyHub == nil { + break + } + + args, err := ec.field_Mutation_deleteMyHub_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.DeleteMyHub(childComplexity, args["hub_id"].(string)), true + + case "Mutation.generaterSSHKey": + if e.complexity.Mutation.GeneraterSSHKey == nil { + break + } + + return e.complexity.Mutation.GeneraterSSHKey(childComplexity), true + case "Mutation.newClusterEvent": if e.complexity.Mutation.NewClusterEvent == nil { break @@ -1020,6 +1069,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.RemoveInvitation(childComplexity, args["member"].(model.MemberInput)), true + case "Mutation.saveMyHub": + if e.complexity.Mutation.SaveMyHub == nil { + break + } + + args, err := ec.field_Mutation_saveMyHub_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.SaveMyHub(childComplexity, args["myhubInput"].(model.CreateMyHub), args["projectID"].(string)), true + case "Mutation.sendInvitation": if e.complexity.Mutation.SendInvitation == nil { break @@ -1042,7 +1103,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Mutation.SyncHub(childComplexity, args["projectID"].(string), args["HubName"].(string)), true + return e.complexity.Mutation.SyncHub(childComplexity, args["id"].(string)), true case "Mutation.updateChaosWorkflow": if e.complexity.Mutation.UpdateChaosWorkflow == nil { @@ -1056,6 +1117,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.UpdateChaosWorkflow(childComplexity, args["input"].(*model.ChaosWorkFlowInput)), true + case "Mutation.updateMyHub": + if e.complexity.Mutation.UpdateMyHub == nil { + break + } + + args, err := ec.field_Mutation_updateMyHub_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.UpdateMyHub(childComplexity, args["myhubInput"].(model.UpdateMyHub), args["projectID"].(string)), true + case "Mutation.updateUser": if e.complexity.Mutation.UpdateUser == nil { break @@ -1080,6 +1153,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.UserClusterReg(childComplexity, args["clusterInput"].(model.ClusterInput)), true + case "MyHub.AuthType": + if e.complexity.MyHub.AuthType == nil { + break + } + + return e.complexity.MyHub.AuthType(childComplexity), true + case "MyHub.CreatedAt": if e.complexity.MyHub.CreatedAt == nil { break @@ -1101,6 +1181,34 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyHub.ID(childComplexity), true + case "MyHub.IsPrivate": + if e.complexity.MyHub.IsPrivate == nil { + break + } + + return e.complexity.MyHub.IsPrivate(childComplexity), true + + case "MyHub.IsRemoved": + if e.complexity.MyHub.IsRemoved == nil { + break + } + + return e.complexity.MyHub.IsRemoved(childComplexity), true + + case "MyHub.LastSyncedAt": + if e.complexity.MyHub.LastSyncedAt == nil { + break + } + + return e.complexity.MyHub.LastSyncedAt(childComplexity), true + + case "MyHub.Password": + if e.complexity.MyHub.Password == nil { + break + } + + return e.complexity.MyHub.Password(childComplexity), true + case "MyHub.ProjectID": if e.complexity.MyHub.ProjectID == nil { break @@ -1122,6 +1230,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyHub.RepoURL(childComplexity), true + case "MyHub.SSHPrivateKey": + if e.complexity.MyHub.SSHPrivateKey == nil { + break + } + + return e.complexity.MyHub.SSHPrivateKey(childComplexity), true + + case "MyHub.Token": + if e.complexity.MyHub.Token == nil { + break + } + + return e.complexity.MyHub.Token(childComplexity), true + case "MyHub.UpdatedAt": if e.complexity.MyHub.UpdatedAt == nil { break @@ -1129,6 +1251,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyHub.UpdatedAt(childComplexity), true + case "MyHub.UserName": + if e.complexity.MyHub.UserName == nil { + break + } + + return e.complexity.MyHub.UserName(childComplexity), true + + case "MyHubStatus.AuthType": + if e.complexity.MyHubStatus.AuthType == nil { + break + } + + return e.complexity.MyHubStatus.AuthType(childComplexity), true + case "MyHubStatus.HubName": if e.complexity.MyHubStatus.HubName == nil { break @@ -1150,6 +1286,34 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyHubStatus.IsAvailable(childComplexity), true + case "MyHubStatus.IsPrivate": + if e.complexity.MyHubStatus.IsPrivate == nil { + break + } + + return e.complexity.MyHubStatus.IsPrivate(childComplexity), true + + case "MyHubStatus.IsRemoved": + if e.complexity.MyHubStatus.IsRemoved == nil { + break + } + + return e.complexity.MyHubStatus.IsRemoved(childComplexity), true + + case "MyHubStatus.LastSyncedAt": + if e.complexity.MyHubStatus.LastSyncedAt == nil { + break + } + + return e.complexity.MyHubStatus.LastSyncedAt(childComplexity), true + + case "MyHubStatus.Password": + if e.complexity.MyHubStatus.Password == nil { + break + } + + return e.complexity.MyHubStatus.Password(childComplexity), true + case "MyHubStatus.RepoBranch": if e.complexity.MyHubStatus.RepoBranch == nil { break @@ -1164,6 +1328,27 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyHubStatus.RepoURL(childComplexity), true + case "MyHubStatus.SSHPrivateKey": + if e.complexity.MyHubStatus.SSHPrivateKey == nil { + break + } + + return e.complexity.MyHubStatus.SSHPrivateKey(childComplexity), true + + case "MyHubStatus.SSHPublicKey": + if e.complexity.MyHubStatus.SSHPublicKey == nil { + break + } + + return e.complexity.MyHubStatus.SSHPublicKey(childComplexity), true + + case "MyHubStatus.Token": + if e.complexity.MyHubStatus.Token == nil { + break + } + + return e.complexity.MyHubStatus.Token(childComplexity), true + case "MyHubStatus.TotalExp": if e.complexity.MyHubStatus.TotalExp == nil { break @@ -1171,6 +1356,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MyHubStatus.TotalExp(childComplexity), true + case "MyHubStatus.UserName": + if e.complexity.MyHubStatus.UserName == nil { + break + } + + return e.complexity.MyHubStatus.UserName(childComplexity), true + case "PackageInformation.Experiments": if e.complexity.PackageInformation.Experiments == nil { break @@ -1396,6 +1588,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Users(childComplexity), true + case "SSHKey.privateKey": + if e.complexity.SSHKey.PrivateKey == nil { + break + } + + return e.complexity.SSHKey.PrivateKey(childComplexity), true + + case "SSHKey.publicKey": + if e.complexity.SSHKey.PublicKey == nil { + break + } + + return e.complexity.SSHKey.PublicKey(childComplexity), true + case "ScheduledWorkflows.cluster_id": if e.complexity.ScheduledWorkflows.ClusterID == nil { break @@ -2015,112 +2221,178 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er } var sources = []*ast.Source{ - &ast.Source{Name: "graph/myhub.graphqls", Input: `type MyHub { - id: ID! - RepoURL: String! - RepoBranch: String! - ProjectID: String! - HubName: String! - CreatedAt: String! - UpdatedAt: String! + &ast.Source{Name: "graph/myhub.graphqls", Input: `enum AuthType { + basic + token + ssh +} + +type MyHub { + id: ID! + RepoURL: String! + RepoBranch: String! + ProjectID: String! + HubName: String! + IsPrivate: Boolean! + # Auth Types- + # token: Token based authentication + # basic: Username/Password based authentication + # ssh: SSH based authentication + AuthType: AuthType! + Token: String + UserName: String + Password: String + SSHPrivateKey: String + IsRemoved: Boolean! + CreatedAt: String! + UpdatedAt: String! + LastSyncedAt: String! } type Charts { - Charts: [Chart!]! + Charts: [Chart!]! } type Chart { - ApiVersion: String! - Kind: String! - Metadata: Metadata! - Spec: Spec! - PackageInfo: PackageInformation! - Experiments: [Chart!]! + ApiVersion: String! + Kind: String! + Metadata: Metadata! + Spec: Spec! + PackageInfo: PackageInformation! + Experiments: [Chart!]! } type Maintainer { - Name: String! - Email: String! + Name: String! + Email: String! } type Link { - Name: String! - Url: String! + Name: String! + Url: String! } type Metadata { - Name: String! - Version: String! - Annotations: Annotation! + Name: String! + Version: String! + Annotations: Annotation! } type Annotation { - Categories: String! - Vendor: String! - CreatedAt: String! - Repository: String! - Support: String! - ChartDescription: String! + Categories: String! + Vendor: String! + CreatedAt: String! + Repository: String! + Support: String! + ChartDescription: String! } type Spec { - DisplayName: String! - CategoryDescription: String! - Keywords: [String!]! - Maturity: String! - Maintainers: [Maintainer!]! - MinKubeVersion: String! - Provider: String! - Links: [Link!]! - Experiments: [String!]! - ChaosExpCRDLink: String! - Platforms: [String!]! - ChaosType: String + DisplayName: String! + CategoryDescription: String! + Keywords: [String!]! + Maturity: String! + Maintainers: [Maintainer!]! + MinKubeVersion: String! + Provider: String! + Links: [Link!]! + Experiments: [String!]! + ChaosExpCRDLink: String! + Platforms: [String!]! + ChaosType: String } type Provider { - Name: String! + Name: String! } type PackageInformation { - PackageName: String! - Experiments: [Experiments!]! + PackageName: String! + Experiments: [Experiments!]! } type Experiments { - Name: String! - CSV: String! - Desc: String! + Name: String! + CSV: String! + Desc: String! } type MyHubStatus { - id: ID! - RepoURL: String! - RepoBranch: String! - IsAvailable: Boolean! - TotalExp: String! - HubName: String! + id: ID! + RepoURL: String! + RepoBranch: String! + IsAvailable: Boolean! + TotalExp: String! + HubName: String! + IsPrivate: Boolean! + # Auth Types- + # token: Token based authentication + # basic: Username/Password based authentication + # ssh: SSH based authentication + AuthType: AuthType! + Token: String + UserName: String + Password: String + IsRemoved: Boolean! + SSHPrivateKey: String + SSHPublicKey: String + LastSyncedAt: String! } input CreateMyHub { - HubName: String! - RepoURL: String! - RepoBranch: String! + HubName: String! + RepoURL: String! + RepoBranch: String! + IsPrivate: Boolean! + # Auth Types- + # token: Token based authentication + # basic: Username/Password based authentication + # ssh: SSH based authentication + AuthType: AuthType! + Token: String + UserName: String + Password: String + SSHPrivateKey: String + SSHPublicKey: String } input ExperimentInput { - ProjectID: String! - ChartName: String! - ExperimentName: String! - HubName: String! - FileType: String + ProjectID: String! + ChartName: String! + ExperimentName: String! + HubName: String! + FileType: String } input CloningInput { - HubName: String! - ProjectID: String! - RepoBranch: String! - RepoURL: String! + HubName: String! + ProjectID: String! + RepoBranch: String! + RepoURL: String! + IsPrivate: Boolean! + # Auth Types- + # token: Token based authentication + # basic: Username/Password based authentication + # ssh: SSH based authentication + AuthType: AuthType! + Token: String + UserName: String + Password: String + SSHPrivateKey: String +} + +input UpdateMyHub { + id: String! + HubName: String! + RepoURL: String! + RepoBranch: String! + IsPrivate: Boolean! + AuthType: AuthType! + Token: String + UserName: String + Password: String + SSHPrivateKey: String + SSHPublicKey: String } `, BuiltIn: false}, &ast.Source{Name: "graph/project.graphqls", Input: `type Project { @@ -2162,287 +2434,300 @@ enum MemberRole { directive @authorized on FIELD_DEFINITION type Cluster { - cluster_id: ID! - project_id: ID! - cluster_name: String! - description: String - platform_name: String! - access_key: String! - is_registered: Boolean! - is_cluster_confirmed: Boolean! - is_active: Boolean! - updated_at: String! - created_at: String! - cluster_type: String! - no_of_schedules: Int - no_of_workflows: Int - token: String! - agent_namespace: String - serviceaccount: String - agent_scope: String! - agent_ns_exists: Boolean - agent_sa_exists: Boolean + cluster_id: ID! + project_id: ID! + cluster_name: String! + description: String + platform_name: String! + access_key: String! + is_registered: Boolean! + is_cluster_confirmed: Boolean! + is_active: Boolean! + updated_at: String! + created_at: String! + cluster_type: String! + no_of_schedules: Int + no_of_workflows: Int + token: String! + agent_namespace: String + serviceaccount: String + agent_scope: String! + agent_ns_exists: Boolean + agent_sa_exists: Boolean } input ClusterInput { - cluster_name: String! - description: String - platform_name: String! - project_id: ID! - cluster_type: String! - agent_namespace: String - serviceaccount: String - agent_scope: String! - agent_ns_exists: Boolean - agent_sa_exists: Boolean + cluster_name: String! + description: String + platform_name: String! + project_id: ID! + cluster_type: String! + agent_namespace: String + serviceaccount: String + agent_scope: String! + agent_ns_exists: Boolean + agent_sa_exists: Boolean } type ClusterEvent { - event_id: ID! - event_type: String! - event_name: String! - description: String! - cluster: Cluster! + event_id: ID! + event_type: String! + event_name: String! + description: String! + cluster: Cluster! } type ActionPayload { - request_type: String! - k8s_manifest: String! - namespace: String! - external_data: String + request_type: String! + k8s_manifest: String! + namespace: String! + external_data: String } type ClusterAction { - project_id: ID! - action: ActionPayload! + project_id: ID! + action: ActionPayload! } input ClusterActionInput { - cluster_id: ID! - action: String! + cluster_id: ID! + action: String! } input ClusterEventInput { - event_name: String! - description: String! - cluster_id: String! - access_key: String! + event_name: String! + description: String! + cluster_id: String! + access_key: String! } input ClusterIdentity { - cluster_id: String! - access_key: String! + cluster_id: String! + access_key: String! } type ClusterConfirmResponse { - isClusterConfirmed: Boolean! - newClusterKey: String - cluster_id: String + isClusterConfirmed: Boolean! + newClusterKey: String + cluster_id: String } input WeightagesInput { - experiment_name: String! - weightage: Int! + experiment_name: String! + weightage: Int! } type weightages { - experiment_name: String! - weightage: Int! + experiment_name: String! + weightage: Int! } input ChaosWorkFlowInput { - workflow_id: String - workflow_manifest: String! - cronSyntax: String! - workflow_name: String! - workflow_description: String! - weightages: [WeightagesInput!]! - isCustomWorkflow: Boolean! - project_id: ID! - cluster_id: ID! + workflow_id: String + workflow_manifest: String! + cronSyntax: String! + workflow_name: String! + workflow_description: String! + weightages: [WeightagesInput!]! + isCustomWorkflow: Boolean! + project_id: ID! + cluster_id: ID! } type ChaosWorkFlowResponse { - workflow_id: String! - cronSyntax: String! - workflow_name: String! - workflow_description: String! - isCustomWorkflow: Boolean! + workflow_id: String! + cronSyntax: String! + workflow_name: String! + workflow_description: String! + isCustomWorkflow: Boolean! } type WorkflowRun { - workflow_run_id: ID! - workflow_id: ID! - cluster_name: String! - last_updated: String! - project_id: ID! - cluster_id: ID! - workflow_name: String! - cluster_type: String - execution_data: String! + workflow_run_id: ID! + workflow_id: ID! + cluster_name: String! + last_updated: String! + project_id: ID! + cluster_id: ID! + workflow_name: String! + cluster_type: String + execution_data: String! } input WorkflowRunInput { - workflow_id: ID! - workflow_run_id: ID! - workflow_name: String! - execution_data: String! - cluster_id: ClusterIdentity! - completed: Boolean! + workflow_id: ID! + workflow_run_id: ID! + workflow_name: String! + execution_data: String! + cluster_id: ClusterIdentity! + completed: Boolean! } type PodLogResponse { - workflow_run_id: ID! - pod_name: String! - pod_type: String! - log: String! + workflow_run_id: ID! + pod_name: String! + pod_type: String! + log: String! } input PodLog { - cluster_id: ClusterIdentity! - request_id: ID! - workflow_run_id: ID! - pod_name: String! - pod_type: String! - log: String! + cluster_id: ClusterIdentity! + request_id: ID! + workflow_run_id: ID! + pod_name: String! + pod_type: String! + log: String! } input PodLogRequest { - cluster_id: ID! - workflow_run_id: ID! - pod_name: String! - pod_namespace: String! - pod_type: String! - exp_pod: String - runner_pod: String - chaos_namespace: String + cluster_id: ID! + workflow_run_id: ID! + pod_name: String! + pod_namespace: String! + pod_type: String! + exp_pod: String + runner_pod: String + chaos_namespace: String } type ScheduledWorkflows { - workflow_id: String! - workflow_manifest: String! - cronSyntax: String! - cluster_name: String! - workflow_name: String! - workflow_description: String! - weightages: [weightages!]! - isCustomWorkflow: Boolean! - updated_at: String! - created_at: String! - project_id: ID! - cluster_id: ID! - cluster_type: String! - isRemoved: Boolean! + workflow_id: String! + workflow_manifest: String! + cronSyntax: String! + cluster_name: String! + workflow_name: String! + workflow_description: String! + weightages: [weightages!]! + isCustomWorkflow: Boolean! + updated_at: String! + created_at: String! + project_id: ID! + cluster_id: ID! + cluster_type: String! + isRemoved: Boolean! } type Workflow { - workflow_id: String! - workflow_manifest: String! - cronSyntax: String! - cluster_name: String! - workflow_name: String! - workflow_description: String! - weightages: [weightages!]! - isCustomWorkflow: Boolean! - updated_at: String! - created_at: String! - project_id: ID! - cluster_id: ID! - cluster_type: String! - isRemoved: Boolean! - workflow_runs: [WorkflowRuns] + workflow_id: String! + workflow_manifest: String! + cronSyntax: String! + cluster_name: String! + workflow_name: String! + workflow_description: String! + weightages: [weightages!]! + isCustomWorkflow: Boolean! + updated_at: String! + created_at: String! + project_id: ID! + cluster_id: ID! + cluster_type: String! + isRemoved: Boolean! + workflow_runs: [WorkflowRuns] } type WorkflowRuns { - execution_data: String! - workflow_run_id: ID! - last_updated: String! + execution_data: String! + workflow_run_id: ID! + last_updated: String! } type clusterRegResponse { - token: String! - cluster_id: String! - cluster_name: String! + token: String! + cluster_id: String! + cluster_name: String! +} + +type SSHKey { + publicKey: String! + privateKey: String! } type Query { - # [Deprecated soon] - getWorkFlowRuns(project_id: String!): [WorkflowRun!]! @authorized + # [Deprecated soon] + getWorkFlowRuns(project_id: String!): [WorkflowRun!]! @authorized - getCluster(project_id: String!, cluster_type: String): [Cluster!]! @authorized + getCluster(project_id: String!, cluster_type: String): [Cluster!]! @authorized - getUser(username: String!): User! @authorized + getUser(username: String!): User! @authorized - getProject(projectID: String!): Project! @authorized + getProject(projectID: String!): Project! @authorized - users: [User!]! @authorized + users: [User!]! @authorized - # [Deprecated soon] - getScheduledWorkflows(project_id: String!): [ScheduledWorkflows]! @authorized + # [Deprecated soon] + getScheduledWorkflows(project_id: String!): [ScheduledWorkflows]! @authorized - ListWorkflow(project_id: String!, workflow_ids: [ID]): [Workflow]! @authorized + ListWorkflow(project_id: String!, workflow_ids: [ID]): [Workflow]! @authorized - getCharts(HubName: String!, projectID: String!): [Chart!]! @authorized + getCharts(HubName: String!, projectID: String!): [Chart!]! @authorized - getHubExperiment(experimentInput: ExperimentInput!): Chart! @authorized + getHubExperiment(experimentInput: ExperimentInput!): Chart! @authorized - getHubStatus(projectID: String!): [MyHubStatus]! @authorized + getHubStatus(projectID: String!): [MyHubStatus]! @authorized - getYAMLData(experimentInput: ExperimentInput!): String! + getYAMLData(experimentInput: ExperimentInput!): String! } type Mutation { - #It is used to create external cluster. - userClusterReg(clusterInput: ClusterInput!): clusterRegResponse! @authorized + #It is used to create external cluster. + userClusterReg(clusterInput: ClusterInput!): clusterRegResponse! @authorized - #It is used to create chaosworkflow - createChaosWorkFlow(input: ChaosWorkFlowInput!): ChaosWorkFlowResponse! - @authorized + #It is used to create chaosworkflow + createChaosWorkFlow(input: ChaosWorkFlowInput!): ChaosWorkFlowResponse! + @authorized - createUser(user: CreateUserInput!): User! @authorized + createUser(user: CreateUserInput!): User! @authorized - updateUser(user: UpdateUserInput!): String! @authorized + updateUser(user: UpdateUserInput!): String! @authorized - deleteChaosWorkflow(workflowid: String!): Boolean! @authorized + deleteChaosWorkflow(workflowid: String!): Boolean! @authorized - sendInvitation(member: MemberInput!): Member @authorized + sendInvitation(member: MemberInput!): Member @authorized - acceptInvitation(member: MemberInput!): String! @authorized + acceptInvitation(member: MemberInput!): String! @authorized - declineInvitation(member: MemberInput!): String! @authorized + declineInvitation(member: MemberInput!): String! @authorized - removeInvitation(member: MemberInput!): String! @authorized + removeInvitation(member: MemberInput!): String! @authorized - #It is used to confirm the subscriber registration - clusterConfirm(identity: ClusterIdentity!): ClusterConfirmResponse! + #It is used to confirm the subscriber registration + clusterConfirm(identity: ClusterIdentity!): ClusterConfirmResponse! - #It is used to send cluster related events from the subscriber - newClusterEvent(clusterEvent: ClusterEventInput!): String! + #It is used to send cluster related events from the subscriber + newClusterEvent(clusterEvent: ClusterEventInput!): String! - chaosWorkflowRun(workflowData: WorkflowRunInput!): String! + chaosWorkflowRun(workflowData: WorkflowRunInput!): String! - podLog(log: PodLog!): String! + podLog(log: PodLog!): String! - addMyHub(myhubInput: CreateMyHub!, projectID: String!): MyHub! @authorized + addMyHub(myhubInput: CreateMyHub!, projectID: String!): MyHub! @authorized - syncHub(projectID: String!, HubName: String!): [MyHubStatus!]! @authorized + saveMyHub(myhubInput: CreateMyHub!, projectID: String!): MyHub! @authorized - updateChaosWorkflow(input: ChaosWorkFlowInput): ChaosWorkFlowResponse! - @authorized + syncHub(id: ID!): [MyHubStatus!]! @authorized - deleteClusterReg(cluster_id: String!): String! @authorized + updateChaosWorkflow(input: ChaosWorkFlowInput): ChaosWorkFlowResponse! + @authorized + + deleteClusterReg(cluster_id: String!): String! @authorized + + generaterSSHKey: SSHKey! @authorized + + updateMyHub(myhubInput: UpdateMyHub!, projectID: String!): MyHub! @authorized + + deleteMyHub(hub_id: String!): Boolean! @authorized } type Subscription { - #It is used to listen cluster events from the graphql server - clusterEventListener(project_id: String!): ClusterEvent! @authorized + #It is used to listen cluster events from the graphql server + clusterEventListener(project_id: String!): ClusterEvent! @authorized - workflowEventListener(project_id: String!): WorkflowRun! @authorized + workflowEventListener(project_id: String!): WorkflowRun! @authorized - getPodLog(podDetails: PodLogRequest!): PodLogResponse! @authorized + getPodLog(podDetails: PodLogRequest!): PodLogResponse! @authorized - #It is used to listen cluster operation request from the graphql server - clusterConnect(clusterInfo: ClusterIdentity!): ClusterAction! + #It is used to listen cluster operation request from the graphql server + clusterConnect(clusterInfo: ClusterIdentity!): ClusterAction! } `, BuiltIn: false}, &ast.Source{Name: "graph/usermanagement.graphqls", Input: `type User { @@ -2616,6 +2901,20 @@ func (ec *executionContext) field_Mutation_deleteClusterReg_args(ctx context.Con return args, nil } +func (ec *executionContext) field_Mutation_deleteMyHub_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["hub_id"]; ok { + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["hub_id"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_newClusterEvent_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -2658,6 +2957,28 @@ func (ec *executionContext) field_Mutation_removeInvitation_args(ctx context.Con return args, nil } +func (ec *executionContext) field_Mutation_saveMyHub_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.CreateMyHub + if tmp, ok := rawArgs["myhubInput"]; ok { + arg0, err = ec.unmarshalNCreateMyHub2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐCreateMyHub(ctx, tmp) + if err != nil { + return nil, err + } + } + args["myhubInput"] = arg0 + var arg1 string + if tmp, ok := rawArgs["projectID"]; ok { + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["projectID"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_sendInvitation_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -2676,21 +2997,13 @@ func (ec *executionContext) field_Mutation_syncHub_args(ctx context.Context, raw var err error args := map[string]interface{}{} var arg0 string - if tmp, ok := rawArgs["projectID"]; ok { - arg0, err = ec.unmarshalNString2string(ctx, tmp) + if tmp, ok := rawArgs["id"]; ok { + arg0, err = ec.unmarshalNID2string(ctx, tmp) if err != nil { return nil, err } } - args["projectID"] = arg0 - var arg1 string - if tmp, ok := rawArgs["HubName"]; ok { - arg1, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } - } - args["HubName"] = arg1 + args["id"] = arg0 return args, nil } @@ -2708,6 +3021,28 @@ func (ec *executionContext) field_Mutation_updateChaosWorkflow_args(ctx context. return args, nil } +func (ec *executionContext) field_Mutation_updateMyHub_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.UpdateMyHub + if tmp, ok := rawArgs["myhubInput"]; ok { + arg0, err = ec.unmarshalNUpdateMyHub2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐUpdateMyHub(ctx, tmp) + if err != nil { + return nil, err + } + } + args["myhubInput"] = arg0 + var arg1 string + if tmp, ok := rawArgs["projectID"]; ok { + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["projectID"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_updateUser_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -6093,6 +6428,67 @@ func (ec *executionContext) _Mutation_addMyHub(ctx context.Context, field graphq return ec.marshalNMyHub2ᚖgithubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐMyHub(ctx, field.Selections, res) } +func (ec *executionContext) _Mutation_saveMyHub(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Mutation", + Field: field, + Args: nil, + IsMethod: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Mutation_saveMyHub_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().SaveMyHub(rctx, args["myhubInput"].(model.CreateMyHub), args["projectID"].(string)) + } + directive1 := func(ctx context.Context) (interface{}, error) { + if ec.directives.Authorized == nil { + return nil, errors.New("directive authorized is not implemented") + } + return ec.directives.Authorized(ctx, nil, directive0) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, err + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(*model.MyHub); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be *github.com/litmuschaos/litmus/litmus-portal/graphql-server/graph/model.MyHub`, tmp) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.MyHub) + fc.Result = res + return ec.marshalNMyHub2ᚖgithubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐMyHub(ctx, field.Selections, res) +} + func (ec *executionContext) _Mutation_syncHub(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -6118,7 +6514,7 @@ func (ec *executionContext) _Mutation_syncHub(ctx context.Context, field graphql resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { directive0 := func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().SyncHub(rctx, args["projectID"].(string), args["HubName"].(string)) + return ec.resolvers.Mutation().SyncHub(rctx, args["id"].(string)) } directive1 := func(ctx context.Context) (interface{}, error) { if ec.directives.Authorized == nil { @@ -6276,6 +6672,182 @@ func (ec *executionContext) _Mutation_deleteClusterReg(ctx context.Context, fiel return ec.marshalNString2string(ctx, field.Selections, res) } +func (ec *executionContext) _Mutation_generaterSSHKey(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Mutation", + Field: field, + Args: nil, + IsMethod: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().GeneraterSSHKey(rctx) + } + directive1 := func(ctx context.Context) (interface{}, error) { + if ec.directives.Authorized == nil { + return nil, errors.New("directive authorized is not implemented") + } + return ec.directives.Authorized(ctx, nil, directive0) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, err + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(*model.SSHKey); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be *github.com/litmuschaos/litmus/litmus-portal/graphql-server/graph/model.SSHKey`, tmp) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.SSHKey) + fc.Result = res + return ec.marshalNSSHKey2ᚖgithubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐSSHKey(ctx, field.Selections, res) +} + +func (ec *executionContext) _Mutation_updateMyHub(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Mutation", + Field: field, + Args: nil, + IsMethod: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Mutation_updateMyHub_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().UpdateMyHub(rctx, args["myhubInput"].(model.UpdateMyHub), args["projectID"].(string)) + } + directive1 := func(ctx context.Context) (interface{}, error) { + if ec.directives.Authorized == nil { + return nil, errors.New("directive authorized is not implemented") + } + return ec.directives.Authorized(ctx, nil, directive0) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, err + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(*model.MyHub); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be *github.com/litmuschaos/litmus/litmus-portal/graphql-server/graph/model.MyHub`, tmp) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.MyHub) + fc.Result = res + return ec.marshalNMyHub2ᚖgithubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐMyHub(ctx, field.Selections, res) +} + +func (ec *executionContext) _Mutation_deleteMyHub(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Mutation", + Field: field, + Args: nil, + IsMethod: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Mutation_deleteMyHub_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + directive0 := func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().DeleteMyHub(rctx, args["hub_id"].(string)) + } + directive1 := func(ctx context.Context) (interface{}, error) { + if ec.directives.Authorized == nil { + return nil, errors.New("directive authorized is not implemented") + } + return ec.directives.Authorized(ctx, nil, directive0) + } + + tmp, err := directive1(rctx) + if err != nil { + return nil, err + } + if tmp == nil { + return nil, nil + } + if data, ok := tmp.(bool); ok { + return data, nil + } + return nil, fmt.Errorf(`unexpected type %T from directive, should be bool`, tmp) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + func (ec *executionContext) _MyHub_id(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -6446,6 +7018,232 @@ func (ec *executionContext) _MyHub_HubName(ctx context.Context, field graphql.Co return ec.marshalNString2string(ctx, field.Selections, res) } +func (ec *executionContext) _MyHub_IsPrivate(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHub", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsPrivate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHub_AuthType(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHub", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.AuthType, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(model.AuthType) + fc.Result = res + return ec.marshalNAuthType2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐAuthType(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHub_Token(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHub", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Token, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHub_UserName(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHub", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.UserName, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHub_Password(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHub", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Password, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHub_SSHPrivateKey(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHub", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SSHPrivateKey, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHub_IsRemoved(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHub", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsRemoved, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + func (ec *executionContext) _MyHub_CreatedAt(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -6514,6 +7312,40 @@ func (ec *executionContext) _MyHub_UpdatedAt(ctx context.Context, field graphql. return ec.marshalNString2string(ctx, field.Selections, res) } +func (ec *executionContext) _MyHub_LastSyncedAt(ctx context.Context, field graphql.CollectedField, obj *model.MyHub) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHub", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.LastSyncedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + func (ec *executionContext) _MyHubStatus_id(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -6718,6 +7550,297 @@ func (ec *executionContext) _MyHubStatus_HubName(ctx context.Context, field grap return ec.marshalNString2string(ctx, field.Selections, res) } +func (ec *executionContext) _MyHubStatus_IsPrivate(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsPrivate, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHubStatus_AuthType(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.AuthType, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(model.AuthType) + fc.Result = res + return ec.marshalNAuthType2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐAuthType(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHubStatus_Token(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Token, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHubStatus_UserName(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.UserName, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHubStatus_Password(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Password, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHubStatus_IsRemoved(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsRemoved, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHubStatus_SSHPrivateKey(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SSHPrivateKey, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHubStatus_SSHPublicKey(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SSHPublicKey, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) _MyHubStatus_LastSyncedAt(ctx context.Context, field graphql.CollectedField, obj *model.MyHubStatus) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MyHubStatus", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.LastSyncedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + func (ec *executionContext) _PackageInformation_PackageName(ctx context.Context, field graphql.CollectedField, obj *model.PackageInformation) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -7904,6 +9027,74 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } +func (ec *executionContext) _SSHKey_publicKey(ctx context.Context, field graphql.CollectedField, obj *model.SSHKey) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "SSHKey", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PublicKey, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _SSHKey_privateKey(ctx context.Context, field graphql.CollectedField, obj *model.SSHKey) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "SSHKey", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PrivateKey, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + func (ec *executionContext) _ScheduledWorkflows_workflow_id(ctx context.Context, field graphql.CollectedField, obj *model.ScheduledWorkflows) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -11672,6 +12863,42 @@ func (ec *executionContext) unmarshalInputCloningInput(ctx context.Context, obj if err != nil { return it, err } + case "IsPrivate": + var err error + it.IsPrivate, err = ec.unmarshalNBoolean2bool(ctx, v) + if err != nil { + return it, err + } + case "AuthType": + var err error + it.AuthType, err = ec.unmarshalNAuthType2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐAuthType(ctx, v) + if err != nil { + return it, err + } + case "Token": + var err error + it.Token, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "UserName": + var err error + it.UserName, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "Password": + var err error + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "SSHPrivateKey": + var err error + it.SSHPrivateKey, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } } } @@ -11858,6 +13085,48 @@ func (ec *executionContext) unmarshalInputCreateMyHub(ctx context.Context, obj i if err != nil { return it, err } + case "IsPrivate": + var err error + it.IsPrivate, err = ec.unmarshalNBoolean2bool(ctx, v) + if err != nil { + return it, err + } + case "AuthType": + var err error + it.AuthType, err = ec.unmarshalNAuthType2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐAuthType(ctx, v) + if err != nil { + return it, err + } + case "Token": + var err error + it.Token, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "UserName": + var err error + it.UserName, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "Password": + var err error + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "SSHPrivateKey": + var err error + it.SSHPrivateKey, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "SSHPublicKey": + var err error + it.SSHPublicKey, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } } } @@ -12086,6 +13355,84 @@ func (ec *executionContext) unmarshalInputPodLogRequest(ctx context.Context, obj return it, nil } +func (ec *executionContext) unmarshalInputUpdateMyHub(ctx context.Context, obj interface{}) (model.UpdateMyHub, error) { + var it model.UpdateMyHub + var asMap = obj.(map[string]interface{}) + + for k, v := range asMap { + switch k { + case "id": + var err error + it.ID, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "HubName": + var err error + it.HubName, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "RepoURL": + var err error + it.RepoURL, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "RepoBranch": + var err error + it.RepoBranch, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "IsPrivate": + var err error + it.IsPrivate, err = ec.unmarshalNBoolean2bool(ctx, v) + if err != nil { + return it, err + } + case "AuthType": + var err error + it.AuthType, err = ec.unmarshalNAuthType2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐAuthType(ctx, v) + if err != nil { + return it, err + } + case "Token": + var err error + it.Token, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "UserName": + var err error + it.UserName, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "Password": + var err error + it.Password, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "SSHPrivateKey": + var err error + it.SSHPrivateKey, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "SSHPublicKey": + var err error + it.SSHPublicKey, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputUpdateUserInput(ctx context.Context, obj interface{}) (model.UpdateUserInput, error) { var it model.UpdateUserInput var asMap = obj.(map[string]interface{}) @@ -12907,6 +14254,11 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { invalids++ } + case "saveMyHub": + out.Values[i] = ec._Mutation_saveMyHub(ctx, field) + if out.Values[i] == graphql.Null { + invalids++ + } case "syncHub": out.Values[i] = ec._Mutation_syncHub(ctx, field) if out.Values[i] == graphql.Null { @@ -12922,6 +14274,21 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { invalids++ } + case "generaterSSHKey": + out.Values[i] = ec._Mutation_generaterSSHKey(ctx, field) + if out.Values[i] == graphql.Null { + invalids++ + } + case "updateMyHub": + out.Values[i] = ec._Mutation_updateMyHub(ctx, field) + if out.Values[i] == graphql.Null { + invalids++ + } + case "deleteMyHub": + out.Values[i] = ec._Mutation_deleteMyHub(ctx, field) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -12969,6 +14336,29 @@ func (ec *executionContext) _MyHub(ctx context.Context, sel ast.SelectionSet, ob if out.Values[i] == graphql.Null { invalids++ } + case "IsPrivate": + out.Values[i] = ec._MyHub_IsPrivate(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "AuthType": + out.Values[i] = ec._MyHub_AuthType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "Token": + out.Values[i] = ec._MyHub_Token(ctx, field, obj) + case "UserName": + out.Values[i] = ec._MyHub_UserName(ctx, field, obj) + case "Password": + out.Values[i] = ec._MyHub_Password(ctx, field, obj) + case "SSHPrivateKey": + out.Values[i] = ec._MyHub_SSHPrivateKey(ctx, field, obj) + case "IsRemoved": + out.Values[i] = ec._MyHub_IsRemoved(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } case "CreatedAt": out.Values[i] = ec._MyHub_CreatedAt(ctx, field, obj) if out.Values[i] == graphql.Null { @@ -12979,6 +14369,11 @@ func (ec *executionContext) _MyHub(ctx context.Context, sel ast.SelectionSet, ob if out.Values[i] == graphql.Null { invalids++ } + case "LastSyncedAt": + out.Values[i] = ec._MyHub_LastSyncedAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -13031,6 +14426,36 @@ func (ec *executionContext) _MyHubStatus(ctx context.Context, sel ast.SelectionS if out.Values[i] == graphql.Null { invalids++ } + case "IsPrivate": + out.Values[i] = ec._MyHubStatus_IsPrivate(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "AuthType": + out.Values[i] = ec._MyHubStatus_AuthType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "Token": + out.Values[i] = ec._MyHubStatus_Token(ctx, field, obj) + case "UserName": + out.Values[i] = ec._MyHubStatus_UserName(ctx, field, obj) + case "Password": + out.Values[i] = ec._MyHubStatus_Password(ctx, field, obj) + case "IsRemoved": + out.Values[i] = ec._MyHubStatus_IsRemoved(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "SSHPrivateKey": + out.Values[i] = ec._MyHubStatus_SSHPrivateKey(ctx, field, obj) + case "SSHPublicKey": + out.Values[i] = ec._MyHubStatus_SSHPublicKey(ctx, field, obj) + case "LastSyncedAt": + out.Values[i] = ec._MyHubStatus_LastSyncedAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -13381,6 +14806,38 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr return out } +var sSHKeyImplementors = []string{"SSHKey"} + +func (ec *executionContext) _SSHKey(ctx context.Context, sel ast.SelectionSet, obj *model.SSHKey) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, sSHKeyImplementors) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("SSHKey") + case "publicKey": + out.Values[i] = ec._SSHKey_publicKey(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "privateKey": + out.Values[i] = ec._SSHKey_privateKey(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + var scheduledWorkflowsImplementors = []string{"ScheduledWorkflows"} func (ec *executionContext) _ScheduledWorkflows(ctx context.Context, sel ast.SelectionSet, obj *model.ScheduledWorkflows) graphql.Marshaler { @@ -14179,6 +15636,15 @@ func (ec *executionContext) marshalNAnnotation2ᚖgithubᚗcomᚋlitmuschaosᚋl return ec._Annotation(ctx, sel, v) } +func (ec *executionContext) unmarshalNAuthType2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐAuthType(ctx context.Context, v interface{}) (model.AuthType, error) { + var res model.AuthType + return res, res.UnmarshalGQL(v) +} + +func (ec *executionContext) marshalNAuthType2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐAuthType(ctx context.Context, sel ast.SelectionSet, v model.AuthType) graphql.Marshaler { + return v +} + func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { return graphql.UnmarshalBoolean(v) } @@ -14835,6 +16301,20 @@ func (ec *executionContext) marshalNProject2ᚖgithubᚗcomᚋlitmuschaosᚋlitm return ec._Project(ctx, sel, v) } +func (ec *executionContext) marshalNSSHKey2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐSSHKey(ctx context.Context, sel ast.SelectionSet, v model.SSHKey) graphql.Marshaler { + return ec._SSHKey(ctx, sel, &v) +} + +func (ec *executionContext) marshalNSSHKey2ᚖgithubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐSSHKey(ctx context.Context, sel ast.SelectionSet, v *model.SSHKey) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._SSHKey(ctx, sel, v) +} + func (ec *executionContext) marshalNScheduledWorkflows2ᚕᚖgithubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐScheduledWorkflows(ctx context.Context, sel ast.SelectionSet, v []*model.ScheduledWorkflows) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup @@ -14929,6 +16409,10 @@ func (ec *executionContext) marshalNString2ᚕstringᚄ(ctx context.Context, sel return ret } +func (ec *executionContext) unmarshalNUpdateMyHub2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐUpdateMyHub(ctx context.Context, v interface{}) (model.UpdateMyHub, error) { + return ec.unmarshalInputUpdateMyHub(ctx, v) +} + func (ec *executionContext) unmarshalNUpdateUserInput2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐUpdateUserInput(ctx context.Context, v interface{}) (model.UpdateUserInput, error) { return ec.unmarshalInputUpdateUserInput(ctx, v) } diff --git a/litmus-portal/graphql-server/graph/model/models_gen.go b/litmus-portal/graphql-server/graph/model/models_gen.go index 4bae2df62..f1c46a83b 100644 --- a/litmus-portal/graphql-server/graph/model/models_gen.go +++ b/litmus-portal/graphql-server/graph/model/models_gen.go @@ -58,10 +58,16 @@ type Charts struct { } type CloningInput struct { - HubName string `json:"HubName"` - ProjectID string `json:"ProjectID"` - RepoBranch string `json:"RepoBranch"` - RepoURL string `json:"RepoURL"` + HubName string `json:"HubName"` + ProjectID string `json:"ProjectID"` + RepoBranch string `json:"RepoBranch"` + RepoURL string `json:"RepoURL"` + IsPrivate bool `json:"IsPrivate"` + AuthType AuthType `json:"AuthType"` + Token *string `json:"Token"` + UserName *string `json:"UserName"` + Password *string `json:"Password"` + SSHPrivateKey *string `json:"SSHPrivateKey"` } type Cluster struct { @@ -137,9 +143,16 @@ type ClusterInput struct { } type CreateMyHub struct { - HubName string `json:"HubName"` - RepoURL string `json:"RepoURL"` - RepoBranch string `json:"RepoBranch"` + HubName string `json:"HubName"` + RepoURL string `json:"RepoURL"` + RepoBranch string `json:"RepoBranch"` + IsPrivate bool `json:"IsPrivate"` + AuthType AuthType `json:"AuthType"` + Token *string `json:"Token"` + UserName *string `json:"UserName"` + Password *string `json:"Password"` + SSHPrivateKey *string `json:"SSHPrivateKey"` + SSHPublicKey *string `json:"SSHPublicKey"` } type CreateUserInput struct { @@ -197,22 +210,39 @@ type Metadata struct { } type MyHub struct { - ID string `json:"id"` - RepoURL string `json:"RepoURL"` - RepoBranch string `json:"RepoBranch"` - ProjectID string `json:"ProjectID"` - HubName string `json:"HubName"` - CreatedAt string `json:"CreatedAt"` - UpdatedAt string `json:"UpdatedAt"` + ID string `json:"id"` + RepoURL string `json:"RepoURL"` + RepoBranch string `json:"RepoBranch"` + ProjectID string `json:"ProjectID"` + HubName string `json:"HubName"` + IsPrivate bool `json:"IsPrivate"` + AuthType AuthType `json:"AuthType"` + Token *string `json:"Token"` + UserName *string `json:"UserName"` + Password *string `json:"Password"` + SSHPrivateKey *string `json:"SSHPrivateKey"` + IsRemoved bool `json:"IsRemoved"` + CreatedAt string `json:"CreatedAt"` + UpdatedAt string `json:"UpdatedAt"` + LastSyncedAt string `json:"LastSyncedAt"` } type MyHubStatus struct { - ID string `json:"id"` - RepoURL string `json:"RepoURL"` - RepoBranch string `json:"RepoBranch"` - IsAvailable bool `json:"IsAvailable"` - TotalExp string `json:"TotalExp"` - HubName string `json:"HubName"` + ID string `json:"id"` + RepoURL string `json:"RepoURL"` + RepoBranch string `json:"RepoBranch"` + IsAvailable bool `json:"IsAvailable"` + TotalExp string `json:"TotalExp"` + HubName string `json:"HubName"` + IsPrivate bool `json:"IsPrivate"` + AuthType AuthType `json:"AuthType"` + Token *string `json:"Token"` + UserName *string `json:"UserName"` + Password *string `json:"Password"` + IsRemoved bool `json:"IsRemoved"` + SSHPrivateKey *string `json:"SSHPrivateKey"` + SSHPublicKey *string `json:"SSHPublicKey"` + LastSyncedAt string `json:"LastSyncedAt"` } type PackageInformation struct { @@ -261,6 +291,11 @@ type Provider struct { Name string `json:"Name"` } +type SSHKey struct { + PublicKey string `json:"publicKey"` + PrivateKey string `json:"privateKey"` +} + type ScheduledWorkflows struct { WorkflowID string `json:"workflow_id"` WorkflowManifest string `json:"workflow_manifest"` @@ -293,6 +328,20 @@ type Spec struct { ChaosType *string `json:"ChaosType"` } +type UpdateMyHub struct { + ID string `json:"id"` + HubName string `json:"HubName"` + RepoURL string `json:"RepoURL"` + RepoBranch string `json:"RepoBranch"` + IsPrivate bool `json:"IsPrivate"` + AuthType AuthType `json:"AuthType"` + Token *string `json:"Token"` + UserName *string `json:"UserName"` + Password *string `json:"Password"` + SSHPrivateKey *string `json:"SSHPrivateKey"` + SSHPublicKey *string `json:"SSHPublicKey"` +} + type UpdateUserInput struct { ID string `json:"id"` Name *string `json:"name"` @@ -376,6 +425,49 @@ type Weightages struct { Weightage int `json:"weightage"` } +type AuthType string + +const ( + AuthTypeBasic AuthType = "basic" + AuthTypeToken AuthType = "token" + AuthTypeSSH AuthType = "ssh" +) + +var AllAuthType = []AuthType{ + AuthTypeBasic, + AuthTypeToken, + AuthTypeSSH, +} + +func (e AuthType) IsValid() bool { + switch e { + case AuthTypeBasic, AuthTypeToken, AuthTypeSSH: + return true + } + return false +} + +func (e AuthType) String() string { + return string(e) +} + +func (e *AuthType) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = AuthType(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid AuthType", str) + } + return nil +} + +func (e AuthType) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} + type MemberRole string const ( diff --git a/litmus-portal/graphql-server/graph/myhub.graphqls b/litmus-portal/graphql-server/graph/myhub.graphqls index 9c659a431..7651ab2f0 100644 --- a/litmus-portal/graphql-server/graph/myhub.graphqls +++ b/litmus-portal/graphql-server/graph/myhub.graphqls @@ -1,107 +1,173 @@ +enum AuthType { + basic + token + ssh +} + type MyHub { - id: ID! - RepoURL: String! - RepoBranch: String! - ProjectID: String! - HubName: String! - CreatedAt: String! - UpdatedAt: String! + id: ID! + RepoURL: String! + RepoBranch: String! + ProjectID: String! + HubName: String! + IsPrivate: Boolean! + # Auth Types- + # token: Token based authentication + # basic: Username/Password based authentication + # ssh: SSH based authentication + AuthType: AuthType! + Token: String + UserName: String + Password: String + SSHPrivateKey: String + IsRemoved: Boolean! + CreatedAt: String! + UpdatedAt: String! + LastSyncedAt: String! } type Charts { - Charts: [Chart!]! + Charts: [Chart!]! } type Chart { - ApiVersion: String! - Kind: String! - Metadata: Metadata! - Spec: Spec! - PackageInfo: PackageInformation! - Experiments: [Chart!]! + ApiVersion: String! + Kind: String! + Metadata: Metadata! + Spec: Spec! + PackageInfo: PackageInformation! + Experiments: [Chart!]! } type Maintainer { - Name: String! - Email: String! + Name: String! + Email: String! } type Link { - Name: String! - Url: String! + Name: String! + Url: String! } type Metadata { - Name: String! - Version: String! - Annotations: Annotation! + Name: String! + Version: String! + Annotations: Annotation! } type Annotation { - Categories: String! - Vendor: String! - CreatedAt: String! - Repository: String! - Support: String! - ChartDescription: String! + Categories: String! + Vendor: String! + CreatedAt: String! + Repository: String! + Support: String! + ChartDescription: String! } type Spec { - DisplayName: String! - CategoryDescription: String! - Keywords: [String!]! - Maturity: String! - Maintainers: [Maintainer!]! - MinKubeVersion: String! - Provider: String! - Links: [Link!]! - Experiments: [String!]! - ChaosExpCRDLink: String! - Platforms: [String!]! - ChaosType: String + DisplayName: String! + CategoryDescription: String! + Keywords: [String!]! + Maturity: String! + Maintainers: [Maintainer!]! + MinKubeVersion: String! + Provider: String! + Links: [Link!]! + Experiments: [String!]! + ChaosExpCRDLink: String! + Platforms: [String!]! + ChaosType: String } type Provider { - Name: String! + Name: String! } type PackageInformation { - PackageName: String! - Experiments: [Experiments!]! + PackageName: String! + Experiments: [Experiments!]! } type Experiments { - Name: String! - CSV: String! - Desc: String! + Name: String! + CSV: String! + Desc: String! } type MyHubStatus { - id: ID! - RepoURL: String! - RepoBranch: String! - IsAvailable: Boolean! - TotalExp: String! - HubName: String! + id: ID! + RepoURL: String! + RepoBranch: String! + IsAvailable: Boolean! + TotalExp: String! + HubName: String! + IsPrivate: Boolean! + # Auth Types- + # token: Token based authentication + # basic: Username/Password based authentication + # ssh: SSH based authentication + AuthType: AuthType! + Token: String + UserName: String + Password: String + IsRemoved: Boolean! + SSHPrivateKey: String + SSHPublicKey: String + LastSyncedAt: String! } input CreateMyHub { - HubName: String! - RepoURL: String! - RepoBranch: String! + HubName: String! + RepoURL: String! + RepoBranch: String! + IsPrivate: Boolean! + # Auth Types- + # token: Token based authentication + # basic: Username/Password based authentication + # ssh: SSH based authentication + AuthType: AuthType! + Token: String + UserName: String + Password: String + SSHPrivateKey: String + SSHPublicKey: String } input ExperimentInput { - ProjectID: String! - ChartName: String! - ExperimentName: String! - HubName: String! - FileType: String + ProjectID: String! + ChartName: String! + ExperimentName: String! + HubName: String! + FileType: String } input CloningInput { - HubName: String! - ProjectID: String! - RepoBranch: String! - RepoURL: String! + HubName: String! + ProjectID: String! + RepoBranch: String! + RepoURL: String! + IsPrivate: Boolean! + # Auth Types- + # token: Token based authentication + # basic: Username/Password based authentication + # ssh: SSH based authentication + AuthType: AuthType! + Token: String + UserName: String + Password: String + SSHPrivateKey: String +} + +input UpdateMyHub { + id: String! + HubName: String! + RepoURL: String! + RepoBranch: String! + IsPrivate: Boolean! + AuthType: AuthType! + Token: String + UserName: String + Password: String + SSHPrivateKey: String + SSHPublicKey: String } diff --git a/litmus-portal/graphql-server/graph/schema.graphqls b/litmus-portal/graphql-server/graph/schema.graphqls index b893b069e..24d52e80d 100644 --- a/litmus-portal/graphql-server/graph/schema.graphqls +++ b/litmus-portal/graphql-server/graph/schema.graphqls @@ -5,285 +5,298 @@ directive @authorized on FIELD_DEFINITION type Cluster { - cluster_id: ID! - project_id: ID! - cluster_name: String! - description: String - platform_name: String! - access_key: String! - is_registered: Boolean! - is_cluster_confirmed: Boolean! - is_active: Boolean! - updated_at: String! - created_at: String! - cluster_type: String! - no_of_schedules: Int - no_of_workflows: Int - token: String! - agent_namespace: String - serviceaccount: String - agent_scope: String! - agent_ns_exists: Boolean - agent_sa_exists: Boolean + cluster_id: ID! + project_id: ID! + cluster_name: String! + description: String + platform_name: String! + access_key: String! + is_registered: Boolean! + is_cluster_confirmed: Boolean! + is_active: Boolean! + updated_at: String! + created_at: String! + cluster_type: String! + no_of_schedules: Int + no_of_workflows: Int + token: String! + agent_namespace: String + serviceaccount: String + agent_scope: String! + agent_ns_exists: Boolean + agent_sa_exists: Boolean } input ClusterInput { - cluster_name: String! - description: String - platform_name: String! - project_id: ID! - cluster_type: String! - agent_namespace: String - serviceaccount: String - agent_scope: String! - agent_ns_exists: Boolean - agent_sa_exists: Boolean + cluster_name: String! + description: String + platform_name: String! + project_id: ID! + cluster_type: String! + agent_namespace: String + serviceaccount: String + agent_scope: String! + agent_ns_exists: Boolean + agent_sa_exists: Boolean } type ClusterEvent { - event_id: ID! - event_type: String! - event_name: String! - description: String! - cluster: Cluster! + event_id: ID! + event_type: String! + event_name: String! + description: String! + cluster: Cluster! } type ActionPayload { - request_type: String! - k8s_manifest: String! - namespace: String! - external_data: String + request_type: String! + k8s_manifest: String! + namespace: String! + external_data: String } type ClusterAction { - project_id: ID! - action: ActionPayload! + project_id: ID! + action: ActionPayload! } input ClusterActionInput { - cluster_id: ID! - action: String! + cluster_id: ID! + action: String! } input ClusterEventInput { - event_name: String! - description: String! - cluster_id: String! - access_key: String! + event_name: String! + description: String! + cluster_id: String! + access_key: String! } input ClusterIdentity { - cluster_id: String! - access_key: String! + cluster_id: String! + access_key: String! } type ClusterConfirmResponse { - isClusterConfirmed: Boolean! - newClusterKey: String - cluster_id: String + isClusterConfirmed: Boolean! + newClusterKey: String + cluster_id: String } input WeightagesInput { - experiment_name: String! - weightage: Int! + experiment_name: String! + weightage: Int! } type weightages { - experiment_name: String! - weightage: Int! + experiment_name: String! + weightage: Int! } input ChaosWorkFlowInput { - workflow_id: String - workflow_manifest: String! - cronSyntax: String! - workflow_name: String! - workflow_description: String! - weightages: [WeightagesInput!]! - isCustomWorkflow: Boolean! - project_id: ID! - cluster_id: ID! + workflow_id: String + workflow_manifest: String! + cronSyntax: String! + workflow_name: String! + workflow_description: String! + weightages: [WeightagesInput!]! + isCustomWorkflow: Boolean! + project_id: ID! + cluster_id: ID! } type ChaosWorkFlowResponse { - workflow_id: String! - cronSyntax: String! - workflow_name: String! - workflow_description: String! - isCustomWorkflow: Boolean! + workflow_id: String! + cronSyntax: String! + workflow_name: String! + workflow_description: String! + isCustomWorkflow: Boolean! } type WorkflowRun { - workflow_run_id: ID! - workflow_id: ID! - cluster_name: String! - last_updated: String! - project_id: ID! - cluster_id: ID! - workflow_name: String! - cluster_type: String - execution_data: String! + workflow_run_id: ID! + workflow_id: ID! + cluster_name: String! + last_updated: String! + project_id: ID! + cluster_id: ID! + workflow_name: String! + cluster_type: String + execution_data: String! } input WorkflowRunInput { - workflow_id: ID! - workflow_run_id: ID! - workflow_name: String! - execution_data: String! - cluster_id: ClusterIdentity! - completed: Boolean! + workflow_id: ID! + workflow_run_id: ID! + workflow_name: String! + execution_data: String! + cluster_id: ClusterIdentity! + completed: Boolean! } type PodLogResponse { - workflow_run_id: ID! - pod_name: String! - pod_type: String! - log: String! + workflow_run_id: ID! + pod_name: String! + pod_type: String! + log: String! } input PodLog { - cluster_id: ClusterIdentity! - request_id: ID! - workflow_run_id: ID! - pod_name: String! - pod_type: String! - log: String! + cluster_id: ClusterIdentity! + request_id: ID! + workflow_run_id: ID! + pod_name: String! + pod_type: String! + log: String! } input PodLogRequest { - cluster_id: ID! - workflow_run_id: ID! - pod_name: String! - pod_namespace: String! - pod_type: String! - exp_pod: String - runner_pod: String - chaos_namespace: String + cluster_id: ID! + workflow_run_id: ID! + pod_name: String! + pod_namespace: String! + pod_type: String! + exp_pod: String + runner_pod: String + chaos_namespace: String } type ScheduledWorkflows { - workflow_id: String! - workflow_manifest: String! - cronSyntax: String! - cluster_name: String! - workflow_name: String! - workflow_description: String! - weightages: [weightages!]! - isCustomWorkflow: Boolean! - updated_at: String! - created_at: String! - project_id: ID! - cluster_id: ID! - cluster_type: String! - isRemoved: Boolean! + workflow_id: String! + workflow_manifest: String! + cronSyntax: String! + cluster_name: String! + workflow_name: String! + workflow_description: String! + weightages: [weightages!]! + isCustomWorkflow: Boolean! + updated_at: String! + created_at: String! + project_id: ID! + cluster_id: ID! + cluster_type: String! + isRemoved: Boolean! } type Workflow { - workflow_id: String! - workflow_manifest: String! - cronSyntax: String! - cluster_name: String! - workflow_name: String! - workflow_description: String! - weightages: [weightages!]! - isCustomWorkflow: Boolean! - updated_at: String! - created_at: String! - project_id: ID! - cluster_id: ID! - cluster_type: String! - isRemoved: Boolean! - workflow_runs: [WorkflowRuns] + workflow_id: String! + workflow_manifest: String! + cronSyntax: String! + cluster_name: String! + workflow_name: String! + workflow_description: String! + weightages: [weightages!]! + isCustomWorkflow: Boolean! + updated_at: String! + created_at: String! + project_id: ID! + cluster_id: ID! + cluster_type: String! + isRemoved: Boolean! + workflow_runs: [WorkflowRuns] } type WorkflowRuns { - execution_data: String! - workflow_run_id: ID! - last_updated: String! + execution_data: String! + workflow_run_id: ID! + last_updated: String! } type clusterRegResponse { - token: String! - cluster_id: String! - cluster_name: String! + token: String! + cluster_id: String! + cluster_name: String! +} + +type SSHKey { + publicKey: String! + privateKey: String! } type Query { - # [Deprecated soon] - getWorkFlowRuns(project_id: String!): [WorkflowRun!]! @authorized + # [Deprecated soon] + getWorkFlowRuns(project_id: String!): [WorkflowRun!]! @authorized - getCluster(project_id: String!, cluster_type: String): [Cluster!]! @authorized + getCluster(project_id: String!, cluster_type: String): [Cluster!]! @authorized - getUser(username: String!): User! @authorized + getUser(username: String!): User! @authorized - getProject(projectID: String!): Project! @authorized + getProject(projectID: String!): Project! @authorized - users: [User!]! @authorized + users: [User!]! @authorized - # [Deprecated soon] - getScheduledWorkflows(project_id: String!): [ScheduledWorkflows]! @authorized + # [Deprecated soon] + getScheduledWorkflows(project_id: String!): [ScheduledWorkflows]! @authorized - ListWorkflow(project_id: String!, workflow_ids: [ID]): [Workflow]! @authorized + ListWorkflow(project_id: String!, workflow_ids: [ID]): [Workflow]! @authorized - getCharts(HubName: String!, projectID: String!): [Chart!]! @authorized + getCharts(HubName: String!, projectID: String!): [Chart!]! @authorized - getHubExperiment(experimentInput: ExperimentInput!): Chart! @authorized + getHubExperiment(experimentInput: ExperimentInput!): Chart! @authorized - getHubStatus(projectID: String!): [MyHubStatus]! @authorized + getHubStatus(projectID: String!): [MyHubStatus]! @authorized - getYAMLData(experimentInput: ExperimentInput!): String! + getYAMLData(experimentInput: ExperimentInput!): String! } type Mutation { - #It is used to create external cluster. - userClusterReg(clusterInput: ClusterInput!): clusterRegResponse! @authorized + #It is used to create external cluster. + userClusterReg(clusterInput: ClusterInput!): clusterRegResponse! @authorized - #It is used to create chaosworkflow - createChaosWorkFlow(input: ChaosWorkFlowInput!): ChaosWorkFlowResponse! - @authorized + #It is used to create chaosworkflow + createChaosWorkFlow(input: ChaosWorkFlowInput!): ChaosWorkFlowResponse! + @authorized - createUser(user: CreateUserInput!): User! @authorized + createUser(user: CreateUserInput!): User! @authorized - updateUser(user: UpdateUserInput!): String! @authorized + updateUser(user: UpdateUserInput!): String! @authorized - deleteChaosWorkflow(workflowid: String!): Boolean! @authorized + deleteChaosWorkflow(workflowid: String!): Boolean! @authorized - sendInvitation(member: MemberInput!): Member @authorized + sendInvitation(member: MemberInput!): Member @authorized - acceptInvitation(member: MemberInput!): String! @authorized + acceptInvitation(member: MemberInput!): String! @authorized - declineInvitation(member: MemberInput!): String! @authorized + declineInvitation(member: MemberInput!): String! @authorized - removeInvitation(member: MemberInput!): String! @authorized + removeInvitation(member: MemberInput!): String! @authorized - #It is used to confirm the subscriber registration - clusterConfirm(identity: ClusterIdentity!): ClusterConfirmResponse! + #It is used to confirm the subscriber registration + clusterConfirm(identity: ClusterIdentity!): ClusterConfirmResponse! - #It is used to send cluster related events from the subscriber - newClusterEvent(clusterEvent: ClusterEventInput!): String! + #It is used to send cluster related events from the subscriber + newClusterEvent(clusterEvent: ClusterEventInput!): String! - chaosWorkflowRun(workflowData: WorkflowRunInput!): String! + chaosWorkflowRun(workflowData: WorkflowRunInput!): String! - podLog(log: PodLog!): String! + podLog(log: PodLog!): String! - addMyHub(myhubInput: CreateMyHub!, projectID: String!): MyHub! @authorized + addMyHub(myhubInput: CreateMyHub!, projectID: String!): MyHub! @authorized - syncHub(projectID: String!, HubName: String!): [MyHubStatus!]! @authorized + saveMyHub(myhubInput: CreateMyHub!, projectID: String!): MyHub! @authorized - updateChaosWorkflow(input: ChaosWorkFlowInput): ChaosWorkFlowResponse! - @authorized + syncHub(id: ID!): [MyHubStatus!]! @authorized - deleteClusterReg(cluster_id: String!): String! @authorized + updateChaosWorkflow(input: ChaosWorkFlowInput): ChaosWorkFlowResponse! + @authorized + + deleteClusterReg(cluster_id: String!): String! @authorized + + generaterSSHKey: SSHKey! @authorized + + updateMyHub(myhubInput: UpdateMyHub!, projectID: String!): MyHub! @authorized + + deleteMyHub(hub_id: String!): Boolean! @authorized } type Subscription { - #It is used to listen cluster events from the graphql server - clusterEventListener(project_id: String!): ClusterEvent! @authorized + #It is used to listen cluster events from the graphql server + clusterEventListener(project_id: String!): ClusterEvent! @authorized - workflowEventListener(project_id: String!): WorkflowRun! @authorized + workflowEventListener(project_id: String!): WorkflowRun! @authorized - getPodLog(podDetails: PodLogRequest!): PodLogResponse! @authorized + getPodLog(podDetails: PodLogRequest!): PodLogResponse! @authorized - #It is used to listen cluster operation request from the graphql server - clusterConnect(clusterInfo: ClusterIdentity!): ClusterAction! + #It is used to listen cluster operation request from the graphql server + clusterConnect(clusterInfo: ClusterIdentity!): ClusterAction! } diff --git a/litmus-portal/graphql-server/graph/schema.resolvers.go b/litmus-portal/graphql-server/graph/schema.resolvers.go index 26a0fa955..799386341 100644 --- a/litmus-portal/graphql-server/graph/schema.resolvers.go +++ b/litmus-portal/graphql-server/graph/schema.resolvers.go @@ -6,6 +6,7 @@ package graph import ( "context" "errors" + "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/myhub/gitops" "log" "strconv" "time" @@ -81,8 +82,12 @@ func (r *mutationResolver) AddMyHub(ctx context.Context, myhubInput model.Create return myhub.AddMyHub(ctx, myhubInput, projectID) } -func (r *mutationResolver) SyncHub(ctx context.Context, projectID string, hubName string) ([]*model.MyHubStatus, error) { - return myhub.SyncHub(ctx, projectID, hubName) +func (r *mutationResolver) SaveMyHub(ctx context.Context, myhubInput model.CreateMyHub, projectID string) (*model.MyHub, error) { + return myhub.SaveMyHub(ctx, myhubInput, projectID) +} + +func (r *mutationResolver) SyncHub(ctx context.Context, id string) ([]*model.MyHubStatus, error) { + return myhub.SyncHub(ctx, id) } func (r *mutationResolver) UpdateChaosWorkflow(ctx context.Context, input *model.ChaosWorkFlowInput) (*model.ChaosWorkFlowResponse, error) { @@ -93,6 +98,26 @@ func (r *mutationResolver) DeleteClusterReg(ctx context.Context, clusterID strin return mutations.DeleteCluster(clusterID, *store) } +func (r *mutationResolver) GeneraterSSHKey(ctx context.Context) (*model.SSHKey, error) { + publicKey, privateKey, err := gitops.GenerateKeys() + if err != nil { + return nil, err + } + + return &model.SSHKey{ + PrivateKey: privateKey, + PublicKey: publicKey, + }, nil +} + +func (r *mutationResolver) UpdateMyHub(ctx context.Context, myhubInput model.UpdateMyHub, projectID string) (*model.MyHub, error) { + return myhub.UpdateMyHub(ctx, myhubInput, projectID) +} + +func (r *mutationResolver) DeleteMyHub(ctx context.Context, hubID string) (bool, error) { + return myhub.DeleteMyHub(ctx, hubID) +} + func (r *queryResolver) GetWorkFlowRuns(ctx context.Context, projectID string) ([]*model.WorkflowRun, error) { return queries.QueryWorkflowRuns(projectID) } diff --git a/litmus-portal/graphql-server/pkg/database/mongodb/operations/myhub.go b/litmus-portal/graphql-server/pkg/database/mongodb/operations/myhub.go index 76f70e7d4..e96edd1af 100644 --- a/litmus-portal/graphql-server/pkg/database/mongodb/operations/myhub.go +++ b/litmus-portal/graphql-server/pkg/database/mongodb/operations/myhub.go @@ -2,6 +2,7 @@ package operations import ( "context" + "errors" "log" "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/database/mongodb" @@ -60,3 +61,27 @@ func GetHubs(ctx context.Context) ([]dbSchema.MyHub, error) { } return MyHubs, nil } + +//GetHubByID +func GetHubByID(ctx context.Context, hubID string) (dbSchema.MyHub, error) { + var myHub dbSchema.MyHub + err := myhubCollection.FindOne(ctx, bson.M{"myhub_id": hubID}).Decode(&myHub) + if err != nil { + return dbSchema.MyHub{}, err + } + + return myHub, nil +} + +func UpdateMyHub(ctx context.Context, query bson.D, update bson.D) error { + updateResult, err := myhubCollection.UpdateOne(ctx, query, update) + if err != nil { + return err + } + + if updateResult.MatchedCount == 0 { + return errors.New("Myhub collection query didn't matched") + } + + return nil +} diff --git a/litmus-portal/graphql-server/pkg/database/mongodb/schema/myhub.go b/litmus-portal/graphql-server/pkg/database/mongodb/schema/myhub.go index ee3e3c534..bff8c15ea 100644 --- a/litmus-portal/graphql-server/pkg/database/mongodb/schema/myhub.go +++ b/litmus-portal/graphql-server/pkg/database/mongodb/schema/myhub.go @@ -4,25 +4,42 @@ import "github.com/litmuschaos/litmus/litmus-portal/graphql-server/graph/model" //MyHub ... type MyHub struct { - ID string `bson:"myhub_id"` - ProjectID string `bson:"project_id"` - RepoURL string `bson:"repo_url"` - RepoBranch string `bson:"repo_branch"` - HubName string `bson:"hub_name"` - CreatedAt string `bson:"created_at"` - UpdatedAt string `bson:"updated_at"` + ID string `bson:"myhub_id"` + ProjectID string `bson:"project_id"` + RepoURL string `bson:"repo_url"` + RepoBranch string `bson:"repo_branch"` + HubName string `bson:"hub_name"` + IsPrivate bool `bson:"IsPrivate"` + AuthType string `bson:"AuthType"` + Token *string `bson:"Token"` + UserName *string `bson:"UserName"` + Password *string `bson:"Password"` + SSHPrivateKey *string `bson:"SSHPrivateKey"` + SSHPublicKey *string `bson:"SSHPublicKey"` + IsRemoved bool `bson:"IsRemoved"` + CreatedAt string `bson:"created_at"` + UpdatedAt string `bson:"updated_at"` + LastSyncedAt string `bson:"last_synced_at"` } //GetOutputMyHub ... func (myhub *MyHub) GetOutputMyHub() *model.MyHub { return &model.MyHub{ - ID: myhub.ID, - ProjectID: myhub.ProjectID, - RepoURL: myhub.RepoURL, - RepoBranch: myhub.RepoBranch, - HubName: myhub.HubName, - CreatedAt: myhub.CreatedAt, - UpdatedAt: myhub.UpdatedAt, + ID: myhub.ID, + ProjectID: myhub.ProjectID, + RepoURL: myhub.RepoURL, + RepoBranch: myhub.RepoBranch, + HubName: myhub.HubName, + IsPrivate: myhub.IsPrivate, + UserName: myhub.UserName, + Password: myhub.Password, + AuthType: model.AuthType(myhub.AuthType), + Token: myhub.Token, + IsRemoved: myhub.IsRemoved, + SSHPrivateKey: myhub.SSHPrivateKey, + CreatedAt: myhub.CreatedAt, + UpdatedAt: myhub.UpdatedAt, + LastSyncedAt: myhub.LastSyncedAt, } } diff --git a/litmus-portal/graphql-server/pkg/myhub/gitops/gitops.go b/litmus-portal/graphql-server/pkg/myhub/gitops/gitops.go index 7e442cdbe..d74dfa301 100644 --- a/litmus-portal/graphql-server/pkg/myhub/gitops/gitops.go +++ b/litmus-portal/graphql-server/pkg/myhub/gitops/gitops.go @@ -2,6 +2,10 @@ package gitops import ( "fmt" + ssh2 "golang.org/x/crypto/ssh" + "gopkg.in/src-d/go-git.v4/plumbing/transport" + "gopkg.in/src-d/go-git.v4/plumbing/transport/http" + "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh" "os" "strings" @@ -11,8 +15,8 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing" ) -//GitConfig ... -type GitConfig struct { +//MyHubConfig ... +type MyHubConfig struct { ProjectID string RepositoryURL string RemoteName string @@ -20,34 +24,38 @@ type GitConfig struct { RemoteCommit string HubName string Branch string + IsPrivate bool + UserName *string + Password *string + AuthType model.AuthType + Token *string + SSHPrivateKey *string } -var ( - repository *git.Repository - workTree *git.Worktree - plumbingRef *plumbing.Reference - status *git.Status - err error -) - const ( defaultPath = "/tmp/version/" ) //GetClonePath is used to construct path for Repository. -func GetClonePath(c GitConfig) string { +func GetClonePath(c MyHubConfig) string { RepoPath := defaultPath + c.ProjectID + "/" + c.HubName return RepoPath } //GitConfigConstruct is used for constructing the gitconfig -func GitConfigConstruct(repoData model.CloningInput) GitConfig { - gitConfig := GitConfig{ +func GitConfigConstruct(repoData model.CloningInput) MyHubConfig { + gitConfig := MyHubConfig{ ProjectID: repoData.ProjectID, HubName: repoData.HubName, RepositoryURL: repoData.RepoURL, RemoteName: "origin", Branch: repoData.RepoBranch, + IsPrivate: repoData.IsPrivate, + UserName: repoData.UserName, + Password: repoData.Password, + AuthType: repoData.AuthType, + Token: repoData.Token, + SSHPrivateKey: repoData.SSHPrivateKey, } return gitConfig @@ -56,18 +64,56 @@ func GitConfigConstruct(repoData model.CloningInput) GitConfig { //GitClone Trigger is reponsible for setting off the go routine for git-op func GitClone(repoData model.CloningInput) error { gitConfig := GitConfigConstruct(repoData) - _, err := gitConfig.getChaosChartRepo() - if err != nil { - fmt.Print("Error in cloning") - return err + if repoData.IsPrivate { + _, err := gitConfig.getPrivateChaosChartRepo() + if err != nil { + fmt.Print("Error in cloning") + return err + } + } else { + _, err := gitConfig.getChaosChartRepo() + if err != nil { + fmt.Print("Error in cloning") + return err + } + } //Successfully Cloned return nil } +//getChaosChartVersion is responsible for plain cloning the repository +func (c MyHubConfig) getChaosChartRepo() (string, error) { + ClonePath := GetClonePath(c) + os.RemoveAll(ClonePath) + _, err := git.PlainClone(ClonePath, false, &git.CloneOptions{ + URL: c.RepositoryURL, Progress: os.Stdout, + ReferenceName: plumbing.NewBranchReferenceName(c.Branch), + }) + return c.Branch, err +} + +//getPrivateChaosChartVersion is responsible for plain cloning the private repository +func (c MyHubConfig) getPrivateChaosChartRepo() (string, error) { + ClonePath := GetClonePath(c) + os.RemoveAll(ClonePath) + + auth, err := c.generateAuthMethod() + if err != nil { + return "", err + } + + _, err = git.PlainClone(ClonePath, false, &git.CloneOptions{ + Auth: auth, + URL: c.RepositoryURL, + Progress: os.Stdout, + ReferenceName: plumbing.NewBranchReferenceName(c.Branch), + }) + return c.Branch, err +} + //GitSyncHandlerForProjects ... func GitSyncHandlerForProjects(repoData model.CloningInput) error { - gitConfig := GitConfigConstruct(repoData) if err := gitConfig.chaosChartSyncHandler(); err != nil { log.Error(err) @@ -78,32 +124,33 @@ func GitSyncHandlerForProjects(repoData model.CloningInput) error { return nil } -//getChaosChartVersion is responsible for plain cloning the repository -func (c GitConfig) getChaosChartRepo() (string, error) { - ClonePath := GetClonePath(c) - os.RemoveAll(ClonePath) - _, err := git.PlainClone(ClonePath, false, &git.CloneOptions{ - URL: c.RepositoryURL, Progress: os.Stdout, - ReferenceName: plumbing.NewBranchReferenceName(c.Branch), - }) - return c.Branch, err -} - // chaosChartSyncHandler is responsible for all the handler functions -func (c GitConfig) chaosChartSyncHandler() error { +func (c MyHubConfig) chaosChartSyncHandler() error { repositoryExists, err := c.isRepositoryExists() if err != nil { return fmt.Errorf("Error while checking repo exists, err: %s", err) } log.WithFields(log.Fields{"repositoryExists": repositoryExists}).Info("Executed isRepositoryExists()... ") + if !repositoryExists { - return c.HandlerForNonExistingRepository() + return GitClone(model.CloningInput{ + HubName: c.HubName, + ProjectID: c.ProjectID, + RepoURL: c.RepositoryURL, + RepoBranch: c.Branch, + IsPrivate: c.IsPrivate, + AuthType: c.AuthType, + Token: c.Token, + UserName: c.UserName, + Password: c.Password, + SSHPrivateKey: c.SSHPrivateKey, + }) } - return c.HandlerForExistingRepository() + return c.GitPull() } // isRepositoryExists checks for the existence of this past existence of this repository -func (c GitConfig) isRepositoryExists() (bool, error) { +func (c MyHubConfig) isRepositoryExists() (bool, error) { RepoPath := GetClonePath(c) _, err := os.Stat(RepoPath) if err != nil { @@ -115,90 +162,25 @@ func (c GitConfig) isRepositoryExists() (bool, error) { return true, nil } -// HandlerForNonExistingRepository calls function GitPlainClone, which is called only when the repository exists -func (c GitConfig) HandlerForNonExistingRepository() error { +func (c MyHubConfig) setterRepositoryWorktreeReference() (*git.Repository, *git.Worktree, *plumbing.Reference, error) { RepoPath := GetClonePath(c) - var referenceName plumbing.ReferenceName - referenceName = plumbing.NewBranchReferenceName(c.Branch) - _, err := git.PlainClone(RepoPath, false, &git.CloneOptions{ - URL: c.RepositoryURL, Progress: os.Stdout, - ReferenceName: referenceName, - }) + repository, err := git.PlainOpen(RepoPath) if err != nil { - return fmt.Errorf("unable to clone '%s' reference of chaos-chart, err: %+v", c.Branch, err) + return nil, nil, nil, fmt.Errorf("error in executing PlainOpen: %s", err) } - return nil -} - -// HandlerForExistingRepository relative functions if the isRepositoryExists fails -func (c GitConfig) HandlerForExistingRepository() error { - dirtyStatus, err := c.GitGetStatus() + workTree, err := repository.Worktree() if err != nil { - return err + return nil, nil, nil, fmt.Errorf("error in executing Worktree: %s", err) } - log.WithFields(log.Fields{"DirtyStatus": dirtyStatus}).Info("Executed GitGetStatus()... ") - if dirtyStatus { - return c.HandlerForDirtyStatus() - } - return c.HandlerForCleanStatus() -} - -// GitGetStatus excutes "git get status --porcelain" for the provided Repository Path, -// returns false if the repository is clean -// and true if the repository is dirtygitConfig -func (c GitConfig) GitGetStatus() (bool, error) { - err := c.setterRepositoryWorktreeReference() + plumbingRef, err := repository.Head() if err != nil { - return true, err + return nil, nil, nil, fmt.Errorf("error in executing Head: %s", err) } - // git status --porcelain - len, _ := getListofFilesChanged() - return !(len == 0), nil -} -func (c GitConfig) setterRepositoryWorktreeReference() error { - RepoPath := GetClonePath(c) - if repository, err = git.PlainOpen(RepoPath); err != nil { - return fmt.Errorf("error in executing PlainOpen: %s", err) - } - if workTree, err = repository.Worktree(); err != nil { - return fmt.Errorf("error in executing Worktree: %s", err) - } - plumbingRef, err = repository.Head() - if err != nil { - return fmt.Errorf("error in executing Head: %s", err) - } - return nil -} - -// HandlerForDirtyStatus calls relative functions if the GitGetStatus gives a clean status as a result -func (c GitConfig) HandlerForDirtyStatus() error { - if err := c.GitHardReset(); err != nil { - return err - } - MatchValue, err := c.CompareLocalandRemoteCommit() - if err != nil { - return err - } - log.WithFields(log.Fields{"MatchValue": MatchValue}).Info("Executed CompareLocalandRemoteCommit()... ") - if !MatchValue { - return c.HandlerForMismatchCommits() - } - return nil -} -func getListofFilesChanged() (int, error) { - status, err := workTree.Status() - if err != nil { - return 0, fmt.Errorf("error in executing Status: %s", err) - } - var listOfFilesChanged []string - for file := range status { - listOfFilesChanged = append(listOfFilesChanged, file) - } - return len(listOfFilesChanged), nil + return repository, workTree, plumbingRef, nil } // GitHardReset executes "git reset --hard HEAD" in provided Repository Path -func (c GitConfig) GitHardReset() error { +func (c MyHubConfig) GitHardReset() error { RepoPath := GetClonePath(c) repository, err := git.PlainOpen(RepoPath) if err != nil { @@ -215,7 +197,7 @@ func (c GitConfig) GitHardReset() error { } // CompareLocalandRemoteCommit compares local and remote latest commit -func (c GitConfig) CompareLocalandRemoteCommit() (bool, error) { +func (c MyHubConfig) CompareLocalandRemoteCommit() (bool, error) { RepoPath := GetClonePath(c) repository, err := git.PlainOpen(RepoPath) if err != nil { @@ -230,36 +212,55 @@ func (c GitConfig) CompareLocalandRemoteCommit() (bool, error) { } // GitPull updates the repository in provided Path -func (c GitConfig) GitPull() error { - err := c.setterRepositoryWorktreeReference() +func (c MyHubConfig) GitPull() error { + _, workTree, plumbingRef, err := c.setterRepositoryWorktreeReference() if err != nil { return err } var referenceName plumbing.ReferenceName referenceName = plumbing.NewBranchReferenceName(c.Branch) - err = workTree.Pull(&git.PullOptions{RemoteName: c.RemoteName, ReferenceName: referenceName}) - c.LocalCommit = strings.Split(plumbingRef.String(), " ")[0] + if !c.IsPrivate { + err = workTree.Pull(&git.PullOptions{RemoteName: c.RemoteName, ReferenceName: referenceName}) + if err == git.NoErrAlreadyUpToDate { + log.Print("Already up-to-date") + return nil + } else if err != nil { + return err + } + c.LocalCommit = strings.Split(plumbingRef.String(), " ")[0] + return nil + } + err = c.gitPullPrivateRepo() + if err == git.NoErrAlreadyUpToDate { + log.Print("Already up-to-date") + return nil + } else if err != nil { + return err + } return nil } -// HandlerForCleanStatus calls relative functions if the GitGetStatus gives a clean status as a result -func (c GitConfig) HandlerForCleanStatus() error { - MatchValue, err := c.CompareLocalandRemoteCommit() +// gitPullPrivateRepo updates the repository of private hubs +func (c MyHubConfig) gitPullPrivateRepo() error { + _, workTree, _, err := c.setterRepositoryWorktreeReference() if err != nil { return err } - log.WithFields(log.Fields{"MatchValue": MatchValue}).Info("Executed CompareLocalandRemoteCommit()... ") - if !MatchValue { - err := c.GitPull() - if err != nil { - return err - } + var referenceName plumbing.ReferenceName + referenceName = plumbing.NewBranchReferenceName(c.Branch) + auth, err := c.generateAuthMethod() + if err != nil { + return nil + } + err = workTree.Pull(&git.PullOptions{RemoteName: c.RemoteName, ReferenceName: referenceName, Auth: auth}) + if err != nil { + return err } return nil } // HandlerForMismatchCommits calls relative functions if the Local and Remote Commits do not match -func (c GitConfig) HandlerForMismatchCommits() error { +func (c MyHubConfig) HandlerForMismatchCommits() error { err := c.GitPull() if err != nil { return err @@ -267,3 +268,28 @@ func (c GitConfig) HandlerForMismatchCommits() error { log.WithFields(log.Fields{"execution": "complete"}).Info("Executed GitPull()... ") return nil } + +// generateAuthMethod creates AuthMethod for private repos +func (c MyHubConfig) generateAuthMethod() (transport.AuthMethod, error) { + var auth transport.AuthMethod + if c.AuthType == model.AuthTypeToken { + auth = &http.BasicAuth{ + Username: "kubera", // this can be anything except an empty string + Password: *c.Token, + } + } else if c.AuthType == model.AuthTypeBasic { + auth = &http.BasicAuth{ + Username: *c.UserName, + Password: *c.Password, + } + } else if c.AuthType == model.AuthTypeSSH { + publicKey, err := ssh.NewPublicKeys("git", []byte(*c.SSHPrivateKey), "") + if err != nil { + return nil, err + } + + auth = publicKey + auth.(*ssh.PublicKeys).HostKeyCallback = ssh2.InsecureIgnoreHostKey() + } + return auth, nil +} diff --git a/litmus-portal/graphql-server/pkg/myhub/gitops/sshkey-gen.go b/litmus-portal/graphql-server/pkg/myhub/gitops/sshkey-gen.go new file mode 100644 index 000000000..467fe8be7 --- /dev/null +++ b/litmus-portal/graphql-server/pkg/myhub/gitops/sshkey-gen.go @@ -0,0 +1,80 @@ +package gitops + +import ( + "crypto/rand" + "crypto/rsa" + "crypto/x509" + "encoding/pem" + "log" + + "golang.org/x/crypto/ssh" +) + +// GenerateKeys ... +func GenerateKeys() (string, string, error) { + bitSize := 4096 + + privateKey, err := generatePrivateKey(bitSize) + if err != nil { + return "", "", err + } + + publicKeyBytes, err := generatePublicKey(&privateKey.PublicKey) + if err != nil { + return "", "", err + } + + privateKeyBytes := encodePrivateKeyToPEM(privateKey) + + return string(publicKeyBytes), string(privateKeyBytes), nil +} + +// generatePrivateKey creates a RSA Private Key of specified byte size +func generatePrivateKey(bitSize int) (*rsa.PrivateKey, error) { + // Private Key generation + privateKey, err := rsa.GenerateKey(rand.Reader, bitSize) + if err != nil { + return nil, err + } + + // Validate Private Key + err = privateKey.Validate() + if err != nil { + return nil, err + } + + log.Println("Private Key generated") + return privateKey, nil +} + +// encodePrivateKeyToPEM encodes Private Key from RSA to PEM format +func encodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte { + // Get ASN.1 DER format + privDER := x509.MarshalPKCS1PrivateKey(privateKey) + + // pem.Block + privBlock := pem.Block{ + Type: "RSA PRIVATE KEY", + Headers: nil, + Bytes: privDER, + } + + // Private key in PEM format + privatePEM := pem.EncodeToMemory(&privBlock) + + return privatePEM +} + +// generatePublicKey take a rsa.PublicKey and return bytes suitable for writing to .pub file +// returns in the format "ssh-rsa ..." +func generatePublicKey(privatekey *rsa.PublicKey) ([]byte, error) { + publicRsaKey, err := ssh.NewPublicKey(privatekey) + if err != nil { + return nil, err + } + + pubKeyBytes := ssh.MarshalAuthorizedKey(publicRsaKey) + + log.Println("Public key generated") + return pubKeyBytes, nil +} diff --git a/litmus-portal/graphql-server/pkg/myhub/myhub.go b/litmus-portal/graphql-server/pkg/myhub/myhub.go index 615b0139c..4d77654f1 100644 --- a/litmus-portal/graphql-server/pkg/myhub/myhub.go +++ b/litmus-portal/graphql-server/pkg/myhub/myhub.go @@ -3,12 +3,15 @@ package myhub import ( "context" "errors" + "fmt" "github.com/google/uuid" + "github.com/jinzhu/copier" "github.com/litmuschaos/litmus/litmus-portal/graphql-server/graph/model" database "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/database/mongodb/operations" dbSchema "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/database/mongodb/schema" "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/myhub/gitops" "github.com/litmuschaos/litmus/litmus-portal/graphql-server/pkg/myhub/handler" + "go.mongodb.org/mongo-driver/bson" "log" "strconv" "time" @@ -26,10 +29,16 @@ func AddMyHub(ctx context.Context, myhub model.CreateMyHub, projectID string) (* } cloneHub := model.CloningInput{ - ProjectID: projectID, - RepoBranch: myhub.RepoBranch, - RepoURL: myhub.RepoURL, - HubName: myhub.HubName, + ProjectID: projectID, + RepoBranch: myhub.RepoBranch, + RepoURL: myhub.RepoURL, + HubName: myhub.HubName, + IsPrivate: myhub.IsPrivate, + UserName: myhub.UserName, + Password: myhub.Password, + AuthType: myhub.AuthType, + Token: myhub.Token, + SSHPrivateKey: myhub.SSHPrivateKey, } //Cloning the repository at a path from myhub link structure. @@ -41,13 +50,22 @@ func AddMyHub(ctx context.Context, myhub model.CreateMyHub, projectID string) (* //Initialize a UID for new Hub. uuid := uuid.New() newHub := &dbSchema.MyHub{ - ID: uuid.String(), - ProjectID: projectID, - RepoURL: myhub.RepoURL, - RepoBranch: myhub.RepoBranch, - HubName: myhub.HubName, - CreatedAt: strconv.FormatInt(time.Now().Unix(), 10), - UpdatedAt: strconv.FormatInt(time.Now().Unix(), 10), + ID: uuid.String(), + ProjectID: projectID, + RepoURL: myhub.RepoURL, + RepoBranch: myhub.RepoBranch, + HubName: myhub.HubName, + IsPrivate: myhub.IsPrivate, + AuthType: string(myhub.AuthType), + Token: myhub.Token, + UserName: myhub.UserName, + Password: myhub.Password, + SSHPrivateKey: myhub.SSHPrivateKey, + SSHPublicKey: myhub.SSHPublicKey, + IsRemoved: false, + CreatedAt: strconv.FormatInt(time.Now().Unix(), 10), + UpdatedAt: strconv.FormatInt(time.Now().Unix(), 10), + LastSyncedAt: strconv.FormatInt(time.Now().Unix(), 10), } //Adding the new hub into database with the given username. @@ -60,6 +78,48 @@ func AddMyHub(ctx context.Context, myhub model.CreateMyHub, projectID string) (* return newHub.GetOutputMyHub(), nil } +//SaveMyHub is used for Adding a new MyHub +func SaveMyHub(ctx context.Context, myhub model.CreateMyHub, projectID string) (*model.MyHub, error) { + + IsExist, err := IsMyHubAvailable(ctx, myhub.HubName, projectID) + if err != nil { + return nil, err + } + if IsExist == true { + return nil, errors.New("HubName Already exists") + } + + //Initialize a UID for new Hub. + uuid := uuid.New() + newHub := &dbSchema.MyHub{ + ID: uuid.String(), + ProjectID: projectID, + RepoURL: myhub.RepoURL, + RepoBranch: myhub.RepoBranch, + HubName: myhub.HubName, + IsPrivate: myhub.IsPrivate, + AuthType: string(myhub.AuthType), + Token: myhub.Token, + UserName: myhub.UserName, + Password: myhub.Password, + SSHPrivateKey: myhub.SSHPrivateKey, + SSHPublicKey: myhub.SSHPublicKey, + IsRemoved: false, + CreatedAt: strconv.FormatInt(time.Now().Unix(), 10), + UpdatedAt: strconv.FormatInt(time.Now().Unix(), 10), + LastSyncedAt: strconv.FormatInt(time.Now().Unix(), 10), + } + + //Adding the new hub into database with the given username without cloning. + err = database.CreateMyHub(ctx, newHub) + if err != nil { + log.Print("ERROR", err) + return nil, err + } + + return newHub.GetOutputMyHub(), nil +} + //HubStatus returns the array of hubdetails with their current status. func HubStatus(ctx context.Context, projectID string) ([]*model.MyHubStatus, error) { @@ -90,12 +150,21 @@ func HubStatus(ctx context.Context, projectID string) ([]*model.MyHubStatus, err } } hubDetail = &model.MyHubStatus{ - IsAvailable: isConfirmed, - ID: hub.ID, - RepoURL: hub.RepoURL, - HubName: hub.HubName, - RepoBranch: hub.RepoBranch, - TotalExp: strconv.Itoa(sum), + IsAvailable: isConfirmed, + ID: hub.ID, + RepoURL: hub.RepoURL, + HubName: hub.HubName, + RepoBranch: hub.RepoBranch, + IsPrivate: hub.IsPrivate, + AuthType: model.AuthType(hub.AuthType), + Token: hub.Token, + UserName: hub.UserName, + Password: hub.Password, + SSHPrivateKey: hub.SSHPrivateKey, + SSHPublicKey: hub.SSHPublicKey, + IsRemoved: hub.IsRemoved, + LastSyncedAt: hub.LastSyncedAt, + TotalExp: strconv.Itoa(sum), } hubDetails = append(hubDetails, hubDetail) } @@ -163,23 +232,39 @@ func GetExperiment(ctx context.Context, experimentInput model.ExperimentInput) ( } //SyncHub is used for syncing the hub again if some not present or some error happens. -func SyncHub(ctx context.Context, projectID string, hubName string) ([]*model.MyHubStatus, error) { - syncHubInput := model.CloningInput{} - myhubs, err := database.GetMyHubByProjectID(ctx, projectID) - for _, n := range myhubs { - if n.HubName == hubName { - syncHubInput = model.CloningInput{ - HubName: hubName, - ProjectID: projectID, - RepoURL: n.RepoURL, - RepoBranch: n.RepoBranch, - } - } +func SyncHub(ctx context.Context, hubID string) ([]*model.MyHubStatus, error) { + myhub, err := database.GetHubByID(ctx, hubID) + if err != nil { + return nil, err } + + syncHubInput := model.CloningInput{ + HubName: myhub.HubName, + ProjectID: myhub.ProjectID, + RepoURL: myhub.RepoURL, + RepoBranch: myhub.RepoBranch, + IsPrivate: myhub.IsPrivate, + UserName: myhub.UserName, + Password: myhub.Password, + AuthType: model.AuthType(myhub.AuthType), + Token: myhub.Token, + SSHPrivateKey: myhub.SSHPrivateKey, + } + + time := strconv.FormatInt(time.Now().Unix(), 10) + query := bson.D{{"myhub_id", hubID}, {"IsRemoved", false}} + update := bson.D{{"$set", bson.D{{"last_synced_at", time}}}} + err = gitops.GitSyncHandlerForProjects(syncHubInput) if err != nil { return nil, err } + //Updating the last_synced_at time using hubID + err = database.UpdateMyHub(ctx, query, update) + if err != nil { + log.Print("ERROR", err) + return nil, err + } return HubStatus(ctx, syncHubInput.ProjectID) } @@ -208,3 +293,72 @@ func GetAllHubs(ctx context.Context) ([]*model.MyHub, error) { return outputMyHubs, nil } + +func UpdateMyHub(ctx context.Context, myhub model.UpdateMyHub, projectID string) (*model.MyHub, error) { + + cloneHub := model.CloningInput{ + ProjectID: projectID, + RepoBranch: myhub.RepoBranch, + RepoURL: myhub.RepoURL, + HubName: myhub.HubName, + IsPrivate: myhub.IsPrivate, + UserName: myhub.UserName, + Password: myhub.Password, + AuthType: myhub.AuthType, + Token: myhub.Token, + SSHPrivateKey: myhub.SSHPrivateKey, + } + + prevMyHub, err := database.GetHubByID(ctx, myhub.ID) + if err != nil { + return nil, err + } + + // Syncing/Cloning the repository at a path from myhub link structure. + if prevMyHub.RepoURL != myhub.RepoURL || prevMyHub.RepoBranch != myhub.RepoBranch || prevMyHub.IsPrivate != myhub.IsPrivate || prevMyHub.AuthType != myhub.AuthType.String() { + fmt.Println(myhub.AuthType.String()) + err := gitops.GitClone(cloneHub) + if err != nil { + return nil, err + } + } else { + err := gitops.GitSyncHandlerForProjects(cloneHub) + if err != nil { + return nil, err + } + } + + time := strconv.FormatInt(time.Now().Unix(), 10) + + query := bson.D{{"myhub_id", myhub.ID}, {"IsRemoved", false}} + update := bson.D{{"$set", bson.D{{"repo_url", myhub.RepoURL}, {"repo_branch", myhub.RepoBranch}, + {"hub_name", myhub.HubName}, {"IsPrivate", myhub.IsPrivate}, {"AuthType", myhub.AuthType}, + {"Token", myhub.Token}, {"UserName", myhub.UserName}, {"Password", myhub.Password}, + {"SSHPrivateKey", myhub.SSHPrivateKey}, {"SSHPublicKey", myhub.SSHPublicKey}, {"updated_at", time}}}} + + //Updating the new hub into database with the given username. + err = database.UpdateMyHub(ctx, query, update) + if err != nil { + log.Print("ERROR", err) + return nil, err + } + + var newMyhub model.MyHub + copier.Copy(&newMyhub, &myhub) + + newMyhub.UpdatedAt = time + + return &newMyhub, nil +} + +func DeleteMyHub(ctx context.Context, hubID string) (bool, error) { + query := bson.D{{"myhub_id", hubID}} + update := bson.D{{"$set", bson.D{{"IsRemoved", true}, {"updated_at", strconv.FormatInt(time.Now().Unix(), 10)}}}} + + err := database.UpdateMyHub(ctx, query, update) + if err != nil { + log.Print("ERROR", err) + return false, err + } + return true, nil +} diff --git a/litmus-portal/graphql-server/pkg/synchandler/sync-handler.go b/litmus-portal/graphql-server/pkg/synchandler/sync-handler.go index b9f478cde..5df0c2fec 100644 --- a/litmus-portal/graphql-server/pkg/synchandler/sync-handler.go +++ b/litmus-portal/graphql-server/pkg/synchandler/sync-handler.go @@ -22,10 +22,16 @@ func RecurringHubSync() { for _, myhub := range myhubs { chartsInput := model.CloningInput{ - HubName: myhub.HubName, - ProjectID: myhub.ProjectID, - RepoURL: myhub.RepoURL, - RepoBranch: myhub.RepoBranch, + HubName: myhub.HubName, + ProjectID: myhub.ProjectID, + RepoURL: myhub.RepoURL, + RepoBranch: myhub.RepoBranch, + IsPrivate: myhub.IsPrivate, + AuthType: myhub.AuthType, + Token: myhub.Token, + UserName: myhub.UserName, + Password: myhub.Password, + SSHPrivateKey: myhub.SSHPrivateKey, } gitops.GitSyncHandlerForProjects(chartsInput)