Skip to content

Commit

Permalink
Feature: Add remaining queries and mutations used by the CLI
Browse files Browse the repository at this point in the history
* Adds various queries for use with the cli

* Adds password reset functionality

* Fixed up naming

* Included import
  • Loading branch information
CGoodwin90 authored May 9, 2024
1 parent 8e6daef commit 94f79c0
Show file tree
Hide file tree
Showing 41 changed files with 797 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mutation (
$project: String!,
$branch: String!,
$project: String!,
$branch: String!,
$branchRef: String,
$returnData: Boolean!,
$buildVariables: [EnvKeyValueInput]) {
Expand All @@ -14,4 +14,4 @@ mutation (
buildVariables: $buildVariables
}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mutation (
$project: String!,
$sourceEnvironment: String!,
$project: String!,
$sourceEnvironment: String!,
$destinationEnvironment: String!,
$returnData: Boolean!,
$buildVariables: [EnvKeyValueInput]) {
Expand All @@ -19,4 +19,4 @@ mutation (
buildVariables: $buildVariables
}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation (
$project: ProjectInput!,
$project: ProjectInput!,
$number: Int!,
$title: String!,
$baseBranchName: String!,
Expand All @@ -20,4 +20,4 @@ mutation (
buildVariables: $buildVariables
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ query (
deployType
environmentType
openshiftProjectName
autoIdle
deployTitle
deployBaseRef
deployHeadRef
updated
created
deleted
Expand Down
14 changes: 14 additions & 0 deletions api/lagoon/client/_lgraphql/projects/allProjects.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query {
allProjects {
id
name
gitUrl
productionEnvironment
developmentEnvironmentsLimit
environments{
id
name
environmentType
}
}
}
9 changes: 9 additions & 0 deletions api/lagoon/client/_lgraphql/projects/deleteProject.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mutation (
$project: String!
){
deleteProject(
input: {
project: $project
}
)
}
7 changes: 7 additions & 0 deletions api/lagoon/client/_lgraphql/projects/projectKeyByName.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query (
$name: String!) {
projectByName(
name: $name) {
publicKey
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query (
$name: String!) {
projectByName(
name: $name) {
privateKey
publicKey
}
}
15 changes: 15 additions & 0 deletions api/lagoon/client/_lgraphql/tasks/addTask.graphql
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
17 changes: 17 additions & 0 deletions api/lagoon/client/_lgraphql/tasks/getTasksForEnvironment.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
query ($project: Int!,
$environment: String!){
environmentByName(
project: $project
name: $environment
){
tasks{
name
id
remoteId
status
created
started
completed
}
}
}
11 changes: 11 additions & 0 deletions api/lagoon/client/_lgraphql/tasks/invokeRegisteredTask.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mutation (
$environment: Int!,
$advancedTaskDefinition: Int!) {
invokeRegisteredTask(
advancedTaskDefinition: $advancedTaskDefinition,
environment: $environment) {
id
name
status
}
}
10 changes: 10 additions & 0 deletions api/lagoon/client/_lgraphql/usergroups/addProjectToGroup.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation (
$project: String!,
$groups: [GroupInput!]!) {
addGroupsToProject(input: {
project: {name: $project}
groups: $groups
}) {
name
}
}
6 changes: 5 additions & 1 deletion api/lagoon/client/_lgraphql/usergroups/addUser.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 6 additions & 0 deletions api/lagoon/client/_lgraphql/usergroups/allGroups.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query allGroups ($name: String) {
allGroups (name: $name) {
name
id
}
}
10 changes: 10 additions & 0 deletions api/lagoon/client/_lgraphql/usergroups/deleteGroup.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation (
$name: String!){
deleteGroup(
input: {
group: {
name: $name
}
}
)
}
10 changes: 10 additions & 0 deletions api/lagoon/client/_lgraphql/usergroups/deleteUser.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation (
$email: String!) {
deleteUser(
input:{
user: {
email: $email
}
}
)
}
10 changes: 10 additions & 0 deletions api/lagoon/client/_lgraphql/usergroups/groupProjects.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
query allGroups ($name: String!) {
allGroups (name: $name) {
id
name
projects{
id
name
}
}
}
10 changes: 10 additions & 0 deletions api/lagoon/client/_lgraphql/usergroups/resetPassword.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation (
$email: String!) {
resetUserPassword(
input: {
user: {
email: $email
}
}
)
}
12 changes: 12 additions & 0 deletions api/lagoon/client/_lgraphql/usergroups/updateUser.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mutation (
$patch: UpdateUserPatchInput!
$user: UserInput!){
updateUser(
input: {
patch: $patch
user: $user
}
){
id
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation (
$input: EnvVariableByNameInput!
) {
addOrUpdateEnvVariableByName(input: $input) {
id
name
value
scope
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation (
$input: DeleteEnvVariableByNameInput!
) {
deleteEnvVariableByName(input: $input)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
query (
$input: EnvVariableByProjectEnvironmentNameInput!
){
getEnvVariablesByProjectEnvironmentName(input: $input) {
id
name
value
scope
}
}
47 changes: 47 additions & 0 deletions api/lagoon/client/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading

0 comments on commit 94f79c0

Please sign in to comment.