Skip to content

[public-api] Simple CLI tool to interact with Public API #9588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2022

Conversation

easyCZ
Copy link
Member

@easyCZ easyCZ commented Apr 27, 2022

Description

Adds api workspaces get --id 123 --token "foo-bar" to interact with Public API. Creates a dir apiundercmd` and gives code-ownership to WebApp.

 ./gpctl 
Gpctl controls a Gitpod installation

Usage:
  gpctl [command]

Available Commands:
  api         Interact with Public API services
  clusters    Controls and inspects cluster
  completion  Generate completion script
  debug       Helps with debugging a component
  help        Help about any command
  imagebuilds Controls and inspects workspace Docker image builds
  workspaces  Controls and inspects workspaces in the Gitpod installation

Flags:
  -h, --help                     help for gpctl
  -c, --kubeconfig string        Path to the kubeconfig file used for connecting to the cluster (default "$HOME/.kube/config")
  -o, --output-format string     Output format. One of: string|json|jsonpath|template (default "template")
      --output-template string   Output format Go template or jsonpath. Use with -o template or -o jsonpath

Use "gpctl [command] --help" for more information about a command.
./gpctl api workspaces get --id 123 --token foo-bar --address api.mp-papi-cmd-yolo.staging.gitpod-dev.com:443
INFO[0000] Estabilishing gRPC connection against api.mp-papi-cmd-yolo.staging.gitpod-dev.com:443 
{"result":{"workspaceId":"123","ownerId":"mock_owner","projectId":"mock_project_id","context"{"contextUrl":"https://github.com/gitpod-io/gitpod"},"description":"This is a mock response"}}%  

Related Issue(s)

Fixes #

How to test

Test the CLI works

cd dev/gpctl
go run main.go api workspaces get --id 123 --token foo-bar --address api.mp-papi-cmd-yolo.staging.gitpod-dev.com:443

Test with a local instance of Public API

  1. Navigate to preview env on main
  2. Open dev console and run
await window._gp.gitpodService.server.generateNewGitpodToken({ type: 1, scopes: ["function:getGitpodTokenScopes",
	"function:getWorkspace",
	"function:getWorkspaces",
	"function:listenForWorkspaceInstanceUpdates",
	"resource:default",]})

, this will obtain a token you can use to access the through a CLI
4. Start the Public API locally with cd components/public-api-server && go run main.go
5. Hit the local API using the CLI, here we need to use --insecure because we're not serving TLS certs

go run main.go api workspaces get --id $WORKSPACE_ID --token $TOKEN --insecure --address localhost:9501

You'll likely get Not Found. To get a response, start a workspace on the main preview env and use its ID as $WORKSPACE_ID

Release Notes

NONE

Documentation

NONE

/uncc

  • /werft without-vm=true

@easyCZ easyCZ changed the title [public-api] Caddy serves gRPC port instead of http [public-api] Simple CLI tool to interact with Public API Apr 27, 2022
@easyCZ easyCZ force-pushed the mp/papi-cmd-yolo branch from 12f6315 to b81f6bb Compare April 28, 2022 07:28
@csweichel
Copy link
Contributor

should be part of gpctl imho

@easyCZ
Copy link
Member Author

easyCZ commented May 3, 2022

@csweichel That's a good point. How do we want to use the first iteration? Should it eventually be a CLI that externals should be able to interact with to consume the API? Or do we want to merge it with gpctl which has an explicit purpose of being used by Gitpod engineers to operate the system.

My inclination is to keep it separate and gear more towards a CLI for the API only, which can be published and consumed by externals.

@easyCZ easyCZ force-pushed the mp/papi-cmd-yolo branch from b81f6bb to fe6fad9 Compare May 3, 2022 12:33
@roboquat roboquat added size/XL and removed size/L labels May 3, 2022
@easyCZ
Copy link
Member Author

easyCZ commented May 3, 2022

/werft run without-vm=true

👍 started the job as gitpod-build-mp-papi-cmd-yolo.8
(with .werft/ from main)

@csweichel
Copy link
Contributor

@easyCZ I'd start with the latter - go for gpctl. It gives you more freedom to move quickly without having to consider breaking changes or the experience of others. If we see a need for a CLI for our public API we can always transform that part of gpctl.

Also, we're noticing a trend where gpctl might become part of the product down the road, if just for "integrators". There's a lot of functionality in there already that's handy in e.g. a self-hosted context.

@easyCZ easyCZ force-pushed the mp/papi-cmd-yolo branch 2 times, most recently from b3b245b to 74ec921 Compare May 4, 2022 14:30
@roboquat roboquat removed the size/XL label May 4, 2022
@easyCZ
Copy link
Member Author

easyCZ commented May 4, 2022

/werft run without-vm=true

👍 started the job as gitpod-build-mp-papi-cmd-yolo.12
(with .werft/ from main)

@easyCZ easyCZ force-pushed the mp/papi-cmd-yolo branch from 5b99d21 to a25e372 Compare May 5, 2022 05:02
@easyCZ easyCZ marked this pull request as ready for review May 5, 2022 05:02
@easyCZ easyCZ requested a review from a team May 5, 2022 05:02
@github-actions github-actions bot added the team: workspace Issue belongs to the Workspace team label May 5, 2022
@easyCZ
Copy link
Member Author

easyCZ commented May 5, 2022

@csweichel @geropl I've now moved this under gpctl. I've put it under an api directory to slightly better manage code-ownership and allow us to make changes without needing workspace reviews.

@easyCZ easyCZ force-pushed the mp/papi-cmd-yolo branch from 29df69e to d5e7cab Compare May 5, 2022 07:11
@easyCZ easyCZ force-pushed the mp/papi-cmd-yolo branch from d5e7cab to e686610 Compare May 5, 2022 07:24
@laushinka
Copy link
Contributor

laushinka commented May 5, 2022

I've tested this and it works like a charm. Can't wait for this to be merged 😍 Thanks for this, @easyCZ!

Copy link
Contributor

@sagor999 sagor999 left a comment

Choose a reason for hiding this comment

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

LGTM except for a minor nit.

/hold

@easyCZ
Copy link
Member Author

easyCZ commented May 6, 2022

/unhold

@roboquat roboquat merged commit 796f80f into main May 6, 2022
@roboquat roboquat deleted the mp/papi-cmd-yolo branch May 6, 2022 06:55
@roboquat roboquat added deployed: workspace Workspace team change is running in production deployed Change is completely running in production labels May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: workspace Workspace team change is running in production deployed Change is completely running in production release-note-none size/L team: workspace Issue belongs to the Workspace team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants