diff --git a/projects/cobbler-api/src/lib/cobbler-api.service.spec.ts b/projects/cobbler-api/src/lib/cobbler-api.service.spec.ts index 1c413839..8016501f 100644 --- a/projects/cobbler-api/src/lib/cobbler-api.service.spec.ts +++ b/projects/cobbler-api/src/lib/cobbler-api.service.spec.ts @@ -133,9 +133,15 @@ describe('CobblerApiService', () => { expect(service).toBeFalsy(); }); - xit('should execute the background_signature_update action on the Cobbler Server', () => { - service.background_signature_update(''); - expect(service).toBeFalsy(); + it('should execute the background_signature_update action on the Cobbler Server', () => { + // eslint-disable-next-line max-len + const methodResponse = `2022-09-30_195846_Updating Signatures_6c5300d51c224984b4319fb536cc21d0` + const result = "2022-09-30_195846_Updating Signatures_6c5300d51c224984b4319fb536cc21d0" + service.background_signature_update('').subscribe(value => { + expect(value).toEqual(result) + }); + const mockRequest = httpTestingController.expectOne('http://localhost/cobbler_api'); + mockRequest.flush(methodResponse); }); it('should execute the get_events action on the Cobbler Server', () => { diff --git a/projects/cobbler-api/src/lib/cobbler-api.service.ts b/projects/cobbler-api/src/lib/cobbler-api.service.ts index 41bd9865..e13cfab5 100644 --- a/projects/cobbler-api/src/lib/cobbler-api.service.ts +++ b/projects/cobbler-api/src/lib/cobbler-api.service.ts @@ -21,6 +21,7 @@ import { SyncSystemsOptions, Version } from './custom-types/misc'; +import {DistroSignatures} from "./custom-types/signatures"; // TODO: Investigate on server side to build and receive well known interfaces, not just plain objects. @@ -307,8 +308,9 @@ export class CobblerApiService { } background_signature_update(token: string): Observable { + const signatureUpdateOptions: XmlRpcStruct = {members: []} return this.client - .methodCall('background_signature_update', [token]) + .methodCall('background_signature_update', [signatureUpdateOptions, token]) .pipe( map((data: MethodResponse | MethodFault) => { if (AngularXmlrpcService.instanceOfMethodResponse(data)) { @@ -2128,17 +2130,54 @@ export class CobblerApiService { ); } - get_signatures(token: string): Observable { + get_signatures(token: string): Observable { return this.client .methodCall('get_signatures', [token]) .pipe( - map((data: MethodResponse | MethodFault) => { + map((data: MethodResponse | MethodFault) => { if (AngularXmlrpcService.instanceOfMethodResponse(data)) { - return data.value as object; + return data.value as XmlRpcStruct; } else if (AngularXmlrpcService.instanceOfMethodFault(data)) { throw new Error('Getting the signatures failed with code "' + data.faultCode + '" and error message "' + data.faultString + '"'); } + }), + map(value => { + let result: DistroSignatures = {breeds: {}} + value.members.forEach(breedStruct => { + const osBreedStruct = breedStruct.value + if (!AngularXmlrpcService.instanceOfXmlRpcStruct(osBreedStruct)) { + throw new Error("Expected to receive XmlRpcStruct!") + } + const osBreedArray = osBreedStruct.members + osBreedArray.forEach(osBreedObject => { + const osBreedName = osBreedObject.name + result.breeds[osBreedName] = {} + const osVersionArray = osBreedObject.value + if (!AngularXmlrpcService.instanceOfXmlRpcStruct(osVersionArray)) { + throw new Error("Expected to receive XmlRpcStruct!") + } + osVersionArray.members.forEach(osVersionStruct => { + const osVersionValueStruct = osVersionStruct.value + const osVersionName = osVersionStruct.name + if (!AngularXmlrpcService.instanceOfXmlRpcStruct(osVersionValueStruct)) { + throw new Error("Expected to receive XmlRpcStruct!") + } + // @ts-ignore - Due to this being dynamically filled + result.breeds[osBreedName][osVersionName] = {} + osVersionValueStruct.members.forEach(osVersionAttribute => { + const attributeName = osVersionAttribute.name + const attributeValue = osVersionAttribute.value + if (AngularXmlrpcService.instanceOfXmlRpcArray(attributeValue)) { + result.breeds[osBreedName][osVersionName][attributeName] = attributeValue.data + } else { + result.breeds[osBreedName][osVersionName][attributeName] = attributeValue + } + }) + }) + }) + }) + return result }) ); } diff --git a/projects/cobbler-api/src/lib/custom-types/signatures.ts b/projects/cobbler-api/src/lib/custom-types/signatures.ts new file mode 100644 index 00000000..106b696f --- /dev/null +++ b/projects/cobbler-api/src/lib/custom-types/signatures.ts @@ -0,0 +1,70 @@ +export interface DistroSignatureOsVersion { + signatures: string[] + version_file: string | null + version_file_regex?: string | null + kernel_arch: string + kernel_arch_regex?: string | null + supported_arches: ( + | "arm" + | "ARM64" + | "armhfp" + | "aarch64" + | "i386" + | "i586" + | "ia64" + | "ppc" + | "ppc64" + | "ppc64le" + | "ppc64el" + | "s390" + | "s390x" + | "x86_64" + | "amd64" + | "AMD64" + | "x86" + )[] + supported_repo_breeds: ("rsync" | "rhn" | "yum" | "apt")[] + kernel_file: string + initrd_file: string + isolinux_ok?: boolean + default_autoinstall: string + kernel_options: string + kernel_options_post: string + template_files?: string + boot_files?: string[] + boot_loaders?: { + arm?: ("pxe" | "ipxe" | "grub")[] + armhfp?: ("pxe" | "ipxe" | "grub")[] + aarch64?: ("pxe" | "ipxe" | "grub")[] + i386?: ("pxe" | "ipxe" | "grub")[] + ia64?: ("pxe" | "ipxe" | "grub")[] + ppc?: ("pxe" | "ipxe" | "grub")[] + ppc64?: ("pxe" | "ipxe" | "grub")[] + ppc64le?: ("pxe" | "ipxe" | "grub")[] + s390?: ("pxe" | "ipxe" | "grub")[] + s390x?: ("pxe" | "ipxe" | "grub")[] + x86_64?: ("pxe" | "ipxe" | "grub")[] + [k: string]: unknown + } +} + +/** + * The different distributions supported by Cobbler. This schema is valid for Cobbler with major version 3. + * + * Generated via: https://transform.tools/json-schema-to-typescript + */ +export interface DistroSignatures { + breeds: { + /** + * This interface was referenced by `undefined`'s JSON-Schema definition + * via the `patternProperty` "redhat|debian|ubuntu|suse|vmware|freebsd|xen|unix|windows|powerkvm|generic". + */ + [k: string]: { + /** + * This interface was referenced by `undefined`'s JSON-Schema definition + * via the `patternProperty` "^[a-zA-Z0-9]*$". + */ + [k: string]: DistroSignatureOsVersion + } + } +} diff --git a/projects/cobbler-api/src/public-api.ts b/projects/cobbler-api/src/public-api.ts index 9f9ff312..0e1953b7 100644 --- a/projects/cobbler-api/src/public-api.ts +++ b/projects/cobbler-api/src/public-api.ts @@ -6,4 +6,5 @@ export * from './lib/cobbler-api.service'; export * from './lib/lib.config'; export * from './lib/custom-types/items'; export * from './lib/custom-types/settings'; +export * from './lib/custom-types/signatures'; export * from './lib/custom-types/misc';