diff --git a/api/api_organizations.gen.go b/api/api_organizations.gen.go index 7a6bdea..32ded94 100644 --- a/api/api_organizations.gen.go +++ b/api/api_organizations.gen.go @@ -67,6 +67,27 @@ type OrganizationsApi interface { */ DeleteOrgsIDMembersIDExecuteWithHttpInfo(r ApiDeleteOrgsIDMembersIDRequest) (*_nethttp.Response, error) + /* + * DeleteOrgsIDOwnersID Remove an owner from an organization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param userID The ID of the owner to remove. + * @param orgID The organization ID. + * @return ApiDeleteOrgsIDOwnersIDRequest + */ + DeleteOrgsIDOwnersID(ctx _context.Context, userID string, orgID string) ApiDeleteOrgsIDOwnersIDRequest + + /* + * DeleteOrgsIDOwnersIDExecute executes the request + */ + DeleteOrgsIDOwnersIDExecute(r ApiDeleteOrgsIDOwnersIDRequest) error + + /* + * DeleteOrgsIDOwnersIDExecuteWithHttpInfo executes the request with HTTP response info returned. The response body is not + * available on the returned HTTP response as it will have already been read and closed; access to the response body + * content should be achieved through the returned response model if applicable. + */ + DeleteOrgsIDOwnersIDExecuteWithHttpInfo(r ApiDeleteOrgsIDOwnersIDRequest) (*_nethttp.Response, error) + /* * GetOrgs List all organizations * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @@ -132,6 +153,28 @@ type OrganizationsApi interface { */ GetOrgsIDMembersExecuteWithHttpInfo(r ApiGetOrgsIDMembersRequest) (ResourceMembers, *_nethttp.Response, error) + /* + * GetOrgsIDOwners List all owners of an organization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param orgID The organization ID. + * @return ApiGetOrgsIDOwnersRequest + */ + GetOrgsIDOwners(ctx _context.Context, orgID string) ApiGetOrgsIDOwnersRequest + + /* + * GetOrgsIDOwnersExecute executes the request + * @return ResourceOwners + */ + GetOrgsIDOwnersExecute(r ApiGetOrgsIDOwnersRequest) (ResourceOwners, error) + + /* + * GetOrgsIDOwnersExecuteWithHttpInfo executes the request with HTTP response info returned. The response body is not + * available on the returned HTTP response as it will have already been read and closed; access to the response body + * content should be achieved through the returned response model if applicable. + * @return ResourceOwners + */ + GetOrgsIDOwnersExecuteWithHttpInfo(r ApiGetOrgsIDOwnersRequest) (ResourceOwners, *_nethttp.Response, error) + /* * PatchOrgsID Update an organization * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @@ -196,6 +239,28 @@ type OrganizationsApi interface { * @return ResourceMember */ PostOrgsIDMembersExecuteWithHttpInfo(r ApiPostOrgsIDMembersRequest) (ResourceMember, *_nethttp.Response, error) + + /* + * PostOrgsIDOwners Add an owner to an organization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param orgID The organization ID. + * @return ApiPostOrgsIDOwnersRequest + */ + PostOrgsIDOwners(ctx _context.Context, orgID string) ApiPostOrgsIDOwnersRequest + + /* + * PostOrgsIDOwnersExecute executes the request + * @return ResourceOwner + */ + PostOrgsIDOwnersExecute(r ApiPostOrgsIDOwnersRequest) (ResourceOwner, error) + + /* + * PostOrgsIDOwnersExecuteWithHttpInfo executes the request with HTTP response info returned. The response body is not + * available on the returned HTTP response as it will have already been read and closed; access to the response body + * content should be achieved through the returned response model if applicable. + * @return ResourceOwner + */ + PostOrgsIDOwnersExecuteWithHttpInfo(r ApiPostOrgsIDOwnersRequest) (ResourceOwner, *_nethttp.Response, error) } // OrganizationsApiService OrganizationsApi service @@ -508,6 +573,160 @@ func (a *OrganizationsApiService) DeleteOrgsIDMembersIDExecuteWithHttpInfo(r Api return localVarHTTPResponse, nil } +type ApiDeleteOrgsIDOwnersIDRequest struct { + ctx _context.Context + ApiService OrganizationsApi + userID string + orgID string + zapTraceSpan *string +} + +func (r ApiDeleteOrgsIDOwnersIDRequest) UserID(userID string) ApiDeleteOrgsIDOwnersIDRequest { + r.userID = userID + return r +} +func (r ApiDeleteOrgsIDOwnersIDRequest) GetUserID() string { + return r.userID +} + +func (r ApiDeleteOrgsIDOwnersIDRequest) OrgID(orgID string) ApiDeleteOrgsIDOwnersIDRequest { + r.orgID = orgID + return r +} +func (r ApiDeleteOrgsIDOwnersIDRequest) GetOrgID() string { + return r.orgID +} + +func (r ApiDeleteOrgsIDOwnersIDRequest) ZapTraceSpan(zapTraceSpan string) ApiDeleteOrgsIDOwnersIDRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiDeleteOrgsIDOwnersIDRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiDeleteOrgsIDOwnersIDRequest) Execute() error { + return r.ApiService.DeleteOrgsIDOwnersIDExecute(r) +} + +func (r ApiDeleteOrgsIDOwnersIDRequest) ExecuteWithHttpInfo() (*_nethttp.Response, error) { + return r.ApiService.DeleteOrgsIDOwnersIDExecuteWithHttpInfo(r) +} + +/* + * DeleteOrgsIDOwnersID Remove an owner from an organization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param userID The ID of the owner to remove. + * @param orgID The organization ID. + * @return ApiDeleteOrgsIDOwnersIDRequest + */ +func (a *OrganizationsApiService) DeleteOrgsIDOwnersID(ctx _context.Context, userID string, orgID string) ApiDeleteOrgsIDOwnersIDRequest { + return ApiDeleteOrgsIDOwnersIDRequest{ + ApiService: a, + ctx: ctx, + userID: userID, + orgID: orgID, + } +} + +/* + * Execute executes the request + */ +func (a *OrganizationsApiService) DeleteOrgsIDOwnersIDExecute(r ApiDeleteOrgsIDOwnersIDRequest) error { + _, err := a.DeleteOrgsIDOwnersIDExecuteWithHttpInfo(r) + return err +} + +/* + * ExecuteWithHttpInfo executes the request with HTTP response info returned. The response body is not available on the + * returned HTTP response as it will have already been read and closed; access to the response body content should be + * achieved through the returned response model if applicable. + */ +func (a *OrganizationsApiService) DeleteOrgsIDOwnersIDExecuteWithHttpInfo(r ApiDeleteOrgsIDOwnersIDRequest) (*_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodDelete + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OrganizationsApiService.DeleteOrgsIDOwnersID") + if err != nil { + return nil, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/orgs/{orgID}/owners/{userID}" + localVarPath = strings.Replace(localVarPath, "{"+"userID"+"}", _neturl.PathEscape(parameterToString(r.userID, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"orgID"+"}", _neturl.PathEscape(parameterToString(r.orgID, "")), -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 nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + newErr := GenericOpenAPIError{ + buildHeader: localVarHTTPResponse.Header.Get("X-Influxdb-Build"), + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + localVarBody, err := _io.ReadAll(body) + body.Close() + if err != nil { + newErr.error = err.Error() + return localVarHTTPResponse, newErr + } + newErr.body = localVarBody + newErr.error = localVarHTTPResponse.Status + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = _fmt.Sprintf("%s: %s", newErr.Error(), err.Error()) + return localVarHTTPResponse, newErr + } + v.SetMessage(_fmt.Sprintf("%s: %s", newErr.Error(), v.GetMessage())) + newErr.model = &v + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + type ApiGetOrgsRequest struct { ctx _context.Context ApiService OrganizationsApi @@ -1071,6 +1290,181 @@ func (a *OrganizationsApiService) GetOrgsIDMembersExecuteWithHttpInfo(r ApiGetOr return localVarReturnValue, localVarHTTPResponse, nil } +type ApiGetOrgsIDOwnersRequest struct { + ctx _context.Context + ApiService OrganizationsApi + orgID string + zapTraceSpan *string +} + +func (r ApiGetOrgsIDOwnersRequest) OrgID(orgID string) ApiGetOrgsIDOwnersRequest { + r.orgID = orgID + return r +} +func (r ApiGetOrgsIDOwnersRequest) GetOrgID() string { + return r.orgID +} + +func (r ApiGetOrgsIDOwnersRequest) ZapTraceSpan(zapTraceSpan string) ApiGetOrgsIDOwnersRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiGetOrgsIDOwnersRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiGetOrgsIDOwnersRequest) Execute() (ResourceOwners, error) { + return r.ApiService.GetOrgsIDOwnersExecute(r) +} + +func (r ApiGetOrgsIDOwnersRequest) ExecuteWithHttpInfo() (ResourceOwners, *_nethttp.Response, error) { + return r.ApiService.GetOrgsIDOwnersExecuteWithHttpInfo(r) +} + +/* + * GetOrgsIDOwners List all owners of an organization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param orgID The organization ID. + * @return ApiGetOrgsIDOwnersRequest + */ +func (a *OrganizationsApiService) GetOrgsIDOwners(ctx _context.Context, orgID string) ApiGetOrgsIDOwnersRequest { + return ApiGetOrgsIDOwnersRequest{ + ApiService: a, + ctx: ctx, + orgID: orgID, + } +} + +/* + * Execute executes the request + * @return ResourceOwners + */ +func (a *OrganizationsApiService) GetOrgsIDOwnersExecute(r ApiGetOrgsIDOwnersRequest) (ResourceOwners, error) { + returnVal, _, err := a.GetOrgsIDOwnersExecuteWithHttpInfo(r) + return returnVal, err +} + +/* + * ExecuteWithHttpInfo executes the request with HTTP response info returned. The response body is not available on the + * returned HTTP response as it will have already been read and closed; access to the response body content should be + * achieved through the returned response model if applicable. + * @return ResourceOwners + */ +func (a *OrganizationsApiService) GetOrgsIDOwnersExecuteWithHttpInfo(r ApiGetOrgsIDOwnersRequest) (ResourceOwners, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodGet + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + localVarReturnValue ResourceOwners + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OrganizationsApiService.GetOrgsIDOwners") + if err != nil { + return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/orgs/{orgID}/owners" + localVarPath = strings.Replace(localVarPath, "{"+"orgID"+"}", _neturl.PathEscape(parameterToString(r.orgID, "")), -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, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + newErr := GenericOpenAPIError{ + buildHeader: localVarHTTPResponse.Header.Get("X-Influxdb-Build"), + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + localVarBody, err := _io.ReadAll(body) + body.Close() + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.body = localVarBody + newErr.error = localVarHTTPResponse.Status + if localVarHTTPResponse.StatusCode == 404 { + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = _fmt.Sprintf("%s: %s", newErr.Error(), err.Error()) + return localVarReturnValue, localVarHTTPResponse, newErr + } + v.SetMessage(_fmt.Sprintf("%s: %s", newErr.Error(), v.GetMessage())) + newErr.model = &v + return localVarReturnValue, localVarHTTPResponse, newErr + } + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = _fmt.Sprintf("%s: %s", newErr.Error(), err.Error()) + return localVarReturnValue, localVarHTTPResponse, newErr + } + v.SetMessage(_fmt.Sprintf("%s: %s", newErr.Error(), v.GetMessage())) + newErr.model = &v + return localVarReturnValue, localVarHTTPResponse, newErr + } + + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + localVarBody, err := _io.ReadAll(body) + body.Close() + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.body = localVarBody + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + type ApiPatchOrgsIDRequest struct { ctx _context.Context ApiService OrganizationsApi @@ -1592,3 +1986,181 @@ func (a *OrganizationsApiService) PostOrgsIDMembersExecuteWithHttpInfo(r ApiPost return localVarReturnValue, localVarHTTPResponse, nil } + +type ApiPostOrgsIDOwnersRequest struct { + ctx _context.Context + ApiService OrganizationsApi + orgID string + addResourceMemberRequestBody *AddResourceMemberRequestBody + zapTraceSpan *string +} + +func (r ApiPostOrgsIDOwnersRequest) OrgID(orgID string) ApiPostOrgsIDOwnersRequest { + r.orgID = orgID + return r +} +func (r ApiPostOrgsIDOwnersRequest) GetOrgID() string { + return r.orgID +} + +func (r ApiPostOrgsIDOwnersRequest) AddResourceMemberRequestBody(addResourceMemberRequestBody AddResourceMemberRequestBody) ApiPostOrgsIDOwnersRequest { + r.addResourceMemberRequestBody = &addResourceMemberRequestBody + return r +} +func (r ApiPostOrgsIDOwnersRequest) GetAddResourceMemberRequestBody() *AddResourceMemberRequestBody { + return r.addResourceMemberRequestBody +} + +func (r ApiPostOrgsIDOwnersRequest) ZapTraceSpan(zapTraceSpan string) ApiPostOrgsIDOwnersRequest { + r.zapTraceSpan = &zapTraceSpan + return r +} +func (r ApiPostOrgsIDOwnersRequest) GetZapTraceSpan() *string { + return r.zapTraceSpan +} + +func (r ApiPostOrgsIDOwnersRequest) Execute() (ResourceOwner, error) { + return r.ApiService.PostOrgsIDOwnersExecute(r) +} + +func (r ApiPostOrgsIDOwnersRequest) ExecuteWithHttpInfo() (ResourceOwner, *_nethttp.Response, error) { + return r.ApiService.PostOrgsIDOwnersExecuteWithHttpInfo(r) +} + +/* + * PostOrgsIDOwners Add an owner to an organization + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @param orgID The organization ID. + * @return ApiPostOrgsIDOwnersRequest + */ +func (a *OrganizationsApiService) PostOrgsIDOwners(ctx _context.Context, orgID string) ApiPostOrgsIDOwnersRequest { + return ApiPostOrgsIDOwnersRequest{ + ApiService: a, + ctx: ctx, + orgID: orgID, + } +} + +/* + * Execute executes the request + * @return ResourceOwner + */ +func (a *OrganizationsApiService) PostOrgsIDOwnersExecute(r ApiPostOrgsIDOwnersRequest) (ResourceOwner, error) { + returnVal, _, err := a.PostOrgsIDOwnersExecuteWithHttpInfo(r) + return returnVal, err +} + +/* + * ExecuteWithHttpInfo executes the request with HTTP response info returned. The response body is not available on the + * returned HTTP response as it will have already been read and closed; access to the response body content should be + * achieved through the returned response model if applicable. + * @return ResourceOwner + */ +func (a *OrganizationsApiService) PostOrgsIDOwnersExecuteWithHttpInfo(r ApiPostOrgsIDOwnersRequest) (ResourceOwner, *_nethttp.Response, error) { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarFormFileName string + localVarFileName string + localVarFileBytes []byte + localVarReturnValue ResourceOwner + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OrganizationsApiService.PostOrgsIDOwners") + if err != nil { + return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/api/v2/orgs/{orgID}/owners" + localVarPath = strings.Replace(localVarPath, "{"+"orgID"+"}", _neturl.PathEscape(parameterToString(r.orgID, "")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + localVarFormParams := _neturl.Values{} + if r.addResourceMemberRequestBody == nil { + return localVarReturnValue, nil, reportError("addResourceMemberRequestBody 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.addResourceMemberRequestBody + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + newErr := GenericOpenAPIError{ + buildHeader: localVarHTTPResponse.Header.Get("X-Influxdb-Build"), + } + + if localVarHTTPResponse.StatusCode >= 300 { + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + localVarBody, err := _io.ReadAll(body) + body.Close() + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.body = localVarBody + newErr.error = localVarHTTPResponse.Status + var v Error + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = _fmt.Sprintf("%s: %s", newErr.Error(), err.Error()) + return localVarReturnValue, localVarHTTPResponse, newErr + } + v.SetMessage(_fmt.Sprintf("%s: %s", newErr.Error(), v.GetMessage())) + newErr.model = &v + return localVarReturnValue, localVarHTTPResponse, newErr + } + + body, err := GunzipIfNeeded(localVarHTTPResponse) + if err != nil { + body.Close() + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + localVarBody, err := _io.ReadAll(body) + body.Close() + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.body = localVarBody + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/api/contract/cli.yml b/api/contract/cli.yml index c3c1196..47d80ec 100644 --- a/api/contract/cli.yml +++ b/api/contract/cli.yml @@ -35,6 +35,10 @@ paths: $ref: "./openapi/src/common/paths/orgs_orgID_members.yml" /api/v2/orgs/{orgID}/members/{userID}: $ref: "./openapi/src/common/paths/orgs_orgID_members_userID.yml" + /api/v2/orgs/{orgID}/owners: + $ref: "./openapi/src/common/paths/orgs_orgID_owners.yml" + /api/v2/orgs/{orgID}/owners/{userID}: + $ref: "./openapi/src/common/paths/orgs_orgID_owners_userID.yml" /api/v2/orgs/{orgID}/secrets: $ref: "./openapi/src/common/paths/orgs_orgID_secrets.yml" /api/v2/orgs/{orgID}/secrets/{delete}: @@ -203,6 +207,10 @@ components: $ref: "./openapi/src/common/schemas/ResourceMembers.yml" ResourceMember: $ref: "./openapi/src/common/schemas/ResourceMember.yml" + ResourceOwners: + $ref: "./openapi/src/common/schemas/ResourceOwners.yml" + ResourceOwner: + $ref: "./openapi/src/common/schemas/ResourceOwner.yml" AddResourceMemberRequestBody: $ref: "./openapi/src/common/schemas/AddResourceMemberRequestBody.yml" WritePrecision: diff --git a/api/model_resource_owner.gen.go b/api/model_resource_owner.gen.go new file mode 100644 index 0000000..c3383e7 --- /dev/null +++ b/api/model_resource_owner.gen.go @@ -0,0 +1,295 @@ +/* + * 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" +) + +// ResourceOwner struct for ResourceOwner +type ResourceOwner struct { + Id *string `json:"id,omitempty" yaml:"id,omitempty"` + OauthID *string `json:"oauthID,omitempty" yaml:"oauthID,omitempty"` + Name string `json:"name" yaml:"name"` + // If inactive the user is inactive. + Status *string `json:"status,omitempty" yaml:"status,omitempty"` + Links *UserResponseLinks `json:"links,omitempty" yaml:"links,omitempty"` + Role *string `json:"role,omitempty" yaml:"role,omitempty"` +} + +// NewResourceOwner instantiates a new ResourceOwner 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 NewResourceOwner(name string) *ResourceOwner { + this := ResourceOwner{} + this.Name = name + var status string = "active" + this.Status = &status + var role string = "owner" + this.Role = &role + return &this +} + +// NewResourceOwnerWithDefaults instantiates a new ResourceOwner 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 NewResourceOwnerWithDefaults() *ResourceOwner { + this := ResourceOwner{} + var status string = "active" + this.Status = &status + var role string = "owner" + this.Role = &role + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *ResourceOwner) GetId() string { + if o == nil || o.Id == nil { + var ret string + return ret + } + 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. +func (o *ResourceOwner) GetIdOk() (*string, bool) { + if o == nil || o.Id == nil { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *ResourceOwner) HasId() bool { + if o != nil && o.Id != nil { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *ResourceOwner) SetId(v string) { + o.Id = &v +} + +// GetOauthID returns the OauthID field value if set, zero value otherwise. +func (o *ResourceOwner) GetOauthID() string { + if o == nil || o.OauthID == nil { + var ret string + return ret + } + return *o.OauthID +} + +// GetOauthIDOk returns a tuple with the OauthID field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ResourceOwner) GetOauthIDOk() (*string, bool) { + if o == nil || o.OauthID == nil { + return nil, false + } + return o.OauthID, true +} + +// HasOauthID returns a boolean if a field has been set. +func (o *ResourceOwner) HasOauthID() bool { + if o != nil && o.OauthID != nil { + return true + } + + return false +} + +// SetOauthID gets a reference to the given string and assigns it to the OauthID field. +func (o *ResourceOwner) SetOauthID(v string) { + o.OauthID = &v +} + +// GetName returns the Name field value +func (o *ResourceOwner) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *ResourceOwner) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *ResourceOwner) SetName(v string) { + o.Name = v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *ResourceOwner) 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 *ResourceOwner) 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 *ResourceOwner) 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 *ResourceOwner) SetStatus(v string) { + o.Status = &v +} + +// GetLinks returns the Links field value if set, zero value otherwise. +func (o *ResourceOwner) GetLinks() UserResponseLinks { + if o == nil || o.Links == nil { + var ret UserResponseLinks + 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 *ResourceOwner) GetLinksOk() (*UserResponseLinks, 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 *ResourceOwner) HasLinks() bool { + if o != nil && o.Links != nil { + return true + } + + return false +} + +// SetLinks gets a reference to the given UserResponseLinks and assigns it to the Links field. +func (o *ResourceOwner) SetLinks(v UserResponseLinks) { + o.Links = &v +} + +// GetRole returns the Role field value if set, zero value otherwise. +func (o *ResourceOwner) GetRole() string { + if o == nil || o.Role == nil { + var ret string + return ret + } + return *o.Role +} + +// GetRoleOk returns a tuple with the Role field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ResourceOwner) GetRoleOk() (*string, bool) { + if o == nil || o.Role == nil { + return nil, false + } + return o.Role, true +} + +// HasRole returns a boolean if a field has been set. +func (o *ResourceOwner) HasRole() bool { + if o != nil && o.Role != nil { + return true + } + + return false +} + +// SetRole gets a reference to the given string and assigns it to the Role field. +func (o *ResourceOwner) SetRole(v string) { + o.Role = &v +} + +func (o ResourceOwner) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Id != nil { + toSerialize["id"] = o.Id + } + if o.OauthID != nil { + toSerialize["oauthID"] = o.OauthID + } + if true { + toSerialize["name"] = o.Name + } + if o.Status != nil { + toSerialize["status"] = o.Status + } + if o.Links != nil { + toSerialize["links"] = o.Links + } + if o.Role != nil { + toSerialize["role"] = o.Role + } + return json.Marshal(toSerialize) +} + +type NullableResourceOwner struct { + value *ResourceOwner + isSet bool +} + +func (v NullableResourceOwner) Get() *ResourceOwner { + return v.value +} + +func (v *NullableResourceOwner) Set(val *ResourceOwner) { + v.value = val + v.isSet = true +} + +func (v NullableResourceOwner) IsSet() bool { + return v.isSet +} + +func (v *NullableResourceOwner) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableResourceOwner(val *ResourceOwner) *NullableResourceOwner { + return &NullableResourceOwner{value: val, isSet: true} +} + +func (v NullableResourceOwner) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableResourceOwner) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/api/model_resource_owner_all_of.gen.go b/api/model_resource_owner_all_of.gen.go new file mode 100644 index 0000000..1171334 --- /dev/null +++ b/api/model_resource_owner_all_of.gen.go @@ -0,0 +1,117 @@ +/* + * 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" +) + +// ResourceOwnerAllOf struct for ResourceOwnerAllOf +type ResourceOwnerAllOf struct { + Role *string `json:"role,omitempty" yaml:"role,omitempty"` +} + +// NewResourceOwnerAllOf instantiates a new ResourceOwnerAllOf 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 NewResourceOwnerAllOf() *ResourceOwnerAllOf { + this := ResourceOwnerAllOf{} + var role string = "owner" + this.Role = &role + return &this +} + +// NewResourceOwnerAllOfWithDefaults instantiates a new ResourceOwnerAllOf 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 NewResourceOwnerAllOfWithDefaults() *ResourceOwnerAllOf { + this := ResourceOwnerAllOf{} + var role string = "owner" + this.Role = &role + return &this +} + +// GetRole returns the Role field value if set, zero value otherwise. +func (o *ResourceOwnerAllOf) GetRole() string { + if o == nil || o.Role == nil { + var ret string + return ret + } + return *o.Role +} + +// GetRoleOk returns a tuple with the Role field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ResourceOwnerAllOf) GetRoleOk() (*string, bool) { + if o == nil || o.Role == nil { + return nil, false + } + return o.Role, true +} + +// HasRole returns a boolean if a field has been set. +func (o *ResourceOwnerAllOf) HasRole() bool { + if o != nil && o.Role != nil { + return true + } + + return false +} + +// SetRole gets a reference to the given string and assigns it to the Role field. +func (o *ResourceOwnerAllOf) SetRole(v string) { + o.Role = &v +} + +func (o ResourceOwnerAllOf) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Role != nil { + toSerialize["role"] = o.Role + } + return json.Marshal(toSerialize) +} + +type NullableResourceOwnerAllOf struct { + value *ResourceOwnerAllOf + isSet bool +} + +func (v NullableResourceOwnerAllOf) Get() *ResourceOwnerAllOf { + return v.value +} + +func (v *NullableResourceOwnerAllOf) Set(val *ResourceOwnerAllOf) { + v.value = val + v.isSet = true +} + +func (v NullableResourceOwnerAllOf) IsSet() bool { + return v.isSet +} + +func (v *NullableResourceOwnerAllOf) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableResourceOwnerAllOf(val *ResourceOwnerAllOf) *NullableResourceOwnerAllOf { + return &NullableResourceOwnerAllOf{value: val, isSet: true} +} + +func (v NullableResourceOwnerAllOf) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableResourceOwnerAllOf) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/api/model_resource_owners.gen.go b/api/model_resource_owners.gen.go new file mode 100644 index 0000000..8d15974 --- /dev/null +++ b/api/model_resource_owners.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" +) + +// ResourceOwners struct for ResourceOwners +type ResourceOwners struct { + Links *UsersLinks `json:"links,omitempty" yaml:"links,omitempty"` + Users *[]ResourceOwner `json:"users,omitempty" yaml:"users,omitempty"` +} + +// NewResourceOwners instantiates a new ResourceOwners 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 NewResourceOwners() *ResourceOwners { + this := ResourceOwners{} + return &this +} + +// NewResourceOwnersWithDefaults instantiates a new ResourceOwners 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 NewResourceOwnersWithDefaults() *ResourceOwners { + this := ResourceOwners{} + return &this +} + +// GetLinks returns the Links field value if set, zero value otherwise. +func (o *ResourceOwners) GetLinks() UsersLinks { + if o == nil || o.Links == nil { + var ret UsersLinks + 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 *ResourceOwners) GetLinksOk() (*UsersLinks, 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 *ResourceOwners) HasLinks() bool { + if o != nil && o.Links != nil { + return true + } + + return false +} + +// SetLinks gets a reference to the given UsersLinks and assigns it to the Links field. +func (o *ResourceOwners) SetLinks(v UsersLinks) { + o.Links = &v +} + +// GetUsers returns the Users field value if set, zero value otherwise. +func (o *ResourceOwners) GetUsers() []ResourceOwner { + if o == nil || o.Users == nil { + var ret []ResourceOwner + return ret + } + return *o.Users +} + +// GetUsersOk returns a tuple with the Users field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ResourceOwners) GetUsersOk() (*[]ResourceOwner, bool) { + if o == nil || o.Users == nil { + return nil, false + } + return o.Users, true +} + +// HasUsers returns a boolean if a field has been set. +func (o *ResourceOwners) HasUsers() bool { + if o != nil && o.Users != nil { + return true + } + + return false +} + +// SetUsers gets a reference to the given []ResourceOwner and assigns it to the Users field. +func (o *ResourceOwners) SetUsers(v []ResourceOwner) { + o.Users = &v +} + +func (o ResourceOwners) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Links != nil { + toSerialize["links"] = o.Links + } + if o.Users != nil { + toSerialize["users"] = o.Users + } + return json.Marshal(toSerialize) +} + +type NullableResourceOwners struct { + value *ResourceOwners + isSet bool +} + +func (v NullableResourceOwners) Get() *ResourceOwners { + return v.value +} + +func (v *NullableResourceOwners) Set(val *ResourceOwners) { + v.value = val + v.isSet = true +} + +func (v NullableResourceOwners) IsSet() bool { + return v.isSet +} + +func (v *NullableResourceOwners) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableResourceOwners(val *ResourceOwners) *NullableResourceOwners { + return &NullableResourceOwners{value: val, isSet: true} +} + +func (v NullableResourceOwners) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableResourceOwners) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/clients/org/org_members.go b/clients/org/org_members.go index a4bdba7..513be72 100644 --- a/clients/org/org_members.go +++ b/clients/org/org_members.go @@ -11,6 +11,7 @@ import ( type AddMemberParams struct { clients.OrgParams MemberId string + IsOwner bool } func (c Client) AddMember(ctx context.Context, params *AddMemberParams) (err error) { @@ -18,24 +19,31 @@ func (c Client) AddMember(ctx context.Context, params *AddMemberParams) (err err if err != nil { return err } - - member, err := c.PostOrgsIDMembers(ctx, orgID). - AddResourceMemberRequestBody(*api.NewAddResourceMemberRequestBody(params.MemberId)). - Execute() - if err != nil { - return fmt.Errorf("failed to add user %q to org %q: %w", params.MemberId, orgID, err) + if params.IsOwner { + owner, err := c.PostOrgsIDOwners(ctx, orgID). + AddResourceMemberRequestBody(*api.NewAddResourceMemberRequestBody(params.MemberId)). + Execute() + if err != nil { + return fmt.Errorf("failed to add user %q as owner of org %q: %w", params.MemberId, orgID, err) + } + _, err = c.StdIO.Write([]byte(fmt.Sprintf("user %q has been added as an owner of org %q\n", *owner.Id, orgID))) + return err + } else { + member, err := c.PostOrgsIDMembers(ctx, orgID). + AddResourceMemberRequestBody(*api.NewAddResourceMemberRequestBody(params.MemberId)). + Execute() + if err != nil { + return fmt.Errorf("failed to add user %q as member of org %q: %w", params.MemberId, orgID, err) + } + _, err = c.StdIO.Write([]byte(fmt.Sprintf("user %q has been added as a member of org %q\n", *member.Id, orgID))) + return err } - - _, err = c.StdIO.Write([]byte(fmt.Sprintf("user %q has been added as a member of org %q\n", *member.Id, orgID))) - return err } type ListMemberParams struct { clients.OrgParams } -const maxConcurrentGetUserRequests = 10 - func (c Client) ListMembers(ctx context.Context, params *ListMemberParams) (err error) { orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi) if err != nil { @@ -46,60 +54,31 @@ func (c Client) ListMembers(ctx context.Context, params *ListMemberParams) (err if err != nil { return fmt.Errorf("failed to find members of org %q: %w", orgID, err) } - - type indexedUser struct { - user api.UserResponse - index int + owners, err := c.GetOrgsIDOwners(ctx, orgID).Execute() + if err != nil { + return fmt.Errorf("failed to find owners of org %q: %w", orgID, err) } - userChan := make(chan indexedUser, maxConcurrentGetUserRequests) - semChan := make(chan struct{}, maxConcurrentGetUserRequests) - errChan := make(chan error) - - var resourceMembers []api.ResourceMember - if members.Users != nil { - resourceMembers = *members.Users - } - // Fetch user details about all members of the org. - for i, member := range resourceMembers { - go func(i int, memberId string) { - semChan <- struct{}{} - defer func() { <-semChan }() - - user, err := c.GetUsersID(ctx, memberId).Execute() - if err != nil { - errChan <- fmt.Errorf("failed to retrieve details for user %q: %w", memberId, err) - return - } - userChan <- indexedUser{user: user, index: i} - }(i, member.GetId()) - } - - users := make([]api.UserResponse, len(resourceMembers)) - for range resourceMembers { - select { - case <-ctx.Done(): - return ctx.Err() - case err := <-errChan: - return err - case user := <-userChan: - users[user.index] = user.user - } + allMembers := members.GetUsers() + resourceOwners := owners.GetUsers() + resourceOwnersAsMembers := make([]api.ResourceMember, len(resourceOwners)) + for i, owner := range resourceOwners { + resourceOwnersAsMembers[i] = api.ResourceMember(owner) } + allMembers = append(resourceOwnersAsMembers, allMembers...) if c.PrintAsJSON { - return c.PrintJSON(users) + return c.PrintJSON(allMembers) } - rows := make([]map[string]interface{}, len(resourceMembers)) - for i, user := range users { + rows := make([]map[string]interface{}, len(allMembers)) + for i, user := range allMembers { rows[i] = map[string]interface{}{ "ID": user.GetId(), "Name": user.GetName(), - "User Type": "member", + "User Type": user.GetRole(), "Status": user.GetStatus(), } } - return c.PrintTable([]string{"ID", "Name", "User Type", "Status"}, rows...) } @@ -115,9 +94,12 @@ func (c Client) RemoveMember(ctx context.Context, params *RemoveMemberParams) (e } if err = c.DeleteOrgsIDMembersID(ctx, params.MemberId, orgID).Execute(); err != nil { - return fmt.Errorf("failed to remove member %q from org %q", params.MemberId, orgID) + if err = c.DeleteOrgsIDOwnersID(ctx, params.MemberId, orgID).Execute(); err != nil { + return fmt.Errorf("failed to remove user %q from org %q", params.MemberId, orgID) + } + _, err = c.StdIO.Write([]byte(fmt.Sprintf("owner %q has been removed from org %q\n", params.MemberId, orgID))) + return err } - _, err = c.StdIO.Write([]byte(fmt.Sprintf("user %q has been removed from org %q\n", params.MemberId, orgID))) return err } diff --git a/clients/org/org_members_test.go b/clients/org/org_members_test.go index fd59df2..7a6bf8a 100644 --- a/clients/org/org_members_test.go +++ b/clients/org/org_members_test.go @@ -159,13 +159,12 @@ func TestClient_ListMembers(t *testing.T) { t.Parallel() testCases := []struct { - name string - params org.ListMemberParams - defaultOrgName string - registerOrgExpectations func(*testing.T, *mock.MockOrganizationsApi) - registerUserExpectations func(*testing.T, *mock.MockUsersApi) - expectedOut []string - expectedErr string + name string + params org.ListMemberParams + defaultOrgName string + registerOrgExpectations func(*testing.T, *mock.MockOrganizationsApi) + expectedOut []string + expectedErr string }{ { name: "no members", @@ -181,6 +180,10 @@ func TestClient_ListMembers(t *testing.T) { req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1) orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req) orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).Return(api.ResourceMembers{}, nil) + + ownerReq := api.ApiGetOrgsIDOwnersRequest{ApiService: orgApi}.OrgID(id1) + orgApi.EXPECT().GetOrgsIDOwners(gomock.Any(), gomock.Eq(id1)).Return(ownerReq) + orgApi.EXPECT().GetOrgsIDOwnersExecute(gomock.Eq(ownerReq)).Return(api.ResourceOwners{}, nil) }, }, { @@ -200,21 +203,51 @@ func TestClient_ListMembers(t *testing.T) { req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1) orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req) orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)). - Return(api.ResourceMembers{Users: &[]api.ResourceMember{{Id: api.PtrString(id2)}}}, nil) - }, - registerUserExpectations: func(t *testing.T, userApi *mock.MockUsersApi) { - req := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id2) - userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id2)).Return(req) - userApi.EXPECT().GetUsersIDExecute(gomock.Eq(req)).Return(api.UserResponse{ - Id: api.PtrString(id2), - Name: "user1", - Status: api.PtrString("active"), - }, nil) + Return(api.ResourceMembers{Users: &[]api.ResourceMember{{ + Id: api.PtrString(id2), + Name: "user1", + Role: api.PtrString("member"), + Status: api.PtrString("active"), + }}}, nil) + + ownerReq := api.ApiGetOrgsIDOwnersRequest{ApiService: orgApi}.OrgID(id1) + orgApi.EXPECT().GetOrgsIDOwners(gomock.Any(), gomock.Eq(id1)).Return(ownerReq) + orgApi.EXPECT().GetOrgsIDOwnersExecute(gomock.Eq(ownerReq)).Return(api.ResourceOwners{}, nil) }, expectedOut: []string{`2222222222222222\s+user1\s+member\s+active`}, }, { - name: "many members", + name: "one owner", + params: org.ListMemberParams{ + OrgParams: clients.OrgParams{OrgName: "org"}, + }, + defaultOrgName: "my-org", + registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) { + orgApi.EXPECT().GetOrgs(gomock.Any()).Return(api.ApiGetOrgsRequest{ApiService: orgApi}) + orgApi.EXPECT().GetOrgsExecute(tmock.MatchedBy(func(in api.ApiGetOrgsRequest) bool { + return assert.Equal(t, "org", *in.GetOrg()) + })).Return(api.Organizations{ + Orgs: &[]api.Organization{{Id: api.PtrString(id1)}}, + }, nil) + + req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1) + orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req) + orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)). + Return(api.ResourceMembers{}, nil) + + ownerReq := api.ApiGetOrgsIDOwnersRequest{ApiService: orgApi}.OrgID(id1) + orgApi.EXPECT().GetOrgsIDOwners(gomock.Any(), gomock.Eq(id1)).Return(ownerReq) + orgApi.EXPECT().GetOrgsIDOwnersExecute(gomock.Eq(ownerReq)).Return(api.ResourceOwners{Users: &[]api.ResourceOwner{{ + Id: api.PtrString(id2), + Name: "user1", + Role: api.PtrString("owner"), + Status: api.PtrString("active"), + }}}, nil) + }, + expectedOut: []string{`2222222222222222\s+user1\s+owner\s+active`}, + }, + { + name: "many users/members", params: org.ListMemberParams{ OrgParams: clients.OrgParams{OrgID: id1}, }, @@ -224,27 +257,44 @@ func TestClient_ListMembers(t *testing.T) { orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req) members := make([]api.ResourceMember, 11) for i := 0; i < 11; i++ { - members[i] = api.ResourceMember{Id: api.PtrString(fmt.Sprintf("%016d", i))} - } - orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).Return(api.ResourceMembers{Users: &members}, nil) - }, - registerUserExpectations: func(t *testing.T, userApi *mock.MockUsersApi) { - for i := 0; i < 11; i++ { - id := fmt.Sprintf("%016d", i) status := "active" if i%2 == 0 { status = "inactive" } - req := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id) - userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id)).Return(req) - userApi.EXPECT().GetUsersIDExecute(gomock.Eq(req)).Return(api.UserResponse{ - Id: &id, + members[i] = api.ResourceMember{ + Id: api.PtrString(fmt.Sprintf("%016d", i)), Name: fmt.Sprintf("user%d", i), Status: &status, - }, nil) + Role: api.PtrString("member"), + } } + orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)).Return(api.ResourceMembers{Users: &members}, nil) + + owners := make([]api.ResourceOwner, 5) + offset := 11 + for i := offset; i < 5+offset; i++ { + status := "active" + if i%2 == 0 { + status = "inactive" + } + owners[i-offset] = api.ResourceOwner{ + Id: api.PtrString(fmt.Sprintf("%016d", i)), + Name: fmt.Sprintf("user%d", i), + Status: &status, + Role: api.PtrString("owner"), + } + } + ownerReq := api.ApiGetOrgsIDOwnersRequest{ApiService: orgApi}.OrgID(id1) + orgApi.EXPECT().GetOrgsIDOwners(gomock.Any(), gomock.Eq(id1)).Return(ownerReq) + orgApi.EXPECT().GetOrgsIDOwnersExecute(gomock.Eq(ownerReq)).Return(api.ResourceOwners{Users: &owners}, nil) }, expectedOut: []string{ + `0000000000000011\s+user11\s+owner\s+active`, + `0000000000000012\s+user12\s+owner\s+inactive`, + `0000000000000013\s+user13\s+owner\s+active`, + `0000000000000014\s+user14\s+owner\s+inactive`, + `0000000000000015\s+user15\s+owner\s+active`, + `0000000000000000\s+user0\s+member\s+inactive`, `0000000000000001\s+user1\s+member\s+active`, `0000000000000002\s+user2\s+member\s+inactive`, @@ -269,24 +319,6 @@ func TestClient_ListMembers(t *testing.T) { }, expectedErr: "not found", }, - { - name: "no such user", - params: org.ListMemberParams{ - OrgParams: clients.OrgParams{OrgID: id1}, - }, - registerOrgExpectations: func(t *testing.T, orgApi *mock.MockOrganizationsApi) { - req := api.ApiGetOrgsIDMembersRequest{ApiService: orgApi}.OrgID(id1) - orgApi.EXPECT().GetOrgsIDMembers(gomock.Any(), gomock.Eq(id1)).Return(req) - orgApi.EXPECT().GetOrgsIDMembersExecute(gomock.Eq(req)). - Return(api.ResourceMembers{Users: &[]api.ResourceMember{{Id: api.PtrString(id2)}}}, nil) - }, - registerUserExpectations: func(t *testing.T, userApi *mock.MockUsersApi) { - req := api.ApiGetUsersIDRequest{ApiService: userApi}.UserID(id2) - userApi.EXPECT().GetUsersID(gomock.Any(), gomock.Eq(id2)).Return(req) - userApi.EXPECT().GetUsersIDExecute(gomock.Eq(req)).Return(api.UserResponse{}, errors.New("not found")) - }, - expectedErr: "user \"2222222222222222\": not found", - }, { name: "missing org", expectedErr: clients.ErrMustSpecifyOrg.Error(), @@ -304,9 +336,6 @@ func TestClient_ListMembers(t *testing.T) { if tc.registerOrgExpectations != nil { tc.registerOrgExpectations(t, orgApi) } - if tc.registerUserExpectations != nil { - tc.registerUserExpectations(t, userApi) - } stdout := bytes.Buffer{} stdio := mock.NewMockStdIO(ctrl) diff --git a/cmd/influx/org_members.go b/cmd/influx/org_members.go index 500d001..fe7a5e6 100644 --- a/cmd/influx/org_members.go +++ b/cmd/influx/org_members.go @@ -45,6 +45,11 @@ func newOrgMembersAddCmd() cli.Command { EnvVar: "INFLUX_ORG_ID", Destination: ¶ms.OrgID, }, + &cli.BoolFlag{ + Name: "owner", + Usage: "Set new member as an owner", + Destination: ¶ms.IsOwner, + }, ), Action: func(ctx *cli.Context) error { client := org.Client{ diff --git a/internal/mock/api_organizations.gen.go b/internal/mock/api_organizations.gen.go index 0daf328..4a628b4 100644 --- a/internal/mock/api_organizations.gen.go +++ b/internal/mock/api_organizations.gen.go @@ -122,6 +122,49 @@ func (mr *MockOrganizationsApiMockRecorder) DeleteOrgsIDMembersIDExecuteWithHttp return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOrgsIDMembersIDExecuteWithHttpInfo", reflect.TypeOf((*MockOrganizationsApi)(nil).DeleteOrgsIDMembersIDExecuteWithHttpInfo), arg0) } +// DeleteOrgsIDOwnersID mocks base method. +func (m *MockOrganizationsApi) DeleteOrgsIDOwnersID(arg0 context.Context, arg1, arg2 string) api.ApiDeleteOrgsIDOwnersIDRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOrgsIDOwnersID", arg0, arg1, arg2) + ret0, _ := ret[0].(api.ApiDeleteOrgsIDOwnersIDRequest) + return ret0 +} + +// DeleteOrgsIDOwnersID indicates an expected call of DeleteOrgsIDOwnersID. +func (mr *MockOrganizationsApiMockRecorder) DeleteOrgsIDOwnersID(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOrgsIDOwnersID", reflect.TypeOf((*MockOrganizationsApi)(nil).DeleteOrgsIDOwnersID), arg0, arg1, arg2) +} + +// DeleteOrgsIDOwnersIDExecute mocks base method. +func (m *MockOrganizationsApi) DeleteOrgsIDOwnersIDExecute(arg0 api.ApiDeleteOrgsIDOwnersIDRequest) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOrgsIDOwnersIDExecute", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteOrgsIDOwnersIDExecute indicates an expected call of DeleteOrgsIDOwnersIDExecute. +func (mr *MockOrganizationsApiMockRecorder) DeleteOrgsIDOwnersIDExecute(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOrgsIDOwnersIDExecute", reflect.TypeOf((*MockOrganizationsApi)(nil).DeleteOrgsIDOwnersIDExecute), arg0) +} + +// DeleteOrgsIDOwnersIDExecuteWithHttpInfo mocks base method. +func (m *MockOrganizationsApi) DeleteOrgsIDOwnersIDExecuteWithHttpInfo(arg0 api.ApiDeleteOrgsIDOwnersIDRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteOrgsIDOwnersIDExecuteWithHttpInfo", arg0) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DeleteOrgsIDOwnersIDExecuteWithHttpInfo indicates an expected call of DeleteOrgsIDOwnersIDExecuteWithHttpInfo. +func (mr *MockOrganizationsApiMockRecorder) DeleteOrgsIDOwnersIDExecuteWithHttpInfo(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOrgsIDOwnersIDExecuteWithHttpInfo", reflect.TypeOf((*MockOrganizationsApi)(nil).DeleteOrgsIDOwnersIDExecuteWithHttpInfo), arg0) +} + // GetOrgs mocks base method. func (m *MockOrganizationsApi) GetOrgs(arg0 context.Context) api.ApiGetOrgsRequest { m.ctrl.T.Helper() @@ -257,6 +300,51 @@ func (mr *MockOrganizationsApiMockRecorder) GetOrgsIDMembersExecuteWithHttpInfo( return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrgsIDMembersExecuteWithHttpInfo", reflect.TypeOf((*MockOrganizationsApi)(nil).GetOrgsIDMembersExecuteWithHttpInfo), arg0) } +// GetOrgsIDOwners mocks base method. +func (m *MockOrganizationsApi) GetOrgsIDOwners(arg0 context.Context, arg1 string) api.ApiGetOrgsIDOwnersRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetOrgsIDOwners", arg0, arg1) + ret0, _ := ret[0].(api.ApiGetOrgsIDOwnersRequest) + return ret0 +} + +// GetOrgsIDOwners indicates an expected call of GetOrgsIDOwners. +func (mr *MockOrganizationsApiMockRecorder) GetOrgsIDOwners(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrgsIDOwners", reflect.TypeOf((*MockOrganizationsApi)(nil).GetOrgsIDOwners), arg0, arg1) +} + +// GetOrgsIDOwnersExecute mocks base method. +func (m *MockOrganizationsApi) GetOrgsIDOwnersExecute(arg0 api.ApiGetOrgsIDOwnersRequest) (api.ResourceOwners, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetOrgsIDOwnersExecute", arg0) + ret0, _ := ret[0].(api.ResourceOwners) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetOrgsIDOwnersExecute indicates an expected call of GetOrgsIDOwnersExecute. +func (mr *MockOrganizationsApiMockRecorder) GetOrgsIDOwnersExecute(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrgsIDOwnersExecute", reflect.TypeOf((*MockOrganizationsApi)(nil).GetOrgsIDOwnersExecute), arg0) +} + +// GetOrgsIDOwnersExecuteWithHttpInfo mocks base method. +func (m *MockOrganizationsApi) GetOrgsIDOwnersExecuteWithHttpInfo(arg0 api.ApiGetOrgsIDOwnersRequest) (api.ResourceOwners, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetOrgsIDOwnersExecuteWithHttpInfo", arg0) + ret0, _ := ret[0].(api.ResourceOwners) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetOrgsIDOwnersExecuteWithHttpInfo indicates an expected call of GetOrgsIDOwnersExecuteWithHttpInfo. +func (mr *MockOrganizationsApiMockRecorder) GetOrgsIDOwnersExecuteWithHttpInfo(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrgsIDOwnersExecuteWithHttpInfo", reflect.TypeOf((*MockOrganizationsApi)(nil).GetOrgsIDOwnersExecuteWithHttpInfo), arg0) +} + // PatchOrgsID mocks base method. func (m *MockOrganizationsApi) PatchOrgsID(arg0 context.Context, arg1 string) api.ApiPatchOrgsIDRequest { m.ctrl.T.Helper() @@ -391,3 +479,48 @@ func (mr *MockOrganizationsApiMockRecorder) PostOrgsIDMembersExecuteWithHttpInfo mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PostOrgsIDMembersExecuteWithHttpInfo", reflect.TypeOf((*MockOrganizationsApi)(nil).PostOrgsIDMembersExecuteWithHttpInfo), arg0) } + +// PostOrgsIDOwners mocks base method. +func (m *MockOrganizationsApi) PostOrgsIDOwners(arg0 context.Context, arg1 string) api.ApiPostOrgsIDOwnersRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PostOrgsIDOwners", arg0, arg1) + ret0, _ := ret[0].(api.ApiPostOrgsIDOwnersRequest) + return ret0 +} + +// PostOrgsIDOwners indicates an expected call of PostOrgsIDOwners. +func (mr *MockOrganizationsApiMockRecorder) PostOrgsIDOwners(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PostOrgsIDOwners", reflect.TypeOf((*MockOrganizationsApi)(nil).PostOrgsIDOwners), arg0, arg1) +} + +// PostOrgsIDOwnersExecute mocks base method. +func (m *MockOrganizationsApi) PostOrgsIDOwnersExecute(arg0 api.ApiPostOrgsIDOwnersRequest) (api.ResourceOwner, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PostOrgsIDOwnersExecute", arg0) + ret0, _ := ret[0].(api.ResourceOwner) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PostOrgsIDOwnersExecute indicates an expected call of PostOrgsIDOwnersExecute. +func (mr *MockOrganizationsApiMockRecorder) PostOrgsIDOwnersExecute(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PostOrgsIDOwnersExecute", reflect.TypeOf((*MockOrganizationsApi)(nil).PostOrgsIDOwnersExecute), arg0) +} + +// PostOrgsIDOwnersExecuteWithHttpInfo mocks base method. +func (m *MockOrganizationsApi) PostOrgsIDOwnersExecuteWithHttpInfo(arg0 api.ApiPostOrgsIDOwnersRequest) (api.ResourceOwner, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PostOrgsIDOwnersExecuteWithHttpInfo", arg0) + ret0, _ := ret[0].(api.ResourceOwner) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// PostOrgsIDOwnersExecuteWithHttpInfo indicates an expected call of PostOrgsIDOwnersExecuteWithHttpInfo. +func (mr *MockOrganizationsApiMockRecorder) PostOrgsIDOwnersExecuteWithHttpInfo(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PostOrgsIDOwnersExecuteWithHttpInfo", reflect.TypeOf((*MockOrganizationsApi)(nil).PostOrgsIDOwnersExecuteWithHttpInfo), arg0) +}