[READ-ONLY] Mirror of https://github.com/FoxxMD/komodo-import. Import existing compose stacks into Komodo foxxmd.github.io/komodo-import
compose docker import komodo toml
0

Configure Feed

Select the types of activity you want to include in your feed.

refactor: Remove komodo api checks from output code

FoxxMD (Aug 13, 2025, 6:14 PM UTC) a1ed04c5 9fff6378

+15 -28
+5 -3
src/common/KomodoApi.ts
··· 5 5 import { ListGitProviderAccountsResponse, ListReposResponse } from "komodo_client/dist/types.js"; 6 6 import { initLogger } from "./logging.js"; 7 7 import { SimpleError } from "./errors.js"; 8 + import { URLData } from "./infrastructure/atomic.js"; 8 9 9 10 export interface KomodoApiOptions { 10 11 url?: string ··· 16 17 options: KomodoApiOptions; 17 18 api: ReturnType<typeof KomodoClient> 18 19 logger: Logger; 20 + urlData: URLData; 19 21 20 22 cachedRepos?: ListReposResponse; 21 23 cachedGitProviders?: ListGitProviderAccountsResponse; ··· 23 25 constructor(logger?: Logger, options?: KomodoApiOptions) { 24 26 this.logger = childLogger(logger ?? initLogger()[0], 'Komodo API'); 25 27 this.options = options; 28 + this.urlData = normalizeWebAddress(process.env.KOMODO_URL); 26 29 } 27 30 28 31 init = () => { ··· 36 39 if (isUndefinedOrEmptyString(process.env.KOMODO_URL)) { 37 40 throw new SimpleError(`Cannot use Komodo API because env KOMODO_URL is missing`); 38 41 } 39 - const urlData = normalizeWebAddress(process.env.KOMODO_URL); 40 - this.logger.verbose(`KOMODO_URL: ${process.env.KOMODO_URL} | Normalized: ${urlData.url.toString()}`); 42 + this.logger.verbose(`KOMODO_URL: ${process.env.KOMODO_URL} | Normalized: ${this.urlData.url.toString()}`); 41 43 42 - this.api = KomodoClient(urlData.url.toString(), { 44 + this.api = KomodoClient(this.urlData.url.toString(), { 43 45 type: "api-key", 44 46 params: { 45 47 key: process.env.API_KEY,
+10 -25
src/exporters/exportToApiSync.ts
··· 1 1 import { childLogger, Logger } from "@foxxmd/logging"; 2 - import { KomodoClient, Types } from "komodo_client"; 2 + import { Types } from "komodo_client"; 3 3 import { isDebugMode, isUndefinedOrEmptyString, parseBool } from "../common/utils/utils.js"; 4 4 import path from 'path'; 5 5 import { stripIndents } from "common-tags"; 6 6 import dayjs from "dayjs"; 7 - import { normalizeWebAddress } from "../common/utils/network.js"; 7 + import { getDefaultKomodoApi } from "../common/utils/komodo.js"; 8 8 9 9 export const exportToSync = async (toml: string, parentLogger: Logger): Promise<void> => { 10 10 const logger = childLogger(parentLogger, 'Sync API'); 11 11 12 12 if (parseBool(process.env.OUTPUT_API_SYNC)) { 13 13 try { 14 - if (isUndefinedOrEmptyString(process.env.API_KEY)) { 15 - logger.error(`Cannot export to Resource Sync because env API_KEY is missing`); 16 - return; 17 - } 18 - if (isUndefinedOrEmptyString(process.env.API_SECRET)) { 19 - logger.error(`Cannot export to Resource Sync because env API_SECRET is missing`); 20 - return; 14 + const komodo = getDefaultKomodoApi(); 15 + if(komodo === undefined) { 16 + throw new Error('Komodo API is unavaiable, cannot export to Sync'); 21 17 } 22 18 const syncName = isUndefinedOrEmptyString(process.env.SYNC_NAME) ? 'komodo-import' : process.env.SYNC_NAME; 23 19 logger.info(`Using '${syncName}' as Sync Name`); 24 20 25 - const urlData = normalizeWebAddress(process.env.KOMODO_URL); 26 - logger.verbose(`KOMODO_URL: ${process.env.KOMODO_URL} | Normalized: ${urlData.url.toString()}`) 27 - 28 - const komodo = KomodoClient(urlData.url.toString(), { 29 - type: "api-key", 30 - params: { 31 - key: process.env.API_KEY, 32 - secret: process.env.API_SECRET 33 - }, 34 - }); 35 - 36 21 let syncId: string; 37 22 let existingBehaviorVal = process.env.EXISTING_SYNC ?? 'append'; 38 23 let existingBehavior: ExistingSyncBehavior; 39 24 let existingSync: Types.ResourceSync; 40 25 41 26 try { 42 - existingSync = await komodo.read('GetResourceSync', { 27 + existingSync = await komodo.api.read('GetResourceSync', { 43 28 sync: syncName 44 29 }); 45 30 syncId = existingSync._id.$oid; ··· 61 46 62 47 63 48 if (syncId === undefined) { 64 - const sync = await komodo.write('CreateResourceSync', { 49 + const sync = await komodo.api.write('CreateResourceSync', { 65 50 name: syncName, 66 51 config: { 67 52 include_resources: true, ··· 72 57 logger.info('Resource Sync created.'); 73 58 } else { 74 59 if (existingBehavior === 'overwrite') { 75 - const sync = await komodo.write('UpdateResourceSync', { 60 + const sync = await komodo.api.write('UpdateResourceSync', { 76 61 id: syncId, 77 62 config: { 78 63 include_resources: true, ··· 82 67 logger.info('Resource Sync overwrriten.'); 83 68 } else { 84 69 const time = dayjs().format('YYYY-MM-DD--HH-mm-ss'); 85 - const sync = await komodo.write('UpdateResourceSync', { 70 + const sync = await komodo.api.write('UpdateResourceSync', { 86 71 id: syncId, 87 72 config: { 88 73 include_resources: true, ··· 99 84 } 100 85 } 101 86 102 - const syncUrl = path.join(urlData.url.toString(), 'resource-syncs', syncId); 87 + const syncUrl = path.join(komodo.urlData.url.toString(), 'resource-syncs', syncId); 103 88 104 89 logger.info(`Resource Sync URL: ${syncUrl}`); 105 90 }