Documentation
¶
Overview ¶
Package httpstate implements the logic for interacting with a web backend.
Index ¶
- Constants
- Variables
- func DefaultURL(ws pkgWorkspace.Context) string
- func IsValidAccessToken(ctx context.Context, cloudURL string, insecure bool, accessToken string) (bool, string, []string, *workspace.TokenInformation, error)
- func RenewLeaseFunc(client *client.Client, update client.UpdateIdentifier, ...) ...
- func ValueOrDefaultURL(ws pkgWorkspace.Context, cloudURL string) string
- func WelcomeUser(opts display.Options)
- type AIPromptRequestBody
- type Backend
- type CodeinfraAILanguage
- type DisplayEventType
- type LoginManager
- type MockHTTPBackend
- func (b *MockHTTPBackend) Client() *client.Client
- func (b *MockHTTPBackend) CloudURL() string
- func (b *MockHTTPBackend) NaturalLanguageSearch(ctx context.Context, orgName string, query string) (*apitype.ResourceSearchResponse, error)
- func (b *MockHTTPBackend) PromptAI(ctx context.Context, requestBody AIPromptRequestBody) (*http.Response, error)
- func (b *MockHTTPBackend) RunDeployment(ctx context.Context, stackRef backend.StackReference, ...) error
- func (b *MockHTTPBackend) Search(ctx context.Context, orgName string, ...) (*apitype.ResourceSearchResponse, error)
- func (b *MockHTTPBackend) StackConsoleURL(stackRef backend.StackReference) (string, error)
- type Stack
Constants ¶
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" )
const (
// AccessTokenEnvVar is the environment variable used to bypass a prompt on login.
AccessTokenEnvVar = "CODEINFRA_ACCESS_TOKEN"
)
const CodeinfraAILanguagesClause = "TypeScript, JavaScript, Python, Go, C#, Java, or YAML"
A natural language list of languages supported by Codeinfra AI.
Variables ¶
var CodeinfraAILanguageOptions = []CodeinfraAILanguage{ CodeinfraAILanguageTypeScript, CodeinfraAILanguageJavaScript, CodeinfraAILanguagePython, CodeinfraAILanguageGo, CodeinfraAILanguageCSharp, CodeinfraAILanguageJava, CodeinfraAILanguageYAML, }
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 ValueOrDefaultURL ¶
func ValueOrDefaultURL(ws pkgWorkspace.Context, cloudURL string) string
ValueOrDefaultURL returns the value if specified, or the default cloud URL otherwise.
func WelcomeUser ¶
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.
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 (b *MockHTTPBackend) Search( ctx context.Context, orgName string, queryParams *apitype.CodeinfraQueryRequest, ) (*apitype.ResourceSearchResponse, error)
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.