Skip to content

Commit

Permalink
docs: fix clients examples to use api key
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
  • Loading branch information
lampajr committed Dec 11, 2024
1 parent 41c1fa5 commit 10deee5
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions docs/site/content/en/docs/Reference/horreum-clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ through the `HorreumClient` instance. Therefore, the interaction with the raw cl

## Prerequisites

In the below sections you can find some usage examples for both clients, the only precondition is that you must have Horreum server up and running (and accessible).
In the below sections you can find some usage examples for both clients, here the prerequisites to properly running below examples:

You can find more details on how to setup Horreum server in the [Get Started](/docs/tutorials/get-started) section.
1. You must have Horreum server up and running (and accessible). You can find more details on how to setup Horreum server in the [Get Started](/docs/tutorials/get-started) section.
2. Generate an API key following these [instructions](/docs/tasks/api-keys/#api-key-creation). Then replace `HUSR_00000000_0000_0000_0000_000000000000` with your generated key.

## Python Client

Expand All @@ -35,15 +36,23 @@ import asyncio
> `asyncio` is required because the client leverages it to perform async requests to the server.
```python
from horreum import new_horreum_client, HorreumCredentials
from horreum import new_horreum_client, ClientConfiguration, AuthMethod, HorreumCredentials
```

> `new_horreum_client` utility function to setup the `HorreumClient` instance
Initialize the Horreum client

```python
client = await new_horreum_client(base_url="http://localhost:8080", credentials=HorreumCredentials(username=username, password=password))
client = await new_horreum_client(
base_url="http://localhost:8080",
credentials=HorreumCredentials(
apikey="HUSR_00000000_0000_0000_0000_000000000000"
),
client_config=ClientConfiguration(
auth_method=AuthMethod.API_KEY
)
)
```

Now let's start playing with it
Expand Down Expand Up @@ -71,29 +80,28 @@ go get github.com/hyperfoil/horreum-client-golang
Import required Go libraries
```go
import (
"github.com/hyperfoil/horreum-client-golang/pkg/horreum"
"github.com/hyperfoil/horreum-client-golang/pkg/horreum"
)
```

Define username and password

```go
var (
username = "user"
password = "secret"
apiKey = "HUSR_00000000_0000_0000_0000_000000000000"
)
```

Initialize the Horreum client

```go
client, err := horreum.NewHorreumClient("http://localhost:8080",
&horreum.HorreumCredentials{
Username: &username,
Password: &password,
},
nil,
)
client, err := horreum.NewHorreumClient("http://localhost:8080",
&horreum.HorreumCredentials{
ApiKey: &apiKey,
}, &horreum.ClientConfiguration{
AuthMethod: horreum.API_KEY,
})

if err != nil {
log.Fatalf("error creating Horreum client: %s", err.Error())
}
Expand Down

0 comments on commit 10deee5

Please sign in to comment.