Skip to content

Commit

Permalink
Merge pull request #31 from entando-k8s/ENG-1395-assets-correlation-code
Browse files Browse the repository at this point in the history
ENG-1395 Extracting assets and contents using correlationCode
  • Loading branch information
ffleandro authored Oct 23, 2020
2 parents 7b690ae + 9f5664d commit 41925f3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/env-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const componentDetailExtractors = {
}),
asset: (components) =>
components.map((c) => {
return { value: c.id, name: `(${c.type}) ${c.path}` };
return { value: c.correlationCode, name: `(${c.type}) ${c.path}` };
}),
group: (components) =>
components.map((c) => {
Expand Down Expand Up @@ -115,7 +115,7 @@ const componentIdExtractors = {
return c.name;
},
asset: (c) => {
return c.id;
return c.correlationCode;
},
group: (c) => {
return c.code;
Expand Down Expand Up @@ -160,7 +160,7 @@ const componentCodeExtractors = {
return c.name;
},
asset: (c) => {
return c.id;
return c.correlationCode;
},
group: (c) => {
return c.name;
Expand Down Expand Up @@ -363,7 +363,12 @@ const componentResponseProcessor = {
asset: async (response, token) => {
const assets = response.data.payload;
const schema = {
'id': 'correlationCode',
'id': [{
key: 'correlationCode',
transform: function(id, source) {
return source.correlationCode !== undefined ? source.correlationCode : id;
}
}],
'type': 'type',
'name': 'name',
'description': 'description',
Expand Down Expand Up @@ -516,7 +521,12 @@ const resourceExtractorByType = {

const processContentAttribute = function(attribute) {
const resourceSchema = {
'id': 'id',
'id': [{
key: 'correlationCode',
transform: function(id, source) {
return source.correlationCode !== undefined ? source.correlationCode : id;
}
}],
'name': 'name',
'metadata': 'metadata',
}
Expand Down Expand Up @@ -568,7 +578,7 @@ const assetComponentDescriptorProcessor = function(type, location, code, compone

const split = coreBaseApi.replace('//', '/').split('/');
const url = split[0] + '//' + split[1] + component.path;
const directory = `${location}/${typePlural}/${component.id}`;
const directory = `${location}/${typePlural}/${code}`;

if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
Expand Down Expand Up @@ -731,6 +741,7 @@ async function recursiveTraverseFileTree (root, token) {
const traversed = await recursiveTraverseFileTree(result.data.payload, token);
return traversed.flat();
} else {
console.log('Collecting File: ' + resource.path);
const response = await axios.get(apiUrlTable.resourceDetails.replace('{path}', resource.path), {
headers: { Authorization: `Bearer ${token}` },
});
Expand All @@ -750,6 +761,7 @@ async function collectAllComponents () {
const cmp = await getComponents(type);
const dtls = componentDetailExtractors[type](cmp);
allComponents[type] = dtls.map(d => d.value);
console.log(`Finished collecting ${typeToPlural(type)}`);
}));

return allComponents;
Expand Down

0 comments on commit 41925f3

Please sign in to comment.