Skip to content

Commit

Permalink
feat: read organization expanded (#1118)
Browse files Browse the repository at this point in the history
Co-authored-by: David Ragot <[email protected]>
  • Loading branch information
Dav-14 and David Ragot authored Jan 15, 2024
1 parent d9d896c commit 3cd2343
Show file tree
Hide file tree
Showing 28 changed files with 1,742 additions and 524 deletions.
16 changes: 8 additions & 8 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ goreleaser:
END
END
WITH DOCKER
RUN --mount=type=cache,id=gomod,target=${GOPATH}/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
--secret GORELEASER_KEY \
--secret GITHUB_TOKEN \
--secret SPEAKEASY_API_KEY \
--secret FURY_TOKEN \
--secret SEGMENT_WRITE_KEY \
goreleaser release -f .goreleaser.yml $buildArgs
RUN --mount=type=cache,id=gomod,target=${GOPATH}/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
--secret GORELEASER_KEY \
--secret GITHUB_TOKEN \
--secret SPEAKEASY_API_KEY \
--secret FURY_TOKEN \
--secret SEGMENT_WRITE_KEY \
goreleaser release -f .goreleaser.yml $buildArgs
END

all-ci-goreleaser:
Expand Down
5 changes: 2 additions & 3 deletions components/fctl/cmd/cloud/organizations/create.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package organizations

import (
"github.com/formancehq/fctl/cmd/cloud/organizations/internal"
"github.com/formancehq/fctl/membershipclient"
fctl "github.com/formancehq/fctl/pkg"
"github.com/spf13/cobra"
)

type CreateStore struct {
Organization *membershipclient.Organization `json:"organization"`
Organization *membershipclient.OrganizationExpanded `json:"organization"`
}
type CreateController struct {
store *CreateStore
Expand Down Expand Up @@ -85,5 +84,5 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab
}

func (c *CreateController) Render(cmd *cobra.Command, args []string) error {
return internal.PrintOrganization(c.store.Organization)
return PrintOrganization(c.store.Organization)
}
12 changes: 6 additions & 6 deletions components/fctl/cmd/cloud/organizations/describe.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package organizations

import (
"github.com/formancehq/fctl/cmd/cloud/organizations/internal"
"github.com/formancehq/fctl/membershipclient"
fctl "github.com/formancehq/fctl/pkg"
"github.com/spf13/cobra"
)

type DescribeStore struct {
Organization *membershipclient.Organization `json:"organization"`
*membershipclient.OrganizationExpanded
}
type DescribeController struct {
store *DescribeStore
Expand All @@ -31,6 +30,7 @@ func NewDescribeCommand() *cobra.Command {
fctl.WithShortDescription("Describe organization"),
fctl.WithArgs(cobra.ExactArgs(1)),
fctl.WithConfirmFlag(),
fctl.WithBoolFlag("expand", false, "Expand the organization"),
fctl.WithController[*DescribeStore](NewDescribeController()),
)
}
Expand All @@ -51,17 +51,17 @@ func (c *DescribeController) Run(cmd *cobra.Command, args []string) (fctl.Render
return nil, err
}

expand := fctl.GetBool(cmd, "expand")
response, _, err := apiClient.DefaultApi.
ReadOrganization(cmd.Context(), args[0]).Execute()
ReadOrganization(cmd.Context(), args[0]).Expand(expand).Execute()
if err != nil {
return nil, err
}

c.store.Organization = response.Data

c.store.OrganizationExpanded = response.Data
return c, nil
}

func (c *DescribeController) Render(cmd *cobra.Command, args []string) error {
return internal.PrintOrganization(c.store.Organization)
return PrintOrganization(c.store.OrganizationExpanded)
}
29 changes: 0 additions & 29 deletions components/fctl/cmd/cloud/organizations/internal/print.go

This file was deleted.

18 changes: 13 additions & 5 deletions components/fctl/cmd/cloud/organizations/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewListCommand() *cobra.Command {
return fctl.NewCommand("list",
fctl.WithAliases("ls", "l"),
fctl.WithShortDescription("List organizations"),
fctl.WithBoolFlag("expand", true, "Expand the organization"),
fctl.WithArgs(cobra.ExactArgs(0)),
fctl.WithController[*ListStore](NewListController()),
)
Expand All @@ -59,7 +60,9 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable
return nil, err
}

organizations, _, err := apiClient.DefaultApi.ListOrganizationsExpanded(cmd.Context()).Execute()
expand := fctl.GetBool(cmd, "expand")

