Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/api/helmChartContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Debug from 'debug'
import { Operation, OperationHandlerArray } from 'express-openapi'
import { OpenApiRequestExt } from 'src/otomi-models'

const debug = Debug('otomi:api:helmChartContent')

export default function (): OperationHandlerArray {
const get: Operation = [
async ({ otomi, query }: OpenApiRequestExt, res): Promise<string[]> => {
debug(`gethelmChartContent ${query?.url}`)
const v = await otomi.getHelmChartContent(query?.url as string)
res.json(v)
return v
},
]
const api = {
get,
}
return api
}
22 changes: 22 additions & 0 deletions src/openapi/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,28 @@ paths:
application/json:
schema:
type: object
'/helmChartContent':
get:
operationId: getHelmChartContent
parameters:
- name: url
in: query
description: URL of the helm chart
schema:
type: string
responses:
<<: *DefaultGetResponses
'200':
description: Successfully obtained helm chart content
content:
application/json:
schema:
type: object
properties:
values:
type: object
error:
type: string
'/createWorkloadCatalog':
post:
operationId: createWorkloadCatalog
Expand Down
26 changes: 14 additions & 12 deletions src/otomi-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import { getPolicies } from './utils/policiesUtils'
import { EncryptedDataRecord, encryptSecretItem, sealedSecretManifest } from './utils/sealedSecretUtils'
import { getKeycloakUsers, isValidUsername } from './utils/userUtils'
import { ObjectStorageClient } from './utils/wizardUtils'
import { fetchWorkloadCatalog, NewChartPayload, sparseCloneChart } from './utils/workloadUtils'
import { fetchChartYaml, fetchWorkloadCatalog, NewHelmChartValues, sparseCloneChart } from './utils/workloadUtils'

interface ExcludedApp extends App {
managed: boolean
Expand Down Expand Up @@ -1236,34 +1236,36 @@ export default class OtomiStack {
}
}

async createWorkloadCatalog(body: NewChartPayload): Promise<boolean> {
const { url, chartName, chartPath, chartIcon, revision, allowTeams } = body
async getHelmChartContent(url: string): Promise<any> {
return await fetchChartYaml(url)
}

async createWorkloadCatalog(body: NewHelmChartValues): Promise<boolean> {
const { gitRepositoryUrl, chartTargetDirName, chartIcon, allowTeams } = body

const uuid = uuidv4()
const helmChartsDir = `/tmp/otomi/charts/${uuid}`
const localHelmChartsDir = `/tmp/otomi/charts/${uuid}`
const helmChartCatalogUrl = env.HELM_CHART_CATALOG
const { user, email } = this.repo

try {
await sparseCloneChart(
url,
gitRepositoryUrl,
localHelmChartsDir,
helmChartCatalogUrl,
user,
email,
chartName,
chartPath,
helmChartsDir,
revision,
chartTargetDirName,
chartIcon,
allowTeams,
)
return true
} catch (err) {
debug(`error while parsing chart ${err.message}`)
} catch (error) {
debug('Error adding new Helm chart to catalog')
return false
} finally {
// Clean up: if the temporary directory exists, remove it.
if (existsSync(helmChartsDir)) rmSync(helmChartsDir, { recursive: true, force: true })
if (existsSync(localHelmChartsDir)) rmSync(localHelmChartsDir, { recursive: true, force: true })
}
}

Expand Down
Loading