Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/cs 40469 - Replaced http calls with axiosInstace of Sdk for marketplace apps in both import and export #1036

Merged
merged 8 commits into from
Sep 26, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ module.exports = class ExportMarketplaceApps {
}

this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config));

this.appSdkAxiosInstance = await managementSDKClient({
host: this.developerHubBaseUrl.split('://').pop()
});
await this.getOrgUid();

const httpClient = new HttpClient();
Expand All @@ -65,7 +67,7 @@ module.exports = class ExportMarketplaceApps {
);
mkdirp.sync(this.marketplaceAppPath);

this.nodeCrypto= await createNodeCryptoInstance(config);
this.nodeCrypto = await createNodeCryptoInstance(config);

return this.exportInstalledExtensions();
}
Expand Down Expand Up @@ -106,8 +108,12 @@ module.exports = class ExportMarketplaceApps {
}

getAllStackSpecificApps(listOfApps = [], skip = 0) {
return this.httpClient
.get(`${this.developerHubBaseUrl}/installations?target_uids=${this.config.source_stack}&skip=${skip}`)
return this.appSdkAxiosInstance.axiosInstance
.get(`/installations?target_uids=${this.config.source_stack}&skip=${skip}`, {
headers: {
organization_uid: this.config.org_uid
},
})
.then(async ({ data }) => {
const { data: apps, count } = data;

Expand Down Expand Up @@ -161,9 +167,9 @@ module.exports = class ExportMarketplaceApps {
} else if (error) {
log(this.config, `Error on exporting ${appName} app and it's config.`, 'error');
}
})
.catch(err => {
log(this.config, `Failed to export ${appName} app config ${formatError(err)}`, 'error');
})
})
.catch((err) => {
log(this.config, `Failed to export ${appName} app config ${formatError(err)}`, 'error');
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { cliux, configHandler, NodeCrypto, HttpClient, managementSDKClient } fro
import { formatError, log } from '../utils';
import { ExportConfig } from '../types';
import { askDeveloperHub } from './interactive';

export const getDeveloperHubUrl = async (exportConfig: ExportConfig) => {
const { cma, name } = configHandler.get('region') || {};
let developerHubBaseUrl = exportConfig?.developerHubUrls[cma];
Expand Down Expand Up @@ -56,8 +55,15 @@ export const getStackSpecificApps = async (params: {
skip: number;
}) => {
const { developerHubBaseUrl, httpClient, config, skip } = params;
return httpClient
.get(`${developerHubBaseUrl}/installations?target_uids=${config.source_stack}&skip=${skip}`)
const appSdkAxiosInstance = await managementSDKClient({
host: developerHubBaseUrl.split('://').pop()
});
return appSdkAxiosInstance.axiosInstance
.get(`${developerHubBaseUrl}/installations?target_uids=${config.source_stack}&skip=${skip}`, {
headers: {
organization_uid: config.org_uid,
},
})
.then((data: any) => data.data)
.catch((error: any) => log(config, `Failed to export marketplace-apps ${formatError(error)}`, 'error'));
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ module.exports = class ImportMarketplaceApps {

this.developerHubBaseUrl = this.config.developerHubBaseUrl || (await getDeveloperHubUrl(this.config));
this.client = await managementSDKClient({ endpoint: this.developerHubBaseUrl });

this.appSdkAxiosInstance = await managementSDKClient({
host: this.developerHubBaseUrl.split('://').pop()
});
await this.getOrgUid();

const httpClient = new HttpClient();
Expand Down Expand Up @@ -519,9 +521,12 @@ module.exports = class ImportMarketplaceApps {
if (_.isEmpty(app) || _.isEmpty(payload) || !uid) {
return Promise.resolve();
}

return this.httpClient
.put(`${this.developerHubBaseUrl}/installations/${uid}`, payload)
return this.appSdkAxiosInstance.axiosInstance
.put(`${this.developerHubBaseUrl}/installations/${uid}`, payload, {
headers: {
organization_uid: this.config.org_uid
},
})
.then(({ data }) => {
if (data.message) {
log(this.config, formatError(data.message), 'success');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class ImportMarketplaceApps extends BaseClass {
public developerHubBaseUrl: string;
public sdkClient: ContentstackClient;
public nodeCrypto: NodeCrypto;

public appSdkAxiosInstance: any
constructor({ importConfig, stackAPIClient }: ModuleClassParams) {
super({ importConfig, stackAPIClient });

Expand Down Expand Up @@ -100,6 +100,9 @@ export default class ImportMarketplaceApps extends BaseClass {
await fsUtil.makeDirectory(this.mapperDirPath);
this.developerHubBaseUrl = this.importConfig.developerHubBaseUrl || (await getDeveloperHubUrl(this.importConfig));
this.sdkClient = await managementSDKClient({ endpoint: this.developerHubBaseUrl });
this.appSdkAxiosInstance = await managementSDKClient({
host: this.developerHubBaseUrl.split('://').pop()
});
this.importConfig.org_uid = await getOrgUid(this.importConfig);
await this.setHttpClient();
await this.startInstallation();
Expand Down Expand Up @@ -403,15 +406,19 @@ export default class ImportMarketplaceApps extends BaseClass {

// TODO migrate this HTTP API call into SDK
// NOTE Use updateAppConfig(this.sdkClient, this.importConfig, app, payload) utility when migrating to SDK call;
return this.httpClient
.put(`${this.developerHubBaseUrl}/installations/${uid}`, payload)
.then(({ data }) => {
if (data.message) {
return this.appSdkAxiosInstance.axiosInstance
.put(`${this.developerHubBaseUrl}/installations/${uid}`, payload, {
headers: {
organization_uid: this.importConfig.org_uid,
},
})
.then(({data}:any) => {
if (data?.message) {
log(this.importConfig, formatError(data.message), 'success');
} else {
log(this.importConfig, `${app.manifest.name} app config updated successfully.!`, 'success');
}
})
.catch((error) => log(this.importConfig, formatError(error), 'error'));
.catch((error:any) => log(this.importConfig, formatError(error), 'error'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ export const getAllStackSpecificApps = async (
httpClient: HttpClient,
config: ImportConfig,
) => {
return await httpClient
.get(`${developerHubBaseUrl}/installations?target_uids=${config.target_stack}`)
.then(({ data }) => data.data)
.catch((error) => log(config, `Failed to export marketplace-apps ${formatError(error)}`, 'error'));
const appSdkAxiosInstance = await managementSDKClient({
host: developerHubBaseUrl.split('://').pop()
});
return await appSdkAxiosInstance.axiosInstance
.get(`${developerHubBaseUrl}/installations?target_uids=${config.target_stack}`, {
headers: {
organization_uid: config.org_uid,
},
})
.then(( {data}:any) => data.data)
.catch((error:any) => log(config, `Failed to export marketplace-apps ${formatError(error)}`, 'error'));
};

export const getDeveloperHubUrl = async (config: ImportConfig): Promise<string> => {
Expand Down