File: agentutils.go

package info (click to toggle)
glab 1.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,936 kB
  • sloc: sh: 295; makefile: 153; perl: 99; ruby: 68; javascript: 67
file content (41 lines) | stat: -rw-r--r-- 1,084 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
package agentutils

import (
	"net/url"

	gitlab "gitlab.com/gitlab-org/api/client-go"
	"gitlab.com/gitlab-org/cli/pkg/iostreams"
	"gitlab.com/gitlab-org/cli/pkg/tableprinter"
	"gitlab.com/gitlab-org/cli/pkg/utils"
)

const (
	kasProxyProtocol = "https"
	kasProxyEndpoint = "k8s-proxy"
)

func DisplayAllAgents(io *iostreams.IOStreams, agents []*gitlab.Agent) string {
	c := io.Color()
	table := tableprinter.NewTablePrinter()
	table.AddRow(c.Bold("ID"), c.Bold("Name"), c.Bold(c.Gray("Created At")))
	for _, r := range agents {
		table.AddRow(r.ID, r.Name, c.Gray(utils.TimeToPrettyTimeAgo(*r.CreatedAt)))
	}
	return table.Render()
}

func GetKasK8SProxyURL(m *gitlab.Metadata) (string, error) {
	switch {
	case m.KAS.ExternalK8SProxyURL != "":
		return m.KAS.ExternalK8SProxyURL, nil
	default:
		// NOTE: this fallback is only here because m.KAS.ExternalK8SProxyURL was recently introduced with 17.6.
		u, err := url.Parse(m.KAS.ExternalURL)
		if err != nil {
			return "", err
		}
		ku := *u.JoinPath(kasProxyEndpoint)
		ku.Scheme = kasProxyProtocol
		return ku.String(), nil
	}
}