github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/config/data.go (about)

     1  package config
     2  
     3  import (
     4  	"golang.org/x/oauth2"
     5  
     6  	"github.com/kubeshop/testkube/pkg/oauth"
     7  )
     8  
     9  type ContextType string
    10  
    11  const (
    12  	ContextTypeCloud      ContextType = "cloud"
    13  	ContextTypeKubeconfig ContextType = "kubeconfig"
    14  
    15  	TokenTypeOIDC = "oidc"
    16  	TokenTypeAPI  = "api"
    17  )
    18  
    19  type CloudContext struct {
    20  	EnvironmentId    string `json:"environment,omitempty"`
    21  	EnvironmentName  string `json:"environmentName,omitempty"`
    22  	OrganizationId   string `json:"organization,omitempty"`
    23  	OrganizationName string `json:"organizationName,omitempty"`
    24  	ApiKey           string `json:"apiKey,omitempty"`
    25  	RefreshToken     string `json:"refreshToken,omitempty"`
    26  	ApiUri           string `json:"apiUri,omitempty"`
    27  	AgentKey         string `json:"agentKey,omitempty"`
    28  	AgentUri         string `json:"agentUri,omitempty"`
    29  	RootDomain       string `json:"rootDomain,omitempty"`
    30  	UiUri            string `json:"uiUri,omitempty"`
    31  	TokenType        string `json:"tokenType,omitempty"`
    32  }
    33  
    34  type Data struct {
    35  	TelemetryEnabled bool       `json:"telemetryEnabled,omitempty"`
    36  	Namespace        string     `json:"namespace,omitempty"`
    37  	Initialized      bool       `json:"initialized,omitempty"`
    38  	APIURI           string     `json:"apiURI,omitempty"`
    39  	APIServerName    string     `json:"apiServerName,omitempty"`
    40  	APIServerPort    int        `json:"apiServerPort,omitempty"`
    41  	DashboardName    string     `json:"dashboardName,omitempty"`
    42  	DashboardPort    int        `json:"dashboardPort,omitempty"`
    43  	OAuth2Data       OAuth2Data `json:"oauth2Data"`
    44  
    45  	ContextType  ContextType  `json:"contextType,omitempty"`
    46  	CloudContext CloudContext `json:"cloudContext,omitempty"`
    47  	Master       Master       `json:"master,omitempty"`
    48  }
    49  
    50  func (c *Data) EnableAnalytics() {
    51  	c.TelemetryEnabled = true
    52  }
    53  
    54  func (c *Data) DisableAnalytics() {
    55  	c.TelemetryEnabled = false
    56  }
    57  
    58  func (c *Data) SetNamespace(ns string) {
    59  	c.Namespace = ns
    60  }
    61  
    62  func (c *Data) SetInitialized() {
    63  	c.Initialized = true
    64  }
    65  
    66  // OAuth2Data contains oauth credentials
    67  type OAuth2Data struct {
    68  	Enabled      bool               `json:"enabled,omitempty"`
    69  	Token        *oauth2.Token      `json:"token,omitempty"`
    70  	ClientID     string             `json:"clientID,omitempty"`
    71  	ClientSecret string             `json:"clientSecret,omitempty"`
    72  	Provider     oauth.ProviderType `json:"providerType,omitempty"`
    73  	Scopes       []string           `json:"scopes"`
    74  }
    75  
    76  // EnableOAuth is oauth enable method
    77  func (c *Data) EnableOAuth() {
    78  	c.OAuth2Data.Enabled = true
    79  }
    80  
    81  // DisableOauth is oauth disable method
    82  func (c *Data) DisableOauth() {
    83  	c.OAuth2Data.Enabled = false
    84  }