-
Notifications
You must be signed in to change notification settings - Fork 13
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
Experimental: Add support to create the Tanzu Hub client #175
Conversation
Have you thought about where instructions/tooling pertaining to generation of query stubs from Hub schema should reside. |
fd49571
to
ef08f99
Compare
ef08f99
to
ede63d2
Compare
ede63d2
to
316d2ff
Compare
client/hub/README.md
Outdated
To create a Tanzu Hub client, plugin authors can just use the `CreateHubClient(contextName string)` API | ||
by providing the `tanzu` context name. An authenticated Tanzu Hub client for the specified tanzu context will be returned. | ||
This client includes an authenticated GraphQLClient from the `github.com/Khan/genqlient` | ||
that can be used to do GraphQL queries. Internally it configures the client with a CSP access token for each request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a CSP access token -> an access token
do we have plans to auto-refresh the token? Given the CLI single command invocation use case (assuming we are not dealing with very long-running operations), this might not be too relevant.
If we are open to the possibility, it might be worth mentioning here and add a TODO in client.go
Also worth mentioning (especially for folks jumping to this doc mostly to learn about hub client integration) that the client if authenticated is assured at least 10-15m access to the graphQL endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
If you are thinking of address the comments in this change.
I would also suggest updating README.md to mention the EXPERIMENTAL nature of the hub client introduction
|
||
TANZU_HUB_PKG_BASE_DIR ?= $(ROOT_DIR)/pkg | ||
TANZU_HUB_PKG_DIR=$(TANZU_HUB_PKG_BASE_DIR)/hub | ||
TANZU_HUB_INIT_FILES := queries.graphql main.go genqlient.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I wonder if we should put (commented out) a very simple example query in queries.graphql.
8808def
to
0344e49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool! Nice way to help project use the client.
Some questions to help me confirm I understood things properly.
for filename in $(TANZU_HUB_INIT_FILES); do \ | ||
[ -f $(TANZU_HUB_PKG_DIR)/$$filename ] && echo "Skipping $(TANZU_HUB_PKG_DIR)/$$filename (already exists)" || wget -O "$(TANZU_HUB_PKG_DIR)/$(filename)" $(TANZU_HUB_INIT_PKG_URL)/$$filename ; \ | ||
done | ||
wget -O "$(TANZU_HUB_PKG_DIR)/schema.graphql" $(TANZU_HUB_SCHEMA_FILE_URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is the schema. I assume it should not be modified by the local project?
- should it be checked-in to git? mine is 98k lines
- can this schema change?
- should a new version be fetched each time the code is compiled? Or should the project dev run
make tanzu-hub-stub-init
once in a while to refresh? or do we not need to re-download at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It does not harm to check in that file in the plugin repository as plugins can manage how it should be consumed and when it needs to be updated. But as schema can change, I don't think we should check it into this repository.
- Yes it can change.
- The expectation at the moment is to run the
make tanzu-hub-stub-init
to refresh the schema file.
.PHONY: tanzu-hub-stub-init | ||
tanzu-hub-stub-init: # Initialize a Tanzu Hub package with stub, schema.graphql and queries.graphql to generate graphQL client APIs | ||
mkdir -p $(TANZU_HUB_PKG_DIR) | ||
for filename in $(TANZU_HUB_INIT_FILES); do \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these three files are stubs but once created, the user may modify then so we don't want to overwrite them, correct? Or is it only queries.graphql
that we need to "protect"? Could the user want to regenerate the other files to update them to a new TPR release? In such a case, how about putting the files that can be changed under a generated/
directory that the user can delete at any time and then run make tanzu-hub-stub-init
again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need time to think about this a bit more. Considering this is an experimental feature, we should be okay to do this change later as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is great!
I'll let you decide what you want to do about the comments as I just started playing with this.
LGTM whatever you decide.
6cd3581
to
764fec1
Compare
…u#175) - Adds support to create authenticated Tanzu Hub client for the specified tanzu context - The Tanzu Hub client exposes a graphQL client implemented using github.com/Khan/genqlient/graphql to query the hub resources with graphQL APIs. - Also provides a Makefile to help plugin authors initialize and generate the stub for the graphQL queries.
- Adds support to create authenticated Tanzu Hub client for the specified tanzu context - The Tanzu Hub client exposes a graphQL client implemented using github.com/Khan/genqlient/graphql to query the hub resources with graphQL APIs. - Also provides a Makefile to help plugin authors initialize and generate the stub for the graphQL queries.
What this PR does / why we need it
github.com/Khan/genqlient/graphql
to query the hub resources with graphQL APIs.Which issue(s) this PR fixes
Fixes #
Describe testing done for PR
Release note
Additional information
Special notes for your reviewer