-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add `cf workflow list` and `cf workflow delete` * update SDK to latest * add docs
- Loading branch information
Showing
7 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@common-fate/cli": minor | ||
--- | ||
|
||
Adds 'cf workflow list' and 'cf workflow delete' commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package workflow | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var Command = cli.Command{ | ||
Name: "workflow", | ||
Usage: "Manage Common Fate Access Workflows", | ||
Subcommands: []*cli.Command{ | ||
&listCommand, | ||
&deleteCommand, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package workflow | ||
|
||
import ( | ||
"fmt" | ||
|
||
"connectrpc.com/connect" | ||
"github.com/common-fate/sdk/config" | ||
configv1alpha1 "github.com/common-fate/sdk/gen/commonfate/control/config/v1alpha1" | ||
"github.com/common-fate/sdk/service/control/configsvc" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var deleteCommand = cli.Command{ | ||
Name: "delete", | ||
Usage: "Delete an Access Workflow", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{Name: "workflow-id", Required: true, Usage: "the workflow ID to delete"}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
ctx := c.Context | ||
|
||
cfg, err := config.LoadDefault(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client := configsvc.NewFromConfig(cfg) | ||
|
||
res, err := client.AccessWorkflow().DeleteAccessWorkflow(ctx, connect.NewRequest(&configv1alpha1.DeleteAccessWorkflowRequest{ | ||
Id: c.String("workflow-id"), | ||
})) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("deleted %s\n", res.Msg.Id) | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package workflow | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"connectrpc.com/connect" | ||
"github.com/common-fate/sdk/config" | ||
resourcev1alpha1 "github.com/common-fate/sdk/gen/commonfate/control/resource/v1alpha1" | ||
"github.com/common-fate/sdk/gen/commonfate/control/resource/v1alpha1/resourcev1alpha1connect" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var listCommand = cli.Command{ | ||
Name: "list", | ||
Action: func(c *cli.Context) error { | ||
ctx := c.Context | ||
|
||
cfg, err := config.LoadDefault(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client := newResourceClient(cfg) | ||
// the Common Fate API doesn't currently expose a ListAccessWorkflows method, so we use the | ||
// QueryResources API. | ||
res, err := client.QueryResources(ctx, connect.NewRequest(&resourcev1alpha1.QueryResourcesRequest{ | ||
Type: "Access::Workflow", | ||
})) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
workflows := allWorkflows{Workflows: []workflow{}} | ||
|
||
for _, w := range res.Msg.Resources { | ||
workflows.Workflows = append(workflows.Workflows, workflow{ | ||
ID: w.Eid.Id, | ||
Name: w.Name, | ||
}) | ||
} | ||
|
||
workflowsJSON, err := json.MarshalIndent(workflows, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(string(workflowsJSON)) | ||
return nil | ||
}, | ||
} | ||
|
||
// allWorkflows is used to ensure the output of the `cf workflows list` | ||
// command remains stable, even if the API that we call changes from | ||
// QueryResources to something else in future (such as ListAccessWorkflows). | ||
type allWorkflows struct { | ||
Workflows []workflow `json:"workflows"` | ||
} | ||
|
||
type workflow struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func newResourceClient(cfg *config.Context) resourcev1alpha1connect.ResourceServiceClient { | ||
return resourcev1alpha1connect.NewResourceServiceClient(cfg.HTTPClient, cfg.APIURL) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters