-
Notifications
You must be signed in to change notification settings - Fork 16
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
14 changed files
with
2,146 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,253 @@ | ||
// 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 client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/conductor-sdk/conductor-go/sdk/model/rbac" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
type AuthorizationResourceApiService struct { | ||
*APIClient | ||
} | ||
|
||
/* | ||
AuthorizationResourceApiService Get the access that have been granted over the given object | ||
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). | ||
- @param type_ | ||
- @param id | ||
@return interface{} | ||
*/ | ||
func (a *AuthorizationResourceApiService) GetPermissions(ctx context.Context, type_ string, id string) (interface{}, *http.Response, error) { | ||
var ( | ||
httpMethod = strings.ToUpper("Get") | ||
postBody interface{} | ||
fileName string | ||
fileBytes []byte | ||
returnValue interface{} | ||
) | ||
|
||
// create path and map variables | ||
path := "/api/auth/authorization/{type}/{id}" | ||
path = strings.Replace(path, "{"+"type"+"}", fmt.Sprintf("%v", type_), -1) | ||
path = strings.Replace(path, "{"+"id"+"}", fmt.Sprintf("%v", id), -1) | ||
|
||
headerParams := make(map[string]string) | ||
queryParams := url.Values{} | ||
formParams := url.Values{} | ||
|
||
// to determine the Content-Type header | ||
contentTypes := []string{} | ||
|
||
// set Content-Type header | ||
contentType := selectHeaderContentType(contentTypes) | ||
if contentType != "" { | ||
headerParams["Content-Type"] = contentType | ||
} | ||
|
||
// to determine the Accept header | ||
headerAccepts := []string{"application/json"} | ||
|
||
// set Accept header | ||
headerAccept := selectHeaderAccept(headerAccepts) | ||
if headerAccept != "" { | ||
headerParams["Accept"] = headerAccept | ||
} | ||
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) | ||
if err != nil { | ||
return returnValue, nil, err | ||
} | ||
|
||
httpResponse, err := a.callAPI(r) | ||
if err != nil || httpResponse == nil { | ||
return returnValue, httpResponse, err | ||
} | ||
|
||
responseBody, err := getDecompressedBody(httpResponse) | ||
httpResponse.Body.Close() | ||
if err != nil { | ||
return returnValue, httpResponse, err | ||
} | ||
|
||
if httpResponse.StatusCode < 300 { | ||
// If we succeed, return the data, otherwise pass on to decode error. | ||
err = a.decode(&returnValue, responseBody, httpResponse.Header.Get("Content-Type")) | ||
if err == nil { | ||
return returnValue, httpResponse, err | ||
} | ||
} | ||
|
||
if httpResponse.StatusCode >= 300 { | ||
newErr := GenericSwaggerError{ | ||
body: responseBody, | ||
error: httpResponse.Status, | ||
} | ||
if httpResponse.StatusCode == 200 { | ||
var v interface{} | ||
err = a.decode(&v, responseBody, httpResponse.Header.Get("Content-Type")) | ||
if err != nil { | ||
newErr.error = err.Error() | ||
return returnValue, httpResponse, newErr | ||
} | ||
newErr.model = v | ||
return returnValue, httpResponse, newErr | ||
} | ||
return returnValue, httpResponse, newErr | ||
} | ||
|
||
return returnValue, httpResponse, nil | ||
} | ||
|
||
/* | ||
AuthorizationResourceApiService Grant access to a user over the target | ||
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). | ||
- @param body | ||
@return Response | ||
*/ | ||
func (a *AuthorizationResourceApiService) GrantPermissions(ctx context.Context, body rbac.AuthorizationRequest) (*http.Response, error) { | ||
var ( | ||
httpMethod = strings.ToUpper("Post") | ||
postBody interface{} | ||
fileName string | ||
fileBytes []byte | ||
) | ||
|
||
// create path and map variables | ||
path := "/api/auth/authorization" | ||
|
||
headerParams := make(map[string]string) | ||
queryParams := url.Values{} | ||
formParams := url.Values{} | ||
|
||
// to determine the Content-Type header | ||
contentTypes := []string{"application/json"} | ||
|
||
// set Content-Type header | ||
contentType := selectHeaderContentType(contentTypes) | ||
if contentType != "" { | ||
headerParams["Content-Type"] = contentType | ||
} | ||
|
||
// to determine the Accept header | ||
headerAccepts := []string{"application/json"} | ||
|
||
// set Accept header | ||
headerAccept := selectHeaderAccept(headerAccepts) | ||
if headerAccept != "" { | ||
headerParams["Accept"] = headerAccept | ||
} | ||
// body params | ||
postBody = &body | ||
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
httpResponse, err := a.callAPI(r) | ||
if err != nil || httpResponse == nil { | ||
return httpResponse, err | ||
} | ||
|
||
responseBody, err := getDecompressedBody(httpResponse) | ||
httpResponse.Body.Close() | ||
if err != nil { | ||
return httpResponse, err | ||
} | ||
|
||
if httpResponse.StatusCode < 300 { | ||
return httpResponse, err | ||
} | ||
|
||
if httpResponse.StatusCode >= 300 { | ||
newErr := GenericSwaggerError{ | ||
body: responseBody, | ||
error: httpResponse.Status, | ||
} | ||
|
||
return httpResponse, newErr | ||
} | ||
|
||
return httpResponse, nil | ||
} | ||
|
||
/* | ||
AuthorizationResourceApiService Remove user's access over the target | ||
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). | ||
- @param body | ||
@return Response | ||
*/ | ||
func (a *AuthorizationResourceApiService) RemovePermissions(ctx context.Context, body rbac.AuthorizationRequest) (*http.Response, error) { | ||
var ( | ||
httpMethod = strings.ToUpper("Delete") | ||
postBody interface{} | ||
fileName string | ||
fileBytes []byte | ||
) | ||
|
||
// create path and map variables | ||
path := "/api/auth/authorization" | ||
|
||
headerParams := make(map[string]string) | ||
queryParams := url.Values{} | ||
formParams := url.Values{} | ||
|
||
// to determine the Content-Type header | ||
contentTypes := []string{"application/json"} | ||
|
||
// set Content-Type header | ||
contentType := selectHeaderContentType(contentTypes) | ||
if contentType != "" { | ||
headerParams["Content-Type"] = contentType | ||
} | ||
|
||
// to determine the Accept header | ||
headerAccepts := []string{"application/json"} | ||
|
||
// set Accept header | ||
headerAccept := selectHeaderAccept(headerAccepts) | ||
if headerAccept != "" { | ||
headerParams["Accept"] = headerAccept | ||
} | ||
// body params | ||
postBody = &body | ||
r, err := a.prepareRequest(ctx, path, httpMethod, postBody, headerParams, queryParams, formParams, fileName, fileBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
httpResponse, err := a.callAPI(r) | ||
if err != nil || httpResponse == nil { | ||
return httpResponse, err | ||
} | ||
|
||
responseBody, err := getDecompressedBody(httpResponse) | ||
httpResponse.Body.Close() | ||
if err != nil { | ||
return httpResponse, err | ||
} | ||
|
||
if httpResponse.StatusCode < 300 { | ||
return httpResponse, err | ||
} | ||
|
||
if httpResponse.StatusCode >= 300 { | ||
newErr := GenericSwaggerError{ | ||
body: responseBody, | ||
error: httpResponse.Status, | ||
} | ||
|
||
return httpResponse, newErr | ||
} | ||
|
||
return httpResponse, nil | ||
} |
Oops, something went wrong.