Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature: Adds a number of queries, mutations & schema updates for use with the CLI #44

Merged
merged 4 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
shreddedbacon marked this conversation as resolved.
Show resolved Hide resolved
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
}
}
}
}
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
}
}
}
}
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, revealValue bool, project *schema.Project) error {
shreddedbacon marked this conversation as resolved.
Show resolved Hide resolved
query := "_lgraphql/projects/projectKeyByName.graphql"
if revealValue {
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