Skip to content

Commit

Permalink
Merge pull request #90 from trickest/update/library-endpoints
Browse files Browse the repository at this point in the history
Update library endpoint usage
  • Loading branch information
mhmdiaa authored Sep 28, 2023
2 parents 264074b + 5bbc922 commit f455d22
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 87 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Current workflow categories are:

[<img src="./banner.png" />](https://trickest.io/auth/register)

# Store
# Library

[Trickest Store](https://trickest.io/dashboard/store) is a collection of public tools, Trickest scripts, and Trickest workflows available on the platform. More info can be found at [Trickest workflows repository](https://github.com/trickest/workflows) <- (Coming soon!)
[Trickest Library](https://trickest.io/dashboard/library) is a collection of public tools, Trickest scripts, and Trickest workflows available on the platform. More info can be found at [Trickest workflows repository](https://github.com/trickest/workflows) <- (Coming soon!)


# Installation
Expand Down Expand Up @@ -118,7 +118,7 @@ trickest execute --workflow <workflow_or_tool_name> --space <space_name> --confi
| Flag | Type | Default | Description |
|------------------|---------|---------|---------------------------------------------------------------------------------------------------------------------------------------------|
| --config | file | / | YAML file for run configuration |
| --workflow | string | / | Workflow from the Store to be executed |
| --workflow | string | / | Workflow from the Library to be executed |
| --max | boolean | / | Use maximum number of machines for workflow execution |
| --output | string | / | A comma-separated list of nodes whose outputs should be downloaded when the execution is finished |
| --output-all | boolean | / | Download all outputs when the execution is finished |
Expand Down Expand Up @@ -191,30 +191,30 @@ trickest output --workflow <workflow_name> --space <space_name> [--nodes <comma_
| --config | file | / | YAML file for run configuration |
| --run | string | / | Download output data of a specific run |
| --runs | integer | 1 | The number of executions to be downloaded sorted by newest |
| --output-dir | string | / | Path to directory which should be used to store outputs |
| --output-dir | string | / | Path to directory which should be used to library outputs |
| --nodes | string | / | A comma separated list of nodes whose outputs should be downloaded |
| --files | string | / | A comma-separated list of file names that should be downloaded from the selected node |

## Output Structure

When using the **output** command, trickest-cli will keep the local directory/file structure the same as on the platform. All your spaces and projects will become directories with the appropriate outputs.

## Store
## Library

Use the **store** command to get more info about Trickest workflows and public tools available in the [Trickest Store](https://trickest.io/dashboard/store).
Use the **library** command to get more info about Trickest workflows and public tools available in the [Trickest Library](https://trickest.io/dashboard/library).

#### List
Use **store list** command to list all public tools & workflows available in the [store](https://trickest.io/dashboard/store), along with their descriptions.
Use **library list** command to list all public tools & workflows available in the [library](https://trickest.io/dashboard/library), along with their descriptions.

```
trickest store list
trickest library list
```

#### Search
Use **store search** to search all Trickest tools & workflows available in the [store](https://trickest.io/dashboard/store), along with their descriptions.
Use **library search** to search all Trickest tools & workflows available in the [library](https://trickest.io/dashboard/library), along with their descriptions.

```
trickest store search subdomain takeover
trickest library search subdomain takeover
```

[<img src="./banner.png" />](https://trickest.io/auth/register)
Expand Down
2 changes: 1 addition & 1 deletion cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func CreateWorkflow(name, description string, spaceID, projectID uuid.UUID, dele
os.Exit(0)
}

resp := request.Trickest.Post().Body(data).DoF("store/workflow/?vault=%s", util.GetVault())
resp := request.Trickest.Post().Body(data).DoF("library/workflow/?vault=%s", util.GetVault())
if resp == nil {
fmt.Println("Error: Couldn't create workflow.")
os.Exit(0)
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func DeleteProject(id uuid.UUID) {
}

func deleteWorkflow(id uuid.UUID) {
resp := request.Trickest.Delete().DoF("store/workflow/%s/", id.String())
resp := request.Trickest.Delete().DoF("workflow/%s/", id.String())
if resp == nil {
fmt.Println("Couldn't delete workflow with ID: " + id.String())
os.Exit(0)
Expand Down
22 changes: 11 additions & 11 deletions cmd/execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var ExecuteCmd = &cobra.Command{
// Executing from a file
version = readWorkflowYAMLandCreateVersion(workflowYAML, newWorkflowName, path)
} else {
// Executing an existing workflow or copying from store
// Executing an existing workflow or copying from library
version = prepareForExec(path)
}
if version == nil {
Expand Down Expand Up @@ -941,12 +941,12 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed {
}
}
} else {
// Executing from store
// Executing from library
wfName := pathSplit[len(pathSplit)-1]
storeWorkflows := list.GetWorkflows(uuid.Nil, uuid.Nil, wfName, true)
if storeWorkflows != nil && len(storeWorkflows) > 0 {
// Executing from store
for _, wf := range storeWorkflows {
libraryWorkflows := list.GetWorkflows(uuid.Nil, uuid.Nil, wfName, true)
if libraryWorkflows != nil && len(libraryWorkflows) > 0 {
// Executing from library
for _, wf := range libraryWorkflows {
if strings.ToLower(wf.Name) == strings.ToLower(wfName) {
if project == nil && createProject {
projectName := util.ProjectName
Expand All @@ -965,14 +965,14 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed {
copyDestination += "/" + project.Name
}
copyDestination += "/" + newWorkflowName
fmt.Println("Copying " + wf.Name + " from the store to " + copyDestination)
fmt.Println("Copying " + wf.Name + " from the library to " + copyDestination)
projID := uuid.Nil
if project != nil {
projID = project.ID
}
newWorkflowID := copyWorkflow(space.ID, projID, wf.ID)
if newWorkflowID == uuid.Nil {
fmt.Println("Couldn't copy workflow from the store!")
fmt.Println("Couldn't copy workflow from the library!")
os.Exit(0)
}

Expand Down Expand Up @@ -1032,9 +1032,9 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed {
}
tools := list.GetTools(math.MaxInt, "", wfName)
if tools == nil || len(tools) == 0 {
fmt.Println("Couldn't find a workflow or tool named " + wfName + " in the store!")
fmt.Println("Use \"trickest store list\" to see all available workflows and tools, " +
"or search the store using \"trickest store search <name/description>\"")
fmt.Println("Couldn't find a workflow or tool named " + wfName + " in the library!")
fmt.Println("Use \"trickest library list\" to see all available workflows and tools, " +
"or search the library using \"trickest library search <name/description>\"")
os.Exit(0)
}
_, _, primitiveNodes = readConfig(configFile, nil, &tools[0])
Expand Down
24 changes: 12 additions & 12 deletions cmd/execute/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func getSplitter() *types.Splitter {
resp := request.Trickest.Get().DoF("store/splitter/")
resp := request.Trickest.Get().DoF("library/splitter/")
if resp == nil {
fmt.Println("Error: Couldn't get splitter.")
}
Expand Down Expand Up @@ -61,7 +61,7 @@ func getScriptByName(name string) *types.Script {
}

func getScripts(pageSize int, search string, name string) []types.Script {
urlReq := "store/script/"
urlReq := "library/script/"
if pageSize > 0 {
urlReq = urlReq + "?page_size=" + strconv.Itoa(pageSize)
} else {
Expand Down Expand Up @@ -162,7 +162,7 @@ func createNewVersion(version *types.WorkflowVersionDetailed) *types.WorkflowVer
os.Exit(0)
}

resp := request.Trickest.Post().Body(data).DoF("store/workflow-version/")
resp := request.Trickest.Post().Body(data).DoF("library/workflow-version/")
if resp == nil {
fmt.Println("Error: Couldn't create version!")
os.Exit(0)
Expand Down Expand Up @@ -245,7 +245,7 @@ func uploadFile(filePath string) string {
}

func GetLatestWorkflowVersion(workflowID uuid.UUID) *types.WorkflowVersionDetailed {
resp := request.Trickest.Get().DoF("store/workflow-version/latest/?workflow=%s", workflowID)
resp := request.Trickest.Get().DoF("library/workflow-version/latest/?workflow=%s", workflowID)
if resp == nil {
fmt.Println("Error: Couldn't get latest workflow version!")
os.Exit(0)
Expand Down Expand Up @@ -280,7 +280,7 @@ func copyWorkflow(destinationSpaceID, destinationProjectID, workflowID uuid.UUID
os.Exit(0)
}

resp := request.Trickest.Post().Body(data).DoF("store/workflow/%s/copy/", workflowID)
resp := request.Trickest.Post().Body(data).DoF("library/workflow/%s/copy/", workflowID)
if resp == nil {
fmt.Println("Error: Couldn't copy workflow!")
os.Exit(0)
Expand Down Expand Up @@ -309,7 +309,7 @@ func updateWorkflow(workflow *types.Workflow, deleteProjectOnError bool) {
os.Exit(0)
}

resp := request.Trickest.Patch().Body(data).DoF("store/workflow/%s/", workflow.ID)
resp := request.Trickest.Patch().Body(data).DoF("library/workflow/%s/", workflow.ID)
if resp == nil {
fmt.Println("Error: Couldn't update workflow!")
os.Exit(0)
Expand Down Expand Up @@ -606,23 +606,23 @@ func getToolScriptOrSplitterFromYAMLNode(node types.WorkflowYAMLNode) (*types.To
fmt.Println("Invalid node ID format: " + node.ID)
os.Exit(0)
}
storeName := strings.TrimSuffix(node.ID, "-"+idSplit[len(idSplit)-1])
libraryName := strings.TrimSuffix(node.ID, "-"+idSplit[len(idSplit)-1])

if node.Script == nil {
tools := list.GetTools(1, "", storeName)
tools := list.GetTools(1, "", libraryName)
if tools == nil || len(tools) == 0 {
splitter = getSplitter()
if splitter == nil {
fmt.Println("Couldn't find a tool named " + storeName + " in the store!")
fmt.Println("Use \"trickest store list\" to see all available workflows and tools, " +
"or search the store using \"trickest store search <name/description>\"")
fmt.Println("Couldn't find a tool named " + libraryName + " in the library!")
fmt.Println("Use \"trickest library list\" to see all available workflows and tools, " +
"or search the library using \"trickest library search <name/description>\"")
os.Exit(0)
}
} else {
tool = &tools[0]
}
} else {
script = getScriptByName(storeName)
script = getScriptByName(libraryName)
if script == nil {
os.Exit(0)
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/store/store.go → cmd/library/library.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package store
package library

import (
"github.com/spf13/cobra"
)

// StoreCmd represents the store command
var StoreCmd = &cobra.Command{
Use: "store",
Short: "Browse workflows and tools in the Trickest store",
// LibraryCmd represents the library command
var LibraryCmd = &cobra.Command{
Use: "library",
Short: "Browse workflows and tools in the Trickest library",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}

func init() {
StoreCmd.SetHelpFunc(func(command *cobra.Command, strings []string) {
LibraryCmd.SetHelpFunc(func(command *cobra.Command, strings []string) {
_ = command.Flags().MarkHidden("space")
_ = command.Flags().MarkHidden("project")
_ = command.Flags().MarkHidden("workflow")
Expand Down
19 changes: 19 additions & 0 deletions cmd/library/libraryList.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package library

import (
"github.com/spf13/cobra"
)

// libraryListCmd represents the libraryList command
var libraryListCmd = &cobra.Command{
Use: "list",
Short: "List workflows and tools from the Trickest library",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
}

func init() {
LibraryCmd.AddCommand(libraryListCmd)
}
12 changes: 6 additions & 6 deletions cmd/store/storeListTools.go → cmd/library/libraryListTools.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package store
package library

import (
"fmt"
Expand All @@ -11,23 +11,23 @@ import (
"github.com/xlab/treeprint"
)

// storeListToolsCmd represents the storeListTools command
var storeListToolsCmd = &cobra.Command{
// libraryListToolsCmd represents the libraryListTools command
var libraryListToolsCmd = &cobra.Command{
Use: "tools",
Short: "List tools from the Trickest store",
Short: "List tools from the Trickest library",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
tools := list.GetTools(math.MaxInt, "", "")
if len(tools) > 0 {
printTools(tools)
} else {
fmt.Println("Couldn't find any tool in the store!")
fmt.Println("Couldn't find any tool in the library!")
}
},
}

func init() {
storeListCmd.AddCommand(storeListToolsCmd)
libraryListCmd.AddCommand(libraryListToolsCmd)
}

func printTools(tools []types.Tool) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package store
package library

import (
"fmt"
Expand All @@ -10,23 +10,23 @@ import (
"github.com/xlab/treeprint"
)

// storeListWorkflowsCmd represents the storeListWorkflows command
var storeListWorkflowsCmd = &cobra.Command{
// libraryListWorkflowsCmd represents the libraryListWorkflows command
var libraryListWorkflowsCmd = &cobra.Command{
Use: "workflows",
Short: "List workflows from the Trickest store",
Short: "List workflows from the Trickest library",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
workflows := list.GetWorkflows(uuid.Nil, uuid.Nil, "", true)
if len(workflows) > 0 {
printWorkflows(workflows)
} else {
fmt.Println("Couldn't find any workflow in the store!")
fmt.Println("Couldn't find any workflow in the library!")
}
},
}

func init() {
storeListCmd.AddCommand(storeListWorkflowsCmd)
libraryListCmd.AddCommand(libraryListWorkflowsCmd)
}

func printWorkflows(workflows []types.WorkflowListResponse) {
Expand Down
14 changes: 7 additions & 7 deletions cmd/store/storeSearch.go → cmd/library/librarySearch.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package store
package library

import (
"fmt"
Expand All @@ -9,10 +9,10 @@ import (
"github.com/trickest/trickest-cli/cmd/list"
)

// storeSearchCmd represents the storeSearch command
var storeSearchCmd = &cobra.Command{
// librarySearchCmd represents the librarySearch command
var librarySearchCmd = &cobra.Command{
Use: "search",
Short: "Search for workflows and tools in the Trickest store",
Short: "Search for workflows and tools in the Trickest library",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
search := ""
Expand All @@ -24,16 +24,16 @@ var storeSearchCmd = &cobra.Command{
if len(tools) > 0 {
printTools(tools)
} else {
fmt.Println("Couldn't find any tool in the store that matches the search!")
fmt.Println("Couldn't find any tool in the library that matches the search!")
}
if len(workflows) > 0 {
printWorkflows(workflows)
} else {
fmt.Println("Couldn't find any workflow in the store that matches the search!")
fmt.Println("Couldn't find any workflow in the library that matches the search!")
}
},
}

func init() {
StoreCmd.AddCommand(storeSearchCmd)
LibraryCmd.AddCommand(librarySearchCmd)
}
Loading

0 comments on commit f455d22

Please sign in to comment.