Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,7 @@ Examples:
| options | map | no | |
| parameters | key (string) & value (string|array) | no | |
| subrequests | map of requests | no | |
| timeout | duration string | no | 5s |

##### `url`
The URL to fetch the data from. It must be accessible from the server that Glance is running on.
Expand Down Expand Up @@ -1770,6 +1771,11 @@ parameters:
- item2
```

#### `timeout`
The maximum time to wait for the API response. The value is a string and must be a number followed by one of s, m, h, d. Example: 10s for 10 seconds, 1m for 1 minute, etc.

Defaults to `5s`

### Extension
Display a widget provided by an external source (3rd party). If you want to learn more about developing extensions, checkout the [extensions documentation](extensions.md) (WIP).

Expand Down
3 changes: 3 additions & 0 deletions internal/glance/widget-custom-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type CustomAPIRequest struct {
} `yaml:"basic-auth"`
bodyReader io.ReadSeeker `yaml:"-"`
httpRequest *http.Request `yaml:"-"`
Timeout durationField `yaml:"timeout"`
}

type customAPIWidget struct {
Expand Down Expand Up @@ -261,6 +262,8 @@ func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*custom
}

client := ternary(req.AllowInsecure, defaultInsecureHTTPClient, defaultHTTPClient)
client.Timeout = ternary(req.Timeout > 0, time.Duration(req.Timeout), client.Timeout)

resp, err := client.Do(req.httpRequest.WithContext(ctx))
if err != nil {
return nil, err
Expand Down