-
Notifications
You must be signed in to change notification settings - Fork 2
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
40 changed files
with
2,203 additions
and
989 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
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
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,225 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. | ||
// This product includes software developed at ApeCloud (https://www.apecloud.com/). | ||
// Copyright 2022-Present ApeCloud Co., Ltd | ||
|
||
package admin | ||
|
||
import ( | ||
_context "context" | ||
_nethttp "net/http" | ||
_neturl "net/url" | ||
"strings" | ||
|
||
"github.com/apecloud/kb-cloud-client-go/api/common" | ||
) | ||
|
||
// ProjectApi service type | ||
type ProjectApi common.Service | ||
|
||
// CreateProject Create a project in an environment. | ||
func (a *ProjectApi) CreateProject(ctx _context.Context, environmentName string, body ProjectCreate) (Project, *_nethttp.Response, error) { | ||
var ( | ||
localVarHTTPMethod = _nethttp.MethodPost | ||
localVarPostBody interface{} | ||
localVarReturnValue Project | ||
) | ||
|
||
localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, ".ProjectApi.CreateProject") | ||
if err != nil { | ||
return localVarReturnValue, nil, common.GenericOpenAPIError{ErrorMessage: err.Error()} | ||
} | ||
|
||
localVarPath := localBasePath + "/admin/v1/environments/{environmentName}/projects" | ||
localVarPath = strings.Replace(localVarPath, "{"+"environmentName"+"}", _neturl.PathEscape(common.ParameterToString(environmentName, "")), -1) | ||
|
||
localVarHeaderParams := make(map[string]string) | ||
localVarQueryParams := _neturl.Values{} | ||
localVarFormParams := _neturl.Values{} | ||
localVarHeaderParams["Content-Type"] = "application/json" | ||
localVarHeaderParams["Accept"] = "application/json" | ||
|
||
// body params | ||
localVarPostBody = &body | ||
common.SetAuthKeys( | ||
ctx, | ||
&localVarHeaderParams, | ||
[2]string{"BearerToken", "authorization"}, | ||
) | ||
req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) | ||
if err != nil { | ||
return localVarReturnValue, nil, err | ||
} | ||
|
||
localVarHTTPResponse, err := a.Client.CallAPI(req) | ||
if err != nil || localVarHTTPResponse == nil { | ||
return localVarReturnValue, localVarHTTPResponse, err | ||
} | ||
|
||
localVarBody, err := common.ReadBody(localVarHTTPResponse) | ||
if err != nil { | ||
return localVarReturnValue, localVarHTTPResponse, err | ||
} | ||
|
||
if localVarHTTPResponse.StatusCode >= 300 { | ||
newErr := common.GenericOpenAPIError{ | ||
ErrorBody: localVarBody, | ||
ErrorMessage: localVarHTTPResponse.Status, | ||
} | ||
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 { | ||
var v APIErrorResponse | ||
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) | ||
if err != nil { | ||
return localVarReturnValue, localVarHTTPResponse, newErr | ||
} | ||
newErr.ErrorModel = v | ||
} | ||
return localVarReturnValue, localVarHTTPResponse, newErr | ||
} | ||
|
||
err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) | ||
if err != nil { | ||
newErr := common.GenericOpenAPIError{ | ||
ErrorBody: localVarBody, | ||
ErrorMessage: err.Error(), | ||
} | ||
return localVarReturnValue, localVarHTTPResponse, newErr | ||
} | ||
|
||
return localVarReturnValue, localVarHTTPResponse, nil | ||
} | ||
|
||
// DeleteProject Delete a project in an environment. | ||
func (a *ProjectApi) DeleteProject(ctx _context.Context, environmentName string, projectName string) (*_nethttp.Response, error) { | ||
var ( | ||
localVarHTTPMethod = _nethttp.MethodDelete | ||
localVarPostBody interface{} | ||
) | ||
|
||
localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, ".ProjectApi.DeleteProject") | ||
if err != nil { | ||
return nil, common.GenericOpenAPIError{ErrorMessage: err.Error()} | ||
} | ||
|
||
localVarPath := localBasePath + "/admin/v1/environments/{environmentName}/projects/{projectName}" | ||
localVarPath = strings.Replace(localVarPath, "{"+"environmentName"+"}", _neturl.PathEscape(common.ParameterToString(environmentName, "")), -1) | ||
localVarPath = strings.Replace(localVarPath, "{"+"projectName"+"}", _neturl.PathEscape(common.ParameterToString(projectName, "")), -1) | ||
|
||
localVarHeaderParams := make(map[string]string) | ||
localVarQueryParams := _neturl.Values{} | ||
localVarFormParams := _neturl.Values{} | ||
localVarHeaderParams["Accept"] = "application/json" | ||
|
||
common.SetAuthKeys( | ||
ctx, | ||
&localVarHeaderParams, | ||
[2]string{"BearerToken", "authorization"}, | ||
) | ||
req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
localVarHTTPResponse, err := a.Client.CallAPI(req) | ||
if err != nil || localVarHTTPResponse == nil { | ||
return localVarHTTPResponse, err | ||
} | ||
|
||
localVarBody, err := common.ReadBody(localVarHTTPResponse) | ||
if err != nil { | ||
return localVarHTTPResponse, err | ||
} | ||
|
||
if localVarHTTPResponse.StatusCode >= 300 { | ||
newErr := common.GenericOpenAPIError{ | ||
ErrorBody: localVarBody, | ||
ErrorMessage: localVarHTTPResponse.Status, | ||
} | ||
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 { | ||
var v APIErrorResponse | ||
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) | ||
if err != nil { | ||
return localVarHTTPResponse, newErr | ||
} | ||
newErr.ErrorModel = v | ||
} | ||
return localVarHTTPResponse, newErr | ||
} | ||
|
||
return localVarHTTPResponse, nil | ||
} | ||
|
||
// ListProjects List projects in an environment. | ||
func (a *ProjectApi) ListProjects(ctx _context.Context, environmentName string) (ProjectList, *_nethttp.Response, error) { | ||
var ( | ||
localVarHTTPMethod = _nethttp.MethodGet | ||
localVarPostBody interface{} | ||
localVarReturnValue ProjectList | ||
) | ||
|
||
localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, ".ProjectApi.ListProjects") | ||
if err != nil { | ||
return localVarReturnValue, nil, common.GenericOpenAPIError{ErrorMessage: err.Error()} | ||
} | ||
|
||
localVarPath := localBasePath + "/admin/v1/environments/{environmentName}/projects" | ||
localVarPath = strings.Replace(localVarPath, "{"+"environmentName"+"}", _neturl.PathEscape(common.ParameterToString(environmentName, "")), -1) | ||
|
||
localVarHeaderParams := make(map[string]string) | ||
localVarQueryParams := _neturl.Values{} | ||
localVarFormParams := _neturl.Values{} | ||
localVarHeaderParams["Accept"] = "application/json" | ||
|
||
common.SetAuthKeys( | ||
ctx, | ||
&localVarHeaderParams, | ||
[2]string{"BearerToken", "authorization"}, | ||
) | ||
req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) | ||
if err != nil { | ||
return localVarReturnValue, nil, err | ||
} | ||
|
||
localVarHTTPResponse, err := a.Client.CallAPI(req) | ||
if err != nil || localVarHTTPResponse == nil { | ||
return localVarReturnValue, localVarHTTPResponse, err | ||
} | ||
|
||
localVarBody, err := common.ReadBody(localVarHTTPResponse) | ||
if err != nil { | ||
return localVarReturnValue, localVarHTTPResponse, err | ||
} | ||
|
||
if localVarHTTPResponse.StatusCode >= 300 { | ||
newErr := common.GenericOpenAPIError{ | ||
ErrorBody: localVarBody, | ||
ErrorMessage: localVarHTTPResponse.Status, | ||
} | ||
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 { | ||
var v APIErrorResponse | ||
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) | ||
if err != nil { | ||
return localVarReturnValue, localVarHTTPResponse, newErr | ||
} | ||
newErr.ErrorModel = v | ||
} | ||
return localVarReturnValue, localVarHTTPResponse, newErr | ||
} | ||
|
||
err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) | ||
if err != nil { | ||
newErr := common.GenericOpenAPIError{ | ||
ErrorBody: localVarBody, | ||
ErrorMessage: err.Error(), | ||
} | ||
return localVarReturnValue, localVarHTTPResponse, newErr | ||
} | ||
|
||
return localVarReturnValue, localVarHTTPResponse, nil | ||
} | ||
|
||
// NewProjectApi Returns NewProjectApi. | ||
func NewProjectApi(client *common.APIClient) *ProjectApi { | ||
return &ProjectApi{ | ||
Client: client, | ||
} | ||
} |
Oops, something went wrong.