Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring
Browse files Browse the repository at this point in the history
kahirokunn committed May 13, 2024
1 parent b275981 commit 8c505ef
Showing 13 changed files with 1,063 additions and 345 deletions.
2 changes: 1 addition & 1 deletion packages/kubekit-prepare/gen-config/sa.yaml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ rules:
- serviceaccounts
verbs:
- get
# for aggregate target service account rules
# for aggregate target subject rules
- apiGroups:
- rbac.authorization.k8s.io
resources:
6 changes: 3 additions & 3 deletions packages/kubekit-prepare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kubekit/prepare",
"version": "0.0.9",
"version": "0.0.11",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "kahirokunn",
@@ -15,8 +15,8 @@
"homepage": "https://github.com/appthrust/kubekit-ts",
"bin": "lib/bin/cli.js",
"scripts": {
"build": "tsc",
"prepare": "tsc && chmod +x ./lib/bin/cli.js",
"build": "rm -rf lib && tsc",
"prepare": "rm -rf lib && tsc && chmod +x ./lib/bin/cli.js",
"gen-openapi": "kubectl apply -f gen-config/sa.yaml && yarn build; chmod +x lib/bin/cli.js; yarn cli ./gen-config/openapi.ts",
"gen-k8s-client": "npx @kubekit/codegen gen-config/k8s-client.ts",
"cli": "lib/bin/cli.js",
20 changes: 12 additions & 8 deletions packages/kubekit-prepare/src/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -3,20 +3,21 @@
import program from 'commander'
import * as path from 'path'
import * as fs from 'fs/promises'
import { patchFunctions } from '../patchOpenApi'
import { enhancementFunctions } from '../utils/openapi/enhance'
import merge from 'lodash.merge'
import { OpenAPIV3 } from 'openapi-types'
import {
type ResourceRules,
inspectRules,
fetchAggregatedPermissions,
mapResourceVerbToKubernetesAction,
} from '../getRules'
import { HttpMethods, assertNotNull } from '../lib'
} from '../utils/k8s/permissionsAggregator.ts'
import { HttpMethods } from '../utils/types'
import { apiClient } from '@kubekit/client'
import { ConfigFile } from '../config'
import { readCoreV1NamespacedServiceAccount } from '../k8s-client'
import { ConfigFile } from '../utils/types'
import { readCoreV1NamespacedServiceAccount } from '../utils/k8s/client'
import { cleanOpenAPISchema } from '../utils/openapi/removeUnusedSchema'
import { prettify } from '../utils/openapi/prettier'
import { assertNotNull } from '../utils/assertNotNull'

let ts = false
try {
@@ -88,7 +89,7 @@ async function generateOpenApi(config: ConfigFile) {
},
rootOpenApiText,
] = await Promise.all([
inspectRules(config.kind, config.name, config.namespace),
fetchAggregatedPermissions(config.kind, config.name, config.namespace),
apiClient<string>({ path: '/openapi/v3' }),
])

@@ -195,6 +196,9 @@ async function generateOpenApi(config: ConfigFile) {
resultDoc.paths[path] = {}
}
const resultPathsObject = resultDoc.paths[path]

// The assertNotNull is used here to satisfy TypeScript's type checking,
// even though resultPathsObject is always assigned above.
assertNotNull(resultPathsObject)
resultPathsObject[httpMethod] =
sourceDoc.paths[path]?.[httpMethod]
@@ -246,7 +250,7 @@ async function generateOpenApi(config: ConfigFile) {

let mergedSwaggerFile = merge({}, ...docs)

for (const patchFunction of patchFunctions) {
for (const patchFunction of enhancementFunctions) {
mergedSwaggerFile = patchFunction(mergedSwaggerFile)
}

2 changes: 1 addition & 1 deletion packages/kubekit-prepare/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { type ConfigFile } from './config'
export { type ConfigFile } from './utils/types'
66 changes: 0 additions & 66 deletions packages/kubekit-prepare/src/patchOpenApi/applyPatch.ts

This file was deleted.

44 changes: 0 additions & 44 deletions packages/kubekit-prepare/src/patchOpenApi/gvk.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/kubekit-prepare/src/patchOpenApi/index.ts

This file was deleted.

Loading

0 comments on commit 8c505ef

Please sign in to comment.