utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const CIRCLE_CI_APP_HOST_URL = "https://circleci.com"

Variables

View Source
var (
	// Version is the current Git tag (the v prefix is stripped) or the name of
	// the snapshot, if you’re using the --snapshot flag
	Version = "0.0.0-dev"
	// Commit is the current git commit SHA
	Commit = "dirty-local-tree"
)

These vars set by `goreleaser`:

View Source
var ValidARMOrMachineImagesUbuntu2004 = []string{

	"ubuntu-2004:current",
	"ubuntu-2004:edge",
	"ubuntu-2004:2023.04.2",
	"ubuntu-2004:2023.04.1",
	"ubuntu-2004:2023.02.1",
	"ubuntu-2004:2022.10.1",
	"ubuntu-2004:2022.07.1",
	"ubuntu-2004:2022.04.2",
	"ubuntu-2004:2022.04.1",
	"ubuntu-2004:202201-02",
	"ubuntu-2004:202201-01",
	"ubuntu-2004:202111-02",
	"ubuntu-2004:202111-01",
	"ubuntu-2004:202107-02",
	"ubuntu-2004:202104-01",
	"ubuntu-2004:202101-01",
	"ubuntu-2004:202010-01",
}
View Source
var ValidARMOrMachineImagesUbuntu2204 = []string{

	"ubuntu-2204:current",
	"ubuntu-2204:edge",
	"ubuntu-2204:2023.04.2",
	"ubuntu-2204:2023.04.1",
	"ubuntu-2204:2023.02.1",
	"ubuntu-2204:2022.10.2",
	"ubuntu-2204:2022.10.1",
	"ubuntu-2204:2022.07.2",
	"ubuntu-2204:2022.07.1",
	"ubuntu-2204:2022.04.2",
	"ubuntu-2204:2022.04.1",
}

Functions

func AddOffsetToRange

func AddOffsetToRange(rng protocol.Range, offset protocol.Position) protocol.Range

func AllLineContentRange

func AllLineContentRange(lineIndexes []int, content []byte) []protocol.Range

Return the exact range of the text on a all given lines. See LineContentRange for more information

func ArePositionEqual

func ArePositionEqual(a protocol.Position, b protocol.Position) bool

Return true if two positions are identical Two positions are identical if they ave the same line and character.

func AreRangeEqual

func AreRangeEqual(a protocol.Range, b protocol.Range) bool

Return true if two ranges are identical Two ranges are identical if they have the same start and end position

func CheckIfMatrixParamIsPartiallyReferenced

func CheckIfMatrixParamIsPartiallyReferenced(content string) bool

func CheckIfOnlyParamUsed

func CheckIfOnlyParamUsed(content string) bool

Returns true if the string is *only* a parameter Example:

param: << parameters.paramName >> -> true
param: << pipeline.parameters.paramName >> -> true
param: `/home/<< parameters.paramName >>/Downloads` -> false

func CheckIfParamIsPartiallyReferenced

func CheckIfParamIsPartiallyReferenced(content string) (bool, bool)

func ComparePosition

func ComparePosition(a protocol.Position, b protocol.Position) int

Compare two positions. Return 0 if the two position are the same Return 1 if a is before b Return -1 if a is after b

func CreateCodeActionTextEdit

func CreateCodeActionTextEdit(title string, textDocumentUri uri.URI, textEdits []protocol.TextEdit, isPreferred bool) protocol.CodeAction

func CreateDiagnosticFromRange

func CreateDiagnosticFromRange(
	rng protocol.Range,
	severity protocol.DiagnosticSeverity,
	msg string,
	codeAction []protocol.CodeAction,
) protocol.Diagnostic

func CreateEmptyAssignationWarning

func CreateEmptyAssignationWarning(rng protocol.Range) protocol.Diagnostic

func CreateErrorDiagnosticFromNode

func CreateErrorDiagnosticFromNode(node *sitter.Node, msg string) protocol.Diagnostic

func CreateErrorDiagnosticFromRange

func CreateErrorDiagnosticFromRange(rng protocol.Range, msg string) protocol.Diagnostic

func CreateHintDiagnosticFromRange

func CreateHintDiagnosticFromRange(rng protocol.Range, msg string) protocol.Diagnostic

func CreateInformationDiagnosticFromRange

