Redash-go-sdk - An SDK for the programmatic management of Redash, in Go

Overview

Redash Go SDK

GitHub release (latest by date) Build Codecov Go Reference Sourcegraph

GitHub Repo stars Twitter Follow

An SDK for the programmatic management of Redash. The main component of the SDK is a client, which is a go wrapper of Redash's REST API.

Usage

Installation

  • TODO add go get instructions

Client Initialization

To initialize the client, you need to know your API key and your Redash address. The Redash address is your server address without protocol and trailing slash /. For example, if your server is on https://localhost:5000/ then you need localhost:5000 as your host.

How to find your API key

After logging in to your Redash instance, go to the profile page:

Profile page button

And then, you can copy your API key in the "Account" tab:

Copy API key

Based on this documentation page.

How to initialize the client

import (
    "fmt"

    redashclient "github.com/recolabs/redash-go-sdk"
    "github.com/recolabs/redash-go-sdk/gen/client"
)

func main() {
    redashClient := redashclient.NewClient(
        "{{.API_KEY}}",
        &client.TransportConfig{
            Host: "{{.HOST_ADDRESS}}",
        })

    // This part is just an example, not required.
    err := redashClient.Administration.Ping()
    if err == nil {
        fmt.Println("Client successfully initialized! Happy Redash-ing.")
    }
}

Queries

List Queries

queries, err := redashClient.Queries.List()

Get Query

queryID := 1
queries, err := redashClient.Queries.Get(1)

Add Query

queryStr := "SELECT * FROM postgres.public.table"
queryName := "swagger query"
queryOptions = `{
        "parameters": []
}`
query, err := queries.NewQuery(queryName, queryOptions, queryStr, 1)
if err != nil {
    fmt.Printf("%v\n", err)
}
responseQuery, err := redashClient.Queries.Add(query)

Archive Query

queryID := 1
err := redashClient.Queries.Archive(1)

Regenerate Query API token

queryID := 1
err := redashClient.Queries.RegenerateQueryAPIKey(1)

DataSources

List DataSource

dataSources, err := redashClient.DataSources.List()

Get DataSource

queryID := 1
queries, err := redashClient.Queries.Get(1)

Add DataSource

import redashclient "github.com/recolabs/redash-go-sdk/datasources"

...

dataSourceType := "pg"
dataSourceName := "test"
postgresqlOptions := `{
    "dbname": "aa",
        "host": "1.1.1.1",
        "port": 5432
}`

ds, err := datasources.NewDataSource(dataSourceType,dataSourceName, postgresqlOptions)
if err != nil {
fmt.Printf("%v\n", err)
}
responseQuery, err := redashClient.Queries.Add(ds)

Delete DataSource

queryID := 1
err := redashClient.DataSources.Delete(queryID)

Visualizations

Get a Visualization's URL

queryID := 1
visualizationID := 1
queryAPIKey := "{API_KEY}"
dataSources, err := redashClient.Visualizations.GetURL(visualizationID, queryID, queryAPIKey)

Add Visualization

import redashclient "github.com/recolabs/redash-go-sdk/visualizations"

...

visualizationType := "CHART"
visualizationName := "test chart"
visualizationOptions := "{}"
description := "test visualization"
queryID := 1

vis, err := visualizations.NewVisualization(visualizationType, visualizationName, visualizationOptions, queryID)
if err != nil {
fmt.Printf("%v\n", err)
}

responseQuery, err := redashClient.Visualizations.Add(vis)

Delete Visualization

queryID := 1
err := redashClient.Visualizations.Delete(queryID)

Users

Get User

userID := 1
dataSources, err := redashClient.Users.Get(userID)

Supported versions

The SDK has been tested against the following Redash versions:

  • 10.1.0

What's included?

  1. Easy to use Go client that covers some parts of the API.
  2. Swagger definition of the Redash API.
  3. Documentation and examples.
  4. Earthly-based build pipeline (lint and test).
  5. Many linters with golangci-lint and good test coverage.

Which parts of the API are covered?

  1. Data Sources
  2. Queries
  3. Visualizations
  4. Users

Note that some of these resources might only be partially covered.

Development

Generating code

Install go-swagger, if you have Homebrew or Linuxbrew run this:

