Skip to content

Commit

Permalink
Better output everywhere, hide nodeproxy apps
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed Aug 7, 2019
1 parent dd8f4dd commit f3af5c3
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 194 deletions.
168 changes: 162 additions & 6 deletions api/client.go
Expand Up @@ -183,16 +183,21 @@ func (client *Client) GetOrganizations() ([]Organization, error) {
return data.Organizations.Nodes, nil
}

func (client *Client) DeployImage(appName, imageTag string) (*Deployment, error) {
func (client *Client) DeployImage(appName, imageTag string) (*Release, error) {
query := `
mutation($input: DeployImageInput!) {
deployImage(input: $input) {
deployment {
release {
id
status
release {
version
version
reason
description
user {
id
email
name
}
createdAt
}
}
}
Expand All @@ -210,7 +215,33 @@ func (client *Client) DeployImage(appName, imageTag string) (*Deployment, error)
return nil, err
}

return &data.DeployImage.Deployment, nil
return &data.DeployImage.Release, nil
}

func (c *Client) GetApps() ([]App, error) {
query := `
query {
apps(type: "container") {
nodes {
id
name
organization {
slug
}
runtime
}
}
}
`

req := c.NewRequest(query)

data, err := c.Run(req)
if err != nil {
return nil, err
}

return data.Apps.Nodes, nil
}

func (c *Client) GetAppReleases(appName string, limit int) ([]Release, error) {
Expand Down Expand Up @@ -246,5 +277,130 @@ func (c *Client) GetAppReleases(appName string, limit int) ([]Release, error) {
}

return data.App.Releases.Nodes, nil
}

func (c *Client) SetSecrets(appName string, secrets map[string]string) (*Release, error) {
query := `
mutation($input: SetSecretsInput!) {
setSecrets(input: $input) {
release {
id
version
reason
description
user {
id
email
name
}
createdAt
}
}
}
`

input := SetSecretsInput{AppID: appName}
for k, v := range secrets {
input.Secrets = append(input.Secrets, SetSecretsInputSecret{Key: k, Value: v})
}

req := c.NewRequest(query)

req.Var("input", input)

data, err := c.Run(req)
if err != nil {
return nil, err
}

return &data.SetSecrets.Release, nil
}

func (c *Client) UnsetSecrets(appName string, keys []string) (*Release, error) {
query := `
mutation($input: UnsetSecretsInput!) {
unsetSecrets(input: $input) {
release {
id
version
reason
description
user {
id
email
name
}
createdAt
}
}
}
`

req := c.NewRequest(query)

req.Var("input", UnsetSecretsInput{AppID: appName, Keys: keys})

data, err := c.Run(req)
if err != nil {
return nil, err
}

return &data.UnsetSecrets.Release, nil
}

func (c *Client) GetAppSecrets(appName string) ([]Secret, error) {
query := `
query ($appName: String!) {
app(name: $appName) {
secrets {
name
digest
createdAt
}
}
}
`

req := c.NewRequest(query)

req.Var("appName", appName)

data, err := c.Run(req)
if err != nil {
return nil, err
}

return data.App.Secrets, nil
}

func (c *Client) CreateApp(name string, runtime string, orgId string) (*App, error) {
query := `
mutation($input: CreateAppInput!) {
createApp(input: $input) {
app {
id
name
organization {
slug
}
runtime
}
}
}
`

req := c.NewRequest(query)

req.Var("input", CreateAppInput{
Name: name,
Runtime: runtime,
OrganizationID: orgId,
})

data, err := c.Run(req)
if err != nil {
return nil, err
}

return &data.CreateApp.App, nil
}
28 changes: 20 additions & 8 deletions api/types.go
Expand Up @@ -19,14 +19,17 @@ type Query struct {

SetSecrets struct {
Deployment Deployment
Release Release
}

UnsetSecrets struct {
Deployment Deployment
Release Release
}

DeployImage struct {
Deployment Deployment
Release Release
}
}

Expand All @@ -39,7 +42,7 @@ type App struct {
AppURL string
Organization Organization
Services []Service
Secrets []string
Secrets []Secret
Deployments struct {
Nodes []Deployment
}
Expand Down Expand Up @@ -93,22 +96,31 @@ type Deployment struct {
}
}

type Secret struct {
Name string
Digest string
CreatedAt time.Time
}

type SetSecretsInput struct {
AppID string
Secrets []SecretInput
AppID string `json:"appId"`
Secrets []SetSecretsInputSecret `json:"secrets"`
}

type SecretInput struct {
Key string
Value string
type SetSecretsInputSecret struct {
Key string `json:"key"`
Value string `json:"value"`
}

type UnsetSecretsInput struct {
AppID string
Keys []string
AppID string `json:"appId"`
Keys []string `json:"keys"`
}

type CreateAppInput struct {
OrganizationID string `json:"organizationId"`
Runtime string `json:"runtime"`
Name string `json:"name"`
}

type LogEntry struct {
Expand Down
32 changes: 7 additions & 25 deletions cmd/appCreate.go
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/manifoldco/promptui"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/cmd/presenters"
"github.com/superfly/flyctl/flyctl"
)

Expand Down Expand Up @@ -68,38 +69,19 @@ func runAppCreate(ctx *CmdContext) error {
return fmt.Errorf("Error setting organization: %s", err)
}

q := `
mutation($input: CreateAppInput!) {
createApp(input: $input) {
app {
id
name
runtime
appUrl
}
}
}
`

req := ctx.FlyClient.NewRequest(q)

req.Var("input", map[string]string{
"organizationId": org,
"runtime": runtime,
"name": name,
})

data, err := ctx.FlyClient.Run(req)
app, err := ctx.FlyClient.CreateApp(name, runtime, org)
if err != nil {
return err
}

newApp := data.CreateApp.App
fmt.Println("Created new app", app.Name)

fmt.Println("Created new app", newApp.Name)
if err := ctx.Render(&presenters.AppsPresenter{App: app}); err != nil {
return err
}

p := flyctl.NewProject(".")
p.SetAppName(newApp.Name)
p.SetAppName(app.Name)

if err := p.SafeWriteConfig(); err != nil {
fmt.Printf(
Expand Down
51 changes: 0 additions & 51 deletions cmd/appReleases.go
Expand Up @@ -17,55 +17,4 @@ func runAppReleasesList(ctx *CmdContext) error {
}

return ctx.Render(&presenters.ReleasePresenter{Releases: releases})

// query := `
// query ($appName: String!) {
// app(id: $appName) {
// deployments {
// nodes {
// id
// number
// status
// inProgress
// currentPhase
// reason
// description
// user {
// email
// }
// createdAt
// updatedAt
// }
// }
// }
// }
// `

// req := ctx.FlyClient.NewRequest(query)

// req.Var("appName", ctx.AppName())
// req.Var("limit", 25)

// data, err := ctx.FlyClient.Run(req)
// if err != nil {
// return err
// }

// table := tablewriter.NewWriter(os.Stdout)
// table.SetHeader([]string{"#", "Status", "Reason", "Description", "User", "Created"})

// for _, deployment := range data.App.Deployments.Nodes {
// table.Append([]string{
// strconv.Itoa(deployment.Number),
// deployment.Status,
// deployment.Reason,
// deployment.Description,
// deployment.User.Email,
// deployment.CreatedAt,
// })
// }

// table.Render()

// return nil
}
21 changes: 2 additions & 19 deletions cmd/apps.go
Expand Up @@ -11,27 +11,10 @@ func newAppListCommand() *Command {
}

func runAppsList(ctx *CmdContext) error {
query := `
query {
apps {
nodes {
id
name
organization {
slug
}
runtime
}
}
}
`

req := ctx.FlyClient.NewRequest(query)

data, err := ctx.FlyClient.Run(req)
apps, err := ctx.FlyClient.GetApps()
if err != nil {
return err
}

return ctx.Render(&presenters.AppsPresenter{Apps: data.Apps.Nodes})
return ctx.Render(&presenters.AppsPresenter{Apps: apps})
}

0 comments on commit f3af5c3

Please sign in to comment.