Debian Codegraph @

v1/registration.go

raw
1 package client
2
3 import (
4 "errors"
5 "net/url"
6 )
7
8 // Registration is used to collect data needed by
9 // Enterprise to properly start the registration
10 // Process.
11 type Registration struct {
12 ClusterID string
13 Product string // influxdb, chronograf, telegraf, kapicator
14 // OPTIONAL: Enterprise will redirect the customer back to the
15 // RedirectURL if it is specified.
16 RedirectURL string
17 }
18
19 // IsValid returns an error if the Registration is not valid.
20 // This is necessary since there is no server-side validation
21 // of this data.
22 func (r Registration) IsValid() error {
23 if r.ClusterID == "" || r.Product == "" {
24 return errors.New("You must supply both a ClusterID and a Product!")
25 }
26 return nil
27 }
28
29 // RegistrationURL returns a URL based on the Registration
30 // data provided. The app can then use this URL to direct
31 // customers over to the Enterprise application to complete
32 // their registration.
33 func (c *Client) RegistrationURL(r Registration) (string, error) {
34 err := r.IsValid()
35 if err != nil {
36 return "", err
37 }
38
39 u, _ := url.Parse(c.URL)
40 u.Path = "/start"
41
42 q := u.Query()
43 q.Set("cluster_id", r.ClusterID)
44 q.Set("product", r.Product)
45 if r.RedirectURL != "" {
46 q.Set("redirect_url", r.RedirectURL)
47 }
48 u.RawQuery = q.Encode()
49
50 return u.String(), nil
51 }