summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fankhauser hiddenalpha.ch2024-10-04 16:36:26 +0200
committerAndreas Fankhauser hiddenalpha.ch2024-10-04 16:36:26 +0200
commitb18874cc0cc699d12703655413c1ff0f28bd3040 (patch)
tree2c13895d33a447ece4c1e74fa29ed952ff388560
parent221fd4f2dba8d119dc1fcc9b1f28346813437667 (diff)
downloadUnspecifiedGarbage-b18874cc0cc699d12703655413c1ff0f28bd3040.zip
UnspecifiedGarbage-b18874cc0cc699d12703655413c1ff0f28bd3040.tar.gz
Thinker around with ObserveDeployedVersions.c
-rw-r--r--doc/note/links/links.txt1
-rw-r--r--makeit23
-rw-r--r--src/main/paisa/ObserveDeployedVersions.c297
3 files changed, 298 insertions, 23 deletions
diff --git a/doc/note/links/links.txt b/doc/note/links/links.txt
index 7d6af9a..048f7a0 100644
--- a/doc/note/links/links.txt
+++ b/doc/note/links/links.txt
@@ -352,6 +352,7 @@ Links (Aka argument amplifiers)
- [Some good examples](https://gitit.post.ch/projects/ISA/repos/vending-transaction-api/browse/src/rest/openapi/api.yaml?at=refs%2Ftags%2Fvending-transaction-api-01.00.00.00#79-80,96-98,112-113,130-131,162-164,197-199,230-232,250-252,270-272,287-288)
- [Why is it so hard to write useful descriptions](https://gitit.post.ch/projects/ISA/repos/vending-payment-api/pull-requests/5/overview?commentId=106020)
- [Why all that clutter?](https://gitit.post.ch/projects/ISA/repos/deployment-pipeline-api/pull-requests/22/overview?commentId=278860)
+- [Remove noisy clutter please](https://gitit.post.ch/projects/ISA/repos/maintenance-issue-api/pull-requests/10/overview?commentId=422458)
- [The Golden Rules of Code Documentation](https://blog.jooq.org/the-golden-rules-of-code-documentation/)
## JenkinsfileRelease Api pipeline broken latest version
diff --git a/makeit b/makeit
deleted file mode 100644
index 3e61dce..0000000
--- a/makeit
+++ /dev/null
@@ -1,23 +0,0 @@
-
-set -e
-
-rm -f build/bin/*
-
-tar c src/main/paisa/LogMerge.c | ssh qemu -oRemoteCommand='cd work && tar x'
-
-ssh qemu -oRemoteCommand='cd work \
- && CC=gcc \
- && LD=gcc \
- && BINEXT= \
- && CFLAGS="-Wall -Werror -pedantic -O0 -g -fmax-errors=1 -Iimport/include" \
- && LDFLAGS="-Wl,--gc-sections,--as-needed,-dn,-lgarbage,-lcJSON,-lexpat,-lmbedtls,-lmbedx509,-lmbedcrypto,-dy,-lpthread,-Limport/lib" \
- && PROJECT_VERSION="$(date -u +0.0.0-%%Y%%m%%d.%%H%%M%%S)" \
- && mkdir -p build/bin \
- && echo \
- && ${CC:?} -c -o /tmp/UJ0lnr5UIy1so7Rc src/main/paisa/LogMerge.c ${CFLAGS:?} -DPROJECT_VERSION=${PROJECT_VERSION:?} \
- && echo \
- && ${LD:?} -o build/bin/LogMerge$BINEXT /tmp/UJ0lnr5UIy1so7Rc ${LDFLAGS:?} \
- && true '
-
-ssh qemu -oRemoteCommand='cd work && tar c build/bin' | tar x
-
diff --git a/src/main/paisa/ObserveDeployedVersions.c b/src/main/paisa/ObserveDeployedVersions.c
new file mode 100644
index 0000000..1ca1ad6
--- /dev/null
+++ b/src/main/paisa/ObserveDeployedVersions.c
@@ -0,0 +1,297 @@
+#if 0
+
+ && HOST_=x86_64-w64-mingw32- \
+ && CC=${HOST_}gcc \
+ && LD=${HOST_}gcc \
+ && OBJDUMP=${HOST_}objdump \
+ && BINEXT=.exe \
+ && CFLAGS="-Wall -Werror -Wextra -pedantic -fmax-errors=3 -Iimport/include" \
+ && LDFLAGS="-Wl,--gc-sections,--as-needed,-dn,-lgarbage,-lcJSON,-lexpat,-lmbedtls,-lmbedx509,-lmbedcrypto,-l:libwinpthread.a,-dy,-lws2_32,-Limport/lib" \
+
+ && PROJECT_VERSION="$(date -u +0.0.0-%Y%m%d.%H%M%S)" \
+ && mkdir -p build/bin \
+ && ${CC:?} -c -o /tmp/gH0AAK5pAACIZwAA src/main/paisa/ObserveDeployedVersions.c ${CFLAGS:?} -DPROJECT_VERSION=${PROJECT_VERSION:?} \
+ && ${LD:?} -o build/bin/ObserveDeployedVersions$BINEXT /tmp/gH0AAK5pAACIZwAA ${LDFLAGS:?} \
+
+ && bullshit=$(${OBJDUMP?} -p build/bin/ObserveDeployedVersions$BINEXT|grep DLL\ Name|egrep -v ' (KERNEL32.dll|SHELL32.dll|WS2_32.dll|ADVAPI32.dll|msvcrt.dll)$'||true) \
+ && if test -n "$bullshit"; then printf '\n ERROR: Bullshit has sneaked in:\n\n%s\n\n' "$bullshit"; rm build/bin/ObserveDeployedVersions$BINEXT; false; fi \
+
+#endif
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#if _WIN32
+# include <windows.h>
+#endif
+
+#include <Garbage.h>
+
+
+#define STR_QUOT_(s) #s
+#define STR_QUOT(s) STR_QUOT_(s)
+#define LOGDBG(...) fprintf(stderr, __VA_ARGS__)
+#define LOGERR(...) fprintf(stderr, __VA_ARGS__)
+#define REGISTER /*no-op*/
+
+#define FLG_isHelp (1<<0)
+
+
+typedef struct App App;
+
+
+#define App_mAGIC (int)0x1B400000
+struct App {
+ int mAGIC;
+ int flg;
+ int exitCode;
+ struct GarbageEnv **env;
+ struct Garbage_Mallocator **mallocator;
+ struct Garbage_SocketMgr **tlsSocketMgr;
+ struct Garbage_HttpClientReq **req;
+ int httpRspCode;
+ void *envMem[SIZEOF_struct_GarbageEnv/sizeof(void*)];
+};
+
+
+static inline struct App* assert_is_App( void*p, char const*f, int l ){
+#if !NDEBUG
+ if( p == NULL ){ LOGDBG("assert(app != NULL) %s:%d\n", f, l); assert(0); }
+ App *a = p;
+ if( a->mAGIC != App_mAGIC ){
+ LOGDBG("assert(app.mAGIC != %d) %s:%d\n", a->mAGIC, f, l); assert(0); }
+#endif
+ return p;
+}
+#define assert_is_App(p) assert_is_App(p, __FILE__, __LINE__)
+
+
+static void printHelp( void ){
+ fprintf(stdout, " \n"
+ " %s " STR_QUOT(PROJECT_VERSION) "\n"
+ " \n"
+ " TODO_PhUAALMDAADGWAAA: Write this help page.\n"
+ " \n"
+ " Options:\n"
+ " \n"
+ " --yolo\n"
+ " WARN: Only use this if you know what you're doing!\n"
+ " \n"
+ "", strrchr(__FILE__,'/')+1
+ );
+}
+
+
+static int parseArgs( App*app, char**argv ){
+ register int iA = 0;
+ int isYolo = 0;
+nextArg:;
+ char *arg = argv[++iA];
+ if( arg == NULL ){ goto verify; }
+ if( !strcmp(arg, "--help") ){
+ app->flg |= FLG_isHelp; return 0;
+ }else if( !strcmp(arg, "--yolo") ){
+ isYolo = !0;
+ }else{
+ LOGERR("EINVAL: %s\n", arg); return-1;
+ }
+ goto nextArg;
+verify:
+ if( !isYolo ){ LOGERR("EINVAL: Try --help\n"); return -1; }
+ return 0;
+}
+
+
+static void pushIoTask( void(*task)(void*arg), void*arg, void*app_ ){
+ App*const app = assert_is_App(app_);
+ (*app->env)->enqueBlocking(app->env, task, arg);
+}
+
+
+static void onHttpsError( int retval, void*mentorCls ){
+ (void)retval; (void)mentorCls;
+ assert(!"TODO_UDUAAB1XAAC3AQAA");
+}
+
+
+static void onHttpRspHdr(
+ const char*proto, int proto_len, int rspCode, const char*phrase, int phrase_len,
+ const struct Garbage_HttpMsg_Hdr*hdrs, int hdrs_cnt,
+ struct Garbage_HttpClientReq**req, void*app_
+){
+ (void)req;
+ App*const app = assert_is_App(app_);
+ app->httpRspCode = rspCode;
+ if( rspCode == 200 ){
+ /*no debug output needed*/
+ }else if( rspCode == 401 || rspCode == 404 ){
+ /*short output is enough*/
+ LOGDBG("%.*s %d %.*s\n", proto_len, proto, rspCode, phrase_len, phrase);
+ }else{ /*unexpected, Log more*/
+ LOGDBG("%.*s %d %.*s\n", proto_len, proto, rspCode, phrase_len, phrase);
+ for( int i = 0 ; i < hdrs_cnt ; ++i ){
+ LOGDBG("%.*s: %.*s\n", hdrs[i].key_len, hdrs[i].key, hdrs[i].val_len, hdrs[i].val);
+ }
+ LOGDBG("\n");
+ }
+}
+
+
+static void onHttpRspBody(
+ const char*buf, int buf_len, struct Garbage_HttpClientReq**req, void*app_
+){
+ (void)req;
+ App*const app = assert_is_App(app_);
+ if( app->httpRspCode != 200 && app->httpRspCode != 404 ){
+ LOGDBG("%.*s", buf_len, buf);
+ return;
+ }
+ LOGDBG("TODO_i2gAAKlYAACxbwAA impl %s()\n", __func__);
+}
+
+
+static void onHttpRspDone( struct Garbage_HttpClientReq**req, void*app_ ){
+ (void)req; (void)app_;
+ //App*const app = assert_is_App(app_);
+ //if( app->flg & FLG_printRspBodyAnyway ){
+ // LOGDBG("\n");/*fix broken server which deliver no LF at TEXT body end*/
+ //}
+ //if( app->httpRspCode == 404 ){
+ // cls->onDone("ENOENT", cls->onDoneArg);
+ // return;
+ //}
+ //if( app->httpRspCode != 200 ){
+ // cls->onDone("ERROR", cls->onDoneArg);
+ // return;
+ //}
+ LOGDBG("TODO_tBkAAMhAABgXAAAK: impl %s())\n", __func__);
+}
+
+
+static struct Garbage_HttpClientReq** newHttpsRequest(
+ App*app,
+ char const*restrict host,
+ char const*restrict mthd,
+ char const*restrict path
+){
+ static struct Garbage_HttpClientReq_Mentor reqMentor = {
+ .pushIoTask = pushIoTask,
+ .onError = onHttpsError,
+ .onRspHdr = onHttpRspHdr,
+ .onRspBody = onHttpRspBody,
+ .onRspDone = onHttpRspDone,
+ };
+ return (*app->env)->newHttpClientReq(app->env, &reqMentor, app, &(struct Garbage_HttpClientReq_Opts){
+ .mallocator = app->mallocator,
+ .socketMgr = app->tlsSocketMgr,
+ .mthd = mthd,
+ .host = host,
+ .url = path,
+ .port = 443,
+ .hdrs_cnt = 0,
+ .hdrs = NULL, // struct Garbage_HttpMsg_Hdr *hdrs;
+ });
+}
+
+
+static void fetchServiceStatus(
+ App*app, char const*restrict svcName, char const*restrict stage,
+ void(*onDone)(void*), void*onDoneArg
+){
+ char *stageLc;
+ if(0){}
+ else if( !strcmp(stage, "PROD" ) ){ stageLc = "prod" ; }
+ else if( !strcmp(stage, "PREPROD" ) ){ stageLc = "preprod" ; }
+ else if( !strcmp(stage, "INT" ) ){ stageLc = "int" ; }
+ else if( !strcmp(stage, "TEST" ) ){ stageLc = "test" ; }
+ else if( !strcmp(stage, "SNAPSHOT") ){ stageLc = "snapshot"; }
+ else{ assert(!LOGDBG("EINVAL: %s\n", stage)); /*TODO onDone(error)*/ }
+ int const host_cap = 48;
+ char host[host_cap];
+ int host_end = snprintf(host, host_cap, "isa-houston-%s.isa.aws.pnetcloud.ch", stageLc);
+ assert(host_end < host_cap);
+ int const path_cap = 64;
+ char path[path_cap];
+ int path_end = snprintf(path, path_cap, "/houston/services/%s/info", svcName);
+ assert(path_end < path_cap);
+ assert(app->req == NULL);
+ app->req = newHttpsRequest(app, host, "GET", path);
+ assert(app->req != NULL);
+ (*app->req)->closeSnk(app->req);
+ (void)onDone; (void)onDoneArg; // TODO onDone(onDoneArg);
+}
+
+
+static void onFetchServiceStatusDone( void*app_ ){
+ (void)app_; //App*const app = assert_is_App(app_);
+ LOGDBG("[DEBUG] TODO impl %s()\n", __func__);
+}
+
+
+static void run( void*app_ ){
+ App*const app = assert_is_App(app_);
+ char const *svcName = "preflux";
+ char const *stage = "TEST";
+ fetchServiceStatus(app, svcName, stage, onFetchServiceStatusDone, app);
+}
+
+
+/*TODO make this obsolete by using newer lib version, which has an impl itself*/
+static void my_realloc(
+ struct Garbage_Mallocator**app_,
+ void*oldPtr,
+ size_t oldPtr_sz,
+ size_t newPtr_sz,
+ void(*onDone)(int eno, void*newPtr,void*arg),
+ void*arg
+){
+ (void)app_; (void)oldPtr; (void)oldPtr_sz; (void)newPtr_sz; (void)onDone; (void)arg;
+ assert(!"TODO_JgYAAPkPAAD1AQAA");
+}
+static void* onReallocBlocking(
+ struct Garbage_Mallocator**app_,
+ void*oldPtr,
+ size_t oldPtr_sz,
+ size_t newPtr_sz
+){
+ (void)app_; (void)oldPtr_sz;
+ return realloc(oldPtr, newPtr_sz);
+}
+static struct Garbage_Mallocator** newMallocator( void ){
+ static struct Garbage_Mallocator vt = {
+ .realloc = my_realloc,
+ .reallocBlocking = onReallocBlocking,
+ }, *globalPimpl = &vt;
+ return &globalPimpl;
+}
+
+
+static void initEnv( App*app ){
+ app->env = GarbageEnv_ctor(app->envMem, sizeof app->envMem); assert(app->env != NULL);
+ app->mallocator = newMallocator();
+ app->tlsSocketMgr = NULL; /*TODO need one here*/
+}
+
+
+int main( int argc, char**argv ){
+ (void)argc;
+ assert((void*)0 == NULL);
+ App*const app = &(App){
+ .mAGIC = App_mAGIC,
+ .exitCode = 1,
+ };
+ if( parseArgs(app, argv) ){ goto endFn; }
+ if( app->flg & FLG_isHelp ){ printHelp(); goto endFn; }
+ app->exitCode = 0;
+ initEnv(app);
+#if _WIN32
+ WSAStartup(1, &(WSADATA){0});
+#endif
+ (*app->env)->enqueBlocking(app->env, run, app);
+ (*app->env)->runUntilDone(app->env);
+endFn:
+ return app->exitCode;
+}
+
+
+