organizations, _, err := apiClient.DefaultApi.ListOrganizations(cmd.Context()).Expand(expand).Execute()
if err != nil {
return nil, err
}
Expand All @@ -73,10 +76,15 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable
c.store.Organizations = fctl.Map(organizations.Data, func(o membershipclient.ListOrganizationExpandedResponseDataInner) *OrgRow {
isMine := fctl.BoolToString(o.OwnerId == claims["sub"].(string))
return &OrgRow{
ID: o.Id,
Name: o.Name,
OwnerID: o.OwnerId,
OwnerEmail: o.Owner.Email,
ID: o.Id,
Name: o.Name,
OwnerID: o.OwnerId,
OwnerEmail: func() string {
if o.Owner == nil {
return ""
}
return o.Owner.Email
}(),
Domain: func() string {
if o.Domain == nil {
return ""
Expand Down
49 changes: 49 additions & 0 deletions components/fctl/cmd/cloud/organizations/print.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package organizations

import (
"strconv"

"github.com/formancehq/fctl/membershipclient"
"github.com/pterm/pterm"
)

func PrintOrganization(store *membershipclient.OrganizationExpanded) error {
pterm.DefaultSection.Println("Organization")

data := [][]string{
{"ID", store.Id},
{"Name", store.Name},
{"Domain", func() string {
if store.Domain == nil {
return "None"
}
return *store.Domain
}()},
{"Default Stack Role", func() string {
if store.DefaultStackAccess == nil {
return "None"
}
return string(*store.DefaultStackAccess)
}()},
{"Default Organization Role", func() string {
if store.DefaultOrganizationAccess == nil {
return "None"
}
return string(*store.DefaultOrganizationAccess)
}()},
}

if store.Owner != nil {
data = append(data, []string{"Owner", store.Owner.Email})
}

if store.TotalUsers != nil {
data = append(data, []string{"Total Users", strconv.Itoa(int(*store.TotalUsers))})
}

if store.TotalStacks != nil {
data = append(data, []string{"Total Stacks", strconv.Itoa(int(*store.TotalStacks))})
}

return pterm.DefaultTable.WithHasHeader().WithData(data).Render()
}
20 changes: 8 additions & 12 deletions components/fctl/cmd/cloud/organizations/update.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package organizations

import (
"github.com/formancehq/fctl/cmd/cloud/organizations/internal"
"github.com/formancehq/fctl/membershipclient"
fctl "github.com/formancehq/fctl/pkg"
"github.com/spf13/cobra"
)

type UpdateStore struct {
Organization *membershipclient.Organization `json:"organization"`
}
type UpdateController struct {
store *UpdateStore
store *DescribeStore
}

var _ fctl.Controller[*UpdateStore] = (*UpdateController)(nil)
var _ fctl.Controller[*DescribeStore] = (*UpdateController)(nil)

func NewDefaultUpdateStore() *UpdateStore {
return &UpdateStore{}
func NewDefaultUpdateStore() *DescribeStore {
return &DescribeStore{}
}

func NewUpdateController() *UpdateController {
Expand All @@ -36,11 +32,11 @@ func NewUpdateCommand() *cobra.Command {
fctl.WithStringSliceFlag("default-stack-role", []string{}, "Default Stack Role"),
fctl.WithStringFlag("domain", "", "Organization Domain"),
fctl.WithStringSliceFlag("default-organization-role", []string{}, "Default Organization Role"),
fctl.WithController[*UpdateStore](NewUpdateController()),
fctl.WithController[*DescribeStore](NewUpdateController()),
)
}

func (c *UpdateController) GetStore() *UpdateStore {
func (c *UpdateController) GetStore() *DescribeStore {
return c.store
}

Expand Down Expand Up @@ -102,11 +98,11 @@ func (c *UpdateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab
return nil, err
}

c.store.Organization = response.Data
c.store.OrganizationExpanded = response.Data

return c, nil
}

func (c *UpdateController) Render(cmd *cobra.Command, args []string) error {
return internal.PrintOrganization(c.store.Organization)
return PrintOrganization(c.store.OrganizationExpanded)
}
49 changes: 37 additions & 12 deletions components/fctl/membership-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ paths:
get:
summary: List organizations of the connected user
operationId: listOrganizations
parameters:
- name: expand
in: query
schema:
type: bool
required: false
responses:
200:
description: List of organizations
content:
application/json:
schema:
$ref: '#/components/schemas/ListOrganizationResponse'
$ref: '#/components/schemas/ListOrganizationExpandedResponse'
post:
summary: Create organization
operationId: createOrganization
Expand All @@ -57,6 +63,7 @@ paths:
get:
summary: List organizations of the connected user with expanded data
operationId: listOrganizationsExpanded
deprecated: true
responses:
200:
description: List of organizations with expanded data
Expand All @@ -74,13 +81,19 @@ paths:
schema:
type: string
required: true
- name: expand
in: query
schema:
type: bool
required: false
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ReadOrganizationResponse'

put:
summary: Update organization
operationId: updateOrganization
Expand Down Expand Up @@ -1126,6 +1139,12 @@ components:
availableSandboxes:
type: integer
description: Number of available sandboxes
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
StackData:
type: object
required:
Expand Down Expand Up @@ -1311,9 +1330,12 @@ components:
type: object
properties:
data:
$ref: '#/components/schemas/Organization'
$ref: '#/components/schemas/OrganizationExpanded'
ReadOrganizationResponse:
$ref: '#/components/schemas/CreateOrganizationResponse'
type: object
properties:
data:
$ref: '#/components/schemas/OrganizationExpanded'
ListStacksResponse:
type: object
properties:
Expand Down Expand Up @@ -1456,15 +1478,18 @@ components:
type: array
items:
allOf:
- $ref: '#/components/schemas/Organization'
- type: object
properties:
totalStacks:
type: integer
totalUsers:
type: integer
owner:
$ref: '#/components/schemas/User'
- $ref: '#/components/schemas/OrganizationExpanded'
OrganizationExpanded:
allOf:
- $ref: '#/components/schemas/Organization'
- type: object
properties:
totalStacks:
type: integer
totalUsers:
type: integer
owner:
$ref: '#/components/schemas/User'
ListRegionsResponse:
type: object
properties:
Expand Down
Loading

1 comment on commit 3cd2343

@vercel
Copy link

@vercel vercel bot commented on 3cd2343 Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.