diff options
author | Andreas Fankhauser hiddenalpha.ch | 2024-04-25 17:39:42 +0200 |
---|---|---|
committer | Andreas Fankhauser hiddenalpha.ch | 2024-04-25 17:39:42 +0200 |
commit | 5bcc0eef6f3097706bf83655a44d2dd94e22c8b8 (patch) | |
tree | 9520d270423e9423e70376fda121afd93d2468ac | |
parent | bfb5d8c8c42bad9ffddb502611d43f13ff54a6bf (diff) | |
download | UnspecifiedGarbage-5bcc0eef6f3097706bf83655a44d2dd94e22c8b8.zip UnspecifiedGarbage-5bcc0eef6f3097706bf83655a44d2dd94e22c8b8.tar.gz |
Begun ocexec.c helper. Update maven doc. Enhance slim helper script.
-rw-r--r-- | doc/note/links/links.txt | 2 | ||||
-rw-r--r-- | doc/note/maven/maven.txt | 6 | ||||
-rw-r--r-- | src/main/c/common/windoof.h | 17 | ||||
-rw-r--r-- | src/main/c/postshit/launch/openshift/ocexec.c | 81 | ||||
-rw-r--r-- | src/main/nodejs/paisa-nonslim/foo.js | 341 |
5 files changed, 318 insertions, 129 deletions
diff --git a/doc/note/links/links.txt b/doc/note/links/links.txt index 53ea66e..838cc1d 100644 --- a/doc/note/links/links.txt +++ b/doc/note/links/links.txt @@ -536,6 +536,8 @@ Links (Aka argument amplifiers) ## security - [SDCISA-4808] Security flaw due to no-security-if-no-identity policy Open - [Make ISA secure (again?)](https://wikit.post.ch/x/n984Mg) +- [platform public IP exposed wont fix](https://jira.post.ch/browse/SDCISA-6998) +- [houston public IP exposed](TODO) ## Bus Factor Faktor - [Bus factor definition wikipedia](https://en.wikipedia.org/wiki/Bus_factor) diff --git a/doc/note/maven/maven.txt b/doc/note/maven/maven.txt index 10a606a..4349551 100644 --- a/doc/note/maven/maven.txt +++ b/doc/note/maven/maven.txt @@ -4,13 +4,13 @@ Maven mvn dependency:help -Ddetail=true -mvn versions:set -DgenerateBackupPoms=false -DnewVersion= +mvn versions:set -DgenerateBackupPoms=false -DallowSnapshots=true -DnewVersion= mvn versions:set -DgenerateBackupPoms=false -DnextSnapshot -mvn versions:update-parent -DparentVersion= +mvn versions:update-parent -DgenerateBackupPoms=false -DallowDowngrade=true -DallowSnapshots=true -DforceUpdate=true -DskipResolution=true -DparentVersion=YOUR_VERSION -mvn versions:set-property -Dproperty=foo.bar -DnewVersion=gugus +mvn versions:set-property -DgenerateBackupPoms=false -DallowSnapshots=true -Dproperty=foo.bar -DnewVersion=gugus export MAVEN_OPTS="..." diff --git a/src/main/c/common/windoof.h b/src/main/c/common/windoof.h new file mode 100644 index 0000000..c156cb7 --- /dev/null +++ b/src/main/c/common/windoof.h @@ -0,0 +1,17 @@ + +#if 0 +# include <windows.h> +#else + + + + + + + + + + + + +#endif /*manual windoof on/off switch*/ diff --git a/src/main/c/postshit/launch/openshift/ocexec.c b/src/main/c/postshit/launch/openshift/ocexec.c new file mode 100644 index 0000000..49e68b4 --- /dev/null +++ b/src/main/c/postshit/launch/openshift/ocexec.c @@ -0,0 +1,81 @@ +/* + +SH: true \ +SH: && `# Configure` \ +SH: && CC=x86_64-w64-mingw32-cc \ +SH: && MKDIR_P="mkdir -p" \ +SH: && CFLAGS="-Wall -Werror -pedantic -O0 -g -Isrc/main/c/common -DPROJECT_VERSION=0.0.0-$(date -u +%s) -fmax-errors=1 -Wno-error=unused-variable" \ +SH: && LDFLAGS="-Wl,--gc-sections,--as-needed" \ +SH: && `# Make` \ +SH: && ${MKDIR_P:?} build/bin \ +SH: && ${CC:?} -o build/bin/ocexec ${CFLAGS:?} src/main/c/postshit/launch/openshift/ocexec.c ${LDFLAGS:?} \ +SH: && true + +*/ + +#include <assert.h> +#include <stdio.h> +#include <string.h> +#if __WIN32 +# include <windoof.h> +#endif + +#define LOGERR(...) fprintf(stderr, __VA_ARGS__) +#if !NDEBUG +# define REGISTER +#else +# define REGISTER register +#endif + +#define FLG_isHelp (1<<0) + + +typedef struct App App; + + +struct App { + int flg; + char const *ocNamespace; +}; + + +static void printHelp( void ){ + printf(" \n" + " TODO write help page\n" + " \n"); +} + + +static int parseArgs( int argc, char**argv, App*app ){ + REGISTER int err; + int iArg = 1; + if( argc <= 1 ){ LOGERR("EINVAL: Luke.. use arguments!\n"); return-1; } +nextArg:; + char const *arg = argv[iArg++]; + if( arg == NULL ) goto verifyArgs; + if( !strcmp(arg,"--help") ){ + app->flg |= FLG_isHelp; + }else if( !strcmp(arg,"-n") || !strcmp(arg,"--namespace") ){ + arg = argv[iArg++]; + if( arg == NULL ){ LOGERR("EINVAL: %s needs value\n", argv[iArg-2]); return-1; } + app->ocNamespace = arg; + }else{ + LOGERR("EINVAL: %s\n", arg); + } + goto nextArg; +verifyArgs: + return 0; +} + + +int main( int argc, char**argv ){ + REGISTER int err; + App app = {0}; assert((void*)0 == NULL); + #define app (&app) + if( !parseArgs(argc, argv, app) ){ err = -1; goto endFn; } + if( app->flg & FLG_isHelp ){ printHelp(); err = 0; goto endFn; } +endFn: + return !!err; + #undef app +} + diff --git a/src/main/nodejs/paisa-nonslim/foo.js b/src/main/nodejs/paisa-nonslim/foo.js index 2ce8e68..ab17a86 100644 --- a/src/main/nodejs/paisa-nonslim/foo.js +++ b/src/main/nodejs/paisa-nonslim/foo.js @@ -17,16 +17,21 @@ +" \n" +" Options:\n" +" \n" - +" --default\n" - +" Perform default action (whatever default means).\n" + +" --fetch\n" + +" Update local repos from remote.\n" +" \n" - +" --print-isaVersion\n" - +" Print a preflux isaVersion to stdout filled with the patched\n" - +" services.\n" + +" --reset-hard\n" + +" Reset worktree to develop.\n" +" \n" - +" --reset-hard-to-develop\n" - +" Resets all the services back to develop. WARN if you've uncommitted\n" - +" work in some of those repos, IT WILL BE LOST!\n" + +" --patch-platform\n" + +" Remove slim packaging from patform and set snapshot version.\n" + +" \n" + +" --patch-services\n" + +" Disable slim packaging in Jenkinsfile and use platform snapshot in\n" + +" pom.\n" + +" \n" + +" --commit\n" + +" Create a git commit with our changes.\n" +" \n" +" --push | --push-force\n" +" Create commits for patched services and push them to upstream. If\n" @@ -44,27 +49,32 @@ function parseArgs( argv, app ){ - var hasArgs = false; + if( argv.length <= 2 ){ + log.write("EINVAL: Refuse to produce damage with zero args.\n"); + return -1; + } for( var iA = 2 ; iA < argv.length ; ++iA ){ var arg = argv[iA]; if( arg == "--help" ){ app.isHelp = true; return 0; - }else if( arg == "--default" ){ - hasArgs = true; + }else if( arg == "--fetch" ){ + app.isFetch = true; + }else if( arg == "--reset-hard" ){ + app.isResetHard = true; + }else if( arg == "--patch-platform" ){ + app.isPatchPlatform = true; + }else if( arg == "--patch-services" ){ + app.isPatchServices = true; + }else if( arg == "--commit" ){ + app.isCommit = true; }else if( arg == "--push" ){ if( app.isPushForce ){ log.write("EINVAL: only one of push and push-force allowed\n"); return-1; } app.isPush = true; - hasArgs = true; }else if( arg == "--push-force" ){ if( app.isPush ){ log.write("EINVAL: only one of push and push-force allowed\n"); return-1; } app.isPushForce = true; - hasArgs = true; - }else if( arg == "--print-isaVersion" ){ - app.isPrintIsaVersion = true; - hasArgs = true; }else if( arg == "--reset-hard-to-develop" ){ app.isResetHardToDevelop = true; - hasArgs = true; //}else if( arg == "--max-parallel" ){ // arg = argv[++iA]; // if( !/^[0-9]+$/.test(arg) ){ log.write("EINVAL: --max-parallel "+ arg +"\n"); return -1; } @@ -74,10 +84,6 @@ return -1; } } - if( !hasArgs ){ - log.write("EINVAL: Refuse to produce damage with zero args.\n"); - return -1; - } return 0; } @@ -97,7 +103,7 @@ function gitUrlOfSync( app, thingyName ){ if( !isThingyNameValid(app, thingyName) ) throw TypeError(thingyName); - return "https://example.com/scm/isa/"+ thingyName +".git"; + return "https://gitit.post.ch/scm/isa/"+ thingyName +".git"; } @@ -146,28 +152,36 @@ * "poms/service/paisa-service-superpom/pom.xml" as described in * SDCISA-15648 */ var patch = "" - +"tVnNcuMoEL7nKbTXzUKc2WRmQk1tZav2Ppd9AYRaEgoCCpBj79NvI0u2E9uJxUg+CJDpr4Fu+k+F" - +"LMuMkEqGjN9Z0/o7D24tBdxZLj0nw4j4zoLD/+McumlVlk+ZfSN1AZssL+9L8fj9cUX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zHY62geKT1w7/EsCM1yUbWHQtD" + +"ZpApcJbT5unxSXLw3TfJo51Xri+8A7Qjee8PqS+MmuiYe1gaFObgtSsHQAooqNyFOfn1AO+O8JHZ" + +"EXL7ey+iqv2yGjIk47YPOxhDyAQDETIhdb2s9Bwdod4AystB7/D57pRWiBCr3gKn/UOS3wCq6Tuc" + +"3ZESnqI1lQDTS2GTtVfgZ6Ww/d6XL+bIi113PK0s+r13Wk1KCoC8pmUViji6fn/1Vw4eCvVAGmsU" + +"D31o1PJlC245OCv0FbEU4V8y68FuK5cbPgdpsJRkju2rxOmKOh5hqCVz5Xm1WIki7feaPf+Ofsbn" + +"Q9M7dsQ8dut+IkX9df24DARSVtN3YIfoqx/egj2nKYQroaE5N0CFW2RiMAqnsEcg6akAh/4IsSIB" + +"J1PO0Z+vPrlXlmkw9cqcD3ueu3E/kGtN5iXqtVR6/jDV2XN8vdUqrzVYHWar3Ju+j+XegfysAHD1" + +"+EE2peSU91siBbj7EAqDQSv7lnPg99q6wNY/dJbXasQZYM3JyoQAYTuv4UymnC8oHjfAx+jagm6Z" + +"Tl5D/0Ppsh/y6c3H969ev/n3zT9X15+v/n7nu8lviEvDOzHKQvla17fdp+84FSJZE2F2ioVtPIKd" + +"APuqBCs6O32+BNmBns9/IL0Y8BmPJw/MXJkFcfV/3mNHXg==" ; patch = Buffer.from(patch, 'base64'); patch = zlib.inflateRaw(patch, function( ex, patch ){ @@ -179,12 +193,7 @@ function getJettyServiceNamesAsArray( app, onDone ){ setImmediate(onDone, null, [ /*TODO get via args/file */ - "allitnil", "babelfish", "barman", - //"benjy", "bentstick", "blart", "captain", "caveman", - //"colin", "deep", "drdan", "guide", "heimdall", "hooli", "jeltz", "kwaltz", "lazlar", - //"loon", "magician", "megacamel", "minetti", "mown", "neutron", "nowwhat", "pobble", - //"poodoo", "prosser", "rob", "slarti", "streetmentioner", "thor", "towel", "trillian", - //"vannharl", "vogon", "vroom", "zaphake", "zem", + TODO_GX0CAJ9hAgCNRAIA9hgCAP5jAgDGCgIA ]); } @@ -235,7 +244,7 @@ } log.write("[DEBUG] "+ thingyName +"$ git add Jenkinsfile\n"); var child = child_process.spawn( - "git", ["add", "Jenkinsfile"], + "git", ["add", "--", "."], { cwd:workdirOfSync(app, thingyName) } ); child.on("error", console.error.bind(console)); @@ -262,9 +271,8 @@ child.on("exit", function( code, signal ){ if( code !== 0 || signal !== null ){ var stdoutStr = ""; - for( var buf in stdoutBufs ){ stdoutStr += buf.toString(); } - if( stdoutStr.length ){ log.write(stdoutStr); } - endFn(Error("code="+ code +", signal="+ signal +"")); + for( var buf in stdoutBufs ){ log.write(buf.toString()); } + endFn(Error("code="+ code +", signal="+ signal)); return; } createBranch(); return; @@ -320,14 +328,39 @@ } + function giveServiceOurSpecialVersion( app, thingyName, onDone ){ + if( typeof onDone != "function" ) throw TypeError("onDone"); + doit(); + function doit( ex ){ + if( ex ) throw ex; + var child = child_process.spawn( + "mvn", ["versions:set", "-DgenerateBackupPoms=false", "-DallowSnapshots=true", + "-DnewVersion="+ app.serviceSnapVersion], + { cwd: workdirOfSync(app, thingyName) }, + ); + child.on("error", console.error.bind(console)); + child.stderr.on("data", logAsString); + child.on("close", function( code, signal ){ + if( code !== 0 || signal !== null ){ + onDone(Error("code "+ code +", signal "+ signal)); + return; + } + onDone(); + }); + } + } + + function setPlatformVersionInService( app, thingyName, onDone ){ if( typeof onDone != "function" ) throw TypeError("onDone"); updateParent(); function updateParent(){ - log.write("[DEBUG] "+ thingyName +" - Set platform version "+ app.platformSnapVersion +"\n"); + log.write("[DEBUG] "+ thingyName +" - Set platform version "+ app.parentVersion +"\n"); var child = child_process.spawn( - "mvn", ["versions:update-parent", "-DparentVersion="+ app.platformSnapVersion], - { cwd: workdirOfSync(app, jettyService) }, + "mvn", ["versions:update-parent", "-DgenerateBackupPoms=false", "-DallowDowngrade=true", + "-DallowSnapshots=true", "-DforceUpdate=true", "-DskipResolution=true", + "-DparentVersion="+app.parentVersion], + { cwd: workdirOfSync(app, thingyName) }, ); child.on("error", console.error.bind(console)); child.stderr.on("data", logAsString); @@ -341,10 +374,11 @@ } function updateProperty( ex ){ if( ex ) throw ex; - log.write("[DEBUG] "+ thingyName +" - Set parent.version "+ app.platformSnapVersion +"\n"); + log.write("[DEBUG] "+ thingyName +" - Set parent.version "+ app.parentVersion +"\n"); var child = child_process.spawn( - "mvn", ["versions:set-property", "-Dproperty=parent.version", "-DnewVersion="+ app.platformSnapVersion], - { cwd: workdirOfSync(app, jettyService) }, + "mvn", ["versions:set-property", "-DgenerateBackupPoms=false", "-DallowSnapshots=true", + "-Dproperty=platform.version", "-DnewVersion="+ app.parentVersion], + { cwd: workdirOfSync(app, thingyName) }, ); child.on("error", console.error.bind(console)); child.stderr.on("data", logAsString); @@ -527,8 +561,10 @@ } endFn(null, null); }); - gitApply.stdin.write(patch); - gitApply.stdin.end(); + setTimeout/*TODO why?*/(function(){ + gitApply.stdin.write(patch); + gitApply.stdin.end(); + }, 42); } function endFn( ex, ret ){ if( onDoneCalledNTimes !== 0 ){ throw Error("assert(onDoneCalledNTimes == 0)"); } @@ -553,38 +589,57 @@ } - function forEachJettyService( app, onService, onDone ){ - var iSvc = 0, services; + function forEachInArrayDo( app, array, onService, onDone ){ + var iE = 0; var isOnDoneCalled = false; - getJettyServiceNamesAsArray(app, onServicesArrived); - function onServicesArrived( ex, ret ){ - if( ex ) throw ex; - services = ret; - nextService(); - } - function nextService( ex ){ + nextElem(); + function nextElem( ex ){ if( ex ){ endFn(ex); return; } - var service = services[iSvc++]; - if( service === undefined ){ endFn(); return; } - onService(app, service, nextService); + if( iE >= array.length ){ endFn(); return; } + onService(app, array[iE++], nextElem); } - function endFn( ex, ret ){ + function endFn( ex ){ if( isOnDoneCalled ){ throw (ex) ? ex : Error("onDone MUST be called ONCE only"); }else{ isOnDoneCalled = true; - onDone(ex, ret); + onDone(ex); } } } + function forEachJettyService( app, onService, onDone ){ + getJettyServiceNamesAsArray(app, onServicesArrived); + function onServicesArrived( ex, services ){ + if( ex ) throw ex; + forEachInArrayDo(app, services, onService, onDone); + } + } + + function resetHardToDevelop( app, thingyName, onDone ){ - if( typeof onDone !== "function" ) throw Error("onDone"); var iRemoteName = 0; - tryResetHard(iRemoteName++); - function tryResetHard( i ){ - var remoteName = app.remoteNamesToTry[i]; + if( typeof onDone !== "function" ) throw Error("onDone"); + detach(); + function detach(){ + log.write("[DEBUG] "+ thingyName +"$ git checkout --detach\n"); + var child = child_process.spawn( + "git", ["checkout", "--detach"], + { cwd:workdirOfSync(app, thingyName) } + ); + child.on("error", console.error.bind(console)); + child.stderr.on("data", logAsString); + child.on("close", function( code, signal ){ + if( code !== 0 || signal !== null ){ + onDone(Error("code "+ code +", signal "+ signal)); + }else{ + tryResetHard(); + } + }); + } + function tryResetHard(){ + var remoteName = app.remoteNamesToTry[iRemoteName++]; if( remoteName === undefined ){ onDone(Error("no usable remote found")); return; } log.write("[DEBUG] "+ thingyName +"$ git reset --hard "+ remoteName +"/develop\n"); var child = child_process.spawn( @@ -597,7 +652,23 @@ if( signal !== null ){ onDone(Error("code "+ code +", signal "+ signal)); }else if( code !== 0 ){ - tryResetHard(iRemoteName++); + tryResetHard(); /*try next remoteName*/ + }else{ + wipeWorktree(); + } + }); + } + function wipeWorktree(){ + log.write("[DEBUG] "+ thingyName +"$ git rimraf\n"); + var child = child_process.spawn( + "git", ["rimraf"/*TODO make portable*/], + { cwd:workdirOfSync(app, thingyName) } + ); + child.on("error", console.error.bind(console)); + child.stderr.on("data", logAsString); + child.on("close", function( code, signal ){ + if( code !== 0 || signal !== null ){ + onDone(Error("code "+ code +", signal "+ signal)); }else{ deleteBranch(); } @@ -630,54 +701,65 @@ } - function run( app ){ - if( app.isResetHardToDevelop ){ - forEachJettyService(app, resetHardToDevelop, endFn); - return; - } - updateFromRemote(); - function updateFromRemote( ex ){ - if( ex ) throw ex; - forEachJettyService(app, fetchChangesFromGitit, - onFetchChangesFromGititForAllJettyServicesDone); - } - function onFetchChangesFromGititForAllJettyServicesDone( ex ){ - if( ex ) throw ex; - forEachJettyService(app, checkoutUpstreamDevelop, - onCheckoutUpstreamDevelopDone); - } - function onCheckoutUpstreamDevelopDone( ex ){ - if( ex ) throw ex; - patchAwaySlimPackagingInPlatform(app, onPatchAwaySlimPackagingInPlatformDone); - } - function onPatchAwaySlimPackagingInPlatformDone( ex, ret ){ + function setPlatformVersionInAllServices( app, onDone ){ + forEachJettyService(app, setPlatformVersionInService, onDone); + } + + + function fetchRemoteChanges( app, onDone ){ + var platformAndServices = app.services.slice(0); + platformAndServices.unshift("platform"); + forEachInArrayDo(app, platformAndServices, fetchChangesFromGitit, onDone); + } + + + function fetchListOfServices( app, onDone ){ + getJettyServiceNamesAsArray(app, function( ex, ret ){ if( ex ) throw ex; - setVersionInPlatform(app, onSetVersionInPlatformDone); - } - function onSetVersionInPlatformDone(){ - dropSlimFromAllJenkinsfiles(app, onDropSlimFromAllJenkinsfilesDone); + app.services = ret; + onDone(); + }); + } + + + function run( app ){ + var actions = [ fetchListOfServices ]; + if( app.isFetch ){ actions.push(fetchRemoteChanges); } + if( app.isResetHard ){ + actions.push(function( app, onDone ){ + forEachInArrayDo(app, app.services, checkoutUpstreamDevelop, onDone); + }); + actions.push(function( app, onDone ){ + forEachInArrayDo(app, app.services, resetHardToDevelop, onDone); + }); } - function onDropSlimFromAllJenkinsfilesDone( ex ){ - if( ex ) throw ex; - forEachJettyService(app, setPlatformVersionInService, onSetPlatformVersionInServiceDone); + if( app.isPatchPlatform ){ + actions.push(patchAwaySlimPackagingInPlatform); + actions.push(setVersionInPlatform); } - function onSetPlatformVersionInServiceDone( ex ){ - if( ex ) throw ex; - if( app.isPush || app.isPushForce ){ - commitAllServices(app, onCommitAllServicesDone); - }else{ - log.write("[DEBUG] Skip commit/push (disabled)\n"); - endFn(); - } + if( app.isPatchServices ){ + actions.push(dropSlimFromAllJenkinsfiles); + actions.push(function( app, onDone ){ + forEachInArrayDo(app, app.services, giveServiceOurSpecialVersion, onDone); + }); } - function onCommitAllServicesDone( ex ){ - if( ex ) throw ex; - if( !app.isPush && !app.isPushForce ) throw Error("assert(isPush || isPushForce)"); - forEachJettyService(app, pushService, endFn); + if( app.isCommit ) actions.push(function( app, onDone ){ + forEachInArrayDo(app, app.services, commitService, onDone); + }); + if( app.isPush || app.isPushForce ){ + actions.push(function( app, onDone ){ + forEachJettyService(app, pushService, onDone); + }); } - function endFn( ex ){ - if( ex ) throw ex; + actions.push(function( app, onDone ){ log.write("[INFO ] App done\n"); + }); + triggerNextAction(); + function triggerNextAction( ex ){ + if( ex ) throw ex; + var action = actions.shift(); + if( action === undefined ){ endFn(); return; } + action(app, triggerNextAction); } } @@ -685,19 +767,26 @@ function main(){ const app = { isHelp: false, - isPrintIsaVersion: false, + isFetch: false, + isResetHard: false, + isPatchPlatform: false, + isPatchServices: false, + iscommit: false, isPush: false, isPushForce: false, isResetHardToDevelop: false, remoteNamesToTry: ["origin"], - platformSnapVersion: null, workdir: "C:/work/tmp/git-scripted", maxParallel: 1, numRunningTasks: 0, + services: null, branchName: "SDCISA-15648-RemoveSlimPackaging-n1", commitMsg: "[SDCISA-15648] Remove slim packaging", + platformSnapVersion: "0.0.0-SNAPSHOT", + serviceSnapVersion: "0.0.0-SNAPSHOT", + parentVersion: null, }; - app.platformSnapVersion = "0.0.0-"+ app.branchName +"-SNAPSHOT"; + app.parentVersion = "0.0.0-"+ app.branchName +"-SNAPSHOT"; if( parseArgs(process.argv, app) !== 0 ){ process.exit(1); } if( app.isHelp ){ printHelp(); return; } run(app); |