import $http from '@/utils/http-service';
import { IResponseUserData, ICustError } from '../pages/User/models/type';
import { UI_REST_FIRMWAREINVENTORY } from '@/api/api';
import { mapReauth } from '@/utils/sensitive';
import { getStoreData } from '@/utils/composition';
export default class CaCertificateService {
public static getCaCertificateList(): Promise<IResponseUserData[]> {
return new Promise((resolve, reject) => {
$http
.get('/UI/Rest/AccessMgnt/CertMgnt/CertsInformation/0')
.then((res: any) => {
resolve(res.data);
})
.catch(error => {
reject(error);
});
});
}
public static deletedCaCertificate(certificateType: string, id: string): Promise<ICustError> {
const allowHttpDelete = getStoreData('loct', 'allowHttpDelete');
return new Promise((resolve, reject) => {
const url = '/UI/Rest/AccessMgnt/CertMgnt/DeleteCert';
let params = { CertificateType: Number(certificateType), ID: Number(id) };
const httpMethod = allowHttpDelete ? 'delete' : 'post';
$http[httpMethod](url, params)
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static certUpdateSaveData(params: any): any {
return new Promise((resolve, reject) => {
const url = '/UI/Rest/AccessMgnt/CertUpdateService';
$http
.patch(url, params)
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static updateCertFromCA(): any {
return new Promise((resolve, reject) => {
const url = '/UI/Rest/AccessMgnt/CertUpdateService/UpdateCertFromCA';
$http
.post(url, {})
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static getData(): any {
return new Promise((resolve, reject) => {
const url = '/UI/Rest/AccessMgnt/CertUpdateService';
$http
.get(url)
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static imporCustomCertificate(fileName: string, password: string) {
let data = { Content: `/tmp/web/${fileName}`, Password: password };
return new Promise((resolve, reject) => {
const url = '/UI/Rest/AccessMgnt/CertUpdateService/ImportClientCert';
$http
.post(url, data)
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static uploadCerFile(formData: FormData) {
return $http.post(UI_REST_FIRMWAREINVENTORY, formData);
}
public static imporCACertificate(fileName: string) {
let data = { Content: `/tmp/web/${fileName}`, CertificateType: '0' };
return new Promise((resolve, reject) => {
const url = '/UI/Rest/AccessMgnt/CertMgnt/ImportCert';
$http
.post(url, data)
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static importCerCtrl(fileName: string, id: string) {
let data = { Content: `/tmp/web/${fileName}`, CertificateType: '0', ID: id };
return new Promise((resolve, reject) => {
const url = '/UI/Rest/AccessMgnt/CertMgnt/ImportCertCrl';
$http
.post(url, data)
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static delCerCrl(id: string): any {
return new Promise((resolve, reject) => {
const url = `/UI/Rest/AccessMgnt/CertMgnt/${id}/DeleteCrlCertificate`;
$http
.post(url, {})
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static importDiyCerCtrl(fileName: string, pwd: string) {
let data = { Content: `/tmp/web/${fileName}`, CertificateType: 'Custom', Password: pwd || '' };
const pwdPath = data.Password ? ['Password'] : [];
return new Promise((resolve, reject) => {
const url = '/UI/Rest/Services/WEBService/ImportCertificate';
mapReauth(pwdPath)(data)
.post(url, data)
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
public static importServersCerCtrl(fileName: string) {
let data = { Content: `/tmp/web/${fileName}`, CertificateType: 'Server' };
return new Promise((resolve, reject) => {
const url = '/UI/Rest/Services/WEBService/ImportCertificate';
$http
.post(url, data)
.then((res: any) => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
}