public async validateZipDeploy()

in src/appservice-rest/Kudu/azure-app-kudu-service.ts [278:319]


    public async validateZipDeploy(webPackage: string): Promise<any> {
        try {
            core.info("Validating deployment package for functions app before Zip Deploy (RBAC)");

            var stats = fs.statSync(webPackage);
            var fileSizeInBytes = stats.size;
            let httpRequest: WebRequest = {
                method: 'POST',
                uri: this._client.getRequestUri(`/api/zipdeploy/validate`),
                headers: {
                    'Content-Length': fileSizeInBytes
                },
                body: fs.createReadStream(webPackage)
            };

            let response = await this._client.beginRequest(httpRequest);
            if(response.statusCode == 200) {
                core.debug(`Validation passed response: ${JSON.stringify(response)}`);
                if (response.body && response.body.result){
                    core.warning(JSON.stringify(response.body.result));          
                }
                return null;
            }
            else if(response.statusCode == 400) {         
                core.debug(`Validation failed response: ${JSON.stringify(response)}`);      
                throw response;
            }
            else {
                core.debug(`Skipping validation with status: ${response.statusCode}`);
                return null;
            }
        }
        catch(error) {
            if (error && error.body && error.body.result && typeof error.body.result.valueOf() == 'string' && error.body.result.includes('ZipDeploy Validation ERROR')) {
                throw new Error(JSON.stringify(error.body.result));
            }           
            else {
                core.debug(`Skipping validation with error: ${JSON.stringify(error)}`);
                return null;
            }
        }
    }