nameczz 3 years ago
parent
commit
734490c430

+ 4 - 0
client/src/http/Collection.ts

@@ -110,6 +110,10 @@ export class CollectionHttp extends BaseModel implements CollectionView {
     return formatNumber(Number(this.rowCount));
   }
 
+  get _isLoaded() {
+    return this.isLoaded;
+  }
+
   get _status() {
     return this.isLoaded === true ? StatusEnum.loaded : StatusEnum.unloaded;
   }

+ 1 - 0
client/src/pages/collections/Types.ts

@@ -10,6 +10,7 @@ export interface CollectionData {
   _desc: string;
   _indexState: ChildrenStatusType;
   _fields?: FieldData[];
+  _isLoaded: boolean;
 }
 
 export interface CollectionView extends CollectionData {

+ 2 - 4
client/src/pages/overview/Overview.tsx

@@ -9,7 +9,6 @@ import { useLoadAndReleaseDialogHook } from '../../hooks/Dialog';
 import { useNavigationHook } from '../../hooks/Navigation';
 import { CollectionHttp } from '../../http/Collection';
 import { ALL_ROUTER_TYPES } from '../../router/Types';
-import { ShowCollectionsType } from '../../types/Milvus';
 import { formatNumber } from '../../utils/Common';
 import CollectionCard from './collectionCard/CollectionCard';
 import { CollectionData } from './collectionCard/Types';
@@ -49,9 +48,8 @@ const Overview = () => {
 
   const fetchData = useCallback(async () => {
     const res = await CollectionHttp.getStatistics();
-    const loadCollections = await CollectionHttp.getCollections({
-      type: ShowCollectionsType.InMemory,
-    });
+    const collections = await CollectionHttp.getCollections();
+    const loadCollections = collections.filter(c => c._isLoaded);
     setStatistics(res);
     setLoadCollections(loadCollections);
   }, []);

+ 1 - 21
server/src/app.controller.spec.ts

@@ -1,20 +1,5 @@
 import { Test, TestingModule } from '@nestjs/testing';
 import { AppController } from './app.controller';
-import { AuthService } from './auth/auth.service';
-
-const testUser = {
-  userId: 1,
-  username: 'milvus',
-  password: 'milvus-admin',
-}
-class AuthServiceMock {
-  login = () => testUser;
-}
-
-const AuthServiceProvider = {
-  provide: AuthService,
-  useClass: AuthServiceMock,
-};
 
 describe('AppController', () => {
   let appController: AppController;
@@ -22,7 +7,7 @@ describe('AppController', () => {
   beforeEach(async () => {
     const app: TestingModule = await Test.createTestingModule({
       controllers: [AppController],
-      providers: [AuthServiceProvider],
+      providers: [],
     }).compile();
 
     appController = app.get<AppController>(AppController);
@@ -32,10 +17,5 @@ describe('AppController', () => {
     it('should defined', () => {
       expect(appController).toBeDefined();
     });
-
-    it('should return result', async () => {
-      const data = await appController.login(1);
-      expect(data).toBe(testUser);
-    });
   });
 });

+ 3 - 10
server/src/app.controller.ts

@@ -1,17 +1,10 @@
-import { Controller, Request, Post, UseGuards, Get } from '@nestjs/common';
-import { AuthGuard } from '@nestjs/passport';
-import { AuthService } from './auth/auth.service';
+import { Controller, Get } from '@nestjs/common';
 
 @Controller()
 export class AppController {
-  constructor(private readonly authService: AuthService) {}
-
-  @UseGuards(AuthGuard('local'))
-  @Post('login')
-  async login(@Request() req) {
-    return this.authService.login(req.user);
-  }
+  constructor() {}
 
+  // used for check healthy after build finished
   @Get('healthy')
   async checkServer() {
     return { status: 200 };

+ 7 - 6
server/src/app.module.ts

@@ -6,9 +6,6 @@ import { AppService } from './app.service';
 import { ErrorInterceptor, TransformResInterceptor } from './interceptors';
 import { MilvusModule } from './milvus/milvus.module';
 import { CollectionsModule } from './collections/collections.module';
-import { UsersService } from './users/users.service';
-import { UsersModule } from './users/users.module';
-import { AuthModule } from './auth/auth.module';
 import { join } from 'path';
 import { PartitionsModule } from './partitions/partitions.module';
 import { SchemaModule } from './schema/schema.module';
@@ -17,16 +14,21 @@ import { LoggingInterceptor } from './interceptors/index';
 
 @Module({
   imports: [
+    // Milvus insight will be available in one docker, so we will build client files in server's client directory
     ServeStaticModule.forRoot({
       rootPath: join(__dirname, '../../', 'build'),
       // renderPath: '/', // only root render static html
     }),
+    // used for connection and checking server stats
+    // TODO: rename to Connect
     MilvusModule,
+    // used for manage collection
     CollectionsModule,
-    UsersModule,
-    AuthModule,
+    // used for manage partitions
     PartitionsModule,
+    // used for manage index
     SchemaModule,
+    // used for events communication
     EventsModule,
   ],
   controllers: [AppController],
@@ -45,7 +47,6 @@ import { LoggingInterceptor } from './interceptors/index';
       provide: APP_INTERCEPTOR,
       useClass: LoggingInterceptor,
     },
-    UsersService,
   ],
 })
 export class AppModule {}

+ 1 - 1
server/src/app.service.ts

@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
 @Injectable()
 export class AppService {
   getHello(): string {
-    return 'Hello World!';
+    return 'Hello Milvus!';
   }
 }

+ 0 - 22
server/src/auth/auth.module.ts

@@ -1,22 +0,0 @@
-import { Module } from '@nestjs/common';
-import { AuthService } from './auth.service';
-import { LocalStrategy } from './local.strategy';
-import { UsersModule } from '../users/users.module';
-import { PassportModule } from '@nestjs/passport';
-import { JwtModule } from '@nestjs/jwt';
-import { jwtConstants } from './const';
-import { JwtStrategy } from './jwt.strategy';
-
-@Module({
-  imports: [
-    PassportModule.register({ defaultStrategy: 'jwt' }),
-    JwtModule.register({
-      secret: jwtConstants.secret,
-      signOptions: { expiresIn: '1d' },
-    }),
-    UsersModule,
-  ],
-  providers: [AuthService, LocalStrategy, JwtStrategy],
-  exports: [AuthService],
-})
-export class AuthModule {}

+ 0 - 58
server/src/auth/auth.service.spec.ts

@@ -1,58 +0,0 @@
-import { Test, TestingModule } from '@nestjs/testing';
-import { AuthService } from './auth.service';
-import { LocalStrategy } from './local.strategy';
-import { UsersModule } from '../users/users.module';
-import { PassportModule } from '@nestjs/passport';
-import { JwtModule } from '@nestjs/jwt';
-import { jwtConstants } from './const';
-import { JwtStrategy } from './jwt.strategy';
-import { HttpStatus } from '@nestjs/common';
-
-describe('AuthService', () => {
-  let service: AuthService;
-  let localStrategy: LocalStrategy;
-
-  beforeEach(async () => {
-    const module: TestingModule = await Test.createTestingModule({
-      imports: [
-        PassportModule.register({ defaultStrategy: 'jwt' }),
-        JwtModule.register({
-          secret: jwtConstants.secret,
-          signOptions: { expiresIn: '1d' },
-        }),
-        UsersModule,
-      ],
-      providers: [AuthService, LocalStrategy, JwtStrategy],
-    }).compile();
-
-    service = module.get<AuthService>(AuthService);
-    localStrategy = module.get<LocalStrategy>(LocalStrategy);
-  });
-
-  it('should be defined', () => {
-    expect(service).toBeDefined();
-  });
-
-  it('validateUser shoule be true', async () => {
-    const res = await service.validateUser('milvus', 'milvus-admin');
-    expect(res).toEqual({ userId: 1, username: 'milvus' });
-  });
-
-  it('validateUser shoule be null', async () => {
-    const res = await service.validateUser('notexist', '123');
-    expect(res).toBeNull();
-  });
-
-  it('login', async () => {
-    const res = await service.login({ username: 'milvus', userId: 1 });
-    expect(res).toHaveProperty('access_token');
-  });
-
-  it('local validate', async () => {
-    try {
-      await localStrategy.validate('notexist', 'asd');
-    } catch (e) {
-      expect(e.status).toEqual(HttpStatus.UNAUTHORIZED);
-    }
-  });
-});

+ 0 - 28
server/src/auth/auth.service.ts

@@ -1,28 +0,0 @@
-import { Logger, Injectable } from '@nestjs/common';
-import { UsersService } from '../users/users.service';
-import { JwtService } from '@nestjs/jwt';
-
-@Injectable()
-export class AuthService {
-  constructor(
-    private readonly usersService: UsersService,
-    private readonly jwtService: JwtService,
-  ) {}
-
-  async validateUser(username: string, pass: string): Promise<any> {
-    const user = await this.usersService.findOne(username);
-    Logger.log(user);
-    if (user && user.password === pass) {
-      const { password, ...result } = user;
-      return result;
-    }
-    return null;
-  }
-
-  async login(user: any) {
-    const payload = { username: user.username, sub: user.userId };
-    return {
-      access_token: this.jwtService.sign(payload),
-    };
-  }
-}

+ 0 - 3
server/src/auth/const.ts

@@ -1,3 +0,0 @@
-export const jwtConstants = {
-  secret: 'secretKey',
-};

+ 0 - 19
server/src/auth/jwt.strategy.ts

@@ -1,19 +0,0 @@
-import { ExtractJwt, Strategy } from 'passport-jwt';
-import { PassportStrategy } from '@nestjs/passport';
-import { Injectable } from '@nestjs/common';
-import { jwtConstants } from './const';
-
-@Injectable()
-export class JwtStrategy extends PassportStrategy(Strategy) {
-  constructor() {
-    super({
-      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
-      ignoreExpiration: false,
-      secretOrKey: jwtConstants.secret,
-    });
-  }
-
-  async validate(payload: any) {
-    return { userId: payload.sub, username: payload.username };
-  }
-}

+ 0 - 20
server/src/auth/local.strategy.ts

@@ -1,20 +0,0 @@
-import { Strategy } from 'passport-local';
-import { PassportStrategy } from '@nestjs/passport';
-import { Injectable, UnauthorizedException } from '@nestjs/common';
-import { AuthService } from './auth.service';
-
-@Injectable()
-export class LocalStrategy extends PassportStrategy(Strategy) {
-  constructor(private readonly authService: AuthService) {
-    super();
-  }
-
-  async validate(username: string, password: string): Promise<any> {
-    const user = await this.authService.validateUser(username, password);
-    if (!user) {
-      throw new UnauthorizedException();
-    }
-
-    return user;
-  }
-}

+ 1 - 0
server/src/schema/schema.controller.ts

@@ -16,6 +16,7 @@ import {
   GetIndexState,
 } from './dto';
 import { SchemaService } from './schema.service';
+
 @ApiTags('schema')
 @Controller('schema')
 export class SchemaController {

+ 0 - 8
server/src/users/users.module.ts

@@ -1,8 +0,0 @@
-import { Module } from '@nestjs/common';
-import { UsersService } from './users.service';
-
-@Module({
-  providers: [UsersService],
-  exports: [UsersService],
-})
-export class UsersModule {}

+ 0 - 32
server/src/users/users.service.spec.ts

@@ -1,32 +0,0 @@
-import { Test, TestingModule } from '@nestjs/testing';
-import { UsersService } from './users.service';
-
-describe('UsersService', () => {
-  let service: UsersService;
-
-  beforeEach(async () => {
-    const module: TestingModule = await Test.createTestingModule({
-      providers: [UsersService],
-    }).compile();
-
-    service = module.get<UsersService>(UsersService);
-  });
-
-  it('should be defined', () => {
-    expect(service).toBeDefined();
-  });
-
-  it('findone should be false', async () => {
-    const res = await service.findOne('a');
-    expect(res).toBeUndefined();
-  });
-
-  it('findone should be truth', async () => {
-    const res = await service.findOne('milvus');
-    expect(res).toEqual({
-      userId: 1,
-      username: 'milvus',
-      password: 'milvus-admin',
-    });
-  });
-});

+ 0 - 23
server/src/users/users.service.ts

@@ -1,23 +0,0 @@
-import { Injectable } from '@nestjs/common';
-
-export type User = any;
-
-@Injectable()
-export class UsersService {
-  private readonly users: User[];
-
-  constructor() {
-    // todo: hardcode user list for now
-    this.users = [
-      {
-        userId: 1,
-        username: 'milvus',
-        password: 'milvus-admin',
-      },
-    ];
-  }
-
-  async findOne(username: string): Promise<User | undefined> {
-    return this.users.find((user) => user.username === username);
-  }
-}