From 74528356fa5e20ef8a434e02d5dcd4560f37f8ae Mon Sep 17 00:00:00 2001 From: lucasgarfield Date: Thu, 27 Jul 2023 12:26:31 +0200 Subject: [PATCH] API: Add programatically generated Content Sources API slice definitions These definitions were generated using the RTKQ code generation tool and will replace the existing definitions. --- api/config/contentSources.ts | 13 + api/schema/contentSources.json | 2314 +++++++++++++++++ package.json | 2 +- .../formComponents/CustomButtons.js | 9 +- .../formComponents/Repositories.js | 14 +- src/api.js | 4 +- src/constants.js | 2 +- src/store/apiSlice.ts | 9 +- src/store/contentSourcesApi.ts | 98 + src/store/emptyContentSourcesApi.ts | 9 + src/store/index.js | 3 + src/test/mocks/handlers.js | 6 +- 12 files changed, 2457 insertions(+), 26 deletions(-) create mode 100644 api/config/contentSources.ts create mode 100644 api/schema/contentSources.json create mode 100644 src/store/contentSourcesApi.ts create mode 100644 src/store/emptyContentSourcesApi.ts diff --git a/api/config/contentSources.ts b/api/config/contentSources.ts new file mode 100644 index 00000000..b6b102e4 --- /dev/null +++ b/api/config/contentSources.ts @@ -0,0 +1,13 @@ +import type { ConfigFile } from '@rtk-query/codegen-openapi' + +const config: ConfigFile = { + schemaFile: '../schema/contentSources.json', + apiFile: '../../src/store/emptyContentSourcesApi.ts', + apiImport: 'emptyContentSourcesApi', + outputFile: '../../src/store/contentSourcesApi.ts', + exportName: 'contentSourcesApi', + hooks: true, + filterEndpoints: ['listRepositories'], +} + +export default config diff --git a/api/schema/contentSources.json b/api/schema/contentSources.json new file mode 100644 index 00000000..79b82347 --- /dev/null +++ b/api/schema/contentSources.json @@ -0,0 +1,2314 @@ +{ + "components": { + "schemas": { + "api.Feature": { + "properties": { + "accessible": { + "description": "Whether the current user can access the feature", + "type": "boolean" + }, + "enabled": { + "description": "Whether the feature is enabled on the running server", + "type": "boolean" + } + }, + "type": "object" + }, + "api.FeatureSet": { + "additionalProperties": { + "$ref": "#/components/schemas/api.Feature" + }, + "type": "object" + }, + "api.FetchGPGKeyResponse": { + "properties": { + "gpg_key": { + "description": "The downloaded GPG Keys from the provided url.", + "type": "string" + } + }, + "type": "object" + }, + "api.GenericAttributeValidationResponse": { + "properties": { + "error": { + "description": "Error message if the attribute is not valid", + "type": "string" + }, + "skipped": { + "description": "Skipped if the attribute is not passed in for validation", + "type": "boolean" + }, + "valid": { + "description": "Valid if not skipped and the provided attribute is valid", + "type": "boolean" + } + }, + "type": "object" + }, + "api.Links": { + "properties": { + "first": { + "description": "Path to first page of results", + "type": "string" + }, + "last": { + "description": "Path to last page of results", + "type": "string" + }, + "next": { + "description": "Path to next page of results", + "type": "string" + }, + "prev": { + "description": "Path to previous page of results", + "type": "string" + } + }, + "type": "object" + }, + "api.PopularRepositoriesCollectionResponse": { + "properties": { + "data": { + "items": { + "$ref": "#/components/schemas/api.PopularRepositoryResponse" + }, + "type": "array" + }, + "links": { + "$ref": "#/components/schemas/api.Links" + }, + "meta": { + "$ref": "#/components/schemas/api.ResponseMetadata" + } + }, + "type": "object" + }, + "api.PopularRepositoryResponse": { + "properties": { + "distribution_arch": { + "description": "Architecture to restrict client usage to", + "example": "x86_64", + "type": "string" + }, + "distribution_versions": { + "description": "Versions to restrict client usage to", + "example": [ + "7", + "8" + ], + "items": { + "type": "string" + }, + "type": "array" + }, + "existing_name": { + "description": "Existing reference name for repository", + "type": "string" + }, + "gpg_key": { + "description": "GPG key for repository", + "type": "string" + }, + "metadata_verification": { + "description": "Verify packages", + "type": "boolean" + }, + "suggested_name": { + "description": "Suggested name of the popular repository", + "type": "string" + }, + "url": { + "description": "URL of the remote yum repository", + "type": "string" + }, + "uuid": { + "description": "UUID of the repository if it exists for the user", + "type": "string" + } + }, + "type": "object" + }, + "api.PublicRepositoryCollectionResponse": { + "properties": { + "data": { + "items": { + "$ref": "#/components/schemas/api.PublicRepositoryResponse" + }, + "type": "array" + }, + "links": { + "$ref": "#/components/schemas/api.Links" + }, + "meta": { + "$ref": "#/components/schemas/api.ResponseMetadata" + } + }, + "type": "object" + }, + "api.PublicRepositoryResponse": { + "properties": { + "last_introspection_error": { + "description": "Error of last attempted introspection", + "type": "string" + }, + "last_introspection_time": { + "description": "Timestamp of last attempted introspection", + "type": "string" + }, + "last_success_introspection_time": { + "description": "Timestamp of last successful introspection", + "type": "string" + }, + "last_update_introspection_time": { + "description": "Timestamp of last introspection that had updates", + "type": "string" + }, + "package_count": { + "description": "Number of packages last read in the repository", + "type": "integer" + }, + "status": { + "description": "Introspection status of the repository", + "type": "string" + }, + "url": { + "description": "URL of the remote yum repository", + "type": "string" + }, + "uuid": { + "description": "UUID of the repository if it exists for the user", + "type": "string" + } + }, + "type": "object" + }, + "api.RepositoryCollectionResponse": { + "properties": { + "data": { + "description": "Requested Data", + "items": { + "$ref": "#/components/schemas/api.RepositoryResponse" + }, + "type": "array" + }, + "links": { + "$ref": "#/components/schemas/api.Links" + }, + "meta": { + "$ref": "#/components/schemas/api.ResponseMetadata" + } + }, + "type": "object" + }, + "api.RepositoryIntrospectRequest": { + "properties": { + "reset_count": { + "description": "Reset the failed introspections count", + "type": "boolean" + } + }, + "type": "object" + }, + "api.RepositoryParameterResponse": { + "properties": { + "distribution_arches": { + "description": "Architectures available for repository creation", + "items": { + "$ref": "#/components/schemas/config.DistributionArch" + }, + "type": "array" + }, + "distribution_versions": { + "description": "Versions available for repository creation", + "items": { + "$ref": "#/components/schemas/config.DistributionVersion" + }, + "type": "array" + } + }, + "type": "object" + }, + "api.RepositoryRequest": { + "properties": { + "distribution_arch": { + "description": "Architecture to restrict client usage to", + "example": "x86_64", + "type": "string" + }, + "distribution_versions": { + "description": "Versions to restrict client usage to", + "example": [ + "7", + "8" + ], + "items": { + "type": "string" + }, + "type": "array" + }, + "gpg_key": { + "description": "GPG key for repository", + "type": "string" + }, + "metadata_verification": { + "description": "Verify packages", + "type": "boolean" + }, + "name": { + "description": "Name of the remote yum repository", + "type": "string" + }, + "snapshot": { + "description": "Enable snapshotting and hosting of this repository", + "type": "boolean" + }, + "url": { + "description": "URL of the remote yum repository", + "type": "string" + } + }, + "type": "object" + }, + "api.RepositoryResponse": { + "properties": { + "account_id": { + "description": "Account ID of the owner", + "readOnly": true, + "type": "string" + }, + "distribution_arch": { + "description": "Architecture to restrict client usage to", + "example": "x86_64", + "type": "string" + }, + "distribution_versions": { + "description": "Versions to restrict client usage to", + "example": [ + "7", + "8" + ], + "items": { + "type": "string" + }, + "type": "array" + }, + "failed_introspections_count": { + "description": "Number of consecutive failed introspections", + "type": "integer" + }, + "gpg_key": { + "description": "GPG key for repository", + "type": "string" + }, + "last_introspection_error": { + "description": "Error of last attempted introspection", + "type": "string" + }, + "last_introspection_time": { + "description": "Timestamp of last attempted introspection", + "type": "string" + }, + "last_success_introspection_time": { + "description": "Timestamp of last successful introspection", + "type": "string" + }, + "last_update_introspection_time": { + "description": "Timestamp of last introspection that had updates", + "type": "string" + }, + "metadata_verification": { + "description": "Verify packages", + "type": "boolean" + }, + "name": { + "description": "Name of the remote yum repository", + "type": "string" + }, + "org_id": { + "description": "Organization ID of the owner", + "readOnly": true, + "type": "string" + }, + "package_count": { + "description": "Number of packages last read in the repository", + "type": "integer" + }, + "snapshot": { + "description": "Enable snapshotting and hosting of this repository", + "type": "boolean" + }, + "status": { + "description": "Status of repository introspection (Valid, Invalid, Unavailable, Pending)", + "type": "string" + }, + "url": { + "description": "URL of the remote yum repository", + "type": "string" + }, + "uuid": { + "description": "UUID of the object", + "readOnly": true, + "type": "string" + } + }, + "type": "object" + }, + "api.RepositoryRpm": { + "properties": { + "arch": { + "description": "The Architecture of the rpm", + "type": "string" + }, + "checksum": { + "description": "The checksum of the rpm", + "type": "string" + }, + "epoch": { + "description": "The epoch of the rpm", + "type": "integer" + }, + "name": { + "description": "The rpm package name", + "type": "string" + }, + "release": { + "description": "The release of the rpm", + "type": "string" + }, + "summary": { + "description": "The summary of the rpm", + "type": "string" + }, + "uuid": { + "description": "Identifier of the rpm", + "type": "string" + }, + "version": { + "description": "The version of the rpm", + "type": "string" + } + }, + "type": "object" + }, + "api.RepositoryRpmCollectionResponse": { + "properties": { + "data": { + "description": "List of rpms", + "items": { + "$ref": "#/components/schemas/api.RepositoryRpm" + }, + "type": "array" + }, + "links": { + "$ref": "#/components/schemas/api.Links" + }, + "meta": { + "$ref": "#/components/schemas/api.ResponseMetadata" + } + }, + "type": "object" + }, + "api.RepositoryValidationRequest": { + "properties": { + "gpg_key": { + "description": "GPGKey of the remote yum repository", + "type": "string" + }, + "metadata_verification": { + "description": "If set, attempt to validate the yum metadata with the specified GPG Key", + "type": "boolean" + }, + "name": { + "description": "Name of the remote yum repository", + "type": "string" + }, + "url": { + "description": "URL of the remote yum repository", + "type": "string" + }, + "uuid": { + "description": "If set, this is an \"Update\" validation", + "type": "string" + } + }, + "type": "object" + }, + "api.RepositoryValidationResponse": { + "properties": { + "gpg_key": { + "$ref": "#/components/schemas/api.GenericAttributeValidationResponse" + }, + "name": { + "$ref": "#/components/schemas/api.GenericAttributeValidationResponse" + }, + "url": { + "$ref": "#/components/schemas/api.UrlValidationResponse" + } + }, + "type": "object" + }, + "api.ResponseMetadata": { + "properties": { + "count": { + "description": "Total count of results", + "type": "integer" + }, + "limit": { + "description": "Limit of results used for the request", + "type": "integer" + }, + "offset": { + "description": "Offset into results used for the request", + "type": "integer" + } + }, + "type": "object" + }, + "api.SearchRpmRequest": { + "properties": { + "limit": { + "description": "Maximum number of records to return for the search", + "type": "integer" + }, + "search": { + "description": "Search string to search rpm names", + "type": "string" + }, + "urls": { + "description": "URLs of repositories to search", + "items": { + "type": "string" + }, + "type": "array" + }, + "uuids": { + "description": "List of RepositoryConfig UUIDs to search", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + }, + "api.SearchRpmResponse": { + "properties": { + "package_name": { + "description": "Package name found", + "type": "string" + }, + "summary": { + "description": "Summary of the package found", + "type": "string" + } + }, + "type": "object" + }, + "api.SnapshotCollectionResponse": { + "properties": { + "data": { + "description": "Requested Data", + "items": { + "$ref": "#/components/schemas/api.SnapshotResponse" + }, + "type": "array" + }, + "links": { + "$ref": "#/components/schemas/api.Links" + }, + "meta": { + "$ref": "#/components/schemas/api.ResponseMetadata" + } + }, + "type": "object" + }, + "api.SnapshotResponse": { + "properties": { + "content_counts": { + "additionalProperties": { + "type": "integer" + }, + "description": "Count of each content type", + "type": "object" + }, + "created_at": { + "description": "Datetime the snapshot was created", + "type": "string" + }, + "distribution_path": { + "description": "Path to pulp distribution", + "type": "string" + } + }, + "type": "object" + }, + "api.TaskInfoCollectionResponse": { + "properties": { + "data": { + "description": "Requested Data", + "items": { + "$ref": "#/components/schemas/api.TaskInfoResponse" + }, + "type": "array" + }, + "links": { + "$ref": "#/components/schemas/api.Links" + }, + "meta": { + "$ref": "#/components/schemas/api.ResponseMetadata" + } + }, + "type": "object" + }, + "api.TaskInfoResponse": { + "properties": { + "created_at": { + "description": "Timestamp of task creation", + "type": "string" + }, + "ended_at": { + "description": "Timestamp task ended running at", + "type": "string" + }, + "error": { + "description": "Error thrown while running task", + "type": "string" + }, + "org_id": { + "description": "Organization ID of the owner", + "type": "string" + }, + "status": { + "description": "Status of task (running, failed, completed, canceled, pending)", + "type": "string" + }, + "uuid": { + "description": "UUID of the object", + "type": "string" + } + }, + "type": "object" + }, + "api.UUIDListRequest": { + "properties": { + "uuids": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + }, + "api.UrlValidationResponse": { + "properties": { + "error": { + "description": "Error message if the attribute is not valid", + "type": "string" + }, + "http_code": { + "description": "If the metadata cannot be fetched successfully, the http code that is returned if the http request was completed", + "type": "integer" + }, + "metadata_present": { + "description": "True if the metadata can be fetched successfully", + "type": "boolean" + }, + "metadata_signature_present": { + "description": "True if a repomd.xml.sig file was found in the repository", + "type": "boolean" + }, + "skipped": { + "description": "Skipped if the URL is not passed in for validation", + "type": "boolean" + }, + "valid": { + "description": "Valid if not skipped and the provided attribute is valid", + "type": "boolean" + } + }, + "type": "object" + }, + "config.DistributionArch": { + "properties": { + "label": { + "description": "Static label of the architecture", + "type": "string" + }, + "name": { + "description": "Human-readable form of the architecture", + "type": "string" + } + }, + "type": "object" + }, + "config.DistributionVersion": { + "properties": { + "label": { + "description": "Static label of the version", + "type": "string" + }, + "name": { + "description": "Human-readable form of the version", + "type": "string" + } + }, + "type": "object" + }, + "errors.ErrorResponse": { + "properties": { + "errors": { + "items": { + "$ref": "#/components/schemas/errors.HandlerError" + }, + "type": "array" + } + }, + "type": "object" + }, + "errors.HandlerError": { + "properties": { + "detail": { + "description": "An explanation specific to the problem", + "type": "string" + }, + "status": { + "description": "HTTP status code applicable to the error", + "type": "integer" + }, + "title": { + "description": "A summary of the problem", + "type": "string" + } + }, + "type": "object" + } + }, + "securitySchemes": { + "RhIdentity": { + "in": "header", + "name": "x-rh-identity", + "type": "apiKey" + } + } + }, + "info": { + "contact": {}, + "description": "API of the Content Sources application on [console.redhat.com](https://console.redhat.com)\n", + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0" + }, + "title": "ContentSourcesBackend", + "version": "v1.0.0" + }, + "openapi": "3.0.3", + "paths": { + "/features/": { + "get": { + "description": "Get features available for the user within their Organization", + "operationId": "listFeatures", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.FeatureSet" + } + } + }, + "description": "OK" + } + }, + "summary": "List Features within the application, whether they are enabled, and whether the requesting user can use them", + "tags": [ + "features" + ] + } + }, + "/popular_repositories/": { + "get": { + "description": "Get popular repositories", + "operationId": "listPopularRepositories", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.PopularRepositoriesCollectionResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "List Popular Repositories", + "tags": [ + "popular_repositories" + ] + } + }, + "/public_repositories/": { + "get": { + "description": "Get public repositories.\nA public repository is a defined repository that is available to all accounts for the purposes of searching for rpm names by URL.\nIt does not show up via the normal repositories API.", + "operationId": "listPublicRepositories", + "parameters": [ + { + "description": "Offset into the list of results to return in the response", + "in": "query", + "name": "offset", + "schema": { + "type": "integer" + } + }, + { + "description": "Limit the number of items returned", + "in": "query", + "name": "limit", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.PublicRepositoryCollectionResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "List Public Repositories", + "tags": [ + "public_repositories" + ] + } + }, + "/repositories/": { + "get": { + "description": "list repositories", + "operationId": "listRepositories", + "parameters": [ + { + "description": "Offset into the list of results to return in the response", + "in": "query", + "name": "offset", + "schema": { + "type": "integer" + } + }, + { + "description": "Limit the number of items returned", + "in": "query", + "name": "limit", + "schema": { + "type": "integer" + } + }, + { + "description": "Comma separated list of architecture to optionally filter-on (e.g. 'x86_64,s390x' would return Repositories with x86_64 or s390x only)", + "in": "query", + "name": "version", + "schema": { + "type": "string" + } + }, + { + "description": "Comma separated list of versions to optionally filter-on (e.g. '7,8' would return Repositories with versions 7 or 8 only)", + "in": "query", + "name": "arch", + "schema": { + "type": "string" + } + }, + { + "description": "Filter by compatible arch (e.g. 'x86_64' would return Repositories with the 'x86_64' arch and Repositories where arch is not set)", + "in": "query", + "name": "available_for_version", + "schema": { + "type": "string" + } + }, + { + "description": "Filter by compatible version (e.g. 7 would return Repositories with the version 7 or where version is not set)", + "in": "query", + "name": "available_for_arch", + "schema": { + "type": "string" + } + }, + { + "description": "Search term for name and url.", + "in": "query", + "name": "search", + "schema": { + "type": "string" + } + }, + { + "description": "Filter repositories by name using an exact match", + "in": "query", + "name": "name", + "schema": { + "type": "string" + } + }, + { + "description": "Filter repositories by name using an exact match", + "in": "query", + "name": "url", + "schema": { + "type": "string" + } + }, + { + "description": "Sets the sort order of the results", + "in": "query", + "name": "sort_by", + "schema": { + "type": "string" + } + }, + { + "description": "Comma separated list of statuses to optionally filter on", + "in": "query", + "name": "status", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryCollectionResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "List Repositories", + "tags": [ + "repositories" + ] + }, + "post": { + "description": "create a repository", + "operationId": "createRepository", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryRequest" + } + } + }, + "description": "request body", + "required": true, + "x-originalParamName": "body" + }, + "responses": { + "201": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryResponse" + } + } + }, + "description": "Created", + "headers": { + "Location": { + "description": "resource URL", + "schema": { + "type": "string" + } + } + } + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "415": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unsupported Media Type" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Create Repository", + "tags": [ + "repositories" + ] + } + }, + "/repositories/bulk_create/": { + "post": { + "description": "bulk create repositories", + "operationId": "bulkCreateRepositories", + "requestBody": { + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/api.RepositoryRequest" + }, + "type": "array" + } + } + }, + "description": "request body", + "required": true, + "x-originalParamName": "body" + }, + "responses": { + "201": { + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/api.RepositoryResponse" + }, + "type": "array" + } + } + }, + "description": "Created", + "headers": { + "Location": { + "description": "resource URL", + "schema": { + "type": "string" + } + } + } + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "415": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unsupported Media Type" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Bulk create repositories", + "tags": [ + "repositories" + ] + } + }, + "/repositories/bulk_delete/": { + "post": { + "description": "bulk delete repositories", + "operationId": "bulkDeleteRepositories", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.UUIDListRequest" + } + } + }, + "description": "Identifiers of the repositories", + "required": true, + "x-originalParamName": "body" + }, + "responses": { + "204": { + "description": "Repositories were successfully deleted" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "415": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unsupported Media Type" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Bulk delete repositories", + "tags": [ + "repositories" + ] + } + }, + "/repositories/{uuid}": { + "delete": { + "operationId": "deleteRepository", + "parameters": [ + { + "description": "Identifier of the Repository", + "in": "path", + "name": "uuid", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "204": { + "description": "Repository was successfully deleted" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Delete a repository", + "tags": [ + "repositories" + ] + }, + "get": { + "description": "Get information about a Repository", + "operationId": "getRepository", + "parameters": [ + { + "description": "Identifier of the Repository", + "in": "path", + "name": "uuid", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Get Repository", + "tags": [ + "repositories" + ] + }, + "patch": { + "description": "Partially Update a repository", + "operationId": "partialUpdateRepository", + "parameters": [ + { + "description": "Identifier of the Repository", + "in": "path", + "name": "uuid", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryRequest" + } + } + }, + "description": "request body", + "required": true, + "x-originalParamName": "body" + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "415": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unsupported Media Type" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Partial Update Repository", + "tags": [ + "repositories" + ] + }, + "put": { + "description": "Fully update a repository", + "operationId": "fullUpdateRepository", + "parameters": [ + { + "description": "Identifier of the Repository", + "in": "path", + "name": "uuid", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryRequest" + } + } + }, + "description": "request body", + "required": true, + "x-originalParamName": "body" + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "415": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unsupported Media Type" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Update Repository", + "tags": [ + "repositories" + ] + } + }, + "/repositories/{uuid}/introspect/": { + "post": { + "operationId": "introspect", + "parameters": [ + { + "description": "Identifier of the Repository", + "in": "path", + "name": "uuid", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "*/*": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryIntrospectRequest" + } + } + }, + "description": "request body", + "x-originalParamName": "body" + }, + "responses": { + "204": { + "description": "Introspection was successfully queued" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "introspect a repository", + "tags": [ + "repositories" + ] + } + }, + "/repositories/{uuid}/rpms": { + "get": { + "description": "list repositories RPMs", + "operationId": "listRepositoriesRpms", + "parameters": [ + { + "description": "Identifier of the Repository", + "in": "path", + "name": "uuid", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "Limit the number of items returned", + "in": "query", + "name": "limit", + "schema": { + "type": "integer" + } + }, + { + "description": "Offset into the list of results to return in the response", + "in": "query", + "name": "offset", + "schema": { + "type": "integer" + } + }, + { + "description": "Search term for name.", + "in": "query", + "name": "search", + "schema": { + "type": "string" + } + }, + { + "description": "Sets the sort order of the results.", + "in": "query", + "name": "sort_by", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryRpmCollectionResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "List Repositories RPMs", + "tags": [ + "repositories", + "rpms" + ] + } + }, + "/repositories/{uuid}/snapshots/": { + "get": { + "operationId": "listSnapshots", + "parameters": [ + { + "description": "Identifier of the Repository", + "in": "path", + "name": "uuid", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.SnapshotCollectionResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "List snapshots of a repository", + "tags": [ + "repositories" + ] + } + }, + "/repository_parameters/": { + "get": { + "description": "get repository parameters (Versions and Architectures)", + "operationId": "listRepositoryParameters", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.RepositoryParameterResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + } + }, + "summary": "List Repository Parameters", + "tags": [ + "repositories" + ] + } + }, + "/repository_parameters/external_gpg_key": { + "post": { + "description": "Fetch gpgkey from URL", + "operationId": "fetchGpgKey", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.FetchGPGKeyResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "415": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unsupported Media Type" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Fetch gpgkey from URL", + "tags": [ + "gpgKey" + ] + } + }, + "/repository_parameters/validate/": { + "post": { + "description": "Validate parameters prior to creating a repository, including checking if remote yum metadata is present", + "operationId": "validateRepositoryParameters", + "requestBody": { + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/api.RepositoryValidationRequest" + }, + "type": "array" + } + } + }, + "description": "request body", + "required": true, + "x-originalParamName": "body" + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/api.RepositoryValidationResponse" + }, + "type": "array" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "415": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unsupported Media Type" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Validate parameters prior to creating a repository", + "tags": [ + "repositories" + ] + } + }, + "/rpms/names": { + "post": { + "description": "Search RPMs for a given list of repositories as URLs or UUIDs", + "operationId": "searchRpm", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.SearchRpmRequest" + } + } + }, + "description": "request body", + "required": true, + "x-originalParamName": "body" + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "items": { + "$ref": "#/components/schemas/api.SearchRpmResponse" + }, + "type": "array" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "415": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unsupported Media Type" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Search RPMs", + "tags": [ + "repositories", + "rpms" + ] + } + }, + "/tasks/": { + "get": { + "description": "list tasks", + "operationId": "listTasks", + "parameters": [ + { + "description": "Offset into the list of results to return in the response", + "in": "query", + "name": "offset", + "schema": { + "type": "integer" + } + }, + { + "description": "Limit the number of items returned", + "in": "query", + "name": "limit", + "schema": { + "type": "integer" + } + }, + { + "description": "Filter tasks by status using an exact match", + "in": "query", + "name": "status", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.TaskInfoCollectionResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "List Tasks", + "tags": [ + "tasks" + ] + } + }, + "/tasks/{uuid}": { + "get": { + "description": "Get information about a Task", + "operationId": "getTask", + "parameters": [ + { + "description": "Identifier of the Task", + "in": "path", + "name": "uuid", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api.TaskInfoResponse" + } + } + }, + "description": "OK" + }, + "400": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Bad Request" + }, + "401": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Unauthorized" + }, + "404": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Not Found" + }, + "500": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/errors.ErrorResponse" + } + } + }, + "description": "Internal Server Error" + } + }, + "summary": "Get Task", + "tags": [ + "tasks" + ] + } + } + }, + "servers": [ + { + "url": "https://api.example.com/api/content-sources/v1.0/" + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 30e61624..8426744d 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "test": "TZ=UTC jest --verbose --no-cache", "test:single": "jest --verbose -w 1", "build": "webpack --config config/prod.webpack.config.js", - "api": "npx @rtk-query/codegen-openapi ./api/config/image-builder.ts & npx @rtk-query/codegen-openapi ./api/config/rhsm.ts", + "api": "npx @rtk-query/codegen-openapi ./api/config/image-builder.ts & npx @rtk-query/codegen-openapi ./api/config/rhsm.ts & npx @rtk-query/codegen-openapi ./api/config/contentSources.ts", "verify": "npm-run-all build lint test" }, "insights": { diff --git a/src/Components/CreateImageWizard/formComponents/CustomButtons.js b/src/Components/CreateImageWizard/formComponents/CustomButtons.js index 2fef0509..5ee5dad7 100644 --- a/src/Components/CreateImageWizard/formComponents/CustomButtons.js +++ b/src/Components/CreateImageWizard/formComponents/CustomButtons.js @@ -5,7 +5,7 @@ import WizardContext from '@data-driven-forms/react-form-renderer/wizard-context import { Button } from '@patternfly/react-core'; import PropTypes from 'prop-types'; -import { usePrefetch } from '../../../store/apiSlice'; +import { contentSourcesApi } from '../../../store/contentSourcesApi'; import { rhsmApi } from '../../../store/rhsmApi'; import { releaseToVersion } from '../../../Utilities/releaseToVersion'; @@ -19,7 +19,8 @@ const CustomButtons = ({ const [isSaving, setIsSaving] = useState(false); const { currentStep, formOptions } = useContext(WizardContext); const prefetchActivationKeys = rhsmApi.usePrefetch('listActivationKeys'); - const prefetchRepositories = usePrefetch('getRepositories'); + const prefetchRepositories = + contentSourcesApi.usePrefetch('listRepositories'); const onNextOrSubmit = () => { if (currentStep.id === 'wizard-review') { @@ -44,8 +45,8 @@ const CustomButtons = ({ const release = getState().values?.release; const version = releaseToVersion(release); prefetchRepositories({ - available_for_arch: 'x86_64', - available_for_version: version, + availableForArch: 'x86_64', + availableForVersion: version, }); } }; diff --git a/src/Components/CreateImageWizard/formComponents/Repositories.js b/src/Components/CreateImageWizard/formComponents/Repositories.js index b5ca3a44..836a1c4e 100644 --- a/src/Components/CreateImageWizard/formComponents/Repositories.js +++ b/src/Components/CreateImageWizard/formComponents/Repositories.js @@ -37,7 +37,7 @@ import { } from '@patternfly/react-table'; import PropTypes from 'prop-types'; -import { useGetRepositoriesQuery } from '../../../store/apiSlice'; +import { useListRepositoriesQuery } from '../../../store/contentSourcesApi'; import { releaseToVersion } from '../../../Utilities/releaseToVersion'; import { useGetEnvironment } from '../../../Utilities/useGetEnvironment'; @@ -205,10 +205,10 @@ const Repositories = (props) => { const release = getState().values?.release; const version = releaseToVersion(release); - const firstRequest = useGetRepositoriesQuery( + const firstRequest = useListRepositoriesQuery( { - available_for_arch: 'x86_64', - available_for_version: version, + availableForArch: 'x86_64', + availableForVersion: version, limit: 100, offset: 0, }, @@ -223,10 +223,10 @@ const Repositories = (props) => { firstRequest?.data?.meta?.count <= 100; // Fetch *all* repositories if there are more than 100 so that typeahead filter works - const followupRequest = useGetRepositoriesQuery( + const followupRequest = useListRepositoriesQuery( { - available_for_arch: 'x86_64', - available_for_version: version, + availableForArch: 'x86_64', + availableForVersion: version, limit: firstRequest?.data?.meta?.count, offset: 0, }, diff --git a/src/api.js b/src/api.js index 02ec85d3..779773eb 100644 --- a/src/api.js +++ b/src/api.js @@ -1,6 +1,6 @@ import axios from 'axios'; -import { CONTENT_SOURCES, IMAGE_BUILDER_API } from './constants'; +import { CONTENT_SOURCES_API, IMAGE_BUILDER_API } from './constants'; const postHeaders = { headers: { 'Content-Type': 'application/json' } }; @@ -51,7 +51,7 @@ async function getPackagesContentSources(repoUrls, search) { }; const path = '/rpms/names'; const request = await axios.post( - CONTENT_SOURCES.concat(path), + CONTENT_SOURCES_API.concat(path), body, postHeaders ); diff --git a/src/constants.js b/src/constants.js index c04d6205..587d2a88 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,6 +1,6 @@ export const IMAGE_BUILDER_API = '/api/image-builder/v1'; export const RHSM_API = '/api/rhsm/v2'; -export const CONTENT_SOURCES = '/api/content-sources/v1'; +export const CONTENT_SOURCES_API = '/api/content-sources/v1'; export const PROVISIONING_SOURCES_ENDPOINT = '/api/provisioning/v1'; export const RHEL_8 = 'rhel-88'; export const RHEL_9 = 'rhel-92'; diff --git a/src/store/apiSlice.ts b/src/store/apiSlice.ts index b367e6e5..51218430 100644 --- a/src/store/apiSlice.ts +++ b/src/store/apiSlice.ts @@ -1,8 +1,6 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'; -import { RepositoryCollectionResponse, SourceResponse, SourceUploadInfoResponse } from '../../types'; - -type GetRepositoriesArgs = { available_for_arch: string, available_for_version: string, limit: number, offset: number } +import { SourceResponse, SourceUploadInfoResponse } from '../../types'; enum Provider { 'azure', @@ -10,7 +8,6 @@ enum Provider { } import { - CONTENT_SOURCES, PROVISIONING_SOURCES_ENDPOINT, } from '../constants'; @@ -25,14 +22,10 @@ export const apiSlice = createApi({ query: (sourceId) => `${PROVISIONING_SOURCES_ENDPOINT}/sources/${sourceId}/upload_info` }), - getRepositories: builder.query({ - query: ({available_for_arch, available_for_version, limit, offset}) => `${CONTENT_SOURCES}/repositories/?available_for_arch=${available_for_arch}&available_for_version=${available_for_version}&limit=${limit}&offset=${offset}`, - }), }), }); export const { - useGetRepositoriesQuery, useGetSourcesQuery, useGetSourceDetailQuery, usePrefetch, diff --git a/src/store/contentSourcesApi.ts b/src/store/contentSourcesApi.ts new file mode 100644 index 00000000..37b6a9f9 --- /dev/null +++ b/src/store/contentSourcesApi.ts @@ -0,0 +1,98 @@ +import { emptyContentSourcesApi as api } from "./emptyContentSourcesApi"; +const injectedRtkApi = api.injectEndpoints({ + endpoints: (build) => ({ + listRepositories: build.query< + ListRepositoriesApiResponse, + ListRepositoriesApiArg + >({ + query: (queryArg) => ({ + url: `/repositories/`, + params: { + offset: queryArg.offset, + limit: queryArg.limit, + version: queryArg.version, + arch: queryArg.arch, + available_for_version: queryArg.availableForVersion, + available_for_arch: queryArg.availableForArch, + search: queryArg.search, + name: queryArg.name, + url: queryArg.url, + sort_by: queryArg.sortBy, + status: queryArg.status, + }, + }), + }), + }), + overrideExisting: false, +}); +export { injectedRtkApi as contentSourcesApi }; +export type ListRepositoriesApiResponse = + /** status 200 OK */ ApiRepositoryCollectionResponse; +export type ListRepositoriesApiArg = { + /** Offset into the list of results to return in the response */ + offset?: number; + /** Limit the number of items returned */ + limit?: number; + /** Comma separated list of architecture to optionally filter-on (e.g. 'x86_64,s390x' would return Repositories with x86_64 or s390x only) */ + version?: string; + /** Comma separated list of versions to optionally filter-on (e.g. '7,8' would return Repositories with versions 7 or 8 only) */ + arch?: string; + /** Filter by compatible arch (e.g. 'x86_64' would return Repositories with the 'x86_64' arch and Repositories where arch is not set) */ + availableForVersion?: string; + /** Filter by compatible version (e.g. 7 would return Repositories with the version 7 or where version is not set) */ + availableForArch?: string; + /** Search term for name and url. */ + search?: string; + /** Filter repositories by name using an exact match */ + name?: string; + /** Filter repositories by name using an exact match */ + url?: string; + /** Sets the sort order of the results */ + sortBy?: string; + /** Comma separated list of statuses to optionally filter on */ + status?: string; +}; +export type ApiRepositoryResponse = { + account_id?: string; + distribution_arch?: string; + distribution_versions?: string[]; + failed_introspections_count?: number; + gpg_key?: string; + last_introspection_error?: string; + last_introspection_time?: string; + last_success_introspection_time?: string; + last_update_introspection_time?: string; + metadata_verification?: boolean; + name?: string; + org_id?: string; + package_count?: number; + snapshot?: boolean; + status?: string; + url?: string; + uuid?: string; +}; +export type ApiLinks = { + first?: string; + last?: string; + next?: string; + prev?: string; +}; +export type ApiResponseMetadata = { + count?: number; + limit?: number; + offset?: number; +}; +export type ApiRepositoryCollectionResponse = { + data?: ApiRepositoryResponse[]; + links?: ApiLinks; + meta?: ApiResponseMetadata; +}; +export type ErrorsHandlerError = { + detail?: string; + status?: number; + title?: string; +}; +export type ErrorsErrorResponse = { + errors?: ErrorsHandlerError[]; +}; +export const { useListRepositoriesQuery } = injectedRtkApi; diff --git a/src/store/emptyContentSourcesApi.ts b/src/store/emptyContentSourcesApi.ts new file mode 100644 index 00000000..10ae73af --- /dev/null +++ b/src/store/emptyContentSourcesApi.ts @@ -0,0 +1,9 @@ +import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' +import {CONTENT_SOURCES_API} from '../constants' + +// initialize an empty api service that we'll inject endpoints into later as needed +export const emptyContentSourcesApi = createApi({ + reducerPath: 'contentSourcesApi', + baseQuery: fetchBaseQuery({ baseUrl: CONTENT_SOURCES_API }), + endpoints: () => ({}), +}) diff --git a/src/store/index.js b/src/store/index.js index d0d3aed8..87780e92 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,6 +5,7 @@ import promiseMiddleware from 'redux-promise-middleware'; import { apiSlice } from './apiSlice'; import clonesSlice from './clonesSlice'; import composesSlice from './composesSlice'; +import { contentSourcesApi } from './contentSourcesApi'; import { imageBuilderApi } from './imageBuilderApi'; import { rhsmApi } from './rhsmApi'; @@ -12,6 +13,7 @@ export const reducer = { [apiSlice.reducerPath]: apiSlice.reducer, clones: clonesSlice, composes: composesSlice, + [contentSourcesApi.reducerPath]: contentSourcesApi.reducer, [imageBuilderApi.reducerPath]: imageBuilderApi.reducer, [rhsmApi.reducerPath]: rhsmApi.reducer, notifications: notificationsReducer, @@ -21,6 +23,7 @@ export const middleware = (getDefaultMiddleware) => getDefaultMiddleware() .concat(promiseMiddleware) .concat(apiSlice.middleware) + .concat(contentSourcesApi.middleware) .concat(imageBuilderApi.middleware) .concat(rhsmApi.middleware); diff --git a/src/test/mocks/handlers.js b/src/test/mocks/handlers.js index 83e76f97..2ed524bc 100644 --- a/src/test/mocks/handlers.js +++ b/src/test/mocks/handlers.js @@ -1,7 +1,7 @@ import { rest } from 'msw'; import { - CONTENT_SOURCES, + CONTENT_SOURCES_API, IMAGE_BUILDER_API, PROVISIONING_SOURCES_ENDPOINT, RHSM_API, @@ -40,7 +40,7 @@ export const handlers = [ } } ), - rest.post(`${CONTENT_SOURCES}/rpms/names`, async (req, res, ctx) => { + rest.post(`${CONTENT_SOURCES_API}/rpms/names`, async (req, res, ctx) => { const { search } = await req.json(); return res(ctx.status(200), ctx.json(mockSourcesPackagesResults(search))); }), @@ -59,7 +59,7 @@ export const handlers = [ const { key } = req.params; return res(ctx.status(200), ctx.json(mockActivationKeyInformation(key))); }), - rest.get(`${CONTENT_SOURCES}/repositories/`, (req, res, ctx) => { + rest.get(`${CONTENT_SOURCES_API}/repositories/`, (req, res, ctx) => { const available_for_arch = req.url.searchParams.get('available_for_arch'); const available_for_version = req.url.searchParams.get( 'available_for_version'