func CreateInformationDiagnosticFromRange(rng protocol.Range, msg string) protocol.Diagnostic

func CreateWarningDiagnosticFromNode

func CreateWarningDiagnosticFromNode(node *sitter.Node, msg string) protocol.Diagnostic

func CreateWarningDiagnosticFromRange

func CreateWarningDiagnosticFromRange(rng protocol.Range, msg string) protocol.Diagnostic

func ExtractParameterName

func ExtractParameterName(parameter string) (string, string)

Given a correct parameter string (example: << parameters.something >>) will return a pair of strings

The first returned value is the full path to the parameter (in example above: parameters.something) The second returned value is the parameter name

func FindInArray

func FindInArray[T comparable](array []T, elem T) int

func GetAllContext

func GetAllContext(lsContext *LsContext, organization string, vcs string, cache *Cache) error

func GetAllProjectEnvVariables

func GetAllProjectEnvVariables(lsContext *LsContext, cache *Cache, cachedFile *CachedFile)

func GetClient

func GetClient() *http.Client

func GetLatestUbuntu2204Image

func GetLatestUbuntu2204Image() string

func GetMachineTrueMessage

func GetMachineTrueMessage(img string) string

func GetOrbCacheFSPath

func GetOrbCacheFSPath(orbYaml string) string

func GetParamNameDefinedAtPos

func GetParamNameDefinedAtPos(parameters map[string]ast.Parameter, pos protocol.Position) string

Search the right parameters that is defined in the given position and return its name

func GetParamNameUsedAtPos

func GetParamNameUsedAtPos(content []byte, position protocol.Position) (string, bool)

Return the name of the parameter used at the given position

func GetParamsInString

func GetParamsInString(content string) ([]struct {
	Name       string
	FullName   string
	ParamRange protocol.Range
}, error)

func GetProjectOrg

func GetProjectOrg(projectSlug string) string

func GetProjectSlug

func GetProjectSlug(configPath string) string

func GetReferencesOfParamInRange

func GetReferencesOfParamInRange(content []byte, paramName string, rng protocol.Range) ([][]int, error)

func GetYAMLBooleanValue

func GetYAMLBooleanValue(str string) bool

func HasStoreTestResultStep

func HasStoreTestResultStep(step []ast.Step) bool

func IndexToPos

func IndexToPos(index int, content []byte) protocol.Position

func IsDefaultRange

func IsDefaultRange(rng protocol.Range) bool

func IsValidYAMLBooleanValue

func IsValidYAMLBooleanValue(str string) bool

func LineContentRange

func LineContentRange(lineIndex int, content []byte) protocol.Range

Return the exact range of the text on a line

For example, with a yaml:

content := `

some-key:
  property: 5

`

LineContentRange(2, []byte(content)) ==> {
	Start: {
	 	Line: 2
		Character: 2
	},
	End: {
		Line: 2,
		Character: 12
  }
}

func NodeAtPos

func NodeAtPos(rootNode *sitter.Node, pos protocol.Position) (*sitter.Node, []*sitter.Node, error)

func PackageManager

func PackageManager() string

func PosInRange

func PosInRange(rng protocol.Range, pos protocol.Position) bool

func PosToIndex

func PosToIndex(pos protocol.Position, content []byte) int

func ToDiagnosticMessage

func ToDiagnosticMessage(message string) string

Diagnostic messages should start with a uppercase letter

Types

type ApiContext

type ApiContext struct {
	Token   string
	HostUrl string
	// contains filtered or unexported fields
}

func (ApiContext) GetUserId

func (apiContext ApiContext) GetUserId() string

func (ApiContext) IsLoggedIn

func (apiContext ApiContext) IsLoggedIn() bool

func (ApiContext) UseDefaultInstance

func (apiContext ApiContext) UseDefaultInstance() bool

type Cache

type Cache struct {
	FileCache          FileCache
	OrbCache           OrbCache
	DockerCache        DockerCache
	DockerTagsCache    DockerTagsCache
	ResourceClassCache ResourceClassCache
	ContextCache       ContextCache
}

func CreateCache

func CreateCache() *Cache

func (*Cache) ClearHostData

func (cache *Cache) ClearHostData()

func (*Cache) RemoveOrbFiles

func (c *Cache) RemoveOrbFiles()

type CachedDockerImage

