diff --git a/api/lagoon/client/_lgraphql/deployments/deployEnvironmentBranch.graphql b/api/lagoon/client/_lgraphql/deployments/deployEnvironmentBranch.graphql index c525929..2ab38e2 100644 --- a/api/lagoon/client/_lgraphql/deployments/deployEnvironmentBranch.graphql +++ b/api/lagoon/client/_lgraphql/deployments/deployEnvironmentBranch.graphql @@ -1,6 +1,6 @@ mutation ( - $project: String!, - $branch: String!, + $project: String!, + $branch: String!, $branchRef: String, $returnData: Boolean!, $buildVariables: [EnvKeyValueInput]) { @@ -14,4 +14,4 @@ mutation ( buildVariables: $buildVariables } ) -} \ No newline at end of file +} diff --git a/api/lagoon/client/_lgraphql/deployments/deployEnvironmentPromote.graphql b/api/lagoon/client/_lgraphql/deployments/deployEnvironmentPromote.graphql index d804faa..e65424f 100644 --- a/api/lagoon/client/_lgraphql/deployments/deployEnvironmentPromote.graphql +++ b/api/lagoon/client/_lgraphql/deployments/deployEnvironmentPromote.graphql @@ -1,6 +1,6 @@ mutation ( - $project: String!, - $sourceEnvironment: String!, + $project: String!, + $sourceEnvironment: String!, $destinationEnvironment: String!, $returnData: Boolean!, $buildVariables: [EnvKeyValueInput]) { @@ -19,4 +19,4 @@ mutation ( buildVariables: $buildVariables } ) -} \ No newline at end of file +} diff --git a/api/lagoon/client/_lgraphql/deployments/deployEnvironmentPullrequest.graphql b/api/lagoon/client/_lgraphql/deployments/deployEnvironmentPullrequest.graphql index 1dba740..2139ee4 100644 --- a/api/lagoon/client/_lgraphql/deployments/deployEnvironmentPullrequest.graphql +++ b/api/lagoon/client/_lgraphql/deployments/deployEnvironmentPullrequest.graphql @@ -1,5 +1,5 @@ mutation ( - $project: ProjectInput!, + $project: ProjectInput!, $number: Int!, $title: String!, $baseBranchName: String!, @@ -20,4 +20,4 @@ mutation ( buildVariables: $buildVariables } ) -} \ No newline at end of file +} diff --git a/api/lagoon/client/_lgraphql/environments/environmentByName.graphql b/api/lagoon/client/_lgraphql/environments/environmentByName.graphql index 5fe9563..5879143 100644 --- a/api/lagoon/client/_lgraphql/environments/environmentByName.graphql +++ b/api/lagoon/client/_lgraphql/environments/environmentByName.graphql @@ -13,6 +13,10 @@ query ( deployType environmentType openshiftProjectName + autoIdle + deployTitle + deployBaseRef + deployHeadRef updated created deleted diff --git a/api/lagoon/client/_lgraphql/projects/allProjects.graphql b/api/lagoon/client/_lgraphql/projects/allProjects.graphql new file mode 100644 index 0000000..ffddac7 --- /dev/null +++ b/api/lagoon/client/_lgraphql/projects/allProjects.graphql @@ -0,0 +1,14 @@ +query { + allProjects { + id + name + gitUrl + productionEnvironment + developmentEnvironmentsLimit + environments{ + id + name + environmentType + } + } +} diff --git a/api/lagoon/client/_lgraphql/projects/deleteProject.graphql b/api/lagoon/client/_lgraphql/projects/deleteProject.graphql new file mode 100644 index 0000000..ab81583 --- /dev/null +++ b/api/lagoon/client/_lgraphql/projects/deleteProject.graphql @@ -0,0 +1,9 @@ +mutation ( + $project: String! +){ + deleteProject( + input: { + project: $project + } + ) +} diff --git a/api/lagoon/client/_lgraphql/projects/projectKeyByName.graphql b/api/lagoon/client/_lgraphql/projects/projectKeyByName.graphql new file mode 100644 index 0000000..b256c3c --- /dev/null +++ b/api/lagoon/client/_lgraphql/projects/projectKeyByName.graphql @@ -0,0 +1,7 @@ +query ( + $name: String!) { + projectByName( + name: $name) { + publicKey + } +} diff --git a/api/lagoon/client/_lgraphql/projects/projectKeyByNameRevealed.graphql b/api/lagoon/client/_lgraphql/projects/projectKeyByNameRevealed.graphql new file mode 100644 index 0000000..350698a --- /dev/null +++ b/api/lagoon/client/_lgraphql/projects/projectKeyByNameRevealed.graphql @@ -0,0 +1,8 @@ +query ( + $name: String!) { + projectByName( + name: $name) { + privateKey + publicKey + } +} diff --git a/api/lagoon/client/_lgraphql/tasks/addTask.graphql b/api/lagoon/client/_lgraphql/tasks/addTask.graphql new file mode 100644 index 0000000..9c92807 --- /dev/null +++ b/api/lagoon/client/_lgraphql/tasks/addTask.graphql @@ -0,0 +1,15 @@ +mutation ( + $environment: Int!, + $name: String!, + $command: String!, + $service: String!) { + addTask(input:{ + environment: $environment + command: $command + execute:true + name: $name + service: $service + }) { + id + } +} diff --git a/api/lagoon/client/_lgraphql/tasks/getAdvancedTasksByEnvironment.graphql b/api/lagoon/client/_lgraphql/tasks/getAdvancedTasksByEnvironment.graphql new file mode 100644 index 0000000..b6aabff --- /dev/null +++ b/api/lagoon/client/_lgraphql/tasks/getAdvancedTasksByEnvironment.graphql @@ -0,0 +1,23 @@ +query ( + $name: String!, + $project: Int! +){ + environmentByName( + name: $name, + project: $project + ){ + id + advancedTasks { + ... on AdvancedTaskDefinitionCommand { + id + name + description + } + ... on AdvancedTaskDefinitionImage { + id + name + description + } + } + } +} diff --git a/api/lagoon/client/_lgraphql/tasks/getInvokableAdvancedTaskDefinitionsByEnvironment.graphql b/api/lagoon/client/_lgraphql/tasks/getInvokableAdvancedTaskDefinitionsByEnvironment.graphql new file mode 100644 index 0000000..549100f --- /dev/null +++ b/api/lagoon/client/_lgraphql/tasks/getInvokableAdvancedTaskDefinitionsByEnvironment.graphql @@ -0,0 +1,19 @@ +query ($project: Int!, $environment: String!){ + environmentByName( + project: $project + name: $environment + ){ + advancedTasks { + ... on AdvancedTaskDefinitionCommand { + id + name + description + } + ... on AdvancedTaskDefinitionImage { + id + name + description + } + } + } +} diff --git a/api/lagoon/client/_lgraphql/tasks/getTasksForEnvironment.graphql b/api/lagoon/client/_lgraphql/tasks/getTasksForEnvironment.graphql new file mode 100644 index 0000000..260450e --- /dev/null +++ b/api/lagoon/client/_lgraphql/tasks/getTasksForEnvironment.graphql @@ -0,0 +1,17 @@ +query ($project: Int!, + $environment: String!){ + environmentByName( + project: $project + name: $environment + ){ + tasks{ + name + id + remoteId + status + created + started + completed + } + } +} diff --git a/api/lagoon/client/_lgraphql/tasks/invokeRegisteredTask.graphql b/api/lagoon/client/_lgraphql/tasks/invokeRegisteredTask.graphql new file mode 100644 index 0000000..50bcbb2 --- /dev/null +++ b/api/lagoon/client/_lgraphql/tasks/invokeRegisteredTask.graphql @@ -0,0 +1,11 @@ +mutation ( + $environment: Int!, + $advancedTaskDefinition: Int!) { + invokeRegisteredTask( + advancedTaskDefinition: $advancedTaskDefinition, + environment: $environment) { + id + name + status + } +} diff --git a/api/lagoon/client/_lgraphql/usergroups/addProjectToGroup.graphql b/api/lagoon/client/_lgraphql/usergroups/addProjectToGroup.graphql new file mode 100644 index 0000000..39545da --- /dev/null +++ b/api/lagoon/client/_lgraphql/usergroups/addProjectToGroup.graphql @@ -0,0 +1,10 @@ +mutation ( + $project: String!, + $groups: [GroupInput!]!) { + addGroupsToProject(input: { + project: {name: $project} + groups: $groups + }) { + name + } +} diff --git a/api/lagoon/client/_lgraphql/usergroups/addUser.graphql b/api/lagoon/client/_lgraphql/usergroups/addUser.graphql index 23e996b..87d869f 100644 --- a/api/lagoon/client/_lgraphql/usergroups/addUser.graphql +++ b/api/lagoon/client/_lgraphql/usergroups/addUser.graphql @@ -2,14 +2,18 @@ mutation ( $email: String!, $firstName: String, $lastName: String, - $comment: String) { + $comment: String, + $resetPassword: Boolean) { addUser(input: { email: $email firstName: $firstName lastName: $lastName comment: $comment + resetPassword: $resetPassword }) { id email + firstName + lastName } } diff --git a/api/lagoon/client/_lgraphql/usergroups/allGroups.graphql b/api/lagoon/client/_lgraphql/usergroups/allGroups.graphql new file mode 100644 index 0000000..168ba42 --- /dev/null +++ b/api/lagoon/client/_lgraphql/usergroups/allGroups.graphql @@ -0,0 +1,6 @@ +query allGroups ($name: String) { + allGroups (name: $name) { + name + id + } +} diff --git a/api/lagoon/client/_lgraphql/usergroups/deleteGroup.graphql b/api/lagoon/client/_lgraphql/usergroups/deleteGroup.graphql new file mode 100644 index 0000000..a653555 --- /dev/null +++ b/api/lagoon/client/_lgraphql/usergroups/deleteGroup.graphql @@ -0,0 +1,10 @@ +mutation ( + $name: String!){ + deleteGroup( + input: { + group: { + name: $name + } + } + ) +} diff --git a/api/lagoon/client/_lgraphql/usergroups/deleteUser.graphql b/api/lagoon/client/_lgraphql/usergroups/deleteUser.graphql new file mode 100644 index 0000000..9471285 --- /dev/null +++ b/api/lagoon/client/_lgraphql/usergroups/deleteUser.graphql @@ -0,0 +1,10 @@ +mutation ( + $email: String!) { + deleteUser( + input:{ + user: { + email: $email + } + } + ) +} diff --git a/api/lagoon/client/_lgraphql/usergroups/groupProjects.graphql b/api/lagoon/client/_lgraphql/usergroups/groupProjects.graphql new file mode 100644 index 0000000..7c5eb63 --- /dev/null +++ b/api/lagoon/client/_lgraphql/usergroups/groupProjects.graphql @@ -0,0 +1,10 @@ +query allGroups ($name: String!) { + allGroups (name: $name) { + id + name + projects{ + id + name + } + } +} diff --git a/api/lagoon/client/_lgraphql/usergroups/resetPassword.graphql b/api/lagoon/client/_lgraphql/usergroups/resetPassword.graphql new file mode 100644 index 0000000..2262529 --- /dev/null +++ b/api/lagoon/client/_lgraphql/usergroups/resetPassword.graphql @@ -0,0 +1,10 @@ +mutation ( + $email: String!) { + resetUserPassword( + input: { + user: { + email: $email + } + } + ) +} diff --git a/api/lagoon/client/_lgraphql/usergroups/updateUser.graphql b/api/lagoon/client/_lgraphql/usergroups/updateUser.graphql new file mode 100644 index 0000000..3e5d9e5 --- /dev/null +++ b/api/lagoon/client/_lgraphql/usergroups/updateUser.graphql @@ -0,0 +1,12 @@ +mutation ( + $patch: UpdateUserPatchInput! + $user: UserInput!){ + updateUser( + input: { + patch: $patch + user: $user + } + ){ + id + } +} diff --git a/api/lagoon/client/_lgraphql/variables/addOrUpdateEnvVariableByName.graphql b/api/lagoon/client/_lgraphql/variables/addOrUpdateEnvVariableByName.graphql new file mode 100644 index 0000000..087b574 --- /dev/null +++ b/api/lagoon/client/_lgraphql/variables/addOrUpdateEnvVariableByName.graphql @@ -0,0 +1,10 @@ +mutation ( + $input: EnvVariableByNameInput! +) { + addOrUpdateEnvVariableByName(input: $input) { + id + name + value + scope + } +} diff --git a/api/lagoon/client/_lgraphql/variables/deleteEnvVariableByName.graphql b/api/lagoon/client/_lgraphql/variables/deleteEnvVariableByName.graphql new file mode 100644 index 0000000..586c915 --- /dev/null +++ b/api/lagoon/client/_lgraphql/variables/deleteEnvVariableByName.graphql @@ -0,0 +1,5 @@ +mutation ( + $input: DeleteEnvVariableByNameInput! +) { + deleteEnvVariableByName(input: $input) +} diff --git a/api/lagoon/client/_lgraphql/variables/getEnvVariablesByProjectEnvironmentName.graphql b/api/lagoon/client/_lgraphql/variables/getEnvVariablesByProjectEnvironmentName.graphql new file mode 100644 index 0000000..cde8006 --- /dev/null +++ b/api/lagoon/client/_lgraphql/variables/getEnvVariablesByProjectEnvironmentName.graphql @@ -0,0 +1,10 @@ +query ( + $input: EnvVariableByProjectEnvironmentNameInput! +){ + getEnvVariablesByProjectEnvironmentName(input: $input) { + id + name + value + scope + } +} diff --git a/api/lagoon/client/projects.go b/api/lagoon/client/projects.go index 6f70775..d4f39f7 100644 --- a/api/lagoon/client/projects.go +++ b/api/lagoon/client/projects.go @@ -242,3 +242,50 @@ func (c *Client) RemoveProjectFromOrganization(ctx context.Context, in *schema.R Response: out, }) } + +// ProjectKeyByName queries the Lagoon API for a project by its name, and returns the public key & optionally the private key. +func (c *Client) ProjectKeyByName(ctx context.Context, name string, revealKey bool, project *schema.Project) error { + query := "_lgraphql/projects/projectKeyByName.graphql" + if revealKey { + query = "_lgraphql/projects/projectKeyByNameRevealed.graphql" + } + req, err := c.newRequest(query, + map[string]interface{}{ + "name": name, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *schema.Project `json:"projectByName"` + }{ + Response: project, + }) +} + +// AllProjects queries the Lagoon API and returns all projects a user has access to. +func (c *Client) AllProjects(ctx context.Context, projects *[]schema.Project) error { + req, err := c.newRequest("_lgraphql/projects/allProjects.graphql", nil) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *[]schema.Project `json:"allProjects"` + }{ + Response: projects, + }) +} + +// DeleteProject deletes a project from Lagoon. +func (c *Client) DeleteProject(ctx context.Context, project string, out *schema.DeleteProject) error { + req, err := c.newRequest("_lgraphql/projects/deleteProject.graphql", + map[string]interface{}{ + "project": project, + }) + if err != nil { + return err + } + return c.client.Run(ctx, req, &out) +} diff --git a/api/lagoon/client/tasks.go b/api/lagoon/client/tasks.go index 8f6a3c3..549e808 100644 --- a/api/lagoon/client/tasks.go +++ b/api/lagoon/client/tasks.go @@ -148,3 +148,95 @@ func (c *Client) UploadFilesForTask(ctx context.Context, return nil } + +// TasksByEnvironment gets tasks for an environment. +func (c *Client) TasksByEnvironment(ctx context.Context, projectID uint, environmentName string, environment *schema.Environment) error { + req, err := c.newRequest("_lgraphql/tasks/getTasksForEnvironment.graphql", + map[string]interface{}{ + "project": projectID, + "environment": environmentName, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *schema.Environment `json:"environmentByName"` + }{ + Response: environment, + }) +} + +// InvokableAdvancedTaskDefinitionsByEnvironment gets tasks for an environment. +func (c *Client) InvokableAdvancedTaskDefinitionsByEnvironment(ctx context.Context, projectID uint, environmentName string, environment *schema.Environment) error { + req, err := c.newRequest("_lgraphql/tasks/getInvokableAdvancedTaskDefinitionsByEnvironment.graphql", + map[string]interface{}{ + "project": projectID, + "environment": environmentName, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *schema.Environment `json:"environmentByName"` + }{ + Response: environment, + }) +} + +// InvokeAdvancedTaskDefinition invokes an advanced task definition. +func (c *Client) InvokeAdvancedTaskDefinition(ctx context.Context, environmentID uint, taskID uint, task *schema.Task) error { + req, err := c.newRequest("_lgraphql/tasks/invokeRegisteredTask.graphql", + map[string]interface{}{ + "environment": environmentID, + "advancedTaskDefinition": taskID, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *schema.Task `json:"invokeRegisteredTask"` + }{ + Response: task, + }) +} + +// AdvancedTasksByEnvironment gets advanced tasks for an environment. +func (c *Client) AdvancedTasksByEnvironment(ctx context.Context, projectID uint, environmentName string, environment *schema.Environment) error { + req, err := c.newRequest("_lgraphql/tasks/getAdvancedTasksByEnvironment.graphql", + map[string]interface{}{ + "project": projectID, + "name": environmentName, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *schema.Environment `json:"environmentByName"` + }{ + Response: environment, + }) +} + +// AddTask adds a task. +func (c *Client) AddTask(ctx context.Context, environmentID uint, task schema.Task, out *schema.Task) error { + req, err := c.newRequest("_lgraphql/tasks/addTask.graphql", + map[string]interface{}{ + "environment": environmentID, + "name": task.Name, + "command": task.Command, + "service": task.Service, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *schema.Task `json:"addTask"` + }{ + Response: out, + }) +} diff --git a/api/lagoon/client/usergroups.go b/api/lagoon/client/usergroups.go index 58b6f4b..3cb8fd6 100644 --- a/api/lagoon/client/usergroups.go +++ b/api/lagoon/client/usergroups.go @@ -81,8 +81,7 @@ func (c *Client) AddUser( } // AddSSHKey adds an SSH key to a user. -func (c *Client) AddSSHKey( - ctx context.Context, in *schema.AddSSHKeyInput, out *schema.SSHKey) error { +func (c *Client) AddSSHKey(ctx context.Context, in *schema.AddSSHKeyInput, out *schema.SSHKey) error { req, err := c.newRequest("_lgraphql/usergroups/addSshKey.graphql", in) if err != nil { return err @@ -141,7 +140,7 @@ func (c *Client) ListAllGroupMembers( }) } -// ListAllGroupMembers queries the Lagoon API for all groups and members, and +// ListGroupMembers queries the Lagoon API for groups and members, and // unmarshals the response into project. func (c *Client) ListGroupMembers( ctx context.Context, name string, groups *schema.Group) error { @@ -400,3 +399,103 @@ func (c *Client) UsersByOrganizationName(ctx context.Context, name string, users json.Unmarshal(data, users) return nil } + +// AddProjectToGroup adds a group to a project. +func (c *Client) AddProjectToGroup( + ctx context.Context, in *schema.ProjectGroupsInput, out *schema.Group) error { + req, err := c.newRequest("_lgraphql/usergroups/addProjectToGroup.graphql", map[string]interface{}{ + "project": in.Project.Name, + "groups": in.Groups, + }) + + if err != nil { + return err + } + return c.client.Run(ctx, req, &struct { + Response *schema.Group `json:"addGroupsToProject"` + }{ + Response: out, + }) +} + +// DeleteGroup deletes a group. +func (c *Client) DeleteGroup(ctx context.Context, name string, out *schema.DeleteGroupInput) error { + req, err := c.newRequest("_lgraphql/usergroups/deleteGroup.graphql", + map[string]interface{}{ + "name": name, + }) + if err != nil { + return err + } + return c.client.Run(ctx, req, &out) +} + +// AllGroups queries the Lagoon API and returns all groups a user has access to. +func (c *Client) AllGroups(ctx context.Context, groups *[]schema.Group) error { + req, err := c.newRequest("_lgraphql/usergroups/allGroups.graphql", nil) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *[]schema.Group `json:"allGroups"` + }{ + Response: groups, + }) +} + +// GroupProjects queries the Lagoon API for a group by its name, returning all projects within the group. +func (c *Client) GroupProjects( + ctx context.Context, name string, group *[]schema.Group) error { + + req, err := c.newRequest("_lgraphql/usergroups/groupProjects.graphql", + map[string]interface{}{ + "name": name, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *[]schema.Group `json:"allGroups"` + }{ + Response: group, + }) +} + +// DeleteUser removes a user from Lagoon. +func (c *Client) DeleteUser(ctx context.Context, in *schema.DeleteUserInput, out *schema.User) error { + req, err := c.newRequest("_lgraphql/usergroups/deleteUser.graphql", + map[string]interface{}{ + "email": in.User.Email, + }) + if err != nil { + return err + } + return c.client.Run(ctx, req, &out) +} + +// UpdateUser updates a user in Lagoon. +func (c *Client) UpdateUser(ctx context.Context, in *schema.UpdateUserInput, out *schema.User) error { + req, err := c.newRequest("_lgraphql/usergroups/updateUser.graphql", in) + if err != nil { + return err + } + return c.client.Run(ctx, req, &struct { + Response *schema.User `json:"updateUser"` + }{ + Response: out, + }) +} + +// ResetPassword resets a user's password. +func (c *Client) ResetPassword(ctx context.Context, in *schema.ResetUserPasswordInput, out *schema.User) error { + req, err := c.newRequest("_lgraphql/usergroups/resetPassword.graphql", + map[string]interface{}{ + "email": in.User.Email, + }) + if err != nil { + return err + } + return c.client.Run(ctx, req, &out) +} diff --git a/api/lagoon/client/variables.go b/api/lagoon/client/variables.go new file mode 100644 index 0000000..b608ce6 --- /dev/null +++ b/api/lagoon/client/variables.go @@ -0,0 +1,55 @@ +package client + +import ( + "context" + "github.com/uselagoon/machinery/api/schema" +) + +// GetEnvVariablesByProjectEnvironmentName queries the Lagoon API for a envvars by project environment and unmarshals the response. +func (c *Client) GetEnvVariablesByProjectEnvironmentName( + ctx context.Context, in *schema.EnvVariableByProjectEnvironmentNameInput, envkeyvalue *[]schema.EnvKeyValue) error { + + req, err := c.newRequest("_lgraphql/variables/getEnvVariablesByProjectEnvironmentName.graphql", + map[string]interface{}{ + "input": in, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *[]schema.EnvKeyValue `json:"getEnvVariablesByProjectEnvironmentName"` + }{ + Response: envkeyvalue, + }) +} + +// AddOrUpdateEnvVariableByName queries the Lagoon API to add or update an envvar by project environment and unmarshals the response. +func (c *Client) AddOrUpdateEnvVariableByName(ctx context.Context, in *schema.EnvVariableByNameInput, envvar *schema.UpdateEnvVarResponse) error { + req, err := c.newRequest("_lgraphql/variables/addOrUpdateEnvVariableByName.graphql", + map[string]interface{}{ + "input": in, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &struct { + Response *schema.UpdateEnvVarResponse `json:"addOrUpdateEnvVariableByName"` + }{ + Response: envvar, + }) +} + +// DeleteEnvVariableByName queries the Lagoon API to delete an envvar by project environment and unmarshals the response. +func (c *Client) DeleteEnvVariableByName(ctx context.Context, in *schema.DeleteEnvVariableByNameInput, out *schema.DeleteEnvVarResponse) error { + req, err := c.newRequest("_lgraphql/variables/deleteEnvVariableByName.graphql", + map[string]interface{}{ + "input": in, + }) + if err != nil { + return err + } + + return c.client.Run(ctx, req, &out) +} diff --git a/api/lagoon/deployment.go b/api/lagoon/deployment.go index d63b396..4f53cec 100644 --- a/api/lagoon/deployment.go +++ b/api/lagoon/deployment.go @@ -51,7 +51,7 @@ func GetDeploymentsByBulkID(ctx context.Context, bulkID string, d Deploy) (*[]sc return &deployments, d.DeploymentsByBulkID(ctx, bulkID, &deployments) } -// GetDeploymentsByEnvironment gets deployments for an envronment. +// GetDeploymentsByEnvironment gets deployments for an environment. func GetDeploymentsByEnvironment(ctx context.Context, projectID uint, environmentName string, d Deploy) (*schema.Environment, error) { environment := schema.Environment{} return &environment, d.DeploymentsByEnvironment(ctx, projectID, environmentName, &environment) diff --git a/api/lagoon/environments.go b/api/lagoon/environments.go index 132c674..4e3be6d 100644 --- a/api/lagoon/environments.go +++ b/api/lagoon/environments.go @@ -50,7 +50,7 @@ func UpdateStorageOnEnvironment(ctx context.Context, storage *schema.UpdateStora return &result, e.UpdateStorageOnEnvironment(ctx, storage, &result) } -// DeleteEnvironment updates environment storage. +// DeleteEnvironment deletes an environment. func DeleteEnvironment(ctx context.Context, name, project string, execute bool, e Environments) (*schema.DeleteEnvironment, error) { result := schema.DeleteEnvironment{} return &result, e.DeleteEnvironment(ctx, name, project, execute, &result) diff --git a/api/lagoon/projects.go b/api/lagoon/projects.go index 95c1ccd..bac2d01 100644 --- a/api/lagoon/projects.go +++ b/api/lagoon/projects.go @@ -22,6 +22,9 @@ type Projects interface { ProjectByNameExtended(ctx context.Context, name string, project *schema.Project) error ProjectsByOrganizationID(ctx context.Context, name uint, project *[]schema.OrgProject) error RemoveProjectFromOrganization(ctx context.Context, in *schema.RemoveProjectFromOrganizationInput, out *schema.Project) error + ProjectKeyByName(ctx context.Context, name string, revealKey bool, project *schema.Project) error + AllProjects(ctx context.Context, project *[]schema.Project) error + DeleteProject(ctx context.Context, project string, result *schema.DeleteProject) error } // GetMinimalProjectByName gets info of projects in lagoon that have matching metadata. @@ -95,3 +98,21 @@ func RemoveProjectFromOrganization(ctx context.Context, in *schema.RemoveProject response := schema.Project{} return &response, out.RemoveProjectFromOrganization(ctx, in, &response) } + +// GetProjectKeyByName gets the project keys of a project in Lagoon. +func GetProjectKeyByName(ctx context.Context, name string, revealKey bool, p Projects) (*schema.Project, error) { + project := schema.Project{} + return &project, p.ProjectKeyByName(ctx, name, revealKey, &project) +} + +// ListAllProjects lists all projects. +func ListAllProjects(ctx context.Context, p Projects) (*[]schema.Project, error) { + project := []schema.Project{} + return &project, p.AllProjects(ctx, &project) +} + +// DeleteProject updates environment storage. +func DeleteProject(ctx context.Context, project string, p Projects) (*schema.DeleteProject, error) { + result := schema.DeleteProject{} + return &result, p.DeleteProject(ctx, project, &result) +} diff --git a/api/lagoon/tasks.go b/api/lagoon/tasks.go index 1ad2c99..333a19c 100644 --- a/api/lagoon/tasks.go +++ b/api/lagoon/tasks.go @@ -14,6 +14,11 @@ type Tasks interface { GetTaskByID(ctx context.Context, id int, result *schema.Task) error UpdateTask(ctx context.Context, id int, patch schema.UpdateTaskPatchInput, result *schema.Task) error UploadFilesForTask(ctx context.Context, id int, files []string, result *schema.Task) error + TasksByEnvironment(ctx context.Context, projectID uint, environmentName string, environment *schema.Environment) error + InvokableAdvancedTaskDefinitionsByEnvironment(ctx context.Context, projectID uint, environmentName string, environment *schema.Environment) error + InvokeAdvancedTaskDefinition(ctx context.Context, environmentID uint, taskID uint, result *schema.Task) error + AdvancedTasksByEnvironment(ctx context.Context, projectID uint, environmentName string, environment *schema.Environment) error + AddTask(ctx context.Context, environmentID uint, task schema.Task, result *schema.Task) error } // ActiveStandbySwitch runs the activestandby switch. @@ -39,3 +44,33 @@ func UploadFilesForTask(ctx context.Context, id int, files []string, t Tasks) (* result := schema.Task{} return &result, t.UploadFilesForTask(ctx, id, files, &result) } + +// GetTasksByEnvironment gets tasks for an environment. +func GetTasksByEnvironment(ctx context.Context, projectID uint, environmentName string, t Tasks) (*schema.Environment, error) { + environment := schema.Environment{} + return &environment, t.TasksByEnvironment(ctx, projectID, environmentName, &environment) +} + +// GetInvokableAdvancedTaskDefinitionsByEnvironment gets a list of tasks invokable against an environment. +func GetInvokableAdvancedTaskDefinitionsByEnvironment(ctx context.Context, projectID uint, environmentName string, t Tasks) (*schema.Environment, error) { + environment := schema.Environment{} + return &environment, t.InvokableAdvancedTaskDefinitionsByEnvironment(ctx, projectID, environmentName, &environment) +} + +// InvokeAdvancedTaskDefinition invokes an advanced task definition. +func InvokeAdvancedTaskDefinition(ctx context.Context, environmentID uint, taskID uint, t Tasks) (*schema.Task, error) { + result := schema.Task{} + return &result, t.InvokeAdvancedTaskDefinition(ctx, environmentID, taskID, &result) +} + +// GetAdvancedTasksByEnvironment gets advanced tasks for an environment. +func GetAdvancedTasksByEnvironment(ctx context.Context, projectID uint, environmentName string, t Tasks) (*schema.Environment, error) { + environment := schema.Environment{} + return &environment, t.AdvancedTasksByEnvironment(ctx, projectID, environmentName, &environment) +} + +// AddTask adds a task to an environment. +func AddTask(ctx context.Context, environmentID uint, task schema.Task, t Tasks) (*schema.Task, error) { + result := schema.Task{} + return &result, t.AddTask(ctx, environmentID, task, &result) +} diff --git a/api/lagoon/usergroups.go b/api/lagoon/usergroups.go index ba930bc..aea84c0 100644 --- a/api/lagoon/usergroups.go +++ b/api/lagoon/usergroups.go @@ -32,6 +32,13 @@ type UserGroups interface { AddGroupToOrganization(ctx context.Context, in *schema.AddGroupToOrganizationInput, out *schema.OrgGroup) error UsersByOrganization(ctx context.Context, id uint, users *[]schema.OrgUser) error UsersByOrganizationName(ctx context.Context, name string, users *[]schema.OrgUser) error + AddProjectToGroup(ctx context.Context, in *schema.ProjectGroupsInput, group *schema.Group) error + DeleteGroup(ctx context.Context, name string, group *schema.DeleteGroupInput) error + AllGroups(ctx context.Context, groups *[]schema.Group) error + GroupProjects(ctx context.Context, name string, group *[]schema.Group) error + DeleteUser(ctx context.Context, in *schema.DeleteUserInput, user *schema.User) error + UpdateUser(ctx context.Context, in *schema.UpdateUserInput, user *schema.User) error + ResetPassword(ctx context.Context, in *schema.ResetUserPasswordInput, user *schema.User) error } // Me gets info on the current user of lagoon. @@ -152,3 +159,44 @@ func UsersByOrganizationName(ctx context.Context, name string, ug UserGroups) (* user := []schema.OrgUser{} return &user, ug.UsersByOrganizationName(ctx, name, &user) } + +// AddProjectToGroup adds a project to a group. +func AddProjectToGroup(ctx context.Context, in *schema.ProjectGroupsInput, ug UserGroups) (*schema.Group, error) { + group := schema.Group{} + return &group, ug.AddProjectToGroup(ctx, in, &group) +} + +func DeleteGroup(ctx context.Context, name string, ug UserGroups) (*schema.DeleteGroupInput, error) { + group := schema.DeleteGroupInput{} + return &group, ug.DeleteGroup(ctx, name, &group) +} + +// ListAllGroups lists all groups the user has access to. +func ListAllGroups(ctx context.Context, ug UserGroups) (*[]schema.Group, error) { + groups := []schema.Group{} + return &groups, ug.AllGroups(ctx, &groups) +} + +// GetGroupProjects gets projects associated with a group. +func GetGroupProjects(ctx context.Context, name string, ug UserGroups) (*[]schema.Group, error) { + group := []schema.Group{} + return &group, ug.GroupProjects(ctx, name, &group) +} + +// DeleteUser removes a user from lagoon. +func DeleteUser(ctx context.Context, in *schema.DeleteUserInput, ug UserGroups) (*schema.User, error) { + user := schema.User{} + return &user, ug.DeleteUser(ctx, in, &user) +} + +// UpdateUser updates a user in lagoon. +func UpdateUser(ctx context.Context, in *schema.UpdateUserInput, ug UserGroups) (*schema.User, error) { + user := schema.User{} + return &user, ug.UpdateUser(ctx, in, &user) +} + +// ResetUserPassword resets a user's password in lagoon. +func ResetUserPassword(ctx context.Context, in *schema.ResetUserPasswordInput, ug UserGroups) (*schema.User, error) { + user := schema.User{} + return &user, ug.ResetPassword(ctx, in, &user) +} diff --git a/api/lagoon/variables.go b/api/lagoon/variables.go new file mode 100644 index 0000000..e8ed572 --- /dev/null +++ b/api/lagoon/variables.go @@ -0,0 +1,30 @@ +// Package lagoon implements high-level functions for interacting with the +// Lagoon API. +package lagoon + +import ( + "context" + "github.com/uselagoon/machinery/api/schema" +) + +type Variables interface { + AddOrUpdateEnvVariableByName(ctx context.Context, in *schema.EnvVariableByNameInput, envvar *schema.UpdateEnvVarResponse) error + DeleteEnvVariableByName(ctx context.Context, in *schema.DeleteEnvVariableByNameInput, envvar *schema.DeleteEnvVarResponse) error + GetEnvVariablesByProjectEnvironmentName(ctx context.Context, in *schema.EnvVariableByProjectEnvironmentNameInput, envvar *[]schema.EnvKeyValue) error +} + +func AddOrUpdateEnvVariableByName(ctx context.Context, in *schema.EnvVariableByNameInput, v Variables) (*schema.UpdateEnvVarResponse, error) { + envvar := schema.UpdateEnvVarResponse{} + return &envvar, v.AddOrUpdateEnvVariableByName(ctx, in, &envvar) +} + +func DeleteEnvVariableByName(ctx context.Context, in *schema.DeleteEnvVariableByNameInput, v Variables) (*schema.DeleteEnvVarResponse, error) { + envvar := schema.DeleteEnvVarResponse{} + return &envvar, v.DeleteEnvVariableByName(ctx, in, &envvar) +} + +// GetEnvVariablesByProjectEnvironmentName lists variables given a project/environment. +func GetEnvVariablesByProjectEnvironmentName(ctx context.Context, in *schema.EnvVariableByProjectEnvironmentNameInput, v Variables) (*[]schema.EnvKeyValue, error) { + envvar := []schema.EnvKeyValue{} + return &envvar, v.GetEnvVariablesByProjectEnvironmentName(ctx, in, &envvar) +} diff --git a/api/schema/env_varirables.go b/api/schema/env_variables.go similarity index 60% rename from api/schema/env_varirables.go rename to api/schema/env_variables.go index a5ba43b..18635ed 100644 --- a/api/schema/env_varirables.go +++ b/api/schema/env_variables.go @@ -41,3 +41,30 @@ type EnvKeyValueInput struct { Name string `json:"name,omitempty"` Value string `json:"value,omitempty"` } + +type EnvVariableByProjectEnvironmentNameInput struct { + Environment string `json:"environment,omitempty"` + Project string `json:"project"` +} + +type EnvVariableByNameInput struct { + Environment string `json:"environment,omitempty"` + Project string `json:"project"` + Scope EnvVariableScope `json:"scope,omitempty"` + Name string `json:"name"` + Value string `json:"value"` +} + +type DeleteEnvVariableByNameInput struct { + Environment string `json:"environment,omitempty"` + Project string `json:"project"` + Name string `json:"name"` +} + +type UpdateEnvVarResponse struct { + EnvKeyValue +} + +type DeleteEnvVarResponse struct { + DeleteEnvVar string `json:"deleteEnvVariableByName,omitempty"` +} diff --git a/api/schema/environment.go b/api/schema/environment.go index ec31cb1..20dd33f 100644 --- a/api/schema/environment.go +++ b/api/schema/environment.go @@ -38,6 +38,7 @@ const ( RocketChatNotification NotificationType = "ROCKETCHAT" EmailNotification NotificationType = "EMAIL" MicrosoftTeamsNotification NotificationType = "MICROSOFTTEAMS" + WebhookNotification NotificationType = "WEBHOOK" ) // AddEnvironmentInput is based on the input to @@ -57,14 +58,16 @@ type AddEnvironmentInput struct { // Environment is the Lagoon API Environment object. type Environment struct { AddEnvironmentInput - AutoIdle uint `json:"autoIdle"` - EnvVariables []EnvKeyValue `json:"envVariables,omitempty"` - Route string `json:"route,omitempty"` - Routes string `json:"routes,omitempty"` - Backups []Backup `json:"backups,omitempty"` - Deployments []Deployment `json:"deployments,omitempty"` - Services []EnvironmentService `json:"services,omitempty"` - DeployTarget DeployTarget `json:"openshift,omitempty"` + AutoIdle uint `json:"autoIdle"` + EnvVariables []EnvKeyValue `json:"envVariables,omitempty"` + Route string `json:"route,omitempty"` + Routes string `json:"routes,omitempty"` + Backups []Backup `json:"backups,omitempty"` + Deployments []Deployment `json:"deployments,omitempty"` + Services []EnvironmentService `json:"services,omitempty"` + DeployTarget DeployTarget `json:"openshift,omitempty"` + Tasks []Task `json:"tasks,omitempty"` + AdvancedTasks []AdvancedTask `json:"advancedTasks,omitempty"` // TODO use a unixtime type Updated string `json:"updated,omitempty"` Created string `json:"created,omitempty"` diff --git a/api/schema/group.go b/api/schema/group.go index 2b580fa..17a2216 100644 --- a/api/schema/group.go +++ b/api/schema/group.go @@ -33,6 +33,7 @@ type Group struct { User User `json:"user"` Role GroupRole `json:"role"` } `json:"members,omitempty"` + Projects []Project `json:"projects,omitempty"` } // GroupConfig embeds AddGroupInput as well as a list of members. @@ -68,3 +69,7 @@ type UserRoleConfig struct { type Groups struct { Groups []Group } + +type DeleteGroupInput struct { + Group GroupInput `json:"group"` +} diff --git a/api/schema/notification.go b/api/schema/notification.go index 5fd875e..8260e93 100644 --- a/api/schema/notification.go +++ b/api/schema/notification.go @@ -13,10 +13,17 @@ type AddNotificationRocketChatInput struct { Organization *uint `json:"organization,omitempty"` } -// UpdateNotificationRocketChatPatchInput is based on the Lagoon API type. +// UpdateNotificationRocketChatInput is based on the Lagoon API type. type UpdateNotificationRocketChatInput struct { - Name string `json:"name"` - Patch AddNotificationRocketChatInput `json:"patch"` + Name string `json:"name"` + Patch UpdateNotificationRocketChatPatchInput `json:"patch"` +} + +// UpdateNotificationRocketChatPatchInput is based on the Lagoon API type. +type UpdateNotificationRocketChatPatchInput struct { + Name *string `json:"name,omitempty"` + Webhook *string `json:"webhook,omitempty"` + Channel *string `json:"channel,omitempty"` } // NotificationRocketChat is based on the Lagoon API type. @@ -33,10 +40,17 @@ type AddNotificationSlackInput struct { Organization *uint `json:"organization,omitempty"` } -// UpdateNotificationSlackPatchInput is based on the Lagoon API type. +// UpdateNotificationSlackInput is based on the Lagoon API type. type UpdateNotificationSlackInput struct { - Name string `json:"name"` - Patch AddNotificationSlackInput `json:"patch"` + Name string `json:"name"` + Patch UpdateNotificationSlackPatchInput `json:"patch"` +} + +// UpdateNotificationSlackPatchInput is based on the Lagoon API type. +type UpdateNotificationSlackPatchInput struct { + Name *string `json:"name,omitempty"` + Webhook *string `json:"webhook,omitempty"` + Channel *string `json:"channel,omitempty"` } // NotificationSlack is based on the Lagoon API type. @@ -52,10 +66,16 @@ type AddNotificationEmailInput struct { Organization *uint `json:"organization,omitempty"` } -// UpdateNotificationEmailPatchInput is based on the Lagoon API type. +// UpdateNotificationEmailInput is based on the Lagoon API type. type UpdateNotificationEmailInput struct { - Name string `json:"name"` - Patch AddNotificationEmailInput `json:"patch"` + Name string `json:"name"` + Patch UpdateNotificationEmailPatchInput `json:"patch"` +} + +// UpdateNotificationEmailPatchInput is based on the Lagoon API type. +type UpdateNotificationEmailPatchInput struct { + Name *string `json:"name,omitempty"` + EmailAddress *string `json:"emailAddress,omitempty"` } // NotificationEmail is based on the Lagoon API type. @@ -71,10 +91,16 @@ type AddNotificationMicrosoftTeamsInput struct { Organization *uint `json:"organization,omitempty"` } -// UpdateNotificationMicrosoftTeamsPatchInput is based on the Lagoon API type. +// UpdateNotificationMicrosoftTeamsInput is based on the Lagoon API type. type UpdateNotificationMicrosoftTeamsInput struct { - Name string `json:"name"` - Patch AddNotificationMicrosoftTeamsInput `json:"patch"` + Name string `json:"name"` + Patch UpdateNotificationMicrosoftTeamsPatchInput `json:"patch"` +} + +// UpdateNotificationMicrosoftTeamsPatchInput is based on the Lagoon API type. +type UpdateNotificationMicrosoftTeamsPatchInput struct { + Name *string `json:"name,omitempty"` + Webhook *string `json:"webhook,omitempty"` } // NotificationMicrosoftTeams is based on the Lagoon API type. @@ -90,10 +116,16 @@ type AddNotificationWebhookInput struct { Organization *uint `json:"organization,omitempty"` } -// UpdateNotificationWebhookPatchInput is based on the Lagoon API type. +// UpdateNotificationWebhookInput is based on the Lagoon API type. type UpdateNotificationWebhookInput struct { - Name string `json:"name"` - Patch AddNotificationWebhookInput `json:"patch"` + Name string `json:"name"` + Patch UpdateNotificationWebhookPatchInput `json:"patch"` +} + +// UpdateNotificationWebhookPatchInput is based on the Lagoon API type. +type UpdateNotificationWebhookPatchInput struct { + Name *string `json:"name,omitempty"` + Webhook *string `json:"webhook,omitempty"` } // NotificationWebhook is based on the Lagoon API type. diff --git a/api/schema/project.go b/api/schema/project.go index df16dff..8384176 100644 --- a/api/schema/project.go +++ b/api/schema/project.go @@ -31,6 +31,7 @@ type AddProjectInput struct { StorageCalc uint `json:"storageCalc"` DevelopmentEnvironmentsLimit uint `json:"developmentEnvironmentsLimit,omitempty"` PrivateKey string `json:"privateKey,omitempty"` + PublicKey string `json:"publicKey,omitempty"` BuildImage string `json:"buildImage,omitempty"` Organization uint `json:"organization,omitempty"` AddOrgOwner bool `json:"addOrgOwner,omitempty"` @@ -127,7 +128,9 @@ type UpdateProjectPatchInput struct { DevelopmentBuildPriority *uint `json:"developmentBuildPriority,omitempty"` DeploymentsDisabled *uint `json:"deploymentsDisabled,omitempty"` // `null` is valid graphql, use a pointer to allow `nil` to be empty - BuildImage *null.String `json:"buildImage,omitempty"` + BuildImage *null.String `json:"buildImage,omitempty"` + Openshift *uint `json:"openshift,omitempty"` + OpenshiftProjectPattern *string `json:"openshiftProjectPattern,omitempty"` } // RemoveProjectFromOrganizationInput is based on the Lagoon API type. @@ -135,3 +138,7 @@ type RemoveProjectFromOrganizationInput struct { Project uint `json:"project"` Organization uint `json:"organization"` } + +type DeleteProject struct { + Project string `json:"name"` +} diff --git a/api/schema/tasks.go b/api/schema/tasks.go index 2f96b50..c0d25ee 100644 --- a/api/schema/tasks.go +++ b/api/schema/tasks.go @@ -57,3 +57,10 @@ type UpdateTaskPatchInput struct { Command string `json:"command,omitempty"` RemoteID string `json:"remoteId,omitempty"` } + +// AdvancedTask task def struct +type AdvancedTask struct { + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description"` +} diff --git a/api/schema/user.go b/api/schema/user.go index 9f820ea..693dfeb 100644 --- a/api/schema/user.go +++ b/api/schema/user.go @@ -4,11 +4,12 @@ import "github.com/google/uuid" // AddUserInput is based on the Lagoon API type. type AddUserInput struct { - Email string `json:"email"` - FirstName string `json:"firstName,omitempty"` - LastName string `json:"lastName,omitempty"` - Comment string `json:"comment,omitempty"` - GitlabID uint `json:"gitlabId,omitempty"` + Email string `json:"email"` + FirstName string `json:"firstName,omitempty"` + LastName string `json:"lastName,omitempty"` + Comment string `json:"comment,omitempty"` + GitlabID uint `json:"gitlabId,omitempty"` + ResetPassword bool `json:"resetPassword,omitempty"` } // User provides for unmarshalling the users contained withing a Group. @@ -40,3 +41,24 @@ type AddUserToOrganizationInput struct { Organization uint `json:"organization"` Owner bool `json:"owner,omitempty"` } + +type DeleteUserInput struct { + User UserInput `json:"user"` +} + +type UpdateUserInput struct { + User UserInput `json:"user"` + Patch UpdateUserPatchInput `json:"patch"` +} + +type UpdateUserPatchInput struct { + Email *string `json:"email,omitempty"` + FirstName *string `json:"firstName,omitempty"` + LastName *string `json:"lastName,omitempty"` + Comment *string `json:"comment,omitempty"` + GitlabID *uint `json:"gitlabId,omitempty"` +} + +type ResetUserPasswordInput struct { + User UserInput `json:"user"` +}