httpstate

package
v3.0.0-...-a5432f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 63 Imported by: 0

Documentation

Overview

Package httpstate implements the logic for interacting with a web backend.

Index

Constants

View Source
const (
	// ConsoleDomainEnvVar overrides the way we infer the domain we assume the Codeinfra Console will
	// be served from, and instead just use this value. e.g. so links to the stack update go to
	// https://codeinfra.example.com/org/project/stack/updates/2 instead.
	ConsoleDomainEnvVar = "CODEINFRA_CONSOLE_DOMAIN"

	// CodeinfraCloudURL is the Cloud URL used if no environment or explicit cloud is chosen.
	CodeinfraCloudURL = "https://" + defaultAPIDomainPrefix + "codeinfra.com"
)
View Source
const (

	// AccessTokenEnvVar is the environment variable used to bypass a prompt on login.
	AccessTokenEnvVar = "CODEINFRA_ACCESS_TOKEN"
)
View Source
const CodeinfraAILanguagesClause = "TypeScript, JavaScript, Python, Go, C#, Java, or YAML"

A natural language list of languages supported by Codeinfra AI.

Variables

All of the languages supported by Codeinfra AI.

Functions

func DefaultURL

func DefaultURL(ws pkgWorkspace.Context) string

DefaultURL returns the default cloud URL. This may be overridden using the CODEINFRA_API environment variable. If no override is found, and we are authenticated with a cloud, choose that. Otherwise, we will default to the https://api.codeinfra.com/ endpoint.

func IsValidAccessToken

func IsValidAccessToken(ctx context.Context, cloudURL string,
	insecure bool, accessToken string,
) (bool, string, []string, *workspace.TokenInformation, error)

IsValidAccessToken tries to use the provided Codeinfra access token and returns if it is accepted or not. Returns error on any unexpected error.

func RenewLeaseFunc

func RenewLeaseFunc(
	client *client.Client, update client.UpdateIdentifier, assumedExpires func() time.Time,
) func(ctx context.Context, duration time.Duration, currentToken string) (string, time.Time, error)

func ValueOrDefaultURL

func ValueOrDefaultURL(ws pkgWorkspace.Context, cloudURL string) string

ValueOrDefaultURL returns the value if specified, or the default cloud URL otherwise.

func WelcomeUser

func WelcomeUser(opts display.Options)

WelcomeUser prints a Welcome to Codeinfra message.

Types

type AIPromptRequestBody

type AIPromptRequestBody struct {
	Language       CodeinfraAILanguage `json:"language"`
	Instructions   string              `json:"instructions"`
	ResponseMode   string              `json:"responseMode"`
	ConversationID string              `json:"conversationId"`
	ConnectionID   string              `json:"connectionId"`
}

type Backend

type Backend interface {
	backend.Backend

	CloudURL() string

	StackConsoleURL(stackRef backend.StackReference) (string, error)
	Client() *client.Client

	RunDeployment(ctx context.Context, stackRef backend.StackReference, req apitype.CreateDeploymentRequest,
		opts display.Options, deploymentInitiator string, streamDeploymentLogs bool) error

	// Queries the backend for resources based on the given query parameters.
	Search(
		ctx context.Context, orgName string, queryParams *apitype.CodeinfraQueryRequest,
	) (*apitype.ResourceSearchResponse, error)
	NaturalLanguageSearch(
		ctx context.Context, orgName string, query string,
	) (*apitype.ResourceSearchResponse, error)
	PromptAI(ctx context.Context, requestBody AIPromptRequestBody) (*http.Response, error)
}

Backend extends the base backend interface with specific information about cloud backends.

func New

func New(d diag.Sink, cloudURL string, project *workspace.Project, insecure bool) (Backend, error)

New creates a new Codeinfra backend for the given cloud API URL and token.

type CodeinfraAILanguage