type CachedDockerImage struct {
	Checked bool
	Exists  bool
}

type CachedDockerTags

type CachedDockerTags struct {
	// A tag to recommended for untagged images
	Recommended string

	// The key of the map are the tag checked and the value is whether this tag exists or not
	CheckedTags map[string]bool
}

type CachedFile

type CachedFile struct {
	TextDocument protocol.TextDocumentItem
	Project      Project
	EnvVariables []string
}

type Client

type Client struct {
	Debug    bool
	Endpoint string
	Host     string
	Token    string
	// contains filtered or unexported fields
}

A Client is an HTTP client for our GraphQL endpoint.

func NewClient

func NewClient(host, endpoint, token string, debug bool) *Client

NewClient returns a reference to a Client.

func (*Client) Reset

func (cl *Client) Reset(host, endpoint, token string, debug bool)

Reset replaces the existing fields with out creating a new client instance

func (*Client) Run

func (cl *Client) Run(request *Request, resp interface{}) error

Run sends an HTTP request to the GraphQL server and deserializes the response or returns an error. TODO(zzak): This function is fairly complex, we should refactor it nolint: gocyclo

type Context

type Context struct {
	Id        string
	Name      string
	CreatedAt string `json:"created_at"`
	// contains filtered or unexported fields
}

type ContextCache

type ContextCache struct {
	// contains filtered or unexported fields
}

func (*ContextCache) AddEnvVariableToOrganizationContext

func (c *ContextCache) AddEnvVariableToOrganizationContext(organizationId string, name string, envVariable string)

func (*ContextCache) GetAllContextOfOrganization

func (c *ContextCache) GetAllContextOfOrganization(organizationId string) map[string]*Context

func (*ContextCache) GetOrganizationContext

func (c *ContextCache) GetOrganizationContext(organizationId string, name string) *Context

func (*ContextCache) RemoveOrganizationContext

func (c *ContextCache) RemoveOrganizationContext(organizationId string, name string)

func (*ContextCache) SetOrganizationContext

func (c *ContextCache) SetOrganizationContext(organizationId string, ctx *Context) *Context

type ContextEnvVariable

type ContextEnvVariable struct {
	Name              string
	AssociatedContext string
}

func GetAllContextEnvVariables

func GetAllContextEnvVariables(lsContext *LsContext, cache *Cache, organizationId string, contexts []string) []ContextEnvVariable

type DockerCache

type DockerCache struct {
	// contains filtered or unexported fields
}

func (*DockerCache) Add

func (c *DockerCache) Add(name string, exists bool) *CachedDockerImage

func (*DockerCache) Get

func (c *DockerCache) Get(name string) *CachedDockerImage

func (*DockerCache) Remove

func (c *DockerCache) Remove(name string)

type DockerTagsCache

type DockerTagsCache struct {
	// contains filtered or unexported fields
}

func (*DockerTagsCache) Add

func (c *DockerTagsCache) Add(namespace, image string, value CachedDockerTags)

func (*DockerTagsCache) Get

func (c *DockerTagsCache) Get(namespace, image string) *CachedDockerTags

type FileCache

type FileCache struct {
	// contains filtered or unexported fields
}

func (*FileCache) AddEnvVariableToProjectLinkedToFile

func (c *FileCache) AddEnvVariableToProjectLinkedToFile(uri protocol.URI, envVariable string)

func (*FileCache) AddProjectSlugToFile

func (c *FileCache) AddProjectSlugToFile(uri protocol.URI, project Project)

func (*FileCache) GetFile

func (c *FileCache) GetFile(uri protocol.URI) *CachedFile

func (*FileCache) GetFiles

func (c *FileCache) GetFiles() map[protocol.URI]*CachedFile

func (*FileCache) RemoveFile

func (c *FileCache) RemoveFile(uri protocol.URI)

func (*FileCache) SetFile

func (c *FileCache) SetFile(cachedFile CachedFile) CachedFile

func (*FileCache) UpdateTextDocument

func (c *FileCache) UpdateTextDocument(uri protocol.URI, textDocument protocol.TextDocumentItem)

type GetAllContextRes

