Path: blob/main/components/local-app/pkg/config/context.go
2500 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package config56import (7"fmt"8"net/url"910"github.com/gitpod-io/local-app/pkg/prettyprint"11"gopkg.in/yaml.v3"12)1314func (c *Config) GetActiveContext() (*ConnectionContext, error) {15if c == nil {16return nil, ErrNoContext17}18if c.ActiveContext == "" {19return nil, ErrNoContext20}21res := c.Contexts[c.ActiveContext]22if res == nil {23return nil, ErrNoContext24}25return res, nil26}2728var ErrNoContext = prettyprint.AddResolution(fmt.Errorf("no active context"),29"sign in using `{gitpod} login`",30"select an existing context using `{gitpod} config use-context`",31"create a new context using `{gitpod} config add-context`",32)3334type ConnectionContext struct {35Host *YamlURL `yaml:"host"`36OrganizationID string `yaml:"organizationID,omitempty"`37Token string `yaml:"token,omitempty"`38}3940type YamlURL struct {41*url.URL42}4344// UnmarshalYAML implements yaml.Unmarshaler45func (u *YamlURL) UnmarshalYAML(value *yaml.Node) error {46var s string47err := value.Decode(&s)48if err != nil {49return err50}5152res, err := url.Parse(s)53if err != nil {54return err55}5657*u = YamlURL{URL: res}58return nil59}6061// MarshalYAML implements yaml.Marshaler62func (u *YamlURL) MarshalYAML() (interface{}, error) {63return u.String(), nil64}656667