brew tap go-swagger/go-swagger
brew install go-swagger

And then, to generate the client code from the swagger definition, run:

scripts/generate_client.sh

Generating Tests

Generating Test Templates

For each go file you'd like to generate tests for, run:

gotests -w -all file.go

For example:

gotests -w -all users/users.go

Generating mocks

The tests mock the swagger generated code (to avoid the need for a live Redash server for the tests). In order to generate the mocks, run

for dir in $(ls gen/client);do  mockery --dir="gen/client/$dir" --all --output=./mocks/"$dir" --outpkg="$dir"mock; done

View documentation

Install godoc.

go install -v golang.org/x/tools/cmd/godoc@latest

Then run the following if you're on Linux:

godoc -http=localhost:6060 &
xdg-open http://localhost:6060/pkg/github.com/recolabs/redash-go-sdk

MacOS:

godoc -http=localhost:6060 &
open http://localhost:6060/pkg/github.com/recolabs/redash-go-sdk

Linting

We use golangci-lint as our linter aggregator. Our linter configurations are stored in the .golangci.yml file. Run the linters using this command:

golangci-lint run

Testing

Simply run go test -v ./....

Why

We needed a way to programmatically control our self-hosted Redash instance from our backend services - we developed a custom dashboard screen in our product and Redash solved many issues for us, so we decided to use it as both the backend and the Data Analyst query development IDE.

