Skip to content

Commit

Permalink
Feature: Organizations support (#24)
Browse files Browse the repository at this point in the history
* Basic add organization functionality
  • Loading branch information
CGoodwin90 authored Nov 27, 2023
1 parent 2224e02 commit 90d6ce1
Show file tree
Hide file tree
Showing 36 changed files with 1,304 additions and 37 deletions.
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,17 @@
query (
$id: Int!) {
organizationById(id: $id) {
deployTargets {
id
name
created
cloudRegion
cloudProvider
friendlyName
sshHost
sshPort
routerPattern
buildImage
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
query (
$name: String!) {
organizationByName(name: $name) {
deployTargets {
id
name
created
cloudRegion
cloudProvider
friendlyName
sshHost
sshPort
routerPattern
buildImage
}
}
}
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: {
name: $name,
friendlyName: $friendlyName,
description: $description,
quotaProject: $quotaProject,
quotaGroup: $quotaGroup,
quotaNotification: $quotaNotification,
quotaEnvironment: $quotaEnvironment,
quotaRoute: $quotaRoute,
}) {
id
name
}
}
13 changes: 13 additions & 0 deletions api/lagoon/client/_lgraphql/organizations/allOrganizations.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query {
allOrganizations {
id
name
description
friendlyName
quotaProject
quotaGroup
quotaNotification
quotaEnvironment
quotaRoute
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mutation (
$id: Int!
){
deleteOrganization(
input: {
id: $id
}
)
}
15 changes: 15 additions & 0 deletions api/lagoon/client/_lgraphql/organizations/organizationById.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
query (
$id: Int!) {
organizationById(
id: $id) {
id
name
description
friendlyName
quotaProject
quotaGroup
quotaNotification
quotaEnvironment
quotaRoute
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
query (
$name: String!) {
organizationByName(
name: $name) {
id
name
description
friendlyName
quotaProject
quotaGroup
quotaNotification
quotaEnvironment
quotaRoute
}
}
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
79 changes: 78 additions & 1 deletion api/lagoon/client/deploytargets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package client

import (
"context"

"encoding/json"
"fmt"
"github.com/machinebox/graphql"
"github.com/uselagoon/machinery/api/schema"
)

Expand Down Expand Up @@ -56,3 +58,78 @@ func (c *Client) DeleteDeployTarget(ctx context.Context, in *schema.DeleteDeploy

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

// DeployTargetsByOrganizationNameOrID queries the Lagoon API for deploy targets by the given organization name
// and unmarshals the response into organization.
// Need to rework the argument types here
func (c *Client) DeployTargetsByOrganizationNameOrID(ctx context.Context, name *string, id *uint, out *[]schema.DeployTarget) error {
var req *graphql.Request
var err error
o := &schema.Organization{}

if name != nil {
req, err = c.newRequest("_lgraphql/deploytargets/deployTargetsByOrganizationName.graphql",
map[string]interface{}{
"name": name,
})
err = c.client.Run(ctx, req, &struct {
Response *schema.Organization `json:"organizationByName"`
}{
Response: o,
})
if err != nil {
return err
}
} else {
if id != nil {
req, err = c.newRequest("_lgraphql/deploytargets/deployTargetsByOrganizationId.graphql",
map[string]interface{}{
"id": id,
})
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
}

// 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

0 comments on commit 90d6ce1

Please sign in to comment.