mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Add allow-insecure to custom-api widget
This commit is contained in:
parent
1ef8315462
commit
7276b3d5ef
@ -1293,6 +1293,7 @@ Examples:
|
|||||||
| url | string | yes | |
|
| url | string | yes | |
|
||||||
| headers | key (string) & value (string) | no | |
|
| headers | key (string) & value (string) | no | |
|
||||||
| frameless | boolean | no | false |
|
| frameless | boolean | no | false |
|
||||||
|
| allow-insecure | boolean | no | false |
|
||||||
| template | string | yes | |
|
| template | string | yes | |
|
||||||
| parameters | key (string) & value (string|array) | no | |
|
| parameters | key (string) & value (string|array) | no | |
|
||||||
| subrequests | map of requests | no | |
|
| subrequests | map of requests | no | |
|
||||||
@ -1312,6 +1313,9 @@ headers:
|
|||||||
##### `frameless`
|
##### `frameless`
|
||||||
When set to `true`, removes the border and padding around the widget.
|
When set to `true`, removes the border and padding around the widget.
|
||||||
|
|
||||||
|
##### `allow-insecure`
|
||||||
|
Whether to ignore invalid/self-signed certificates.
|
||||||
|
|
||||||
##### `template`
|
##### `template`
|
||||||
The template that will be used to display the data. It relies on Go's `html/template` package so it's recommended to go through [its documentation](https://pkg.go.dev/text/template) to understand how to do basic things such as conditionals, loops, etc. In addition, it also uses [tidwall's gjson](https://github.com/tidwall/gjson) package to parse the JSON data so it's worth going through its documentation if you want to use more advanced JSON selectors. You can view additional examples with explanations and function definitions [here](custom-api.md).
|
The template that will be used to display the data. It relies on Go's `html/template` package so it's recommended to go through [its documentation](https://pkg.go.dev/text/template) to understand how to do basic things such as conditionals, loops, etc. In addition, it also uses [tidwall's gjson](https://github.com/tidwall/gjson) package to parse the JSON data so it's worth going through its documentation if you want to use more advanced JSON selectors. You can view additional examples with explanations and function definitions [here](custom-api.md).
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ var customAPIWidgetTemplate = mustParseTemplate("custom-api.html", "widget-base.
|
|||||||
// Needs to be exported for the YAML unmarshaler to work
|
// Needs to be exported for the YAML unmarshaler to work
|
||||||
type CustomAPIRequest struct {
|
type CustomAPIRequest struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
AllowInsecure bool `json:"allow-insecure"`
|
||||||
Headers map[string]string `json:"headers"`
|
Headers map[string]string `json:"headers"`
|
||||||
Parameters queryParametersField `json:"parameters"`
|
Parameters queryParametersField `json:"parameters"`
|
||||||
httpRequest *http.Request `yaml:"-"`
|
httpRequest *http.Request `yaml:"-"`
|
||||||
@ -125,7 +126,8 @@ func (data *customAPITemplateData) Subrequest(key string) *customAPIResponseData
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchCustomAPIRequest(ctx context.Context, req *CustomAPIRequest) (*customAPIResponseData, error) {
|
func fetchCustomAPIRequest(ctx context.Context, req *CustomAPIRequest) (*customAPIResponseData, error) {
|
||||||
resp, err := defaultHTTPClient.Do(req.httpRequest.WithContext(ctx))
|
client := ternary(req.AllowInsecure, defaultInsecureHTTPClient, defaultHTTPClient)
|
||||||
|
resp, err := client.Do(req.httpRequest.WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user