utils

package
v2.34.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 60 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBlueprintsRepo is the default repository for blueprints.
	DefaultBlueprintsRepo = "github.com/fluxninja/aperture/blueprints"
	// DefaultDashboardsRepo is the default repository for dashboards.
	DefaultDashboardsRepo = "github.com/fluxninja/aperture/dashboards"
	// LatestTag is the tag for the latest version of blueprints.
	LatestTag = "latest"
)

Variables

View Source
var (
	// AllowDeprecated is a flag to allow deprecated blueprints to be listed.
	AllowDeprecated = false

	// AperturectlRootDir is the root directory for aperturectl.
	AperturectlRootDir = ".aperturectl"
	// BlueprintsCacheRoot is the root directory for blueprints cache.
	BlueprintsCacheRoot = filepath.Join(AperturectlRootDir, "blueprints")
	// BuilderCacheRoot is the root directory for builder cache.
	BuilderCacheRoot = filepath.Join(AperturectlRootDir, "build")
)

Functions

func ApplyDynamicConfigUsingAPI added in v2.18.0

func ApplyDynamicConfigUsingAPI(client SelfHostedPolicyClient, dynamicConfigYAML map[string]interface{}, policyName string) error

ApplyDynamicConfig applies the dynamic config.

func BackupFile

func BackupFile(file string) error

BackupFile backs up a file. If backup exists, it will be restored first.

func CheckForUpdate added in v2.18.0

func CheckForUpdate(name string, force bool) (bool, error)

CheckForUpdate checks if the user wants to update the policy.

func CompilePolicy

func CompilePolicy(name string, policyBytes []byte) (*circuitfactory.Circuit, *languagev1.Policy, error)

CompilePolicy compiles the policy and returns the circuit.

func DecisionsPreRun added in v2.18.0

func DecisionsPreRun(all bool, decisionType string) (string, error)

DecisionsPreRun validates the decisions command.

func DeletePolicyUsingAPI added in v2.18.0

func DeletePolicyUsingAPI(client PolicyClient, policyName string) error

DeletePolicyUsingAPI deletes the policy using the API.

func FetchPolicyFromCR

func FetchPolicyFromCR(crPath string) (string, error)

FetchPolicyFromCR extracts the spec key from a CR and saves it to a temp file.

func GenerateDotFile

func GenerateDotFile(circuit *circuitfactory.Circuit, dotFilePath string, depth int) error

GenerateDotFile generates a DOT file from the given circuit with the specified depth. The depth determines how many levels of components in the tree should be expanded in the graph. If maxDepth is set to -1, the function will expand components up to the maximum possible depth.

Parameters:

  • circuit: A pointer to the circuitfactory.Circuit object to be used for generating the DOT file.
  • dotFilePath: The file path where the generated DOT file should be saved.
  • maxDepth: The maximum depth the graph should be expanded to. If set to -1, the function will expand components up to the maximum possible depth.

Returns:

  • An error if any issues occur during the file creation or writing process, otherwise nil.

Example usage:

err := GenerateDotFile(circuit, "output.dot", 3)
// This will generate a DOT file with components expanded up to a depth of 3.

err := GenerateDotFile(circuit, "output.dot", -1)
// This will generate a DOT file with components expanded up to the maximum possible depth.

func GenerateGraphFile added in v2.22.0

func GenerateGraphFile(circuit *circuitfactory.Circuit, graphFilePath string, depth int) error

GenerateGraphFile generates a graph from the given circuit with the specified depth. The depth determines how many levels of components in the tree should be expanded in the graph. If maxDepth is set to -1, the function will expand components up to the maximum possible depth.

Parameters:

  • circuit: A pointer to the circuitfactory.Circuit object to be used for generating the graph.
  • graphFilePath: The file path where the generated graph should be saved.
  • maxDepth: The maximum depth the graph should be expanded to. If set to -1, the function will expand components up to the maximum possible depth.

