apache / openwhisk-client-go

Go client library for the Apache OpenWhisk platform
https://openwhisk.apache.org/
Apache License 2.0
35 stars 44 forks source link

How can I specify "--insecure" using this library? #131

Open ukulililixl opened 4 years ago

ukulililixl commented 4 years ago

I install openwhisk in ubuntu in my own computer and I can access it using wsk -i ....... However, I have problems using this library to access openwhisk.

For example: I can run the following command to list all the actions I have created in openwhisk. wsk -i action list The output is

actions
/guest/test                                                          private blackbox

However, when I try to do the same thing in a GO program using this library, something wrong happens. Here are my codes:

config := &whisk.Config{
                Host: "http://172.17.0.1",
        Version: "v1",
        Verbose: true,
        Namespace: "_",
        AuthToken: "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP",
        Debug: true,
        Insecure: true,
    }
client, err := whisk.NewClient(http.DefaultClient, config)

if err != nil {
    fmt.Println(err)
    os.Exit(-1)
}

options := &whisk.ActionListOptions{
        Limit: 30,
    Skip: 0,
}

actions, resp, err := client.Actions.List("",options)
if err != nil {
        fmt.Println(err)
        os.Exit(-1)
}
fmt.Println("Returned with status: ", resp.Status)
fmt.Println("Returned actions: \n%+v", actions)

The error message is:

The resource requires authentication, which was not supplied with the request (code df76048ef1abc23514e2a73aa26c910b)

I wonder if I did something wrong in the GO program. Thanks!

ukulililixl commented 4 years ago

The problem is fixed. I just use ~/.wskprop and set AUTH as well as APIHOST in it. Then I can access openwhisk using the following codes:

client, _ := whisk.NewClient(http.DefaultClient, nil)
options := &whisk.ActionListOptions{
      Limit: 30,
      Skip: 0,
}
actions, resp, err := client.Actions.List("", options)

New question is, why there is no need to specify something like "--insecure"?

rabbah commented 4 years ago

Hello. The first comment shows you’re using http as your app host. Is that correct? If so the insecure option has no effect.

The second comment is puzzling to me as you should be able to use the client without a WskProps file at all.

ukulililixl commented 4 years ago

Hello. The first comment shows you’re using http as your app host. Is that correct? If so the insecure option has no effect.

The second comment is puzzling to me as you should be able to use the client without a WskProps file at all.

For the first comment, when I remove the configuration of Insecure: true in config, I get the following error:

Get https://172.17.0.1/api/v1/namespaces/_/actions?limit=30&skip=0: x509: cannot validate certificate for 172.17.0.1 because it doesn't contain any IP SANs

I don't know why it is still trying to access openwhisk via https even if I configure http in Host.

For the second comment, I try to remove ~/.wskprops and re-run the program and it fails. It seems that when we create a new client, GetDefaultConfig is called to load default configurations. I guess this function will load data from ~/.wskprops by default.