Comments
  • Add data_sources GET(id) and UPDATE(id)

    Add data_sources GET(id) and UPDATE(id)

    Fixes #9

    Proposed Changes

    Add data_sources GET(id) and UPDATE(id).

    Checklist

    • [x] Does it work? Share logs/screenshots if relevant.
    • [ ] Does CI pass?
    • [x] Have you read the contribution guide?
    opened by petercable 2
  • Some dependent libraries are much unmaintained :(

    Some dependent libraries are much unmaintained :(

    While starting to poke through this Redash Go SDK today, something interesting turned up. Two of the Go libraries it uses are unmaintained (one is even archived):

    • https://github.com/PuerkitoBio/urlesc
      • Archived by the project owner. It's pretty doubtful that using this is a good idea.
    • https://github.com/PuerkitoBio/purell
      • It's not archived (yet), instead it has a message saying it's looking for a maintainer to take it over:
      LOOKING FOR A MAINTAINER. I don't use purell these days, and as such I don't give it much attention and
      care.  If you use it in your project(s) and would be interested in taking good care of it, please reach
      out.  See https://github.com/PuerkitoBio/purell/issues/33.
      

    Not a complete blocker, but they should probably be either swapped out for something else, or picked up and carried forward (eg become the maintainer, etc).

    wontfix 
    opened by justinclift 2
  • data_sources.go does not implement `Get`

    data_sources.go does not implement `Get`

    Describe the bug

    The README describes getting a data source but the code is just a copy paste of the Get method for Queries.

    queryID := 1
    queries, err := redashClient.Queries.Get(1)
    

    data_sources.go is missing the Get method entirely.

    To Reproduce

    N/A

    Expected behavior

    data_sources.go implements the Get method and the README is updated to reflect actual usage.

    Notes

    It appears the redash api supports fetching a data source by id:

    {
      "id": 1,
      "name": "fake",
      "type": "clickhouse",
      "syntax": "sql",
      "paused": 0,
      "pause_reason": null,
      "supports_auto_limit": true,
      "options": {
        "dbname": "fake2",
        "password": "--------",
        "url": "http://clickhouse:8123",
        "user": "fake"
      },
      "queue_name": "queries",
      "scheduled_queue_name": "scheduled_queries",
      "groups": {
        "2": false
      },
      "view_only": false
    }
    
    bug 
    opened by petercable 1
  • Update README.md

    Update README.md

    Fixes #7.

    Proposed Changes

    Correct link.

    Checklist

    • [x] Does it work? Share logs/screenshots if relevant.

    image

    • [x] Does CI pass? - no need
    • [x] Have you read the contribution guide? - I wrote it ;)
    documentation 
    opened by ShayNehmad-RecoLabs 1
  • Add some extra documentation

    Add some extra documentation

    Fixes an internal RecoLabs Jira issue RND-2560.

    Proposed Changes

    Nothing special, mostly based on templates.

    • code of conduct
    • badges
    • contribution guidelines

    Checklist

    • [x] Does it work? Share logs/screenshots if relevant.
    • [x] Does CI pass?
    • [x] Have you read the contribution guide?
    documentation 
    opened by ShayNehmad-RecoLabs 1
  • Test coverage: Added coverage file locally and codecov in CI

    Test coverage: Added coverage file locally and codecov in CI

    Signed-off-by: Shay Nehmad [email protected]

    Partially Fixes internal RecoLabs Jira ticket RND-2650.

    Proposed Changes

    See commit.

    Checklist

    • [x] Does it work? Share logs/screenshots if relevant.
    • [x] Does CI pass?
    • [ ] Have you read the contribution guide?
    enhancement 
    opened by ShayNehmad-RecoLabs 1
  • (docs): Update README.md

    (docs): Update README.md

    add a link to the contributing section

    Fixes #.

    Proposed Changes

    PUT THE PROPOSED CHANGE HERE.

    Checklist

    • [ ] Does it work? Share logs/screenshots if relevant.
    • [ ] Does CI pass?
    • [ ] Have you read the contribution guide?
    opened by katz-itai 0
  • fix imports and go format

    fix imports and go format

    Signed-off-by: Shay Nehmad [email protected]

    Fixes build in main.

    Proposed Changes

    Simple formatting issues.

    Checklist

    • [x] Does it work? Share logs/screenshots if relevant.
    • [x] Does CI pass?
    • [x] Have you read the contribution guide? I wrote it 😉
    bug 
    opened by ShayNehmad-RecoLabs 0
  • RND-2650/setup build pipeline

    RND-2650/setup build pipeline

    Added an initial build pipeline with a small version of our internal Earthly file.

    Also:

    • fixed the package name and the go.sum file
    • Linted and tested everything, works (both locally and in Earthly)

    image

    enhancement 
    opened by ShayNehmad-RecoLabs 0
  • update golang/x/text dep to 0.4.0

    update golang/x/text dep to 0.4.0

    includes 0.3.7 a vulnerability: https://security.snyk.io/vuln/SNYK-GOLANG-GOLANGORGXTEXTLANGUAGE-3043869

    Signed-off-by: Yuval Carmon [email protected]

    Fixes #.

    Proposed Changes

    PUT THE PROPOSED CHANGE HERE.

    Checklist

    • [ ] Does it work? Share logs/screenshots if relevant.
    • [x] Does CI pass?
    • [x] Have you read the contribution guide?
    opened by YuvalCarmon-RecoLabs 0
  • Handle pagination better in list calls

    Handle pagination better in list calls

    Describe the bug

    When there are many items (for example queries), list doesn't address pagination correctly.

    To Reproduce

    Steps to reproduce the behavior:

    1. Create many queries
    2. Call ListQueries
    3. Don't get all the results back

    Expected behavior

    List should aggregate and return all the queries.

    Environment data (please complete the following information)

    • Redash Version: 10.1.0
    bug 
    opened by ShayNehmad-RecoLabs 0
Releases(v1.1.0)
  • v1.1.0(Nov 27, 2022)

    What's Changed

    • Update README.md by @ShayNehmad-RecoLabs in https://github.com/RecoLabs/redash-go-sdk/pull/8
    • Add data_sources GET(id) and UPDATE(id) by @petercable in https://github.com/RecoLabs/redash-go-sdk/pull/10
    • fix imports and go format by @ShayNehmad-RecoLabs in https://github.com/RecoLabs/redash-go-sdk/pull/12
    • (docs): Update README.md by @katz-itai in https://github.com/RecoLabs/redash-go-sdk/pull/13

    New Contributors

    • @petercable made their first contribution in https://github.com/RecoLabs/redash-go-sdk/pull/10
    • @katz-itai made their first contribution in https://github.com/RecoLabs/redash-go-sdk/pull/13

    Full Changelog: https://github.com/RecoLabs/redash-go-sdk/compare/v1.0.0...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Jan 18, 2022)

Owner
RecoLabs
Coming soon.
RecoLabs
A go sdk for baidu netdisk open platform 百度网盘开放平台 Go SDK

Pan Go Sdk 该代码库为百度网盘开放平台Go语言的SDK

Jsyz Chen 80 Nov 22, 2022
Nextengine-sdk-go: the NextEngine SDK for the Go programming language

NextEngine SDK for Go nextengine-sdk-go is the NextEngine SDK for the Go programming language. Getting Started Install go get github.com/takaaki-s/nex

null 0 Dec 7, 2021
Commercetools-go-sdk is fork of original commercetools-go-sdk

commercetools-go-sdk The Commercetools Go SDK is automatically generated based on the official API specifications of Commercetools. It should therefor

Flink 0 Dec 13, 2021
Sdk-go - Go version of the Synapse SDK

synapsesdk-go Synapse Protocol's Go SDK. Currently in super duper alpha, do not

null 0 Jan 7, 2022
Identity & Access Management simplified and secure.

IAM Zero Identity & Access Management simplified and secure. ?? Get Started | ?? Support What is IAM Zero? IAM Zero detects identity and access manage

Common Fate 220 Dec 30, 2022
Open Cluster Management API

Open Cluster Management API Community, discussion, contribution, and support Getting Started Prerequisites Security Response The api repository define

Open Cluster Management 216 Dec 23, 2022
RESTful based volume management framework for GlusterFS

Heketi Heketi provides a RESTful management interface which can be used to manage the life cycle of GlusterFS volumes. With Heketi, cloud services lik

null 1 Nov 18, 2020
💾 Wolke API is the API behind Wolke image storage and processing aswell as user management

?? Wolke API Wolke API is the API behind Wolke image storage and processing aswell as user management Deploying To deploy Wolke Bot you'll need podman

wolke.casa 1 Dec 21, 2021
gRPC Network Management Interface

gNMI - gRPC Network Management Interface This repository contains reference Go implementations for gNMI. Note: This is not an official Google product.

OpenConfig 373 Jan 8, 2023
lightweight, self-service AWS IAM management

Contents Overview Architecture Prerequisites Workflow What groups exist? Who do I ask for access? What groups am I in? How do I add group members? How

Mike Hoskins 0 Jan 16, 2022
Khan - An interactive CLI management tool for Nomad

Khan An interactive CLI management tool for Hashicorp's Nomad Why Nomad has a gr

Brandon Fulljames 7 Apr 26, 2022
AWS SDK for the Go programming language.

AWS SDK for Go aws-sdk-go is the official AWS SDK for the Go programming language. Checkout our release notes for information about the latest bug fix

Amazon Web Services 8.1k Dec 31, 2022
A Facebook Graph API SDK For Go.

A Facebook Graph API SDK In Golang This is a Go package that fully supports the Facebook Graph API with file upload, batch request and marketing API.

Huan Du 1.1k Dec 12, 2022
A Golang SDK for Medium's OAuth2 API

Medium SDK for Go This repository contains the open source SDK for integrating Medium's OAuth2 API into your Go app. Install go get github.com/Medium/

Medium 132 Nov 28, 2022
MinIO Client SDK for Go

MinIO Go Client SDK for Amazon S3 Compatible Cloud Storage The MinIO Go Client SDK provides simple APIs to access any Amazon S3 compatible object stor

High Performance, Kubernetes Native Object Storage 1.8k Dec 29, 2022
Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK)

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Rohan Verma 95 Nov 4, 2022
Twilight is an unofficial Golang SDK for Twilio APIs

Twilight is an unofficial Golang SDK for Twilio APIs. Twilight was born as a result of my inability to spell Twilio correctly. I searched for a Twillio Golang client library and couldn’t find any, I decided to build one. Halfway through building this, I realized I had spelled Twilio as Twillio when searching for a client library on Github.

Ghvst Code 18 Jul 2, 2021
Wechat Pay SDK(V3) Write by Go.

WechatPay GO(v3) Introduction Wechat Pay SDK(V3) Write by Go. API V3 of Office document is here. Features Signature/Verify messages Encrypt/Decrypt ce

luoji 23 May 23, 2022
Go Wechaty is a Conversational SDK for Chatbot Makers Written in Go

go-wechaty Connecting Chatbots Wechaty is a RPA SDK for Wechat Individual Account that can help you create a chatbot in 6 lines of Go. Voice of the De

Wechaty 308 Dec 30, 2022