Returns:

  • An error if any issues occur during the file creation or writing process, otherwise nil.

Example usage:

	err := GenerateGraphFile(circuit, "output.json", 3)
	// This will generate a graph with components expanded up to a depth of 3.

	err := GenerateGraphFile(circuit, "output.json", -1)
 // This will generate a graph with components expanded up to the maximum possible depth.

func GenerateMermaidFile

func GenerateMermaidFile(circuit *circuitfactory.Circuit, mermaidFile string, depth int) error

GenerateMermaidFile generates a Mermaid file from the given circuit with the specified depth. The depth determines how many levels of components in the tree should be expanded in the graph. If maxDepth is set to -1, the function will expand components up to the maximum possible depth.

Parameters:

  • circuit: A pointer to the circuitfactory.Circuit object to be used for generating the Mermaid file.
  • mermaidFile: The file path where the generated Mermaid file should be saved.
  • maxDepth: The maximum depth the graph should be expanded to. If set to -1, the function will expand components up to the maximum possible depth.

Returns:

  • An error if any issues occur during the file creation or writing process, otherwise nil.

Example usage:

err := GenerateMermaidFile(circuit, "output.mmd", 3)
// This will generate a Mermaid file with components expanded up to a depth of 3.

err := GenerateMermaidFile(circuit, "output.mmd", -1)
// This will generate a Mermaid file with components expanded up to the maximum possible depth.

func GenerateTreeGraph added in v2.22.0

func GenerateTreeGraph(circuit *circuitfactory.Circuit, treeFilePath string) error

GenerateTreeGraph generates a tree graph from the given circuit.

func GetBlueprints added in v2.18.1

func GetBlueprints(blueprintsDir string) ([]string, error)

GetBlueprints returns a list of files that look like blueprints.

func GetBlueprintsTUIModel added in v2.18.1

func GetBlueprintsTUIModel(blueprintsDir string, selectAll bool) ([]string, *tui.CheckBoxModel, error)

GetBlueprintsTUIModel prepares the TUI model for the blueprints command.

func GetControllerDeployment

func GetControllerDeployment(kubeRestConfig *rest.Config, namespace string) (*appsv1.Deployment, error)

GetControllerDeployment returns the deployment of the Aperture Controller.

func GetControllerNs added in v2.1.1

func GetControllerNs() string

GetControllerNs returns namespace in which the Aperture Controller is running.

func GetDynamicConfigBytes added in v2.18.0

func GetDynamicConfigBytes(policyName, dynamicConfigFile string) ([]byte, error)

GetDynamicConfigBytes returns the bytes of the dynamic config file.

func GetDynamicConfigUsingAPI added in v2.20.1

func GetDynamicConfigUsingAPI(client SelfHostedPolicyClient, policyName string) error

GetDynamicConfigUsingAPI gets the dynamic config.

func GetKubeConfig

func GetKubeConfig(kubeConfig string) (*rest.Config, error)

GetKubeConfig prepares Kubernetes config to connect with the cluster using provided or default kube config file location.

func GetPolicies added in v2.16.0

func GetPolicies(policyDir string) ([]string, error)

GetPolicies returns path of valid files having a valid Aperture Policy .

func GetPoliciesTUIModel added in v2.18.1

func GetPoliciesTUIModel(policyDir string, selectAll bool) ([]string, *tui.CheckBoxModel, error)

GetPoliciesTUIModel prepares the TUI model for selecting policies to apply from the given directory path.

func GetPolicy added in v2.16.0

func GetPolicy(policyFile string) ([]byte, string, error)

GetPolicy returns the policy from the policy file.

func GetPolicyCR added in v2.16.0

func GetPolicyCR(policyBytes []byte) (*policyv1alpha1.Policy, error)

GetPolicyCR returns the policy CR from the policy bytes.

func GetRelPath

func GetRelPath(dir string) string

