Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kahirokunn committed May 13, 2024
1 parent b275981 commit a536808
Show file tree
Hide file tree
Showing 12 changed files with 836 additions and 343 deletions.
2 changes: 1 addition & 1 deletion packages/kubekit-prepare/gen-config/sa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion 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.10",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "kahirokunn",
Expand Down
20 changes: 12 additions & 8 deletions packages/kubekit-prepare/src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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' }),
])

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}

Expand Down
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.

195 changes: 0 additions & 195 deletions packages/kubekit-prepare/src/patchOpenApi/op.ts

This file was deleted.

Loading

0 comments on commit a536808

Please sign in to comment.