type CodeinfraAILanguage string
const (
	CodeinfraAILanguageTypeScript CodeinfraAILanguage = "TypeScript"
	CodeinfraAILanguageJavaScript CodeinfraAILanguage = "JavaScript"
	CodeinfraAILanguagePython     CodeinfraAILanguage = "Python"
	CodeinfraAILanguageGo         CodeinfraAILanguage = "Go"
	CodeinfraAILanguageCSharp     CodeinfraAILanguage = "C#"
	CodeinfraAILanguageJava       CodeinfraAILanguage = "Java"
	CodeinfraAILanguageYAML       CodeinfraAILanguage = "YAML"
)

func (*CodeinfraAILanguage) Set

func (e *CodeinfraAILanguage) Set(v string) error

func (*CodeinfraAILanguage) String

func (e *CodeinfraAILanguage) String() string

func (*CodeinfraAILanguage) Type

func (e *CodeinfraAILanguage) Type() string

type DisplayEventType

type DisplayEventType string
const (
	UpdateEvent   DisplayEventType = "UpdateEvent"
	ShutdownEvent DisplayEventType = "Shutdown"
)

type LoginManager

type LoginManager interface {
	// Current returns the current cloud backend if one is already logged in.
	Current(ctx context.Context, cloudURL string, insecure, setCurrent bool) (*workspace.Account, error)

	// Login logs into the target cloud URL and returns the cloud backend for it.
	Login(
		ctx context.Context,
		cloudURL string,
		insecure bool,
		command string,
		message string,
		welcome func(display.Options),
		current bool,
		opts display.Options,
	) (*workspace.Account, error)
}

LoginManager provides a slim wrapper around functions related to backend logins.

func NewLoginManager

func NewLoginManager() LoginManager

NewLoginManager returns a LoginManager for handling backend logins.

type MockHTTPBackend

type MockHTTPBackend struct {
	backend.MockBackend
	FClient   func() *client.Client
	FCloudURL func() string
	FSearch   func(ctx context.Context,
		orgName string,
		queryParams *apitype.CodeinfraQueryRequest,
	) (*apitype.ResourceSearchResponse, error)
	FNaturalLanguageSearch func(ctx context.Context, orgName string, query string) (*apitype.ResourceSearchResponse, error)
	FPromptAI              func(ctx context.Context, requestBody AIPromptRequestBody) (*http.Response, error)
	FStackConsoleURL       func(stackRef backend.StackReference) (string, error)
	FRunDeployment         func(
		ctx context.Context,
		stackRef backend.StackReference,
		req apitype.CreateDeploymentRequest,
		opts display.Options,
		deploymentInitiator string,
		suppressStreamLogs bool,
	) error
}

func (*MockHTTPBackend) Client

func (b *MockHTTPBackend) Client() *client.Client

func (*MockHTTPBackend) CloudURL

func (b *MockHTTPBackend) CloudURL() string

func (*MockHTTPBackend) NaturalLanguageSearch

func (b *MockHTTPBackend) NaturalLanguageSearch(
	ctx context.Context, orgName string, query string,
) (*apitype.ResourceSearchResponse, error)

func (*MockHTTPBackend) PromptAI

func (b *MockHTTPBackend) PromptAI(
	ctx context.Context, requestBody AIPromptRequestBody,
) (*http.Response, error)

func (*MockHTTPBackend) RunDeployment

func (b *MockHTTPBackend) RunDeployment(
	ctx context.Context,
	stackRef backend.StackReference,
	req apitype.CreateDeploymentRequest,
	opts display.Options,
	deploymentInitiator string,
	suppressStreamLogs bool,
) error

func (*MockHTTPBackend) Search

func (*MockHTTPBackend) StackConsoleURL

func (b *MockHTTPBackend) StackConsoleURL(stackRef backend.StackReference) (string, error)

type Stack

type Stack interface {
	backend.Stack
	OrgName() string                            // the organization that owns this stack.
	CurrentOperation() *apitype.OperationStatus // in progress operation, if applicable.
	StackIdentifier() client.StackIdentifier
}

Stack is a cloud stack. This simply adds some cloud-specific properties atop the standard backend stack interface.

Directories

Path Synopsis
Package client implements a client for the Codeinfra Service HTTP/REST API.
Package client implements a client for the Codeinfra Service HTTP/REST API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL