Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright 2020 The Flux CD contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package gitlab | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/xanzy/go-gitlab" | ||
) | ||
|
||
// gitlabClientImpl is a wrapper around *github.Client, which implements higher-level methods, | ||
// operating on the go-github structs. Pagination is implemented for all List* methods, all returned | ||
// objects are validated, and HTTP errors are handled/wrapped using handleHTTPError. | ||
// This interface is also fakeable, in order to unit-test the client. | ||
type gitlabClient interface { | ||
// Client returns the underlying *github.Client | ||
Client() *gitlab.Client | ||
|
||
// Group methods | ||
|
||
// GetGroup is a wrapper for "GET /groups/{group}". | ||
// This function HTTP error wrapping, and validates the server result. | ||
GetGroup(ctx context.Context, groupName string) (*gitlab.Group, error) | ||
// ListGroups is a wrapper for "GET /groups". | ||
// This function handles pagination, HTTP error wrapping, and validates the server result. | ||
ListGroups(ctx context.Context) (*gitlab.Group, error) | ||
// ListSubgroups is a wrapper for "GET /groups/{group}/subgroups". | ||
// This function handles pagination, HTTP error wrapping, and validates the server result. | ||
ListSubgroups(ctx context.Context, groupName string) (*gitlab.Group, error) | ||
// ListGroupProjects is a wrapper for "GET /groups/{group}/projects". | ||
// This function handles pagination, HTTP error wrapping, and validates the server result. | ||
ListGroupProjects(ctx context.Context, groupName string) (*[]gitlab.Project, error) | ||
// ListGroupTeamMembers is a wrapper for "GET /groups/{group}/members". | ||
// This function handles pagination, HTTP error wrapping, and validates the server result. | ||
ListGroupTeamMembers(ctx context.Context, groupName string) ([]*gitlab.User, error) | ||
|
||
// Project methods | ||
|
||
// GetProjects is a wrapper for "GET /projects". | ||
// This function handles HTTP error wrapping, and validates the server result. | ||
GetProjects(ctx context.Context) ([]*gitlab.Project, error) | ||
// ListProjectTeamMembers is a wrapper for "GET /projects/{project}/members". | ||
// This function handles pagination, HTTP error wrapping, and validates the server result. | ||
ListProjectTeamMembers(ctx context.Context, projectName string) ([]*gitlab.User, error) | ||
// GetProject is a wrapper for "GET /projects/{project}". | ||
// This function handles HTTP error wrapping, and validates the server result. | ||
GetProject(ctx context.Context, projectName string) (*gitlab.Project, error) | ||
// ListUserProjects is a wrapper for "GET /users/{username}/projects". | ||
// This function handles pagination, HTTP error wrapping, and validates the server result. | ||
ListUserProjects(ctx context.Context, username string) ([]*gitlab.Project, error) | ||
// CreateProject is a wrapper for "POST /projects" | ||
// This function handles HTTP error wrapping, and validates the server result. | ||
CreateProject(ctx context.Context, req *gitlab.Project) (*gitlab.Project, error) | ||
// UpdateProject is a wrapper for "PUT /projects/{project}". | ||
// This function handles HTTP error wrapping, and validates the server result. | ||
UpdateProject(ctx context.Context, req *gitlab.Repository) (*gitlab.Repository, error) | ||
// DeleteRepo is a wrapper for "DELETE /projects/{project}". | ||
// This function handles HTTP error wrapping. | ||
// DANGEROUS COMMAND: In order to use this, you must set destructiveActions to true. | ||
DeleteRepo(ctx context.Context, projectName string) error | ||
|
||
// Deploy key methods | ||
|
||
// ListProjectKeys is a wrapper for "GET /projects/{project}/deploy_keys". | ||
// This function handles pagination, HTTP error wrapping, and validates the server result. | ||
ListProjectKeys(ctx context.Context, projectName string) ([]*gitlab.Key, error) | ||
// CreateProjectKey is a wrapper for "POST /projects/{project}/deploy_keys". | ||
// This function handles HTTP error wrapping, and validates the server result. | ||
CreateProjectKey(ctx context.Context, projectName string, req *gitlab.Key) (*gitlab.Key, error) | ||
// DeleteKey is a wrapper for "DELETE /projects/{project}/deploy_keys/{key_id}". | ||
// This function handles HTTP error wrapping. | ||
DeleteProjectKey(ctx context.Context, projectName string, id int64) error | ||
} | ||
|
||
// gitlabClientImpl is a wrapper around *gitlab.Client, which implements higher-level methods, | ||
// operating on the go-gitlab structs. See the gitlabClient interface for method documentation. | ||
// Pagination is implemented for all List* methods, all returned | ||
// objects are validated, and HTTP errors are handled/wrapped using handleHTTPError. | ||
type gitlabClientImpl struct { | ||
c *gitlab.Client | ||
destructiveActions bool | ||
} |