File: gob_settings.go

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (43 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download
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
package api

import (
	"fmt"
	"net/url"
)

var (
	errDetailsNotSpecified    = fmt.Errorf("gob details not specified")
	errBackendNotSpecified    = fmt.Errorf("gob backend not specified")
	errIncorrectBackendScheme = fmt.Errorf("gob only supports http/https protocols")
)

// GOBSettings holds the configuration for proxying a request to the upstream
// GitLab Observability Backend
type GOBSettings struct {
	// The location of the GitLab Observability Backend (GOB) instance to connect to.
	Backend string `json:"backend"`
	// Any headers (e.g., Authorization) to send with the upstream request
	Headers map[string]string `json:"headers"`
}

// Upstream returns the GitLab Observability Backend location
func (g *GOBSettings) Upstream() (*url.URL, error) {
	if g == nil {
		return nil, errDetailsNotSpecified
	}

	if g.Backend == "" {
		return nil, errBackendNotSpecified
	}

	u, err := url.Parse(g.Backend)
	if err != nil {
		return nil, err
	}

	if u.Scheme != "http" && u.Scheme != "https" {
		return nil, errIncorrectBackendScheme
	}

	return u, nil
}