-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): implement function creation (#427)
Signed-off-by: maslow <wangfugen@126.com>
- Loading branch information
Showing
8 changed files
with
215 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
export class CreateFunctionDto {} | ||
import { ApiProperty } from '@nestjs/swagger' | ||
|
||
export class CreateFunctionDto { | ||
@ApiProperty({ | ||
description: 'Function name is unique in the application', | ||
}) | ||
name: string | ||
|
||
@ApiProperty() | ||
description: string | ||
|
||
@ApiProperty() | ||
websocket: boolean | ||
|
||
@ApiProperty({ | ||
enum: ['HEAD', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH'], | ||
}) | ||
methods: string[] = [] | ||
|
||
@ApiProperty({ | ||
description: 'The source code of the function', | ||
}) | ||
codes: string | ||
|
||
validate() { | ||
if (!this.name) { | ||
return 'name is required' | ||
} | ||
|
||
const valid = this.methods.every((method) => { | ||
return ['HEAD', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH'].includes(method) | ||
}) | ||
if (!valid) { | ||
return 'methods is invalid' | ||
} | ||
|
||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,95 @@ | ||
export class Function {} | ||
import { KubernetesListObject, KubernetesObject } from '@kubernetes/client-node' | ||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' | ||
import { ObjectMeta } from 'src/core/kubernetes.interface' | ||
|
||
export class CloudFunctionSource { | ||
@ApiProperty() | ||
codes: string | ||
|
||
@ApiProperty() | ||
uri?: string | ||
|
||
@ApiProperty() | ||
version: number | ||
|
||
constructor() { | ||
this.version = 0 | ||
} | ||
} | ||
|
||
export class CloudFunctionSpec { | ||
@ApiProperty() | ||
description: string | ||
|
||
@ApiProperty() | ||
websocket: boolean | ||
|
||
@ApiProperty() | ||
methods: string[] | ||
|
||
@ApiProperty() | ||
source: CloudFunctionSource | ||
|
||
constructor() { | ||
this.source = new CloudFunctionSource() | ||
} | ||
} | ||
|
||
export enum CloudFunctionState { | ||
Deployed = 'Deployed', | ||
} | ||
|
||
export class CloudFunctionStatus { | ||
@ApiProperty({ | ||
enum: CloudFunctionState, | ||
}) | ||
state: CloudFunctionState | ||
} | ||
|
||
export class CloudFunction implements KubernetesObject { | ||
@ApiProperty() | ||
apiVersion: string | ||
|
||
@ApiProperty() | ||
kind: string | ||
|
||
@ApiProperty() | ||
metadata: ObjectMeta | ||
|
||
@ApiProperty() | ||
spec: CloudFunctionSpec | ||
|
||
@ApiPropertyOptional() | ||
status?: CloudFunctionStatus | ||
|
||
static readonly Group = 'runtime.laf.dev' | ||
static readonly Version = 'v1' | ||
static readonly PluralName = 'functions' | ||
static readonly Kind = 'Function' | ||
static get GroupVersion() { | ||
return `${this.Group}/${this.Version}` | ||
} | ||
|
||
constructor(name: string, namespace: string) { | ||
this.apiVersion = CloudFunction.GroupVersion | ||
this.kind = CloudFunction.Kind | ||
this.metadata = { | ||
name, | ||
namespace, | ||
} | ||
this.spec = new CloudFunctionSpec() | ||
} | ||
} | ||
|
||
export class CloudFunctionList implements KubernetesListObject<CloudFunction> { | ||
@ApiProperty() | ||
apiVersion?: string | ||
|
||
@ApiProperty() | ||
kind?: string = 'FunctionList' | ||
|
||
@ApiProperty({ | ||
type: [CloudFunction], | ||
}) | ||
items: CloudFunction[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Module } from '@nestjs/common' | ||
import { FunctionsService } from './functions.service' | ||
import { FunctionsController } from './functions.controller' | ||
import { ApplicationsService } from 'src/applications/applications.service' | ||
|
||
@Module({ | ||
controllers: [FunctionsController], | ||
providers: [FunctionsService], | ||
providers: [FunctionsService, ApplicationsService], | ||
}) | ||
export class FunctionsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters