forked from grafana/grizzly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to grafana-openapi-client-go (grafana#262)
* Add grafana-openapi-client-go, add to provider * Update unit test for rules and workflow * folders use Grafana golang api * datasources use Grafana golang api * dashboards use Grafana golang api * Remove code that is dead due to previous changes * Unit test fixes
- Loading branch information
Showing
22 changed files
with
489 additions
and
960 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package grafana | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"os" | ||
|
||
gclient "github.com/grafana/grafana-openapi-client-go/client" | ||
) | ||
|
||
func GetClient() (*gclient.GrafanaHTTPAPI, error) { | ||
grafanaURL, exists := os.LookupEnv("GRAFANA_URL") | ||
if !exists { | ||
return nil, fmt.Errorf("require GRAFANA_URL (optionally GRAFANA_TOKEN & GRAFANA_USER)") | ||
} | ||
parsedUrl, err := url.Parse(grafanaURL) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid Grafana URL") | ||
} | ||
|
||
transportConfig := gclient.DefaultTransportConfig().WithHost(parsedUrl.Host).WithSchemes([]string{parsedUrl.Scheme}) | ||
if token, exists := os.LookupEnv("GRAFANA_TOKEN"); exists { | ||
if user, exists := os.LookupEnv("GRAFANA_USER"); exists { | ||
transportConfig.BasicAuth = url.UserPassword(user, token) | ||
} else { | ||
transportConfig.APIKey = token | ||
} | ||
} | ||
grafanaClient := gclient.NewHTTPClientWithConfig(nil, transportConfig) | ||
return grafanaClient, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.