diff --git a/api/api_legacy_authorizations.gen.go b/api/api_legacy_authorizations.gen.go new file mode 100644 index 0000000..a95e187 --- /dev/null +++ b/api/api_legacy_authorizations.gen.go @@ -0,0 +1,1032 @@ +/* + * Subset of Influx API covered by Influx CLI + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * API version: 2.0.0 + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api + +import ( + _context "context" + _ioutil "io/ioutil" + _nethttp "net/http" + _neturl "net/url" + "strings" +) + +// Linger please +var ( + _ _context.Context +) + +type LegacyAuthorizationsApi interface { + + /* + * DeleteAuthorizationsID Delete an authorization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param authID The ID of the authorization to delete. + * @return ApiDeleteAuthorizationsIDRequest + */ + DeleteAuthorizationsID(ctx _context.Context, authID string) ApiDeleteAuthorizationsIDRequest + + /* + * DeleteAuthorizationsIDExecute executes the request + */ + DeleteAuthorizationsIDExecute(r ApiDeleteAuthorizationsIDRequest) error + + /* + * GetAuthorizations List all authorizations + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @return ApiGetAuthorizationsRequest + */ + GetAuthorizations(ctx _context.Context) ApiGetAuthorizationsRequest + + /* + * GetAuthorizationsExecute executes the request + * @return Authorizations + */ + GetAuthorizationsExecute(r ApiGetAuthorizationsRequest) (Authorizations, error) + + /* + * GetAuthorizationsID Retrieve an authorization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param authID The ID of the authorization to get. + * @return ApiGetAuthorizationsIDRequest + */ + GetAuthorizationsID(ctx _context.Context, authID string) ApiGetAuthorizationsIDRequest + + /* + * GetAuthorizationsIDExecute executes the request + * @return Authorization + */ + GetAuthorizationsIDExecute(r ApiGetAuthorizationsIDRequest) (Authorization, error) + + /* + * PatchAuthorizationsID Update an authorization to be active or inactive + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param authID The ID of the authorization to update. + * @return ApiPatchAuthorizationsIDRequest + */ + PatchAuthorizationsID(ctx _context.Context, authID string) ApiPatchAuthorizationsIDRequest + + /* + * PatchAuthorizationsIDExecute executes the request + * @return Authorization + */ + PatchAuthorizationsIDExecute(r ApiPatchAuthorizationsIDRequest) (Authorization, error) + + /* + * PostAuthorizations Create an authorization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @return ApiPostAuthorizationsRequest + */ + PostAuthorizations(ctx _context.Context) ApiPostAuthorizationsRequest + + /* + * PostAuthorizationsExecute executes the request + * @return Authorization + */ + PostAuthorizationsExecute(r ApiPostAuthorizationsRequest) (Authorization, error) + + /* + * PostAuthorizationsIDPassword Set an authorization password + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param authID The ID of the authorization to update. + * @return ApiPostAuthorizationsIDPasswordRequest + */ + PostAuthorizationsIDPassword(ctx _context.Context, authID string) ApiPostAuthorizationsIDPasswordRequest + + /* + * PostAuthorizationsIDPasswordExecute executes the request + */ + PostAuthorizationsIDPasswordExecute(r ApiPostAuthorizationsIDPasswordRequest) error +} + +// LegacyAuthorizationsApiService LegacyAuthorizationsApi service +type LegacyAuthorizationsApiService service + +type ApiDeleteAuthorizationsIDRequest struct { + ctx _context.Context + ApiService LegacyAuthorizationsApi + authID string + zapTraceSpan *string +} + +func (r ApiDeleteAuthorizationsIDRequest) AuthID(authID string) ApiDeleteAuthorizationsIDRequest { + r.authID = authID + return r +} +func (r ApiDeleteAuthorizationsIDRequest) GetAuthID() string { + return r.authID +} + +func (r ApiDeleteAuthorizationsIDRequest) ZapTraceSpan(zapTraceSpan string) ApiDeleteAuthorizationsIDRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiDeleteAuthorizationsIDRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiDeleteAuthorizationsIDRequest) Execute() error { + return r.ApiService.DeleteAuthorizationsIDExecute(r) +} + +/* + * DeleteAuthorizationsID Delete an authorization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param authID The ID of the authorization to delete. + * @return ApiDeleteAuthorizationsIDRequest + */ +func (a *LegacyAuthorizationsApiService) DeleteAuthorizationsID(ctx _context.Context, authID string) ApiDeleteAuthorizationsIDRequest { + return ApiDeleteAuthorizationsIDRequest{ + ApiService: a, + ctx: ctx, + authID: authID, + } +} + +/* + * Execute executes the request + */ +func (a *LegacyAuthorizationsApiService) DeleteAuthorizationsIDExecute(r ApiDeleteAuthorizationsIDRequest) error { + var ( + localVarHTTPMethod = _nethttp.MethodDelete + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LegacyAuthorizationsApiService.DeleteAuthorizationsID") + if err != nil { + return GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/legacy/authorizations/{authID}" + localVarPath = strings.Replace(localVarPath, "{"+"authID"+"}", _neturl.PathEscape(parameterToString(r.authID, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.zapTraceSpan != nil { + localVarHeaderParams["Zap-Trace-Span"] = parameterToString(*r.zapTraceSpan, "") + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return err + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return err + } + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return newErr + } + newErr.model = &v + return newErr + } + + return nil +} + +type ApiGetAuthorizationsRequest struct { + ctx _context.Context + ApiService LegacyAuthorizationsApi + zapTraceSpan *string + userID *string + user *string + orgID *string + org *string + token *string + authID *string +} + +func (r ApiGetAuthorizationsRequest) ZapTraceSpan(zapTraceSpan string) ApiGetAuthorizationsRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiGetAuthorizationsRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiGetAuthorizationsRequest) UserID(userID string) ApiGetAuthorizationsRequest { + r.userID = &userID + return r +} +func (r ApiGetAuthorizationsRequest) GetUserID() *string { + return r.userID +} + +func (r ApiGetAuthorizationsRequest) User(user string) ApiGetAuthorizationsRequest { + r.user = &user + return r +} +func (r ApiGetAuthorizationsRequest) GetUser() *string { + return r.user +} + +func (r ApiGetAuthorizationsRequest) OrgID(orgID string) ApiGetAuthorizationsRequest { + r.orgID = &orgID + return r +} +func (r ApiGetAuthorizationsRequest) GetOrgID() *string { + return r.orgID +} + +func (r ApiGetAuthorizationsRequest) Org(org string) ApiGetAuthorizationsRequest { + r.org = &org + return r +} +func (r ApiGetAuthorizationsRequest) GetOrg() *string { + return r.org +} + +func (r ApiGetAuthorizationsRequest) Token(token string) ApiGetAuthorizationsRequest { + r.token = &token + return r +} +func (r ApiGetAuthorizationsRequest) GetToken() *string { + return r.token +} + +func (r ApiGetAuthorizationsRequest) AuthID(authID string) ApiGetAuthorizationsRequest { + r.authID = &authID + return r +} +func (r ApiGetAuthorizationsRequest) GetAuthID() *string { + return r.authID +} + +func (r ApiGetAuthorizationsRequest) Execute() (Authorizations, error) { + return r.ApiService.GetAuthorizationsExecute(r) +} + +/* + * GetAuthorizations List all authorizations + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @return ApiGetAuthorizationsRequest + */ +func (a *LegacyAuthorizationsApiService) GetAuthorizations(ctx _context.Context) ApiGetAuthorizationsRequest { + return ApiGetAuthorizationsRequest{ + ApiService: a, + ctx: ctx, + } +} + +/* + * Execute executes the request + * @return Authorizations + */ +func (a *LegacyAuthorizationsApiService) GetAuthorizationsExecute(r ApiGetAuthorizationsRequest) (Authorizations, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + localVarReturnValue Authorizations + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LegacyAuthorizationsApiService.GetAuthorizations") + if err != nil { + return localVarReturnValue, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/legacy/authorizations" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + + if r.userID != nil { + localVarQueryParams.Add("userID", parameterToString(*r.userID, "")) + } + if r.user != nil { + localVarQueryParams.Add("user", parameterToString(*r.user, "")) + } + if r.orgID != nil { + localVarQueryParams.Add("orgID", parameterToString(*r.orgID, "")) + } + if r.org != nil { + localVarQueryParams.Add("org", parameterToString(*r.org, "")) + } + if r.token != nil { + localVarQueryParams.Add("token", parameterToString(*r.token, "")) + } + if r.authID != nil { + localVarQueryParams.Add("authID", parameterToString(*r.authID, "")) + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.zapTraceSpan != nil { + localVarHeaderParams["Zap-Trace-Span"] = parameterToString(*r.zapTraceSpan, "") + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return localVarReturnValue, err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return localVarReturnValue, err + } + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, newErr + } + newErr.model = &v + return localVarReturnValue, newErr + } + + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return localVarReturnValue, err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return localVarReturnValue, err + } + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + +type ApiGetAuthorizationsIDRequest struct { + ctx _context.Context + ApiService LegacyAuthorizationsApi + authID string + zapTraceSpan *string +} + +func (r ApiGetAuthorizationsIDRequest) AuthID(authID string) ApiGetAuthorizationsIDRequest { + r.authID = authID + return r +} +func (r ApiGetAuthorizationsIDRequest) GetAuthID() string { + return r.authID +} + +func (r ApiGetAuthorizationsIDRequest) ZapTraceSpan(zapTraceSpan string) ApiGetAuthorizationsIDRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiGetAuthorizationsIDRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiGetAuthorizationsIDRequest) Execute() (Authorization, error) { + return r.ApiService.GetAuthorizationsIDExecute(r) +} + +/* + * GetAuthorizationsID Retrieve an authorization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param authID The ID of the authorization to get. + * @return ApiGetAuthorizationsIDRequest + */ +func (a *LegacyAuthorizationsApiService) GetAuthorizationsID(ctx _context.Context, authID string) ApiGetAuthorizationsIDRequest { + return ApiGetAuthorizationsIDRequest{ + ApiService: a, + ctx: ctx, + authID: authID, + } +} + +/* + * Execute executes the request + * @return Authorization + */ +func (a *LegacyAuthorizationsApiService) GetAuthorizationsIDExecute(r ApiGetAuthorizationsIDRequest) (Authorization, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + localVarReturnValue Authorization + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LegacyAuthorizationsApiService.GetAuthorizationsID") + if err != nil { + return localVarReturnValue, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/legacy/authorizations/{authID}" + localVarPath = strings.Replace(localVarPath, "{"+"authID"+"}", _neturl.PathEscape(parameterToString(r.authID, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.zapTraceSpan != nil { + localVarHeaderParams["Zap-Trace-Span"] = parameterToString(*r.zapTraceSpan, "") + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return localVarReturnValue, err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return localVarReturnValue, err + } + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, newErr + } + newErr.model = &v + return localVarReturnValue, newErr + } + + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return localVarReturnValue, err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return localVarReturnValue, err + } + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + +type ApiPatchAuthorizationsIDRequest struct { + ctx _context.Context + ApiService LegacyAuthorizationsApi + authID string + authorizationUpdateRequest *AuthorizationUpdateRequest + zapTraceSpan *string +} + +func (r ApiPatchAuthorizationsIDRequest) AuthID(authID string) ApiPatchAuthorizationsIDRequest { + r.authID = authID + return r +} +func (r ApiPatchAuthorizationsIDRequest) GetAuthID() string { + return r.authID +} + +func (r ApiPatchAuthorizationsIDRequest) AuthorizationUpdateRequest(authorizationUpdateRequest AuthorizationUpdateRequest) ApiPatchAuthorizationsIDRequest { + r.authorizationUpdateRequest = &authorizationUpdateRequest + return r +} +func (r ApiPatchAuthorizationsIDRequest) GetAuthorizationUpdateRequest() *AuthorizationUpdateRequest { + return r.authorizationUpdateRequest +} + +func (r ApiPatchAuthorizationsIDRequest) ZapTraceSpan(zapTraceSpan string) ApiPatchAuthorizationsIDRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiPatchAuthorizationsIDRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiPatchAuthorizationsIDRequest) Execute() (Authorization, error) { + return r.ApiService.PatchAuthorizationsIDExecute(r) +} + +/* + * PatchAuthorizationsID Update an authorization to be active or inactive + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param authID The ID of the authorization to update. + * @return ApiPatchAuthorizationsIDRequest + */ +func (a *LegacyAuthorizationsApiService) PatchAuthorizationsID(ctx _context.Context, authID string) ApiPatchAuthorizationsIDRequest { + return ApiPatchAuthorizationsIDRequest{ + ApiService: a, + ctx: ctx, + authID: authID, + } +} + +/* + * Execute executes the request + * @return Authorization + */ +func (a *LegacyAuthorizationsApiService) PatchAuthorizationsIDExecute(r ApiPatchAuthorizationsIDRequest) (Authorization, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPatch + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + localVarReturnValue Authorization + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LegacyAuthorizationsApiService.PatchAuthorizationsID") + if err != nil { + return localVarReturnValue, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/legacy/authorizations/{authID}" + localVarPath = strings.Replace(localVarPath, "{"+"authID"+"}", _neturl.PathEscape(parameterToString(r.authID, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if r.authorizationUpdateRequest == nil { + return localVarReturnValue, reportError("authorizationUpdateRequest is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.zapTraceSpan != nil { + localVarHeaderParams["Zap-Trace-Span"] = parameterToString(*r.zapTraceSpan, "") + } + // body params + localVarPostBody = r.authorizationUpdateRequest + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return localVarReturnValue, err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return localVarReturnValue, err + } + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, newErr + } + newErr.model = &v + return localVarReturnValue, newErr + } + + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return localVarReturnValue, err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return localVarReturnValue, err + } + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + +type ApiPostAuthorizationsRequest struct { + ctx _context.Context + ApiService LegacyAuthorizationsApi + legacyAuthorizationPostRequest *LegacyAuthorizationPostRequest + zapTraceSpan *string +} + +func (r ApiPostAuthorizationsRequest) LegacyAuthorizationPostRequest(legacyAuthorizationPostRequest LegacyAuthorizationPostRequest) ApiPostAuthorizationsRequest { + r.legacyAuthorizationPostRequest = &legacyAuthorizationPostRequest + return r +} +func (r ApiPostAuthorizationsRequest) GetLegacyAuthorizationPostRequest() *LegacyAuthorizationPostRequest { + return r.legacyAuthorizationPostRequest +} + +func (r ApiPostAuthorizationsRequest) ZapTraceSpan(zapTraceSpan string) ApiPostAuthorizationsRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiPostAuthorizationsRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiPostAuthorizationsRequest) Execute() (Authorization, error) { + return r.ApiService.PostAuthorizationsExecute(r) +} + +/* + * PostAuthorizations Create an authorization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @return ApiPostAuthorizationsRequest + */ +func (a *LegacyAuthorizationsApiService) PostAuthorizations(ctx _context.Context) ApiPostAuthorizationsRequest { + return ApiPostAuthorizationsRequest{ + ApiService: a, + ctx: ctx, + } +} + +/* + * Execute executes the request + * @return Authorization + */ +func (a *LegacyAuthorizationsApiService) PostAuthorizationsExecute(r ApiPostAuthorizationsRequest) (Authorization, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + localVarReturnValue Authorization + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LegacyAuthorizationsApiService.PostAuthorizations") + if err != nil { + return localVarReturnValue, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/legacy/authorizations" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if r.legacyAuthorizationPostRequest == nil { + return localVarReturnValue, reportError("legacyAuthorizationPostRequest is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.zapTraceSpan != nil { + localVarHeaderParams["Zap-Trace-Span"] = parameterToString(*r.zapTraceSpan, "") + } + // body params + localVarPostBody = r.legacyAuthorizationPostRequest + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return localVarReturnValue, err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return localVarReturnValue, err + } + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + if localVarHTTPResponse.StatusCode == 400 { + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, newErr + } + newErr.model = &v + return localVarReturnValue, newErr + } + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, newErr + } + newErr.model = &v + return localVarReturnValue, newErr + } + + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return localVarReturnValue, err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return localVarReturnValue, err + } + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + +type ApiPostAuthorizationsIDPasswordRequest struct { + ctx _context.Context + ApiService LegacyAuthorizationsApi + authID string + passwordResetBody *PasswordResetBody + zapTraceSpan *string +} + +func (r ApiPostAuthorizationsIDPasswordRequest) AuthID(authID string) ApiPostAuthorizationsIDPasswordRequest { + r.authID = authID + return r +} +func (r ApiPostAuthorizationsIDPasswordRequest) GetAuthID() string { + return r.authID +} + +func (r ApiPostAuthorizationsIDPasswordRequest) PasswordResetBody(passwordResetBody PasswordResetBody) ApiPostAuthorizationsIDPasswordRequest { + r.passwordResetBody = &passwordResetBody + return r +} +func (r ApiPostAuthorizationsIDPasswordRequest) GetPasswordResetBody() *PasswordResetBody { + return r.passwordResetBody +} + +func (r ApiPostAuthorizationsIDPasswordRequest) ZapTraceSpan(zapTraceSpan string) ApiPostAuthorizationsIDPasswordRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiPostAuthorizationsIDPasswordRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiPostAuthorizationsIDPasswordRequest) Execute() error { + return r.ApiService.PostAuthorizationsIDPasswordExecute(r) +} + +/* + * PostAuthorizationsIDPassword Set an authorization password + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param authID The ID of the authorization to update. + * @return ApiPostAuthorizationsIDPasswordRequest + */ +func (a *LegacyAuthorizationsApiService) PostAuthorizationsIDPassword(ctx _context.Context, authID string) ApiPostAuthorizationsIDPasswordRequest { + return ApiPostAuthorizationsIDPasswordRequest{ + ApiService: a, + ctx: ctx, + authID: authID, + } +} + +/* + * Execute executes the request + */ +func (a *LegacyAuthorizationsApiService) PostAuthorizationsIDPasswordExecute(r ApiPostAuthorizationsIDPasswordRequest) error { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LegacyAuthorizationsApiService.PostAuthorizationsIDPassword") + if err != nil { + return GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/legacy/authorizations/{authID}/password" + localVarPath = strings.Replace(localVarPath, "{"+"authID"+"}", _neturl.PathEscape(parameterToString(r.authID, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if r.passwordResetBody == nil { + return reportError("passwordResetBody is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.zapTraceSpan != nil { + localVarHeaderParams["Zap-Trace-Span"] = parameterToString(*r.zapTraceSpan, "") + } + // body params + localVarPostBody = r.passwordResetBody + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return err + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + return err + } + localVarBody, err := _ioutil.ReadAll(body) + body.Close() + if err != nil { + return err + } + newErr := GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return newErr + } + newErr.model = &v + return newErr + } + + return nil +} diff --git a/api/client.gen.go b/api/client.gen.go index 542076a..ce3e3e0 100644 --- a/api/client.gen.go +++ b/api/client.gen.go @@ -61,6 +61,8 @@ type APIClient struct { HealthApi HealthApi + LegacyAuthorizationsApi LegacyAuthorizationsApi + OrganizationsApi OrganizationsApi QueryApi QueryApi @@ -107,6 +109,7 @@ func NewAPIClient(cfg *Configuration) *APIClient { c.DashboardsApi = (*DashboardsApiService)(&c.common) c.DeleteApi = (*DeleteApiService)(&c.common) c.HealthApi = (*HealthApiService)(&c.common) + c.LegacyAuthorizationsApi = (*LegacyAuthorizationsApiService)(&c.common) c.OrganizationsApi = (*OrganizationsApiService)(&c.common) c.QueryApi = (*QueryApiService)(&c.common) c.RestoreApi = (*RestoreApiService)(&c.common) diff --git a/api/configuration.gen.go b/api/configuration.gen.go index 3c01c36..5aa7ee1 100644 --- a/api/configuration.gen.go +++ b/api/configuration.gen.go @@ -113,6 +113,42 @@ func NewConfiguration() *Configuration { Description: "No description provided", }, }, + "LegacyAuthorizationsApiService.DeleteAuthorizationsID": { + { + URL: "/private", + Description: "No description provided", + }, + }, + "LegacyAuthorizationsApiService.GetAuthorizations": { + { + URL: "/private", + Description: "No description provided", + }, + }, + "LegacyAuthorizationsApiService.GetAuthorizationsID": { + { + URL: "/private", + Description: "No description provided", + }, + }, + "LegacyAuthorizationsApiService.PatchAuthorizationsID": { + { + URL: "/private", + Description: "No description provided", + }, + }, + "LegacyAuthorizationsApiService.PostAuthorizations": { + { + URL: "/private", + Description: "No description provided", + }, + }, + "LegacyAuthorizationsApiService.PostAuthorizationsIDPassword": { + { + URL: "/private", + Description: "No description provided", + }, + }, }, } return cfg diff --git a/api/contract/cli.yml b/api/contract/cli.yml index 706298b..9399e38 100644 --- a/api/contract/cli.yml +++ b/api/contract/cli.yml @@ -83,6 +83,18 @@ paths: $ref: "./openapi/src/common/paths/dbrps.yml" "/dbrps/{dbrpID}": $ref: "./openapi/src/common/paths/dbrps_dbrpID.yml" + /legacy/authorizations: + servers: + - url: "/private" + $ref: "./openapi/src/oss/paths/legacy_authorizations.yml" + /legacy/authorizations/{authID}: + servers: + - url: "/private" + $ref: "./openapi/src/oss/paths/legacy_authorizations_authID.yml" + /legacy/authorizations/{authID}/password: + servers: + - url: "/private" + $ref: "./openapi/src/oss/paths/legacy_authorizations_authID_password.yml" components: parameters: TraceSpan: @@ -369,3 +381,7 @@ components: $ref: "./openapi/src/common/schemas/DBRPUpdate.yml" DBRPGet: $ref: "./openapi/src/common/schemas/DBRPGet.yml" + Authorizations: + $ref: "./openapi/src/common/schemas/Authorizations.yml" + LegacyAuthorizationPostRequest: + $ref: "./openapi/src/oss/schemas/LegacyAuthorizationPostRequest.yml" diff --git a/api/contract/openapi b/api/contract/openapi index 8a47036..6b464c8 160000 --- a/api/contract/openapi +++ b/api/contract/openapi @@ -1 +1 @@ -Subproject commit 8a47036bed515857a28d7fba103c3b1b13ac64fd +Subproject commit 6b464c86dde496960da2f68b45a3e21a7a6f0b58 diff --git a/api/model_authorizations.gen.go b/api/model_authorizations.gen.go new file mode 100644 index 0000000..ed06fb9 --- /dev/null +++ b/api/model_authorizations.gen.go @@ -0,0 +1,149 @@ +/* + * Subset of Influx API covered by Influx CLI + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * API version: 2.0.0 + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api + +import ( + "encoding/json" +) + +// Authorizations struct for Authorizations +type Authorizations struct { + Links *Links `json:"links,omitempty"` + Authorizations *[]Authorization `json:"authorizations,omitempty"` +} + +// NewAuthorizations instantiates a new Authorizations object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewAuthorizations() *Authorizations { + this := Authorizations{} + return &this +} + +// NewAuthorizationsWithDefaults instantiates a new Authorizations object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewAuthorizationsWithDefaults() *Authorizations { + this := Authorizations{} + return &this +} + +// GetLinks returns the Links field value if set, zero value otherwise. +func (o *Authorizations) GetLinks() Links { + if o == nil || o.Links == nil { + var ret Links + return ret + } + return *o.Links +} + +// GetLinksOk returns a tuple with the Links field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Authorizations) GetLinksOk() (*Links, bool) { + if o == nil || o.Links == nil { + return nil, false + } + return o.Links, true +} + +// HasLinks returns a boolean if a field has been set. +func (o *Authorizations) HasLinks() bool { + if o != nil && o.Links != nil { + return true + } + + return false +} + +// SetLinks gets a reference to the given Links and assigns it to the Links field. +func (o *Authorizations) SetLinks(v Links) { + o.Links = &v +} + +// GetAuthorizations returns the Authorizations field value if set, zero value otherwise. +func (o *Authorizations) GetAuthorizations() []Authorization { + if o == nil || o.Authorizations == nil { + var ret []Authorization + return ret + } + return *o.Authorizations +} + +// GetAuthorizationsOk returns a tuple with the Authorizations field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Authorizations) GetAuthorizationsOk() (*[]Authorization, bool) { + if o == nil || o.Authorizations == nil { + return nil, false + } + return o.Authorizations, true +} + +// HasAuthorizations returns a boolean if a field has been set. +func (o *Authorizations) HasAuthorizations() bool { + if o != nil && o.Authorizations != nil { + return true + } + + return false +} + +// SetAuthorizations gets a reference to the given []Authorization and assigns it to the Authorizations field. +func (o *Authorizations) SetAuthorizations(v []Authorization) { + o.Authorizations = &v +} + +func (o Authorizations) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Links != nil { + toSerialize["links"] = o.Links + } + if o.Authorizations != nil { + toSerialize["authorizations"] = o.Authorizations + } + return json.Marshal(toSerialize) +} + +type NullableAuthorizations struct { + value *Authorizations + isSet bool +} + +func (v NullableAuthorizations) Get() *Authorizations { + return v.value +} + +func (v *NullableAuthorizations) Set(val *Authorizations) { + v.value = val + v.isSet = true +} + +func (v NullableAuthorizations) IsSet() bool { + return v.isSet +} + +func (v *NullableAuthorizations) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableAuthorizations(val *Authorizations) *NullableAuthorizations { + return &NullableAuthorizations{value: val, isSet: true} +} + +func (v NullableAuthorizations) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableAuthorizations) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/api/model_legacy_authorization_post_request.gen.go b/api/model_legacy_authorization_post_request.gen.go new file mode 100644 index 0000000..942bed6 --- /dev/null +++ b/api/model_legacy_authorization_post_request.gen.go @@ -0,0 +1,289 @@ +/* + * Subset of Influx API covered by Influx CLI + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * API version: 2.0.0 + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api + +import ( + "encoding/json" +) + +// LegacyAuthorizationPostRequest struct for LegacyAuthorizationPostRequest +type LegacyAuthorizationPostRequest struct { + // If inactive the token is inactive and requests using the token will be rejected. + Status *string `json:"status,omitempty"` + // A description of the token. + Description *string `json:"description,omitempty"` + // ID of org that authorization is scoped to. + OrgID string `json:"orgID"` + // ID of user that authorization is scoped to. + UserID *string `json:"userID,omitempty"` + // Token (name) of the authorization + Token *string `json:"token,omitempty"` + // List of permissions for an auth. An auth must have at least one Permission. + Permissions []Permission `json:"permissions"` +} + +// NewLegacyAuthorizationPostRequest instantiates a new LegacyAuthorizationPostRequest object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLegacyAuthorizationPostRequest(orgID string, permissions []Permission) *LegacyAuthorizationPostRequest { + this := LegacyAuthorizationPostRequest{} + var status string = "active" + this.Status = &status + this.OrgID = orgID + this.Permissions = permissions + return &this +} + +// NewLegacyAuthorizationPostRequestWithDefaults instantiates a new LegacyAuthorizationPostRequest object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLegacyAuthorizationPostRequestWithDefaults() *LegacyAuthorizationPostRequest { + this := LegacyAuthorizationPostRequest{} + var status string = "active" + this.Status = &status + return &this +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *LegacyAuthorizationPostRequest) GetStatus() string { + if o == nil || o.Status == nil { + var ret string + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequest) GetStatusOk() (*string, bool) { + if o == nil || o.Status == nil { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *LegacyAuthorizationPostRequest) HasStatus() bool { + if o != nil && o.Status != nil { + return true + } + + return false +} + +// SetStatus gets a reference to the given string and assigns it to the Status field. +func (o *LegacyAuthorizationPostRequest) SetStatus(v string) { + o.Status = &v +} + +// GetDescription returns the Description field value if set, zero value otherwise. +func (o *LegacyAuthorizationPostRequest) GetDescription() string { + if o == nil || o.Description == nil { + var ret string + return ret + } + return *o.Description +} + +// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequest) GetDescriptionOk() (*string, bool) { + if o == nil || o.Description == nil { + return nil, false + } + return o.Description, true +} + +// HasDescription returns a boolean if a field has been set. +func (o *LegacyAuthorizationPostRequest) HasDescription() bool { + if o != nil && o.Description != nil { + return true + } + + return false +} + +// SetDescription gets a reference to the given string and assigns it to the Description field. +func (o *LegacyAuthorizationPostRequest) SetDescription(v string) { + o.Description = &v +} + +// GetOrgID returns the OrgID field value +func (o *LegacyAuthorizationPostRequest) GetOrgID() string { + if o == nil { + var ret string + return ret + } + + return o.OrgID +} + +// GetOrgIDOk returns a tuple with the OrgID field value +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequest) GetOrgIDOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.OrgID, true +} + +// SetOrgID sets field value +func (o *LegacyAuthorizationPostRequest) SetOrgID(v string) { + o.OrgID = v +} + +// GetUserID returns the UserID field value if set, zero value otherwise. +func (o *LegacyAuthorizationPostRequest) GetUserID() string { + if o == nil || o.UserID == nil { + var ret string + return ret + } + return *o.UserID +} + +// GetUserIDOk returns a tuple with the UserID field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequest) GetUserIDOk() (*string, bool) { + if o == nil || o.UserID == nil { + return nil, false + } + return o.UserID, true +} + +// HasUserID returns a boolean if a field has been set. +func (o *LegacyAuthorizationPostRequest) HasUserID() bool { + if o != nil && o.UserID != nil { + return true + } + + return false +} + +// SetUserID gets a reference to the given string and assigns it to the UserID field. +func (o *LegacyAuthorizationPostRequest) SetUserID(v string) { + o.UserID = &v +} + +// GetToken returns the Token field value if set, zero value otherwise. +func (o *LegacyAuthorizationPostRequest) GetToken() string { + if o == nil || o.Token == nil { + var ret string + return ret + } + return *o.Token +} + +// GetTokenOk returns a tuple with the Token field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequest) GetTokenOk() (*string, bool) { + if o == nil || o.Token == nil { + return nil, false + } + return o.Token, true +} + +// HasToken returns a boolean if a field has been set. +func (o *LegacyAuthorizationPostRequest) HasToken() bool { + if o != nil && o.Token != nil { + return true + } + + return false +} + +// SetToken gets a reference to the given string and assigns it to the Token field. +func (o *LegacyAuthorizationPostRequest) SetToken(v string) { + o.Token = &v +} + +// GetPermissions returns the Permissions field value +func (o *LegacyAuthorizationPostRequest) GetPermissions() []Permission { + if o == nil { + var ret []Permission + return ret + } + + return o.Permissions +} + +// GetPermissionsOk returns a tuple with the Permissions field value +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequest) GetPermissionsOk() (*[]Permission, bool) { + if o == nil { + return nil, false + } + return &o.Permissions, true +} + +// SetPermissions sets field value +func (o *LegacyAuthorizationPostRequest) SetPermissions(v []Permission) { + o.Permissions = v +} + +func (o LegacyAuthorizationPostRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Status != nil { + toSerialize["status"] = o.Status + } + if o.Description != nil { + toSerialize["description"] = o.Description + } + if true { + toSerialize["orgID"] = o.OrgID + } + if o.UserID != nil { + toSerialize["userID"] = o.UserID + } + if o.Token != nil { + toSerialize["token"] = o.Token + } + if true { + toSerialize["permissions"] = o.Permissions + } + return json.Marshal(toSerialize) +} + +type NullableLegacyAuthorizationPostRequest struct { + value *LegacyAuthorizationPostRequest + isSet bool +} + +func (v NullableLegacyAuthorizationPostRequest) Get() *LegacyAuthorizationPostRequest { + return v.value +} + +func (v *NullableLegacyAuthorizationPostRequest) Set(val *LegacyAuthorizationPostRequest) { + v.value = val + v.isSet = true +} + +func (v NullableLegacyAuthorizationPostRequest) IsSet() bool { + return v.isSet +} + +func (v *NullableLegacyAuthorizationPostRequest) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLegacyAuthorizationPostRequest(val *LegacyAuthorizationPostRequest) *NullableLegacyAuthorizationPostRequest { + return &NullableLegacyAuthorizationPostRequest{value: val, isSet: true} +} + +func (v NullableLegacyAuthorizationPostRequest) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLegacyAuthorizationPostRequest) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/api/model_legacy_authorization_post_request_all_of.gen.go b/api/model_legacy_authorization_post_request_all_of.gen.go new file mode 100644 index 0000000..01ce189 --- /dev/null +++ b/api/model_legacy_authorization_post_request_all_of.gen.go @@ -0,0 +1,225 @@ +/* + * Subset of Influx API covered by Influx CLI + * + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * API version: 2.0.0 + */ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api + +import ( + "encoding/json" +) + +// LegacyAuthorizationPostRequestAllOf struct for LegacyAuthorizationPostRequestAllOf +type LegacyAuthorizationPostRequestAllOf struct { + // ID of org that authorization is scoped to. + OrgID *string `json:"orgID,omitempty"` + // ID of user that authorization is scoped to. + UserID *string `json:"userID,omitempty"` + // Token (name) of the authorization + Token *string `json:"token,omitempty"` + // List of permissions for an auth. An auth must have at least one Permission. + Permissions *[]Permission `json:"permissions,omitempty"` +} + +// NewLegacyAuthorizationPostRequestAllOf instantiates a new LegacyAuthorizationPostRequestAllOf object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLegacyAuthorizationPostRequestAllOf() *LegacyAuthorizationPostRequestAllOf { + this := LegacyAuthorizationPostRequestAllOf{} + return &this +} + +// NewLegacyAuthorizationPostRequestAllOfWithDefaults instantiates a new LegacyAuthorizationPostRequestAllOf object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLegacyAuthorizationPostRequestAllOfWithDefaults() *LegacyAuthorizationPostRequestAllOf { + this := LegacyAuthorizationPostRequestAllOf{} + return &this +} + +// GetOrgID returns the OrgID field value if set, zero value otherwise. +func (o *LegacyAuthorizationPostRequestAllOf) GetOrgID() string { + if o == nil || o.OrgID == nil { + var ret string + return ret + } + return *o.OrgID +} + +// GetOrgIDOk returns a tuple with the OrgID field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequestAllOf) GetOrgIDOk() (*string, bool) { + if o == nil || o.OrgID == nil { + return nil, false + } + return o.OrgID, true +} + +// HasOrgID returns a boolean if a field has been set. +func (o *LegacyAuthorizationPostRequestAllOf) HasOrgID() bool { + if o != nil && o.OrgID != nil { + return true + } + + return false +} + +// SetOrgID gets a reference to the given string and assigns it to the OrgID field. +func (o *LegacyAuthorizationPostRequestAllOf) SetOrgID(v string) { + o.OrgID = &v +} + +// GetUserID returns the UserID field value if set, zero value otherwise. +func (o *LegacyAuthorizationPostRequestAllOf) GetUserID() string { + if o == nil || o.UserID == nil { + var ret string + return ret + } + return *o.UserID +} + +// GetUserIDOk returns a tuple with the UserID field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequestAllOf) GetUserIDOk() (*string, bool) { + if o == nil || o.UserID == nil { + return nil, false + } + return o.UserID, true +} + +// HasUserID returns a boolean if a field has been set. +func (o *LegacyAuthorizationPostRequestAllOf) HasUserID() bool { + if o != nil && o.UserID != nil { + return true + } + + return false +} + +// SetUserID gets a reference to the given string and assigns it to the UserID field. +func (o *LegacyAuthorizationPostRequestAllOf) SetUserID(v string) { + o.UserID = &v +} + +// GetToken returns the Token field value if set, zero value otherwise. +func (o *LegacyAuthorizationPostRequestAllOf) GetToken() string { + if o == nil || o.Token == nil { + var ret string + return ret + } + return *o.Token +} + +// GetTokenOk returns a tuple with the Token field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequestAllOf) GetTokenOk() (*string, bool) { + if o == nil || o.Token == nil { + return nil, false + } + return o.Token, true +} + +// HasToken returns a boolean if a field has been set. +func (o *LegacyAuthorizationPostRequestAllOf) HasToken() bool { + if o != nil && o.Token != nil { + return true + } + + return false +} + +// SetToken gets a reference to the given string and assigns it to the Token field. +func (o *LegacyAuthorizationPostRequestAllOf) SetToken(v string) { + o.Token = &v +} + +// GetPermissions returns the Permissions field value if set, zero value otherwise. +func (o *LegacyAuthorizationPostRequestAllOf) GetPermissions() []Permission { + if o == nil || o.Permissions == nil { + var ret []Permission + return ret + } + return *o.Permissions +} + +// GetPermissionsOk returns a tuple with the Permissions field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LegacyAuthorizationPostRequestAllOf) GetPermissionsOk() (*[]Permission, bool) { + if o == nil || o.Permissions == nil { + return nil, false + } + return o.Permissions, true +} + +// HasPermissions returns a boolean if a field has been set. +func (o *LegacyAuthorizationPostRequestAllOf) HasPermissions() bool { + if o != nil && o.Permissions != nil { + return true + } + + return false +} + +// SetPermissions gets a reference to the given []Permission and assigns it to the Permissions field. +func (o *LegacyAuthorizationPostRequestAllOf) SetPermissions(v []Permission) { + o.Permissions = &v +} + +func (o LegacyAuthorizationPostRequestAllOf) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.OrgID != nil { + toSerialize["orgID"] = o.OrgID + } + if o.UserID != nil { + toSerialize["userID"] = o.UserID + } + if o.Token != nil { + toSerialize["token"] = o.Token + } + if o.Permissions != nil { + toSerialize["permissions"] = o.Permissions + } + return json.Marshal(toSerialize) +} + +type NullableLegacyAuthorizationPostRequestAllOf struct { + value *LegacyAuthorizationPostRequestAllOf + isSet bool +} + +func (v NullableLegacyAuthorizationPostRequestAllOf) Get() *LegacyAuthorizationPostRequestAllOf { + return v.value +} + +func (v *NullableLegacyAuthorizationPostRequestAllOf) Set(val *LegacyAuthorizationPostRequestAllOf) { + v.value = val + v.isSet = true +} + +func (v NullableLegacyAuthorizationPostRequestAllOf) IsSet() bool { + return v.isSet +} + +func (v *NullableLegacyAuthorizationPostRequestAllOf) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLegacyAuthorizationPostRequestAllOf(val *LegacyAuthorizationPostRequestAllOf) *NullableLegacyAuthorizationPostRequestAllOf { + return &NullableLegacyAuthorizationPostRequestAllOf{value: val, isSet: true} +} + +func (v NullableLegacyAuthorizationPostRequestAllOf) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLegacyAuthorizationPostRequestAllOf) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/api/model_permission_resource.gen.go b/api/model_permission_resource.gen.go index 8b972e6..7558326 100644 --- a/api/model_permission_resource.gen.go +++ b/api/model_permission_resource.gen.go @@ -18,13 +18,13 @@ import ( type PermissionResource struct { Type string `json:"type"` // If ID is set that is a permission for a specific resource. if it is not set it is a permission for all resources of that resource type. - Id NullableString `json:"id,omitempty"` + Id *string `json:"id,omitempty"` // Optional name of the resource if the resource has a name field. - Name NullableString `json:"name,omitempty"` + Name *string `json:"name,omitempty"` // If orgID is set that is a permission for all resources owned my that org. if it is not set it is a permission for all resources of that resource type. - OrgID NullableString `json:"orgID,omitempty"` + OrgID *string `json:"orgID,omitempty"` // Optional name of the organization of the organization with orgID. - Org NullableString `json:"org,omitempty"` + Org *string `json:"org,omitempty"` } // NewPermissionResource instantiates a new PermissionResource object @@ -69,176 +69,132 @@ func (o *PermissionResource) SetType(v string) { o.Type = v } -// GetId returns the Id field value if set, zero value otherwise (both if not set or set to explicit null). +// GetId returns the Id field value if set, zero value otherwise. func (o *PermissionResource) GetId() string { - if o == nil || o.Id.Get() == nil { + if o == nil || o.Id == nil { var ret string return ret } - return *o.Id.Get() + return *o.Id } // GetIdOk returns a tuple with the Id field value if set, nil otherwise // and a boolean to check if the value has been set. -// NOTE: If the value is an explicit nil, `nil, true` will be returned func (o *PermissionResource) GetIdOk() (*string, bool) { - if o == nil { + if o == nil || o.Id == nil { return nil, false } - return o.Id.Get(), o.Id.IsSet() + return o.Id, true } // HasId returns a boolean if a field has been set. func (o *PermissionResource) HasId() bool { - if o != nil && o.Id.IsSet() { + if o != nil && o.Id != nil { return true } return false } -// SetId gets a reference to the given NullableString and assigns it to the Id field. +// SetId gets a reference to the given string and assigns it to the Id field. func (o *PermissionResource) SetId(v string) { - o.Id.Set(&v) + o.Id = &v } -// SetIdNil sets the value for Id to be an explicit nil -func (o *PermissionResource) SetIdNil() { - o.Id.Set(nil) -} - -// UnsetId ensures that no value is present for Id, not even an explicit nil -func (o *PermissionResource) UnsetId() { - o.Id.Unset() -} - -// GetName returns the Name field value if set, zero value otherwise (both if not set or set to explicit null). +// GetName returns the Name field value if set, zero value otherwise. func (o *PermissionResource) GetName() string { - if o == nil || o.Name.Get() == nil { + if o == nil || o.Name == nil { var ret string return ret } - return *o.Name.Get() + return *o.Name } // GetNameOk returns a tuple with the Name field value if set, nil otherwise // and a boolean to check if the value has been set. -// NOTE: If the value is an explicit nil, `nil, true` will be returned func (o *PermissionResource) GetNameOk() (*string, bool) { - if o == nil { + if o == nil || o.Name == nil { return nil, false } - return o.Name.Get(), o.Name.IsSet() + return o.Name, true } // HasName returns a boolean if a field has been set. func (o *PermissionResource) HasName() bool { - if o != nil && o.Name.IsSet() { + if o != nil && o.Name != nil { return true } return false } -// SetName gets a reference to the given NullableString and assigns it to the Name field. +// SetName gets a reference to the given string and assigns it to the Name field. func (o *PermissionResource) SetName(v string) { - o.Name.Set(&v) + o.Name = &v } -// SetNameNil sets the value for Name to be an explicit nil -func (o *PermissionResource) SetNameNil() { - o.Name.Set(nil) -} - -// UnsetName ensures that no value is present for Name, not even an explicit nil -func (o *PermissionResource) UnsetName() { - o.Name.Unset() -} - -// GetOrgID returns the OrgID field value if set, zero value otherwise (both if not set or set to explicit null). +// GetOrgID returns the OrgID field value if set, zero value otherwise. func (o *PermissionResource) GetOrgID() string { - if o == nil || o.OrgID.Get() == nil { + if o == nil || o.OrgID == nil { var ret string return ret } - return *o.OrgID.Get() + return *o.OrgID } // GetOrgIDOk returns a tuple with the OrgID field value if set, nil otherwise // and a boolean to check if the value has been set. -// NOTE: If the value is an explicit nil, `nil, true` will be returned func (o *PermissionResource) GetOrgIDOk() (*string, bool) { - if o == nil { + if o == nil || o.OrgID == nil { return nil, false } - return o.OrgID.Get(), o.OrgID.IsSet() + return o.OrgID, true } // HasOrgID returns a boolean if a field has been set. func (o *PermissionResource) HasOrgID() bool { - if o != nil && o.OrgID.IsSet() { + if o != nil && o.OrgID != nil { return true } return false } -// SetOrgID gets a reference to the given NullableString and assigns it to the OrgID field. +// SetOrgID gets a reference to the given string and assigns it to the OrgID field. func (o *PermissionResource) SetOrgID(v string) { - o.OrgID.Set(&v) + o.OrgID = &v } -// SetOrgIDNil sets the value for OrgID to be an explicit nil -func (o *PermissionResource) SetOrgIDNil() { - o.OrgID.Set(nil) -} - -// UnsetOrgID ensures that no value is present for OrgID, not even an explicit nil -func (o *PermissionResource) UnsetOrgID() { - o.OrgID.Unset() -} - -// GetOrg returns the Org field value if set, zero value otherwise (both if not set or set to explicit null). +// GetOrg returns the Org field value if set, zero value otherwise. func (o *PermissionResource) GetOrg() string { - if o == nil || o.Org.Get() == nil { + if o == nil || o.Org == nil { var ret string return ret } - return *o.Org.Get() + return *o.Org } // GetOrgOk returns a tuple with the Org field value if set, nil otherwise // and a boolean to check if the value has been set. -// NOTE: If the value is an explicit nil, `nil, true` will be returned func (o *PermissionResource) GetOrgOk() (*string, bool) { - if o == nil { + if o == nil || o.Org == nil { return nil, false } - return o.Org.Get(), o.Org.IsSet() + return o.Org, true } // HasOrg returns a boolean if a field has been set. func (o *PermissionResource) HasOrg() bool { - if o != nil && o.Org.IsSet() { + if o != nil && o.Org != nil { return true } return false } -// SetOrg gets a reference to the given NullableString and assigns it to the Org field. +// SetOrg gets a reference to the given string and assigns it to the Org field. func (o *PermissionResource) SetOrg(v string) { - o.Org.Set(&v) -} - -// SetOrgNil sets the value for Org to be an explicit nil -func (o *PermissionResource) SetOrgNil() { - o.Org.Set(nil) -} - -// UnsetOrg ensures that no value is present for Org, not even an explicit nil -func (o *PermissionResource) UnsetOrg() { - o.Org.Unset() + o.Org = &v } func (o PermissionResource) MarshalJSON() ([]byte, error) { @@ -246,17 +202,17 @@ func (o PermissionResource) MarshalJSON() ([]byte, error) { if true { toSerialize["type"] = o.Type } - if o.Id.IsSet() { - toSerialize["id"] = o.Id.Get() + if o.Id != nil { + toSerialize["id"] = o.Id } - if o.Name.IsSet() { - toSerialize["name"] = o.Name.Get() + if o.Name != nil { + toSerialize["name"] = o.Name } - if o.OrgID.IsSet() { - toSerialize["orgID"] = o.OrgID.Get() + if o.OrgID != nil { + toSerialize["orgID"] = o.OrgID } - if o.Org.IsSet() { - toSerialize["org"] = o.Org.Get() + if o.Org != nil { + toSerialize["org"] = o.Org } return json.Marshal(toSerialize) } diff --git a/clients/v1_auth/v1_auth.go b/clients/v1_auth/v1_auth.go new file mode 100644 index 0000000..8b68c62 --- /dev/null +++ b/clients/v1_auth/v1_auth.go @@ -0,0 +1,438 @@ +package v1_auth + +import ( + "context" + "fmt" + + "github.com/influxdata/influx-cli/v2/api" + "github.com/influxdata/influx-cli/v2/clients" + "github.com/influxdata/influx-cli/v2/pkg/influxid" +) + +type Client struct { + clients.CLI + api.LegacyAuthorizationsApi + api.UsersApi + api.OrganizationsApi +} + +type AuthLookupParams struct { + ID influxid.ID + Username string +} + +func (p AuthLookupParams) Validate() (err error) { + if p.Username == "" && !p.ID.Valid() { + err = fmt.Errorf("id or username required") + } else if p.Username != "" && p.ID.Valid() { + err = fmt.Errorf("specify id or username, not both") + } + return +} + +func (p AuthLookupParams) IsSet() bool { + return p.ID.Valid() || p.Username != "" +} + +type v1PrintOpts struct { + deleted bool + token *v1Token + tokens []v1Token +} + +type v1Token struct { + ID string `json:"id"` + Description string `json:"description"` + Token string `json:"token"` + Status string `json:"status"` + UserName string `json:"userName"` + UserID string `json:"userID"` + Permissions []string `json:"permissions"` +} + +type CreateParams struct { + clients.OrgParams + Desc string + Username string + Password string + NoPassword bool + ReadBucket []string + WriteBucket []string +} + +func (c Client) Create(ctx context.Context, params *CreateParams) error { + if params.Password != "" && params.NoPassword { + return fmt.Errorf("only one of --password and --no-password may be specified") + } + + orgID, err := c.getOrgID(ctx, params.OrgParams) + if err != nil { + return err + } + + // verify an existing token with the same username doesn't already exist + auths, err := c.LegacyAuthorizationsApi.GetAuthorizations(ctx).Token(params.Username).Execute() + if apiError, ok := err.(api.ApiError); ok { + if apiError.ErrorCode() != api.ERRORCODE_NOT_FOUND { + return fmt.Errorf("failed to verify username %q has no auth: %w", params.Username, err) + } else if len(auths.GetAuthorizations()) != 0 { + return fmt.Errorf("authorization with username %q already exists", params.Username) + } + } + + password := params.Password + if password == "" && !params.NoPassword { + pass, err := c.StdIO.GetPassword("Please type your password") + if err != nil { + return err + } + password = pass + } + + bucketPerms := []struct { + action string + perms []string + }{ + {action: "read", perms: params.ReadBucket}, + {action: "write", perms: params.WriteBucket}, + } + + var permissions []api.Permission + for _, bp := range bucketPerms { + for _, p := range bp.perms { + // verify the input ID + if _, err := influxid.IDFromString(p); err != nil { + return fmt.Errorf("invalid bucket ID '%s': %w (did you pass a bucket name instead of an ID?)", p, err) + } + + newPerm := api.Permission{ + Action: bp.action, + Resource: api.PermissionResource{ + Type: "buckets", + Id: &p, + OrgID: &orgID, + }, + } + permissions = append(permissions, newPerm) + } + } + authReq := api.LegacyAuthorizationPostRequest{ + Description: ¶ms.Desc, + OrgID: orgID, + Permissions: permissions, + Token: ¶ms.Username, + } + + newAuth, err := c.LegacyAuthorizationsApi.PostAuthorizations(ctx).LegacyAuthorizationPostRequest(authReq).Execute() + if err != nil { + return fmt.Errorf("failed to create new authorization: %w", err) + } + + if password != "" { + err := c.LegacyAuthorizationsApi.PostAuthorizationsIDPassword(ctx, newAuth.GetId()). + PasswordResetBody(api.PasswordResetBody{Password: password}). + Execute() + if err != nil { + _ = c.LegacyAuthorizationsApi.DeleteAuthorizationsID(ctx, newAuth.GetId()).Execute() + return fmt.Errorf("failed to set password for %q: %w", params.Username, err) + } + } + + usr, err := c.UsersApi.GetUsersID(ctx, newAuth.GetUserID()).Execute() + if err != nil { + return err + } + + ps := make([]string, 0, len(newAuth.Permissions)) + for _, p := range newAuth.Permissions { + ps = append(ps, permString(p)) + } + + return c.printV1Tokens(&v1PrintOpts{ + token: &v1Token{ + ID: newAuth.GetId(), + Description: newAuth.GetDescription(), + Token: newAuth.GetToken(), + Status: newAuth.GetStatus(), + UserName: usr.GetName(), + UserID: usr.GetId(), + Permissions: ps, + }, + }) +} + +type RemoveParams struct { + AuthLookupParams +} + +func (c Client) Remove(ctx context.Context, params *RemoveParams) error { + id, err := c.getAuthReqID(ctx, ¶ms.AuthLookupParams) + if err != nil { + return err + } + + auth, err := c.LegacyAuthorizationsApi.GetAuthorizationsID(ctx, id).Execute() + if err != nil { + return fmt.Errorf("could not find Authorization from ID %q: %w", id, err) + } + err = c.LegacyAuthorizationsApi.DeleteAuthorizationsID(ctx, id).Execute() + if err != nil { + return fmt.Errorf("could not remove Authorization with ID %q: %w", id, err) + } + + usr, err := c.UsersApi.GetUsersID(ctx, auth.GetUserID()).Execute() + if err != nil { + return fmt.Errorf("could not find user from user ID %q: %w", auth.GetUserID(), err) + } + + ps := make([]string, 0, len(auth.GetPermissions())) + for _, p := range auth.GetPermissions() { + ps = append(ps, permString(p)) + } + + return c.printV1Tokens(&v1PrintOpts{ + deleted: true, + token: &v1Token{ + ID: auth.GetId(), + Description: auth.GetDescription(), + Token: auth.GetToken(), + Status: auth.GetStatus(), + UserName: usr.GetName(), + UserID: usr.GetId(), + Permissions: ps, + }, + }) +} + +type ListParams struct { + clients.OrgParams + AuthLookupParams + User string + UserID string +} + +func (c Client) List(ctx context.Context, params *ListParams) error { + req := c.LegacyAuthorizationsApi.GetAuthorizations(ctx) + + if params.User != "" { + req = req.User(params.User) + } + if params.UserID != "" { + req = req.UserID(params.UserID) + } + if params.OrgID.Valid() { + req = req.OrgID(params.OrgID.String()) + } + if params.OrgName != "" { + req = req.Org(params.OrgName) + } + if params.Username != "" { + req = req.Token(params.Username) + } + if params.ID.Valid() { + req = req.AuthID(params.ID.String()) + } + + auths, err := req.Execute() + if err != nil { + return fmt.Errorf("could not find Authorizations for specified arguments: %w", err) + } + + var tokens []v1Token + for _, a := range auths.GetAuthorizations() { + var permissions []string + for _, p := range a.GetPermissions() { + permissions = append(permissions, permString(p)) + } + + usr, err := c.UsersApi.GetUsersID(ctx, a.GetUserID()).Execute() + if err != nil { + return fmt.Errorf("could not find user with ID %q: %w", a.GetUserID(), err) + } + + tokens = append(tokens, v1Token{ + ID: a.GetId(), + Description: a.GetDescription(), + Token: a.GetToken(), + Status: a.GetStatus(), + UserName: usr.GetName(), + UserID: usr.GetId(), + Permissions: permissions, + }) + } + + return c.printV1Tokens(&v1PrintOpts{tokens: tokens}) +} + +type ActiveParams struct { + AuthLookupParams +} + +func (c Client) SetActive(ctx context.Context, params *ActiveParams, active bool) error { + id, err := c.getAuthReqID(ctx, ¶ms.AuthLookupParams) + if err != nil { + return err + } + + req := c.LegacyAuthorizationsApi.PatchAuthorizationsID(ctx, id) + var status string + if active { + status = "active" + } else { + status = "inactive" + } + req = req.AuthorizationUpdateRequest(api.AuthorizationUpdateRequest{ + Status: &status, + }) + + auth, err := req.Execute() + if err != nil { + return fmt.Errorf("failed to update status of authorization with ID %q: %w", id, err) + } + + usr, err := c.UsersApi.GetUsersID(ctx, auth.GetUserID()).Execute() + if err != nil { + return fmt.Errorf("could not find user from User ID %q: %w", auth.GetUserID(), err) + } + + ps := make([]string, 0, len(auth.GetPermissions())) + for _, p := range auth.GetPermissions() { + ps = append(ps, permString(p)) + } + + return c.printV1Tokens(&v1PrintOpts{ + token: &v1Token{ + ID: auth.GetId(), + Description: auth.GetDescription(), + Token: auth.GetToken(), + Status: auth.GetStatus(), + UserName: usr.GetName(), + UserID: usr.GetId(), + Permissions: ps, + }, + }) +} + +type SetPasswordParams struct { + AuthLookupParams + Password string +} + +func (c Client) SetPassword(ctx context.Context, params *SetPasswordParams) error { + id, err := c.getAuthReqID(ctx, ¶ms.AuthLookupParams) + if err != nil { + return err + } + + password := params.Password + if password == "" { + pass, err := c.StdIO.GetPassword("Please type new password") + if err != nil { + return err + } + password = pass + } + + err = c.LegacyAuthorizationsApi.PostAuthorizationsIDPassword(ctx, id). + PasswordResetBody(api.PasswordResetBody{Password: password}). + Execute() + if err != nil { + return fmt.Errorf("error setting password: %w", err) + } + + return nil +} + +func (c Client) printV1Tokens(params *v1PrintOpts) error { + if c.PrintAsJSON { + var v interface{} + if params.token != nil { + v = params.token + } else { + v = params.tokens + } + return c.PrintJSON(v) + } + + headers := []string{ + "ID", + "Description", + "Name / Token", + "User Name", + "User ID", + "Permissions", + } + if params.deleted { + headers = append(headers, "Deleted") + } + if params.token != nil { + params.tokens = append(params.tokens, *params.token) + } + + var rows []map[string]interface{} + for _, u := range params.tokens { + row := map[string]interface{}{ + "ID": u.ID, + "Description": u.Description, + "Name / Token": u.Token, + "User Name": u.UserName, + "User ID": u.UserID, + "Permissions": u.Permissions, + } + if params.deleted { + row["Deleted"] = true + } + rows = append(rows, row) + } + return c.PrintTable(headers, rows...) +} + +func permString(p api.Permission) string { + ret := p.GetAction() + ":" + r := p.GetResource() + + if r.GetOrgID() != "" { + ret += "orgs/" + r.GetOrgID() + } + ret += "/" + r.GetType() + if r.GetId() != "" { + ret += "/" + r.GetId() + } + return ret +} + +func (c Client) getAuthReqID(ctx context.Context, params *AuthLookupParams) (id string, err error) { + if params.ID.Valid() { + id = params.ID.String() + } else { + var auths api.Authorizations + auths, err = c.LegacyAuthorizationsApi.GetAuthorizations(ctx).Token(params.Username).Execute() + if err != nil || len(auths.GetAuthorizations()) == 0 { + err = fmt.Errorf("could not find v1 auth with token (username) %q: %w", params.Username, err) + } else { + id = auths.GetAuthorizations()[0].GetId() + } + } + return +} + +func (c Client) getOrgID(ctx context.Context, params clients.OrgParams) (string, error) { + if !params.OrgID.Valid() && params.OrgName == "" && c.ActiveConfig.Org == "" { + return "", clients.ErrMustSpecifyOrg + } + if params.OrgID.Valid() { + return params.OrgID.String(), nil + } + name := params.OrgName + if name == "" { + name = c.ActiveConfig.Org + } + org, err := c.GetOrgs(ctx).Org(name).Execute() + if err != nil { + return "", fmt.Errorf("failed to lookup org with name %q: %w", name, err) + } + if len(org.GetOrgs()) == 0 { + return "", fmt.Errorf("no organization with name %q: %w", name, err) + } + return org.GetOrgs()[0].GetId(), nil +} diff --git a/cmd/influx/v1_auth.go b/cmd/influx/v1_auth.go new file mode 100644 index 0000000..7edf126 --- /dev/null +++ b/cmd/influx/v1_auth.go @@ -0,0 +1,233 @@ +package main + +import ( + "github.com/influxdata/influx-cli/v2/clients/v1_auth" + "github.com/influxdata/influx-cli/v2/pkg/cli/middleware" + "github.com/urfave/cli/v2" +) + +// getAuthLookupFlags returns flags used for authorization, requiring either an ID or Username, +// and can specify to require one but not both. +func getAuthLookupFlags(params *v1_auth.AuthLookupParams) []cli.Flag { + return []cli.Flag{ + &cli.GenericFlag{ + Name: "id", + Usage: "The ID of the authorization", + Value: ¶ms.ID, + }, + &cli.StringFlag{ + Name: "username", + Usage: "The username of the authorization", + Destination: ¶ms.Username, + }, + } +} + +func newV1AuthCommand() *cli.Command { + return &cli.Command{ + Name: "auth", + Usage: "Authorization management commands for v1 APIs", + Aliases: []string{"authorization"}, + Subcommands: []*cli.Command{ + newCreateV1AuthCmd(), + newRemoveV1AuthCmd(), + newListV1AuthCmd(), + newSetActiveV1AuthCmd(), + newSetInactiveV1AuthCmd(), + newSetPswdV1AuthCmd(), + }, + } +} + +func newCreateV1AuthCmd() *cli.Command { + var params v1_auth.CreateParams + flags := append(commonFlags(), getOrgFlags(¶ms.OrgParams)...) + flags = append(flags, + &cli.StringFlag{ + Name: "description", + Usage: "Token description", + Aliases: []string{"d"}, + Destination: ¶ms.Desc, + }, + &cli.StringFlag{ + Name: "username", + Usage: "The username to identify this token", + Required: true, + Destination: ¶ms.Username, + }, + &cli.StringFlag{ + Name: "password", + Usage: "The password to set on this token", + Destination: ¶ms.Password, + }, + &cli.BoolFlag{ + Name: "no-password", + Usage: "Don't prompt for a password. You must use v1 auth set-password command before using the token.", + Destination: ¶ms.NoPassword, + }, + &cli.StringSliceFlag{ + Name: "read-bucket", + Usage: "The bucket id", + }, + &cli.StringSliceFlag{ + Name: "write-bucket", + Usage: "The bucket id", + }, + ) + return &cli.Command{ + Name: "create", + Usage: "Create authorization", + Flags: flags, + Before: middleware.WithBeforeFns(withCli(), withApi(true)), + Action: func(ctx *cli.Context) error { + params.ReadBucket = ctx.StringSlice("read-bucket") + params.WriteBucket = ctx.StringSlice("write-bucket") + api := getAPI(ctx) + client := v1_auth.Client{ + CLI: getCLI(ctx), + LegacyAuthorizationsApi: api.LegacyAuthorizationsApi, + UsersApi: api.UsersApi, + OrganizationsApi: api.OrganizationsApi, + } + return client.Create(ctx.Context, ¶ms) + }, + } +} + +func newRemoveV1AuthCmd() *cli.Command { + var params v1_auth.RemoveParams + flags := append(commonFlags(), getAuthLookupFlags(¶ms.AuthLookupParams)...) + return &cli.Command{ + Name: "delete", + Usage: "Delete authorization", + Flags: flags, + Before: middleware.WithBeforeFns(withCli(), withApi(true)), + Action: func(ctx *cli.Context) error { + if err := params.AuthLookupParams.Validate(); err != nil { + return err + } + + api := getAPI(ctx) + client := v1_auth.Client{ + CLI: getCLI(ctx), + LegacyAuthorizationsApi: api.LegacyAuthorizationsApi, + UsersApi: api.UsersApi, + OrganizationsApi: api.OrganizationsApi, + } + return client.Remove(ctx.Context, ¶ms) + }, + } +} + +func newListV1AuthCmd() *cli.Command { + var params v1_auth.ListParams + flags := append(commonFlags(), getOrgFlags(¶ms.OrgParams)...) + flags = append(flags, getAuthLookupFlags(¶ms.AuthLookupParams)...) + flags = append(flags, + &cli.StringFlag{ + Name: "user", + Usage: "The user", + Aliases: []string{"u"}, + Destination: ¶ms.User, + }, + &cli.StringFlag{ + Name: "user-id", + Usage: "The user ID", + Destination: ¶ms.UserID, + }, + ) + return &cli.Command{ + Name: "list", + Usage: "List authorizations", + Aliases: []string{"ls", "find"}, + Flags: flags, + Before: middleware.WithBeforeFns(withCli(), withApi(true)), + Action: func(ctx *cli.Context) error { + api := getAPI(ctx) + client := v1_auth.Client{ + CLI: getCLI(ctx), + LegacyAuthorizationsApi: api.LegacyAuthorizationsApi, + UsersApi: api.UsersApi, + OrganizationsApi: api.OrganizationsApi, + } + return client.List(ctx.Context, ¶ms) + }, + } +} + +func newSetActiveV1AuthCmd() *cli.Command { + var params v1_auth.ActiveParams + flags := append(commonFlags(), getAuthLookupFlags(¶ms.AuthLookupParams)...) + return &cli.Command{ + Name: "set-active", + Usage: "Change the status of an authorization to active", + Flags: flags, + Before: middleware.WithBeforeFns(withCli(), withApi(true)), + Action: func(ctx *cli.Context) error { + if err := params.AuthLookupParams.Validate(); err != nil { + return err + } + + api := getAPI(ctx) + client := v1_auth.Client{ + CLI: getCLI(ctx), + LegacyAuthorizationsApi: api.LegacyAuthorizationsApi, + UsersApi: api.UsersApi, + OrganizationsApi: api.OrganizationsApi, + } + return client.SetActive(ctx.Context, ¶ms, true) + }, + } +} + +func newSetInactiveV1AuthCmd() *cli.Command { + var params v1_auth.ActiveParams + flags := append(commonFlags(), getAuthLookupFlags(¶ms.AuthLookupParams)...) + return &cli.Command{ + Name: "set-inactive", + Usage: "Change the status of an authorization to inactive", + Flags: flags, + Before: middleware.WithBeforeFns(withCli(), withApi(true)), + Action: func(ctx *cli.Context) error { + if err := params.AuthLookupParams.Validate(); err != nil { + return err + } + + api := getAPI(ctx) + client := v1_auth.Client{ + CLI: getCLI(ctx), + LegacyAuthorizationsApi: api.LegacyAuthorizationsApi, + UsersApi: api.UsersApi, + OrganizationsApi: api.OrganizationsApi, + } + return client.SetActive(ctx.Context, ¶ms, false) + }, + } +} + +func newSetPswdV1AuthCmd() *cli.Command { + var params v1_auth.SetPasswordParams + flags := append(coreFlags(), commonTokenFlag()) + flags = append(flags, getAuthLookupFlags(¶ms.AuthLookupParams)...) + flags = append(flags, + &cli.StringFlag{ + Name: "password", + Usage: "Password to set on the authorization", + Destination: ¶ms.Password, + }, + ) + return &cli.Command{ + Name: "set-password", + Usage: "Set a password for an existing authorization", + Flags: flags, + Before: middleware.WithBeforeFns(withCli(), withApi(true)), + Action: func(ctx *cli.Context) error { + api := getAPI(ctx) + client := v1_auth.Client{ + CLI: getCLI(ctx), + LegacyAuthorizationsApi: api.LegacyAuthorizationsApi, + } + return client.SetPassword(ctx.Context, ¶ms) + }, + } +} diff --git a/cmd/influx/v1_commands.go b/cmd/influx/v1_commands.go index 05b8594..6dffd99 100644 --- a/cmd/influx/v1_commands.go +++ b/cmd/influx/v1_commands.go @@ -8,6 +8,7 @@ func newV1SubCommand() *cli.Command { Usage: "InfluxDB v1 management commands", Subcommands: []*cli.Command{ newV1DBRPCmd(), + newV1AuthCommand(), }, } }