type GetAllContextRes struct {
	Organization struct {
		Id       string
		Contexts struct {
			Edges []struct {
				Node struct {
					Groups struct {
						Edges []struct {
							Node struct {
								Name string
							}
						}
					}
					Id        string
					Name      string
					Resources []struct {
						Variable string
					}
				}
			}
			PageInfo struct {
				HasPreviousPage bool
				HasNextPage     bool
			}
			TotalCount int
		}
	}
}

type LsContext

type LsContext struct {
	Api                ApiContext
	UserIdForTelemetry string
	IsCciExtension     bool
}

type MeRes

type MeRes struct {
	Id    string
	Login string
	Name  string
}

type OrbCache

type OrbCache struct {
	// contains filtered or unexported fields
}

func (*OrbCache) GetOrb

func (c *OrbCache) GetOrb(orbID string) *ast.OrbInfo

func (*OrbCache) HasOrb

func (c *OrbCache) HasOrb(orbID string) bool

func (*OrbCache) RemoveOrb

func (c *OrbCache) RemoveOrb(orbID string)

func (*OrbCache) RemoveOrbs

func (c *OrbCache) RemoveOrbs()

func (*OrbCache) SetOrb

func (c *OrbCache) SetOrb(orb *ast.OrbInfo, orbID string) ast.OrbInfo

func (*OrbCache) UpdateOrbParsedAttributes

func (c *OrbCache) UpdateOrbParsedAttributes(orbID string, parsedOrbAttributes ast.OrbParsedAttributes) ast.OrbParsedAttributes

type Project

type Project struct {
	Slug             string
	Name             string
	Id               string
	OrganizationName string `json:"organization_name"`
	OrganizationSlug string `json:"organization_slug"`
	OrganizationId   string `json:"organization_id"`
	VcsInfo          struct {
		VcsUrl         string `json:"vcs_url"`
		Provider       string
		Default_branch string `json:"default_branch"`
	} `json:"vcs_info"`
}

func GetProjectId

func GetProjectId(projectSlug string, lsContext *LsContext) (Project, error)

type ProjectEnvVariableRes

type ProjectEnvVariableRes struct {
	Items []struct {
		Name  string
		Value string
	}
	NextPageToken string `json:"next_page_token,omitempty"`
}

type Request

type Request struct {
	Query     string                 `json:"query"`
	Variables map[string]interface{} `json:"variables"`

	// Header represent any request headers that will be set
	// when the request is made.
	Header http.Header `json:"-"`
}

Request is a GraphQL request.

func NewRequest

func NewRequest(query string) *Request

NewRequest returns a new GraphQL request.

func (*Request) Encode

func (request *Request) Encode() (bytes.Buffer, error)

Encode will return a buffer of the JSON encoded request body

func (*Request) SetToken

func (request *Request) SetToken(token string)

SetToken sets the Authorization header for the request with the given token.

func (*Request) SetUserId

func (request *Request) SetUserId(userId string)

SetUserId sets the Authorization header for the request with the given user id.

func (*Request) Var

func (request *Request) Var(key string, value interface{})

Var sets a variable.

type ResourceClassCache

type ResourceClassCache struct {
	// contains filtered or unexported fields
}

func (*ResourceClassCache) GetResourceClassOfFile

func (c *ResourceClassCache) GetResourceClassOfFile(uri protocol.URI) []string

func (*ResourceClassCache) SetResourceClassForFile

func (c *ResourceClassCache) SetResourceClassForFile(uri protocol.URI, resourceClass *[]string) *[]string

type Response

type Response struct {
	Data   interface{}
	Errors ResponseErrorsCollection
}

Response wraps the result from our GraphQL server response including out-of-band errors and the data itself.

type ResponseError

type ResponseError struct {
	Message   string
	Locations []struct {
		Line   int
		Column int
	}
	Extensions struct {
		Field         string
		Argument      string
		Value         string
		AllowedValues []string `json:"allowed-values"`
		EnumType      string   `json:"enum-type"`
	}
}

ResponseError represents the key-value pair of data returned by the GraphQL server to represent errors.

type ResponseErrorsCollection

type ResponseErrorsCollection []ResponseError

ResponseErrorsCollection represents a slice of errors returned by the GraphQL server out-of-band from the actual data.

func (ResponseErrorsCollection) Error

func (errs ResponseErrorsCollection) Error() string

Error turns a ResponseErrorsCollection into an acceptable error string that can be printed to the user.

Jump to

Keyboard shortcuts

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