Example of using client-go with self-hosted Grafeas instance?

48 views
Skip to first unread message

laf...@gmail.com

unread,
Jun 18, 2020, 9:21:29 AM6/18/20
to Grafeas Users
Hi,

I'm trying to make use of the client-go, https://github.com/grafeas/client-go, library to work with a self-hosted instance of Grafeas (running in my Kubernetes cluster, based on the provided helm charts).

Is there any worked example of how to do this, as it's not clear how to get started with it the client library?

Otherwise, I can build my own client integration with the backend over raw HTTP, but I'd like to avoid recreating any wheels.

Happy to answer any questions if this isn't enough info. Really appreciate any help.

Cheers
Barry

laf...@gmail.com

unread,
Jun 18, 2020, 12:58:44 PM6/18/20
to Grafeas Users
In particular, I'm not sure on what to pass as `parent` to the method `GrafeasV1Beta1ApiService.ListNotes`

I have something that looks like this:

import(
    "context"
    "fmt"
    v1beta1 "github.com/grafeas/client-go/0.1.0"
)

func main
() {
    config
:= v1beta1.NewConfiguration()
    config
.BasePath = "http://localhost:9090" // port-forwarding using kubectl
    client
:= v1beta1.NewAPIClient(config)
    request_ctx := context.Background()


    api_resp, http_resp, err := client.GrafeasV1Beta1Api.ListNotes(ctx, "myproj", &v1beta1.ListNotesOpts{}) 
    if err != nil {                                                                                                      
        fmt.Println("error getting note", err)                                                                           
    } else {
        fmt.Println(api_resp)
        fmt.Println(http_resp)
    }
}


Which returns `"error getting note 404 Not Found"`. The 404 makes me think that it's sending _something_ to the grafeas server, but the path is badly formatted.

If I construct the request manually on the CLI with curl, this works:


So I would expect the client-go library to construct a request that looks broadly similar.

Digging further into the documentation here, https://github.com/grafeas/client-go/blob/master/0.1.0/docs/GrafeasV1Beta1Api.md#listnotes

parentstringThe name of the project to list notes for in the form of `projects/[PROJECT_ID]`.

I've tried passing in my parent string a "projects/myproj" but with the same 404 outcome.



 localVarPath
:= a.client.cfg.BasePath + "/v1beta1/{parent=projects/*}/notes"
 localVarPath
= strings.Replace(localVarPath, "{"+"parent"+"}", fmt.Sprintf("%v", parent), -1)


I'm afraid I'm just not sure how to read this path manipulation, but from what I can tell, it doesn't actually do anything with the `parent` parameter.

`localVarPath` is first instantiated as "http://localhost:9090/v1beta1/{parent=projects/*}/notes" and then the Replace function tries to replease `"{"+"parent"+"}"` (="{parent}") with my argument `parent` (= "projects/krypton"). But (unless I'm completely misunderstanding the intent of this line, or how golang string manipluations work) this doesn't do anything, since "{parent}" doesn't exist in the initial string.

Hence, the request seems to be sent to the path `http://localhost:9090/v1beta1/{parent=projects/*}/notes`, which correctly returns a 404.

Am I missing something obvious here? I haven't tried working through any of the other methods exposed in `GrafeasV1Beta1ApiService`, but judging by the code I would expect the same to happen.

Wiktor Kozlik

unread,
Jun 19, 2020, 9:48:44 AM6/19/20
to Grafeas Users
This is a known issue (https://github.com/grafeas/client-go/issues/13) rooted in differences between OpenAPI used by Swagger and GoogleAPI. There is a work in progress to address this issue - https://github.com/grafeas/client-go/pull/15

laf...@gmail.com

unread,
Jun 19, 2020, 2:17:12 PM6/19/20
to Grafeas Users
Thanks for the response Wiktor!

So... until the PR https://github.com/grafeas/client-go/pull/15/files is merged, should I just assume that this client library is broken?

I can fork the repo and manually update the strings `{parent=projects/*}` to `{parent}` in the generated code? Unless there's some other recommended workaround that you would recommend?

Wiktor Kozlik

unread,
Jun 22, 2020, 9:58:12 AM6/22/20
to Grafeas Users
You, the client library is currently broken. Your approach sounds reasonable as a short term solution.
Reply all
Reply to author
Forward
0 new messages