GetRelPath returns the relative path to the dependency.

func GetSource

func GetSource(dir string) string

GetSource returns the source of the dependency.

func GetVersion

func GetVersion(dir string) string

GetVersion returns the version of the dependency.

func GetYAMLString added in v2.20.0

func GetYAMLString(bytes []byte) (string, error)

func IsBlueprintDeprecated

func IsBlueprintDeprecated(policyDir string) (bool, string)

IsBlueprintDeprecated whether the policyDir is deprecated it reads metadata.yaml and checks for deprecated key the value of that key is the deprecation message.

func IsCurrentVersionNewer added in v2.19.0

func IsCurrentVersionNewer(version string) (bool, error)

IsCurrentVersionNewer checks if the version of aperturectl is newer than on disk.

func IsNoMatchError added in v2.18.0

func IsNoMatchError(err error) bool

func ListAgents added in v2.18.0

func ListAgents(client IntrospectionClient, agentGroup string) error

func ListPolicies added in v2.18.0

func ListPolicies(client SelfHostedPolicyClient) error

ListPolicies lists the policies using the API.

func ParseAutoScaleControlPoints added in v2.18.0

func ParseAutoScaleControlPoints(client IntrospectionClient) error

ParseAutoScaleControlPoints parses the control points.

func ParseControlPoints added in v2.18.0

func ParseControlPoints(client IntrospectionClient) error

ParseControlPoints parses the control points.

func ParseDecisions added in v2.18.0

func ParseDecisions(cmd *cobra.Command, client SelfHostedPolicyClient, all bool, decisionType string) error

ParseDecisions parses the decisions.

func ParseEntities added in v2.18.0

func ParseEntities(client IntrospectionClient, findBy, agentGroup string) error

ParseEntities parses the entities from the cluster.

func ParseGlobalCacheDelete added in v2.25.1

func ParseGlobalCacheDelete(client IntrospectionClient, input CacheDeleteInput) error

func ParseGlobalCacheLookup added in v2.25.1

func ParseGlobalCacheLookup(client IntrospectionClient, input CacheLookupInput) error

func ParseGlobalCacheUpsert added in v2.25.1

func ParseGlobalCacheUpsert(client IntrospectionClient, input CacheUpsertInput) error

func ParsePreview added in v2.18.0

func ParsePreview(client IntrospectionClient, input PreviewInput) error

ParsePreview parses the preview.

func ParseResultCacheDelete added in v2.25.0

func ParseResultCacheDelete(client IntrospectionClient, input CacheDeleteInput) error

func ParseResultCacheLookup added in v2.25.0

func ParseResultCacheLookup(client IntrospectionClient, input CacheLookupInput) error

func ParseResultCacheUpsert added in v2.25.0

func ParseResultCacheUpsert(client IntrospectionClient, input CacheUpsertInput) error

func ParseStatus added in v2.18.0

func ParseStatus(client StatusClient) error

ParseStatus parses the status.

func ProcessPolicy added in v2.23.1

func ProcessPolicy(policyPath string) (*circuitfactory.Circuit, string, string, []byte, error)

ProcessPolicy processes the policy and returns the circuit and graph.

func Pull added in v2.23.1

func Pull(uri, version, cacheDirName, defaultRepo string, skipPull, localAllowed bool) (string, string, string, error)

Pull pulls the content from the given URI and version.

func PullSource

func PullSource(dir, uri string) error

PullSource pulls the source of the dependency and updates the lock file.

func RestoreFile

func RestoreFile(file string)

RestoreFile restores a file from its backup.

func URIToRawContentURL added in v2.18.1

func URIToRawContentURL(uri string) string

URIToRawContentURL converts a URI to a raw content URL, mainly for GitHub right now.

func UpdatePolicyUsingAPI added in v2.18.0

func UpdatePolicyUsingAPI(client PolicyClient, listClient SelfHostedPolicyClient, name string, policyBytes []byte, force bool) error

