File: registration.go

package info (click to toggle)
golang-github-influxdb-usage-client 0.0~git20151204.0.475977e-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 152 kB
  • sloc: makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,274 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package client

import (
	"errors"
	"net/url"
)

// Registration is used to collect data needed by
// Enterprise to properly start the registration
// Process.
type Registration struct {
	ClusterID string
	Product   string // influxdb, chronograf, telegraf, kapicator
	// OPTIONAL: Enterprise will redirect the customer back to the
	// RedirectURL if it is specified.
	RedirectURL string
}

// IsValid returns an error if the Registration is not valid.
// This is necessary since there is no server-side validation
// of this data.
func (r Registration) IsValid() error {
	if r.ClusterID == "" || r.Product == "" {
		return errors.New("You must supply both a ClusterID and a Product!")
	}
	return nil
}

// RegistrationURL returns a URL based on the Registration
// data provided. The app can then use this URL to direct
// customers over to the Enterprise application to complete
// their registration.
func (c *Client) RegistrationURL(r Registration) (string, error) {
	err := r.IsValid()
	if err != nil {
		return "", err
	}

	u, _ := url.Parse(c.URL)
	u.Path = "/start"

	q := u.Query()
	q.Set("cluster_id", r.ClusterID)
	q.Set("product", r.Product)
	if r.RedirectURL != "" {
		q.Set("redirect_url", r.RedirectURL)
	}
	u.RawQuery = q.Encode()

	return u.String(), nil
}