Skip to content

Commit

Permalink
fix: add field displayName of endorsePolicy(#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy authored and Carrotzpc committed Mar 16, 2023
1 parent c4c1264 commit 17bec25
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/epolicy/dto/new-epolicy.input.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Field, InputType } from '@nestjs/graphql';
import { Length } from 'class-validator';

@InputType()
export class NewEpolicyInput {
/** 策略名称(metadata.name) */
/** 策略名称 */
@Field(() => String, {
description:
'策略名称,规则:小写字母、数字、“-”,开头和结尾只能是字母或数字([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)',
description: '策略名称',
})
@Length(3, 63)
name: string;
displayName: string;

/** 策略描述 */
description?: string;
Expand Down
2 changes: 2 additions & 0 deletions src/epolicy/epolicy.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
query getEpolicies($network: String) {
epolicies(network: $network) {
name
displayName
description
channel
value
Expand All @@ -14,6 +15,7 @@ query getEpolicies($network: String) {
mutation createEpolicy($epolicy: NewEpolicyInput!) {
epolicyCreate(epolicy: $epolicy) {
name
displayName
value
description
channel
Expand Down
7 changes: 5 additions & 2 deletions src/epolicy/epolicy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ForbiddenException, Injectable } from '@nestjs/common';
import { ChannelService } from 'src/channel/channel.service';
import { Channel } from 'src/channel/models/channel.model';
import { K8sV1Status } from 'src/common/models/k8s-v1-status.model';
import { genNanoid } from 'src/common/utils';
import { KubernetesService } from 'src/kubernetes/kubernetes.service';
import { CRD } from 'src/kubernetes/lib';
import { NetworkService } from 'src/network/network.service';
Expand All @@ -28,6 +29,7 @@ export class EpolicyService {
: creationTimestamp;
return {
name: epolicy.metadata?.name,
displayName: epolicy.spec?.displayName,
creationTimestamp,
lastHeartbeatTime,
channel: epolicy.spec?.channel,
Expand Down Expand Up @@ -60,13 +62,14 @@ export class EpolicyService {
auth: JwtAuth,
epolicy: NewEpolicyInput,
): Promise<Epolicy> {
const { name, description, channel, value } = epolicy;
const { displayName, description, channel, value } = epolicy;
const k8s = await this.k8sService.getClient(auth);
const { body } = await k8s.endorsePolicy.create({
metadata: {
name,
name: genNanoid('epolicy'),
},
spec: {
displayName,
description,
channel,
value,
Expand Down
3 changes: 3 additions & 0 deletions src/epolicy/models/epolicy.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export class Epolicy {
@Field(() => ID, { description: 'name' })
name: string;

/** 策略名称 */
displayName?: string;

/** 所在通道 */
channel: string;

Expand Down
1 change: 1 addition & 0 deletions src/kubernetes/lib/interfaces/crd/endorse-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface EndorsePolicy {
spec?: {
channel: string;
description?: string;
displayName: string;
value: string;
[k: string]: any;
};
Expand Down
9 changes: 5 additions & 4 deletions src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ type Epolicy {
"""描述"""
description: String

"""策略名称"""
displayName: String

"""更新时间"""
lastHeartbeatTime: String

Expand Down Expand Up @@ -443,10 +446,8 @@ input NewEpolicyInput {
"""策略描述"""
description: String

"""
策略名称,规则:小写字母、数字、“-”,开头和结尾只能是字母或数字([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)
"""
name: String!
"""策略名称"""
displayName: String!

"""
策略内容:可选组织为已选通道内的成员,语法参考(https://hyperledger-fabric.readthedocs.io/en/latest/endorsement-policies.html#endorsement-policy-syntax)
Expand Down

0 comments on commit 17bec25

Please sign in to comment.