UpdatePolicyUsingAPI updates the policy using the API.

func UpdateVersionFile added in v2.19.0

func UpdateVersionFile(version string) error

UpdateVersionFile updates the version file with the current version.

func ValidateWithJSONSchema

func ValidateWithJSONSchema(rootSchema string, schemas []string, documentFile string) error

ValidateWithJSONSchema validates the given document (YAML) against the given JSON schema.

Types

type CacheDeleteInput added in v2.25.0

type CacheDeleteInput struct {
	AgentGroup   string
	ControlPoint string
	Key          string
}

type CacheLookupInput added in v2.25.0

type CacheLookupInput struct {
	AgentGroup   string
	ControlPoint string
	Key          string
}

type CacheUpsertInput added in v2.25.0

type CacheUpsertInput struct {
	AgentGroup   string
	ControlPoint string
	Key          string
	Value        string
	TTL          time.Duration
}

type CloudBlueprintsClient added in v2.20.0

type CloudBlueprintsClient interface {
	List(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*cloudv1.ListResponse, error)
	Get(ctx context.Context, in *cloudv1.GetRequest, opts ...grpc.CallOption) (*cloudv1.GetResponse, error)
	Apply(ctx context.Context, in *cloudv1.ApplyRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
	Delete(ctx context.Context, in *cloudv1.DeleteRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
	Archive(ctx context.Context, in *cloudv1.DeleteRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
}

CloudBlueprintsClient is a subset of cloudv1.CloudControllerClient that covers APIs related to cloud blueprints.

type CloudPolicyClient added in v2.18.0

type CloudPolicyClient interface {
	UpsertPolicy(ctx context.Context, in *policylangv1.UpsertPolicyRequest, opts ...grpc.CallOption) (*policylangv1.UpsertPolicyResponse, error)
	DeletePolicy(ctx context.Context, in *policylangv1.DeletePolicyRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
	ArchivePolicy(ctx context.Context, in *policylangv1.DeletePolicyRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
}

CloudPolicyClient is a subset of cloudv1.CloudControllerClient that covers APIs related to policies.

type ControllerConn

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

ControllerConn manages flags for connecting to controller – either via address or kubeconfig.

func (*ControllerConn) GetKubeRestConfig added in v2.1.1

func (c *ControllerConn) GetKubeRestConfig() *rest.Config

GetKubeRestConfig returns kubeRestConfig.

func (*ControllerConn) InitFlags

func (c *ControllerConn) InitFlags(flags *flag.FlagSet)

InitFlags sets up flags for kubeRestConfig.

func (*ControllerConn) IntrospectionClient added in v2.16.0

func (c *ControllerConn) IntrospectionClient() (IntrospectionClient, error)

client returns Controller IntrospectionClient, connecting to controller if not yet connected.

func (*ControllerConn) IsKube added in v2.1.1

func (c *ControllerConn) IsKube() bool

IsKube returns true if controller should be found in Kubernetes cluster.

func (*ControllerConn) PolicyClient added in v2.16.0

func (c *ControllerConn) PolicyClient() (SelfHostedPolicyClient, error)

client returns Controller PolicyClient, connecting to controller if not yet connected.

func (*ControllerConn) PostRun

func (c *ControllerConn) PostRun(_ *cobra.Command, _ []string)

PostRun cleans up ControllerConn's resources, and should be run at PostRun stage.

func (*ControllerConn) PreRunE

func (c *ControllerConn) PreRunE(_ *cobra.Command, _ []string) error

PreRunE verifies flags (optionally loading kubeconfig) and should be run at PreRunE stage.

func (*ControllerConn) StatusClient added in v2.16.0

func (c *ControllerConn) StatusClient() (StatusClient, error)

client returns Controller StatusClient, connecting to controller if not yet connected.

type IntrospectionClient added in v2.16.0

type IntrospectionClient interface {
	ListAgents(ctx context.Context, in *cmdv1.ListAgentsRequest, opts ...grpc.CallOption) (*cmdv1.ListAgentsResponse, error)
	// Seems to be unimplemented on the controller at all?!
	ListServices(ctx context.Context, in *cmdv1.ListServicesRequest, opts ...grpc.CallOption) (*cmdv1.ListServicesControllerResponse, error)
	ListFlowControlPoints(ctx context.Context, in *cmdv1.ListFlowControlPointsRequest, opts ...grpc.CallOption) (*cmdv1.ListFlowControlPointsControllerResponse, error)
	ListAutoScaleControlPoints(ctx context.Context, in *cmdv1.ListAutoScaleControlPointsRequest, opts ...grpc.CallOption) (*cmdv1.ListAutoScaleControlPointsControllerResponse, error)
	ListDiscoveryEntities(ctx context.Context, in *cmdv1.ListDiscoveryEntitiesRequest, opts ...grpc.CallOption) (*cmdv1.ListDiscoveryEntitiesControllerResponse, error)
	ListDiscoveryEntity(ctx context.Context, in *cmdv1.ListDiscoveryEntityRequest, opts ...grpc.CallOption) (*cmdv1.ListDiscoveryEntityAgentResponse, error)
	PreviewFlowLabels(ctx context.Context, in *cmdv1.PreviewFlowLabelsRequest, opts ...grpc.CallOption) (*cmdv1.PreviewFlowLabelsControllerResponse, error)
	PreviewHTTPRequests(ctx context.Context, in *cmdv1.PreviewHTTPRequestsRequest, opts ...grpc.CallOption) (*cmdv1.PreviewHTTPRequestsControllerResponse, error)
	// Caching
	CacheLookup(ctx context.Context, in *cmdv1.GlobalCacheLookupRequest, opts ...grpc.CallOption) (*flowcontrolv1.CacheLookupResponse, error)
	CacheUpsert(ctx context.Context, in *cmdv1.GlobalCacheUpsertRequest, opts ...grpc.CallOption) (*flowcontrolv1.CacheUpsertResponse, error)
	CacheDelete(ctx context.Context, in *cmdv1.GlobalCacheDeleteRequest, opts ...grpc.CallOption) (*flowcontrolv1.CacheDeleteResponse, error)
}

IntrospectionClient is a subset of cmdv1.ControllerClient that covers APIs that need controller to grab information from agents via reverse rpc.

These are currently not supported for the cloud controller.

FIXME: Perhaps it'd be better to split the service on proto level (keep backcompat in mind).

type PolicyClient added in v2.16.0

type PolicyClient interface {
	UpsertPolicy(ctx context.Context, in *policylangv1.UpsertPolicyRequest, opts ...grpc.CallOption) (*policylangv1.UpsertPolicyResponse, error)
	DeletePolicy(ctx context.Context, in *policylangv1.DeletePolicyRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
}

PolicyClient is a subset of cmdv1.ControllerClient that covers APIs related to policies.

type PreviewInput added in v2.18.0

type PreviewInput struct {
	AgentGroup    string
	Service       string
	ControlPoint  string
	NumSamples    int
	IsHTTPPreview bool
}

type SelfHostedPolicyClient added in v2.20.2

SelfHostedPolicyClient is a subset of cmdv1.ControllerClient that covers APIs related to policies.

FIXME: Perhaps it'd be better to split the service on proto level (keep backcompat in mind).

type StatusClient added in v2.16.0

type StatusClient interface {
	GetStatus(ctx context.Context, in *statusv1.GroupStatusRequest, opts ...grpc.CallOption) (*statusv1.GroupStatus, error)
}

StatusClient is a subset of cmdv1.ControllerClient that covers APIs related to status.

FIXME: Perhaps it'd be better to split the service on proto level (keep backcompat in mind).

Jump to

Keyboard shortcuts

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