Documentation
¶
Overview ¶
Package gitlabimporter provides implementations of the Importer interface for GitLab resources in Crossplane functions. It enables importing existing GitLab resources (such as groups and projects) into Crossplane compositions by resolving their IDs and setting them as external-names.
The package includes:
- GroupImporter: Handles importing GitLab groups by locating a subgroup within a parent group.
- ProjectImporter: Handles importing GitLab projects by locating a project within a parent group.
These importers use the GitLab API client to query resources and support pagination for large datasets.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetGroup ¶
GetGroup returns the ID of a GitLab subgroup given its namespace ID and path. It retrieves all subgroups under the specified parent group and searches for a match.
Returns:
- The subgroup ID if found.
- An error if the subgroup cannot be found or the API call fails.
func GetProject ¶
GetProject returns the ID of a GitLab project given its namespace ID and path. It retrieves all projects under the specified namespace and searches for a match.
Returns:
- The project ID if found.
- An error if the project cannot be found or the API call fails.
Types ¶
type GroupImporter ¶
GroupImporter implements the Importer interface for GitLab groups. It uses the GitLab API client to locate an existing subgroup within a parent group based on the desired resource specification, and sets its ID as the external-name in the Crossplane composition.
This type is intended for Crossplane functions that need to import existing GitLab groups rather than creating new ones.
func (*GroupImporter) GetContext ¶
func (g *GroupImporter) GetContext() (string, error)
GetContext returns the full path of the external group resource.
It expects the following values to be available:
- GroupImporter.groupID: Needs this value to search group on gitlab.
- GroupImporter.Client: Needs the client to interact with the gitlab-API.
func (*GroupImporter) Import ¶
func (g *GroupImporter) Import(des *resource.DesiredComposed) (string, error)
Import locates an existing GitLab group based on the desired resource specification and sets its ID as the external-name in the Crossplane composition.
It performs the following steps:
- Retrieves the parent group ID (namespaceID) and path from the desired resource.
- Uses the GitLab API client to find the subgroup within the parent group.
- Converts the group ID to a string and sets it as the external-name.
Returns:
- The external-name (group ID as a string) if successful.
- An error if the resource cannot be imported or the group cannot be found.
func (*GroupImporter) PassClient ¶
func (g *GroupImporter) PassClient(client any) error
PassClient assigns a GitLab client to the GroupImporter.
It expects the provided client to be of type *gitlab.Client. If the type assertion fails, an error is returned indicating the expected and actual types.
type ProjectImporter ¶
ProjectImporter implements the Importer interface for GitLab projects. It uses the GitLab API client to locate an existing project within a namespace based on the desired resource specification, and sets its ID as the external-name in the Crossplane composition.
This type is intended for Crossplane functions that need to import existing GitLab projects rather than creating new ones.
func (*ProjectImporter) GetContext ¶
func (p *ProjectImporter) GetContext() (string, error)
GetContext returns the full path of the external project resource.
It expects the following values to be available:
- ProjectImporter.projectID: Needs this value to search project on gitlab.
- ProjectImporter.Client: Needs the client to interact with the gitlab-API.
func (*ProjectImporter) Import ¶
func (p *ProjectImporter) Import(des *resource.DesiredComposed) (string, error)
Import locates an existing GitLab project based on the desired resource specification and sets its ID as the external-name in the Crossplane composition.
It performs the following steps:
- Retrieves the namespace ID and path from the desired resource.
- Uses the GitLab API client to find the project within the namespace.
- Converts the project ID to a string and sets it as the external-name.
Returns:
- The external-name (project ID as a string) if successful.
- An error if the resource cannot be imported or the project cannot be found.
func (*ProjectImporter) PassClient ¶
func (p *ProjectImporter) PassClient(client any) error
PassClient assigns a GitLab client to the ProjectImporter.
It expects the provided client to be of type *gitlab.Client. If the type assertion fails, an error is returned indicating the expected and actual types.