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: Organizations support #24

Merged
merged 23 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
@@ -0,0 +1,11 @@
mutation (
$deployTarget: Int!,
$organization: Int!,){
addDeployTargetToOrganization(input: {
deployTarget: $deployTarget,
organization: $organization,
}) {
id
name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
query (
$id: Int!) {
organizationById(
id: $id) {
deployTargets {
id
name
created
consoleUrl
cloudRegion
cloudProvider
friendlyName
token
shreddedbacon marked this conversation as resolved.
Show resolved Hide resolved
sshHost
sshPort
routerPattern
buildImage
monitoringConfig
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
query (
$name: String!) {
organizationByName(
name: $name) {
deployTargets {
id
name
created
consoleUrl
cloudRegion
cloudProvider
friendlyName
token
sshHost
sshPort
routerPattern
buildImage
monitoringConfig
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mutation (
$deployTarget: Int!,
$organization: Int!,){
removeDeployTargetFromOrganization(input: {
deployTarget: $deployTarget,
organization: $organization,
}) {
id
name
}
}
23 changes: 23 additions & 0 deletions api/lagoon/client/_lgraphql/organizations/addOrganization.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mutation (
$name: String!,
$friendlyName: String,
$description: String,
$quotaProject: Int,
$quotaGroup: Int,
$quotaNotification: Int,
$quotaEnvironment: Int,
$quotaRoute: Int,) {
addOrganization(input: {
CGoodwin90 marked this conversation as resolved.
Show resolved Hide resolved
name: $name,
friendlyName: $friendlyName,
description: $description,
quotaProject: $quotaProject,
quotaGroup: $quotaGroup,
quotaNotification: $quotaNotification,
quotaEnvironment: $quotaEnvironment,
quotaRoute: $quotaRoute,
}) {
id
name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mutation (
$id: Int!
){
deleteOrganization(
input: {
id: $id
}
)
}
13 changes: 13 additions & 0 deletions api/lagoon/client/_lgraphql/organizations/organizationById.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query (
$id: Int!) {
organizationById(
CGoodwin90 marked this conversation as resolved.
Show resolved Hide resolved
id: $id) {
id
name
description
quotaProject
friendlyName
quotaGroup
quotaNotification
shreddedbacon marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query (
$name: String!) {
organizationByName(
name: $name) {
id
name
description
quotaProject
friendlyName
quotaGroup
quotaNotification
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutation (
$id: Int!
$patch: UpdateOrganizationPatchInput!){
updateOrganization(
input: {
id: $id
patch: $patch
}
){
id
name
}
}
4 changes: 4 additions & 0 deletions api/lagoon/client/_lgraphql/projects/addProject.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mutation (
$name: String!,
$organization: Int,
$gitUrl: String!,
$subfolder: String,
$openshift: Int!,
Expand All @@ -10,9 +11,11 @@ mutation (
$autoIdle: Int,
$storageCalc: Int,
$developmentEnvironmentsLimit: Int,
$addOrgOwner: Boolean,
$privateKey: String) {
addProject(input: {
name: $name,
organization: $organization,
gitUrl: $gitUrl,
subfolder: $subfolder,
openshift: $openshift,
Expand All @@ -23,6 +26,7 @@ mutation (
autoIdle: $autoIdle,
storageCalc: $storageCalc,
developmentEnvironmentsLimit: $developmentEnvironmentsLimit,
addOrgOwner: $addOrgOwner,
privateKey: $privateKey
}) {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ query (
developmentEnvironmentsLimit
gitUrl
autoIdle
organization
openshift{
id
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
query (
$id: Int!) {
organizationById(
id: $id) {
projects {
id
name
organization
groupCount
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mutation (
$project: Int!,
$organization: Int!,){
removeProjectFromOrganization(input: {
project: $project,
organization: $organization,
}) {
id
name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mutation (
$name: String!,
$organization: Int!,){
addGroupToOrganization(input: {
name: $name,
organization: $organization,
}) {
id
name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutation (
$user: UserInput!,
$organization: Int!,
$owner: Boolean) {
addUserToOrganization(input: {
user: $user
organization: $organization
owner: $owner
}) {
id
name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query (
$id: Int!) {
organizationById(
id: $id) {
groups {
id
name
type
memberCount
organization
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutation (
$user: UserInput!,
$organization: Int!,
$owner: Boolean) {
removeUserFromOrganization(input: {
user: $user
organization: $organization
owner: $owner
}) {
id
name
}
}
12 changes: 12 additions & 0 deletions api/lagoon/client/_lgraphql/usergroups/usersByOrganization.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
query (
$id: Int!) {
usersByOrganization(
organization: $id) {
id
email
firstName
lastName
owner
comment
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query (
$name: String!) {
organizationByName(
name: $name) {
owners {
id
email
firstName
lastName
owner
comment
}
}
}
2 changes: 1 addition & 1 deletion api/lagoon/client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go-bindata -pkg lgraphql -o lgraphql/lgraphql.go -nometadata _lgraphql/ _lgraphql/deployments/ _lgraphql/deploytargets/ _lgraphql/deploytargetconfigs/ _lgraphql/projects/ _lgraphql/environments/ _lgraphql/tasks/ _lgraphql/usergroups/
//go:generate go-bindata -pkg lgraphql -o lgraphql/lgraphql.go -nometadata _lgraphql/ _lgraphql/deployments/ _lgraphql/deploytargets/ _lgraphql/deploytargetconfigs/ _lgraphql/projects/ _lgraphql/environments/ _lgraphql/tasks/ _lgraphql/usergroups/ _lgraphql/organizations/

// Package client implements the interfaces required by the parent lagoon
// package.
Expand Down
92 changes: 92 additions & 0 deletions api/lagoon/client/deploytargets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package client

import (
"context"
"encoding/json"
"fmt"

"github.com/uselagoon/machinery/api/schema"
)
Expand Down Expand Up @@ -56,3 +58,93 @@ func (c *Client) DeleteDeployTarget(ctx context.Context, in *schema.DeleteDeploy

return c.client.Run(ctx, req, &out)
}

// DeployTargetsByOrganizationId queries the Lagoon API for deploy targets by the given organization id
// and unmarshals the response into organization.
func (c *Client) DeployTargetsByOrganizationId(ctx context.Context, id uint, out *[]schema.DeployTarget) error {
shreddedbacon marked this conversation as resolved.
Show resolved Hide resolved

req, err := c.newRequest("_lgraphql/deploytargets/deployTargetsByOrganizationId.graphql",
map[string]interface{}{
"id": id,
})
if err != nil {
return err
}

o := &schema.Organization{}
err = c.client.Run(ctx, req, &struct {
Response *schema.Organization `json:"organizationById"`
}{
Response: o,
})
if err != nil {
return err
}
if len(o.DeployTargets) == 0 {
return fmt.Errorf("no deploy targets found for organization %s", o.Name)
}
data, err := json.Marshal(o.DeployTargets)
if err != nil {
return err
}
json.Unmarshal(data, out)
return nil
}

// DeployTargetsByOrganizationName queries the Lagoon API for deploy targets by the given organization name
// and unmarshals the response into organization.
func (c *Client) DeployTargetsByOrganizationName(ctx context.Context, name string, out *[]schema.DeployTarget) error {

req, err := c.newRequest("_lgraphql/deploytargets/deployTargetsByOrganizationName.graphql",
map[string]interface{}{
"name": name,
})
if err != nil {
return err
}

o := &schema.Organization{}
err = c.client.Run(ctx, req, &struct {
Response *schema.Organization `json:"organizationByName"`
}{
Response: o,
})
if err != nil {
return err
}
if len(o.DeployTargets) == 0 {
return fmt.Errorf("no deploy targets found for organization %s", o.Name)
}
data, err := json.Marshal(o.DeployTargets)
if err != nil {
return err
}
json.Unmarshal(data, out)
return nil
}

// AddDeployTargetToOrganization adds an existing deploytarget to an organization.
func (c *Client) AddDeployTargetToOrganization(ctx context.Context, in *schema.AddDeployTargetToOrganizationInput, out *schema.AddDeployTargetResponse) error {
req, err := c.newRequest("_lgraphql/deploytargets/addDeployTargetToOrganization.graphql", in)
if err != nil {
return err
}
return c.client.Run(ctx, req, &struct {
Response *schema.AddDeployTargetResponse `json:"addDeployTargetToOrganization"`
}{
Response: out,
})
}

// RemoveDeployTargetFromOrganization removes a deploytarget from an organization.
func (c *Client) RemoveDeployTargetFromOrganization(ctx context.Context, in *schema.RemoveDeployTargetFromOrganizationInput, out *schema.DeleteDeployTargetResponse) error {
req, err := c.newRequest("_lgraphql/deploytargets/removeDeployTargetFromOrganization.graphql", in)
if err != nil {
return err
}
return c.client.Run(ctx, req, &struct {
Response *schema.DeleteDeployTargetResponse `json:"removeDeployTargetFromOrganization"`
}{
Response: out,
})
}
Loading