From 1ed6c050117e3814bd04c996a13350dfbf1921c7 Mon Sep 17 00:00:00 2001 From: Marsell Kukuljevic Date: Tue, 27 Apr 2021 00:03:21 +0200 Subject: [PATCH] Add support for /rates/packages.json and /rates/images.json. These files are served up from the rates/ directory, although in production the current in-repo files are substituted with JSON pulled in from the VM's internal_metadata configuration. --- README.md | 22 +++- bin/server.js | 7 ++ rates/images.json | 6 ++ rates/packages.json | 248 ++++++++++++++++++++++++++++++++++++++++++++ smf/run.sh | 6 ++ 5 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 rates/images.json create mode 100644 rates/packages.json diff --git a/README.md b/README.md index be1aa5c..732795e 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,13 @@ Be familiar with the steps in [Installation][] below, since it is needed to build the Angular app first. Once the Angular app is built, provision a small base-64-lts 20.4.0 VM, -connected solely to the external network (aka public Internet). From within -the VM, the following steps are needed: +connected solely to the external network (aka public Internet). It should +(although does not require) two JSON hash tables in the VM's internal\_metadata: +sc:image\_subscription\_rates and sc:package\_rates; both map UUID strings to +floats, with the image float representing a monthly subscription rate, and the +package float representing the rate per hour. + +Once the VM is running, the following steps are needed from within the VM: pkgin in gmake mkdir -p /opt/spearhead/portal @@ -97,6 +102,19 @@ All calls will be passed through to cloudapi. For these calls to succeed, they MUST provide an X-Auth-Token header, containing the token returned from SSO. +## GET /rates/packages.json + +Returns a JSON file mapping package UUIDs (a string) to the hourly rate +(a float) that a customer will be charged for running a VM using that package. +This is charged fractionally down to a minute granularity. + +## GET /rates/images.json + +Returns a JSON file mapping image UUIDs (a string) to the monthly rate +(a float) that a customer will be charged for running a VM using that image. +This is a flat monthly charge, regardless how long the VM exists for (even if +only a few minutes). + # Interaction cycle client --- GET /api/login --------> this server diff --git a/bin/server.js b/bin/server.js index 6ddc839..510760e 100755 --- a/bin/server.js +++ b/bin/server.js @@ -20,6 +20,8 @@ const LOGIN_PATH = '/api/login'; const API_PATH = '/api'; // all calls here go to cloudapi const API_RE = new RegExp('^' + API_PATH + '/'); const STATIC_RE = new RegExp('^/'); +const RATES_RE = new RegExp('^/(packages|images)\.json$'); + // Take any HTTP request that has a token, sign that request with an // HTTP-Signature header, and pass it along to cloudapi. Return any response @@ -190,6 +192,11 @@ function main() { server.post(API_RE, proxy); server.head(API_RE, proxy); + // where to serve the package and image rates data from + server.get(RATES_RE, mod_restify.plugins.serveStatic({ + directory: 'rates' + })); + // where to serve static content from let staticHandler = mod_restify.plugins.serveStatic({ directory: 'static', diff --git a/rates/images.json b/rates/images.json new file mode 100644 index 0000000..11e6d49 --- /dev/null +++ b/rates/images.json @@ -0,0 +1,6 @@ +{ + "9d73e502-9fa6-11e3-7da8-bb6a8876bb21": 70, + "8d73e502-9fa6-11e3-7da8-bb6a8876bb21": 70, + "6d73e502-9fa6-11e3-7da8-bb6a8876bb21": 70, + "3d73e502-9fa6-11e3-8fa8-bb6a8876bb21": 70 +} diff --git a/rates/packages.json b/rates/packages.json new file mode 100644 index 0000000..5c917d5 --- /dev/null +++ b/rates/packages.json @@ -0,0 +1,248 @@ +{ + "22218452-a2d5-ea3c-d7db-8ac394f396b7": 0.066, + "f10e7447-c35f-4e0f-9e0b-f7d22366341e": 0.027, + "8b4fdd0b-6448-692e-8b47-924d9b6fa298": 0.089, + "47fe0a45-c839-eecf-df1a-ffbb835ceb79": 0.034, + "468c03e2-334c-cd99-a8cd-c24e220f18c8": 0.296, + "0b95abef-a7b4-4875-db2b-d7711f4ea31f": 0.186, + "372b15e7-2a4f-4e1a-b46d-97f795623ec7": 0.178, + "127a3a30-d7a3-c31b-cac3-b76c79afca71": 0.186, + "372271df-c3b6-e9a1-9308-e2e91ea7a83b": 0.027, + "a6df1682-d50b-c357-9c11-de94d5893c44": 0.044, + "5af898f4-34c9-c9bc-c232-aef873f37c07": 0.089, + "bd32d8e3-e5b7-6e8e-91f1-8eadc2e3fbd9": 0.355, + "182a5990-a524-cd82-eb2e-90aa1b092abc": 0.044, + "948d12c0-3270-c097-9d0c-8efb9f9353eb": 0.034, + "db0093fc-916f-682b-c1c1-b69275ed45bf": 0.298, + "7cca3866-dad8-615e-b349-b28c632b625a": 0.298, + "c3c0de9d-91a6-46d0-f750-b3da8437bd74": 0.235, + "88e0f747-29fc-6787-9c11-ac0914bd7527": 0.178, + "600737b8-081a-ceed-8ff9-ffae9feba617": 0.044, + "cedb1804-54df-4bb2-e069-cdd4cc684704": 0.044, + "8d88e28a-ef4f-ef3a-a006-917c252e3c70": 0.178, + "70bc395a-3d8b-4833-81d1-af4be39af974": 0.089, + "52068036-7178-4645-b988-be84f5195332": 0.355, + "26a95af3-dd19-6df2-d22c-a14c8d485cd8": 0.004, + "8ed7a214-dfa9-6462-923a-ff67279cfa66": 0.002, + "5dd22dfb-e595-4f36-bada-f690b8166376": 0.006, + "0580e086-d4a6-442c-c7a7-d674f2245301": 0.008, + "8e93c22f-d513-6fd8-d440-ffcaf0cd4589": 0.012, + "6de53561-6e14-6a8a-bc94-a1566b5725a9": 0.014, + "3e64d126-0a6e-c4e4-9d84-81243ea43493": 0.016, + "c47d5124-63cd-6ceb-dbba-b6f42464b147": 0.041, + "c37a77ba-f0cd-42fa-feb6-9e8dff956d87": 0.062, + "4faddb31-1c71-ef29-bcd8-b7910ea3e6fe": 0.021, + "ed4d095d-f18c-443a-c847-ad64c4af44fa": 0.018, + "393e32ae-79f7-6b97-c43c-e5e7614cacf4": 0.082, + "1b2cc5f5-5ce4-62c8-f552-f3b8dec2caea": 0.010, + "fb25ac7c-78ee-6cd1-ede4-dd7e1c703a89": 0.103, + "bf25f174-41d3-eae5-b158-980dcdd99051": 0.123, + "0737f0ad-4303-ed1d-d400-88cc21698cd8": 0.164, + "683e437e-1f9c-c713-caed-fd2a89e15ac5": 0.185, + "4406105d-ff34-438e-f097-d8f3c1a3fc49": 0.144, + "963b791d-b101-4021-bf51-fed400088ab3": 0.205, + "9031e7d1-2965-65e2-9c57-801930bdf67f": 0.030, + "123407e6-c995-6ece-b2cf-b391e653385c": 0.060, + "8238843b-5daf-c98f-8c65-c09f064370d9": 0.040, + "edd4d2b9-ee55-ebbb-aff4-ef0a61917bed": 0.080, + "22b44234-b13b-47a7-f7fa-dcb68cccc3e5": 0.160, + "03ce4af4-4d24-c4b6-f31e-ad2e9fede8f6": 0.268, + "0fcc3289-8cdf-ce8c-83ec-ab275fec9183": 0.276, + "a188646b-530d-cd90-cd22-cf2f42a93351": 0.276, + "a93f6fd2-ca7b-e15c-96e8-cc1c3b61fce8": 0.283, + "c88e3006-6f04-66d6-a742-ad6b43e1ccd2": 0.283, + "3e64bdda-ef4e-4c9a-c481-e15c0d40c9b9": 0.030, + "53213fe1-3d60-6ed6-9904-ed8c32aab4e6": 0.040, + "d9a46a90-9816-6a74-abed-f67a198f646e": 0.080, + "fe4bcadd-eb50-e1c9-e712-fb0cd724aefe": 0.160, + "34e48ec3-3872-c4e6-c17c-eb626145833e": 0.268, + "14b4c0d9-32ab-e23c-a03a-b7420829c66c": 0.276, + "232ef917-2e0a-68d0-9238-b825e08e640f": 0.060, + "b03c27ca-bf76-e6e1-8404-e486b0aee197": 0.117, + "2950e56a-33af-ca43-b19a-ea165f64632e": 0.241, + "cca75627-5669-4fd6-8849-df2bf3fe3891": 0.121, + "ff3348da-dc29-40c8-a5b5-c3f73198e27e": 0.024, + "28804ada-03e5-ef21-94a2-bf1af50ed71f": 0.093, + "9c20bda4-aeb2-ed87-e90f-e965ea6bb06a": 0.320, + "64ceedda-b153-e18b-bcd6-8c604fd7aa8e": 0.076, + "85b4bd34-19fa-6d7b-f957-bc041f74f465": 1.682, + "f8130ce9-6f0a-cdb6-9d15-d6975a0db5d2": 0.118, + "380a57a4-7b12-cf8f-b376-eef360d3d544": 0.235, + "3f9f4d22-e762-cb15-db7b-b9a354ae4ccd": 0.026, + "402b7496-63f3-e60a-d852-96e3f1abc976": 0.053, + "d577dcb8-f7a5-672c-ae2a-b83141659f83": 0.106, + "b7a97f19-4b0a-4704-fcf0-a3796a2c04fe": 0.211, + "b31fc9e7-59ae-46ec-bd37-9038abffe940": 0.422, + "5d04037d-313d-cc39-e780-baafeb352376": 0.855, + "c387fb70-f95a-4026-f470-ef8a6ec170c9": 0.080, + "0702404f-94e7-666e-cc33-ec0d602d13ea": 0.150, + "b76821ed-d842-6965-a960-b576cb239153": 0.300, + "082aa0f1-5cae-6789-98e2-cacacbf0c13d": 0.370, + "28001852-d8c0-4697-b36c-fe3d41b092b4": 0.422, + "50cdae86-3136-ead9-b3e1-fe9b369fa43c": 0.034, + "7f69ed8b-2c9e-6757-bae1-9732710fc965": 0.159, + "69e46054-1961-487a-9e6f-a37ebdfe2048": 0.283, + "06959c2d-2390-ce94-9a6b-fc38537e632e": 0.024, + "aa7976f9-ee28-e16e-8a91-f0bd601dd0d1": 0.076, + "03b52642-7572-cbb4-89b1-80bd1b93e2e4": 0.060, + "ad22bdf1-a3c4-c6b8-b5b9-e2dc5d67b1cd": 0.060, + "dd153024-c7fe-44b0-929c-ea3e3e16e1ae": 0.117, + "063843ba-dc3b-6a09-8630-cf34c11245e2": 0.040, + "d4341f46-c9e6-e4cc-e9f3-b9fb3f9c8adb": 0.380, + "e90e0436-f01b-c3a2-bad3-92e37659c34b": 0.370, + "74ca19ac-741e-cd9f-fba7-dd87f8ad7caa": 0.370, + "71eb8b96-1792-c639-94e7-924f76014bf6": 0.053, + "7e1ac676-b3df-c80e-cf10-d7550caccd07": 0.106, + "e516512d-1539-6dc5-e1b5-9d6acb812279": 0.211, + "7f588535-1e16-e77a-dde0-b133031f96c1": 0.855, + "430ae3ee-a8c6-e92d-feb7-aebe6d86d897": 0.080, + "19e12410-1f04-e822-e828-999d7a7a4140": 0.150, + "8847f7dc-a195-66a2-a316-c273e9622f04": 0.300, + "1951fdbe-b753-e80f-89b1-aca3bffdc20d": 0.380, + "6e47f0c5-8d86-6ae1-b9e9-85d9d60177f8": 0.283, + "034ede05-5bc4-cc9d-cebe-9e013e9b8fa2": 0.159, + "eb662801-1f41-6b49-96d0-f19baf370978": 0.040, + "e22534bb-bbee-e834-a158-c46a4debe1cb": 0.080, + "80930ddd-cb9d-6cf6-d4fd-ddb6c9b3dd99": 0.160, + "1d08bf5d-c5a3-cf4f-ab6b-a1c224415cf5": 0.268, + "a9fb2452-5674-efee-be80-b07f1e1fa713": 0.276, + "d75a45f1-5063-4b6b-d4b1-d02c3fb342e7": 0.121, + "7e6f2e3e-f644-47a3-b751-fd94f3f1acec": 0.211, + "9047dfd5-0c2e-6b2e-8e37-d41d1687b7a5": 0.320, + "39207fcc-338c-e0e5-ad8e-f528ce4fc684": 0.093, + "cca6a0a8-5685-cd79-de28-ac7bda8427bc": 0.283, + "87828074-22c5-6e4e-a2de-9783bf424eb2": 0.118, + "a22daa6c-6973-ecba-c354-eb618808f8f6": 0.241, + "42b27154-3478-ce5d-8425-f026fb6b52f7": 1.682, + "8f799461-8139-cc23-9b26-9b049d2c62f8": 0.106, + "8b9cf667-aac9-69a0-c3ea-fcb7a4824a0d": 0.106, + "fb92e427-a4b9-4cae-dfa7-dc71bcd41863": 0.076, + "85293756-d2b1-6c50-d79c-ea0d9bcfc7e5": 0.079, + "287c3d76-deec-4aed-9407-c0bb73e6ba4a": 0.134, + "c62c0364-b47c-c723-b48a-a98299d3133d": 0.268, + "52e42908-74e9-e702-a1ef-a54e92587f92": 0.390, + "a585f939-ea86-6a4d-a28e-b083f08a8cea": 0.280, + "67764556-cc01-c47d-c994-99e1fd03b768": 0.241, + "c76cd2f7-6034-e117-f796-d54364002ecf": 0.022, + "d2170614-2c80-cdc8-853f-e92bbd09e568": 0.022, + "0b5f4762-9666-eeba-d3d7-95eecc815db7": 0.022, + "e131e417-f7e3-48bf-91b4-ea12d5df6b94": 0.038, + "9a6c17ba-02f4-c187-b16a-9e9c8cfbf575": 0.030, + "d60377d2-3e4f-ecf0-c013-b9231e814df4": 0.049, + "059da774-2e9f-eeb7-eaea-a25275e534f4": 0.380, + "0c592d4a-5bd6-e2d3-c58c-885ee024c88f": 0.607, + "8cf5eca4-a00e-e826-b803-a38398bb0a81": 0.607, + "2c0eb6a0-896b-c60c-ce38-cbae9aa3705f": 0.243, + "05859b98-ecfe-cd38-a06e-ac5bf224031f": 0.133, + "e8079c97-09ce-ea1c-8d58-ea864d22d836": 0.017, + "b80a7cd8-4699-ed26-dbe6-c9c804f03d9c": 0.268, + "7fb90259-f044-c432-bf27-f5008963e37e": 0.117, + "f5bee04c-208c-66e5-927c-86ebed05fe4e": 0.117, + "f3cfc57b-5aa8-ebdc-c4ff-ea1ea9ccbab4": 0.106, + "3bead424-e188-60e8-d435-82ebec698c4d": 0.053, + "125117ae-5d01-ca19-a9db-bd55fcae6149": 0.268, + "a1b71c42-f9ca-6874-d6eb-b10053bf17c1": 0.106, + "e97fd9a8-afe3-4b95-e7c1-b6fc186b615c": 0.080, + "5e62be81-ae92-efc4-c42a-c6954a23de78": 0.117, + "aaabc1cb-9857-4f7a-8893-ff179dde23c6": 0.243, + "f4979b69-4fd0-6e1a-db4c-ff4de8170071": 0.076, + "66b73715-85ed-cb64-b5a1-bab78eb20e15": 0.160, + "b744d6d8-82f4-6a6c-bc10-a8fc2034ef0d": 0.205, + "d7544477-53b3-e8eb-e70f-eb3142bc4e19": 0.034, + "af1bce69-09ed-6ba4-c3a6-d2f14a3ad493": 0.026, + "5597cead-e17a-e675-9a4b-e412610cad07": 0.205, + "99fc25e2-605c-c1a7-f490-a445aef18795": 0.060, + "113ebd76-81b3-ed7d-f35f-f713bdb72249": 0.241, + "78283ad0-7c5e-6a76-d46b-b5dad5d06338": 0.211, + "1e95adcb-e160-c773-e375-b57933d0aae0": 0.040, + "a40afe3b-67be-64fa-df7e-aadda730e283": 0.855, + "6c01f552-6cd4-687d-b7f4-81ae67cbde18": 0.133, + "406815fc-dd97-48da-904d-c7bd311aba76": 0.283, + "d799e656-b36d-ef42-f1ee-cfef82af082f": 0.283, + "8688a1b3-9242-c57c-a845-aa3d4119bb5b": 0.320, + "5a134b97-60d7-ea74-8913-c52f4c94e4b5": 0.012, + "62e20132-3f0d-eb82-ecbd-cf90c04093ce": 0.013, + "8b15210a-da5f-4964-b851-d618cff5c573": 0.027, + "63c21b52-935a-4e05-f646-9d373cc3a133": 0.028, + "20f10e49-027a-c0bb-932a-f1eec8ca113f": 0.042, + "34301e2d-bcf5-4dad-b796-c2d3a3cdbe47": 0.043, + "12f9fee9-5784-c680-da49-b4ada33f1d9b": 0.017, + "70f9800c-a6a3-c9c5-c849-8ebf193ddeea": 0.018, + "5e9d3545-69c0-ca03-f18b-c99c45c9791f": 0.029, + "17888b77-0366-6ae5-8639-a5eec5fef1b9": 0.030, + "a7c106f6-547d-cc81-95a1-b42c61c5816d": 0.044, + "421b3879-dd3c-6898-fa54-a720ff473999": 0.045, + "4a2b3050-ac7f-4b4a-b31c-c64e7cf2dcfc": 0.034, + "4840c833-6512-4fb7-fcf3-d72dbf29dbe2": 0.036, + "a7bca2ec-1117-6655-8dc7-8f41f3d50b64": 0.039, + "539774b0-a675-48f2-fd0d-8315e0542693": 0.040, + "7bdee0ba-8645-cbfc-9445-b95921ebcd62": 0.054, + "c0ef4b70-5de1-c3b3-ef3a-f54d831c3784": 0.055, + "ef90a622-ca4b-ef21-8ba7-e8121b3ee67a": 0.085, + "0a045323-e248-6e15-8d1e-f7444dae67e9": 0.086, + "bf2a90a7-8c9d-6c6d-e64c-c2544cbe04a7": 0.059, + "6366217f-de24-6582-b579-87bfa760ce82": 0.061, + "ed2a66de-e6f2-c271-cd3e-efdbca767414": 0.089, + "5102fab9-de80-67ea-ef04-c705196db078": 0.091, + "094a37cd-30a4-6d7f-cc50-e4fc847c8f73": 0.149, + "21dbb603-b3cf-4b45-9daf-9540266c28d9": 0.151, + "de83c846-d1ff-c3db-8b00-b4f9ebb80f65": 0.270, + "c28d671a-d97e-eefc-90c3-da266d2feb03": 0.272, + "9d7ef1b3-827f-4450-ed67-c33eb23c475f": 0.067, + "7e248a9a-1733-e896-e807-c477cd7c238c": 0.071, + "8ab362c8-845a-cca8-cc92-cfa4ab63edfa": 0.097, + "d61d0546-34a3-c830-d417-9d6585e0330e": 0.101, + "c67ffac8-a5b9-cc1b-d7b3-8af7972c877d": 0.157, + "34c08664-8df3-68ea-af28-941c23b90f18": 0.162, + "e5946d15-cf2b-4c6d-f873-c99429791c62": 0.084, + "771a1b42-ee5a-c1c8-cf05-ec1585008c1e": 0.092, + "bbef2ee6-d72a-cc18-b20e-ec8b67bbb313": 0.114, + "0916e773-ee6e-4e19-eef9-80f481758a32": 0.122, + "0ba70a68-2c1f-657d-e7f4-a2930a996dfe": 0.174, + "cc8a39a7-3c24-4da7-e899-b3214081ce97": 0.183, + "172e9c01-80e6-ecae-de2a-e7228cbfa144": 0.295, + "95449608-bf37-cbcc-e2eb-d60f2ac1db35": 0.303, + "166bebac-fd73-e468-fe2d-e8b699375053": 0.042, + "cf102146-317d-e11b-e16c-f9187cc3b00b": 0.053, + "ae407ea8-8461-41e3-a472-f75d2d522416": 0.117, + "eccca454-7282-e301-a195-8254ecde71ad": 0.121, + "10678275-7ed1-66d1-b3a9-eaf6683e90b9": 0.178, + "0835d49c-1457-614e-d313-bf1453dc3cff": 0.182, + "653d6003-d480-e1b7-a5a3-ccd543831f39": 0.298, + "47e9a13d-b26f-ea6b-d612-c9f027387076": 0.302, + "2e4fda7b-f26f-c154-8269-de574d471aba": 0.419, + "30c668ce-60b3-e16c-c5aa-8639aebaf204": 0.423, + "a52bf2a8-30a5-438c-b12c-86c409f57d8e": 0.134, + "95c502a0-f3a6-690a-d879-e818fb5459c3": 0.142, + "1a7bde87-21c2-e8d2-c377-909561a5c012": 0.194, + "44070f9d-a679-e7a1-a6cc-829b28353331": 0.203, + "6045d5d1-b32d-6f99-bfbd-aa9b9b10f75f": 0.315, + "e8f0e856-34d1-efca-b4d5-fd77122e779c": 0.323, + "23944cb0-9ad9-60aa-f030-b83fee428a0f": 0.436, + "e176dbf4-2b1b-e2cf-cd67-faf4294f0c3d": 0.444, + "ce0d9d18-4ed9-e6fb-8a0e-ddd9c809a69d": 0.469, + "39595bee-160e-6138-b7f3-9b115f68b843": 0.486, + "96b20a93-a579-e27b-fbdb-e37f83e7334e": 0.094, + "782b2dcc-0d37-cb1f-e84b-ee07558e9af1": 0.188, + "f724f364-6e29-4333-d486-9b262317c0a4": 0.192, + "299def39-e8cd-67b5-bedd-896e10e6dede": 0.235, + "53d7d9d5-b32e-614f-dcf7-9ab961195d48": 0.243, + "a36a2eb4-00a2-6a53-8077-83e69d4275f7": 0.355, + "f4a527f7-04a0-61af-e076-b118055acaaf": 0.363, + "6bf8b9dd-538c-ce57-8acc-9dda062bab3c": 0.476, + "d0457e57-85f6-656e-f06f-cb642d149934": 0.484, + "910f7fe4-c6f4-c880-fca5-d8c9a879a33f": 0.268, + "8a83258f-fbe1-caf7-c66f-f3ee258cb8a0": 0.285, + "2c0aeb79-14e4-c554-ff83-9becfbd22549": 0.389, + "ba3ffdf0-c362-60f0-96b1-c16a7be36c51": 0.405, + "23ed3a18-5664-4349-f927-c9d67fd3c4a5": 0.509, + "e06b4d1b-14d3-4d44-fca8-d61449a8830d": 0.526, + "ae681b38-58c1-6047-e038-9aefa021f7de": 0.288, + "9f2ec40f-2ae6-441f-b1a3-9f3ae518b912": 0.305, + "de01c282-b7e2-45a3-c789-87102bf13cde": 0.469, + "69f98564-9094-4582-ba4d-ae90ce769325": 0.486, + "f35153c9-d979-6a17-f66e-82c3532f76ef": 0.576, + "4a3c6572-84ba-4149-d619-e02002a082ae": 0.610, + "93602faa-c78c-e104-fb0b-f7e802f4bd97": 0.992, + "1efc247e-0213-e7de-97de-daa5767dd3cf": 1.059 +} diff --git a/smf/run.sh b/smf/run.sh index 9a02084..b7736d8 100755 --- a/smf/run.sh +++ b/smf/run.sh @@ -1,4 +1,10 @@ #!/bin/sh cd /opt/spearhead/portal + +# first extract the package and image rates from VM metadata +/usr/sbin/mdata-get sc:image_subscription_rates > rates/images.json +/usr/sbin/mdata-get sc:package_rates > rates/packages.json + +# start up our server /opt/local/bin/node bin/server.js cfg/prod.json &