Skip to content

Commit

Permalink
Merge pull request #1167 from jumpserver/dev
Browse files Browse the repository at this point in the history
merge: from dev to master
  • Loading branch information
BaiJiangJie authored Sep 19, 2024
2 parents dfce101 + e42713f commit 81e3fad
Show file tree
Hide file tree
Showing 33 changed files with 857 additions and 545 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-base-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
tag: ${{ steps.get_version.outputs.TAG }}
- uses: actions/setup-node@v2
with:
node-version: '16.20'
node-version: '20.15'
- name: Install dependencies
run: yarn install
- name: Build web
Expand Down
6 changes: 6 additions & 0 deletions proxy.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"ws": true,
"changeOrigin": true
},
"/koko/k8s/*": {
"target": "http://localhost:5000",
"secure": false,
"ws": true,
"changeOrigin": true
},
"/koko/static/*": {
"target": "http://localhost:5000",
"secure": false,
Expand Down
60 changes: 10 additions & 50 deletions src/app/elements/asset-tree/asset-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class Tree {
})
export class ElementAssetTreeComponent implements OnInit {
@Input() query: string;
@Input() isK8s: boolean = false;
@Input() searchEvt$: BehaviorSubject<string>;
@ViewChild('rMenu', {static: false}) rMenu: ElementRef;
setting = {
Expand Down Expand Up @@ -150,21 +149,21 @@ export class ElementAssetTreeComponent implements OnInit {
'id': 'connect',
'name': 'Connect',
'fa': 'fa-terminal',
'hide': cnode.isParent && !this.isK8s,
'hide': cnode.isParent,
'click': this.onMenuConnect.bind(this)
},
{
'id': 'new-connection',
'name': 'Open in new window',
'fa': 'fa-external-link',
'hide': this.isK8s || cnode.isParent,
'hide': cnode.isParent,
'click': this.onMenuConnectNewTab.bind(this)
},
{
'id': 'split-connect',
'name': 'Split connect',
'fa': 'fa-columns',
'hide': viewList.length <= 0 || cnode.isParent || cnode.meta.data.platform_type ==='k8s' || this.isK8s,
'hide': viewList.length <= 0 || cnode.isParent,
'click': this.onMenuConnect.bind(this, true)
},
{
Expand Down Expand Up @@ -205,14 +204,14 @@ export class ElementAssetTreeComponent implements OnInit {
'id': 'favorite',
'name': 'Favorite',
'fa': 'fa-star-o',
'hide': this.isAssetFavorite() || this.isK8s || cnode.isParent,
'hide': this.isAssetFavorite() || cnode.isParent,
'click': this.onMenuFavorite.bind(this)
},
{
'id': 'disfavor',
'name': 'Disfavor',
'fa': 'fa-star',
'hide': !this.isAssetFavorite() || this.isK8s || cnode.isParent,
'hide': !this.isAssetFavorite() || cnode.isParent,
'click': this.onMenuFavorite.bind(this)
}
];
Expand All @@ -236,12 +235,8 @@ export class ElementAssetTreeComponent implements OnInit {
}

initTree() {
if (this.isK8s) {
this.initK8sTree().then();
} else {
this.initAssetTree().then();
this.initTypeTree().then();
}
this.initAssetTree().then();
this.initTypeTree().then();
}

onNodeClick(event, treeId, treeNode, clickFlag) {
Expand Down Expand Up @@ -270,39 +265,6 @@ export class ElementAssetTreeComponent implements OnInit {
this.assetTreeChecked = ztree.getCheckedNodes().filter(i => !i.isParent);
}

async initK8sTree(refresh = false) {
const tree = new Tree(
'K8sTree',
this._i18n.instant('Kubernetes'),
true,
true,
false,
false
);
const token = this._route.snapshot.queryParams.token;
const url = `/api/v1/perms/users/self/nodes/children-with-k8s/tree/?token=${token}`;
const config = {
refresh,
url,
asyncUrl: url,
setting: {
async: {
enable: true,
autoParam: ['id=key', 'name=n', 'level=lv'],
type: 'get',
headers: {
'X-JMS-ORG': this.currentOrgID
}
}
},
showFavoriteAssets: false
};
if (!refresh) {
this.trees.push(tree);
}
this.initTreeInfo(tree, config).then();
}

async initAssetTree(refresh = false) {
const config = {
refresh,
Expand Down Expand Up @@ -506,9 +468,7 @@ export class ElementAssetTreeComponent implements OnInit {
async refreshTree(event, tree) {
event.stopPropagation();
this.searchValue = '';
if (this.isK8s) {
this.initK8sTree(true).then();
} else if (tree.name === 'AssetTree') {
if (tree.name === 'AssetTree') {
this.initAssetTree(true).then();
} else if (tree.name === 'AssetTypeTree') {
this.initTypeTree(true).then();
Expand All @@ -520,7 +480,7 @@ export class ElementAssetTreeComponent implements OnInit {
}

async connectAsset(node: TreeNode) {
const action = this.isK8s ? 'k8s' : 'asset';
const action = 'asset';
const evt = new ConnectEvt(node, action);
connectEvt.next(evt);
}
Expand Down Expand Up @@ -619,7 +579,7 @@ export class ElementAssetTreeComponent implements OnInit {
return;
}
const node = this.rightClickSelectNode;
const action = this.isK8s ? 'k8s' : 'connect';
const action = 'connect';
const evt = splitConnect ? new ConnectEvt(node, action, true) : new ConnectEvt(node, action);
connectEvt.next(evt);
}
Expand Down
74 changes: 8 additions & 66 deletions src/app/elements/connect/connect.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SettingService,
ViewService
} from '@app/services';
import {Account, Asset, ConnectData, ConnectionToken, K8sInfo, View} from '@app/model';
import {Account, Asset, ConnectData, ConnectionToken, View} from '@app/model';
import {ElementConnectDialogComponent} from './connect-dialog/connect-dialog.component';
import {ElementDownloadDialogComponent} from './download-dialog/download-dialog.component';
import {launchLocalApp} from '@app/utils/common';
Expand Down Expand Up @@ -82,71 +82,11 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
return idObject;
}

connectK8sAsset(id) {
const idObject = this.analysisId(id);
const token = this._route.snapshot.queryParams.token;
this._http.getConnectToken(token).subscribe(connToken => {
this._http.getAssetDetail(connToken.asset.id).subscribe(asset => {
const accountList = asset.permed_accounts;
let account = new Account();
if (['@INPUT', '@USER'].includes(connToken.account)) {
account.name = connToken.input_username;
account.username = connToken.input_username;
account.alias = connToken.account;
} else {
const accounts = accountList.filter(item => item.name === connToken.account);
if (accounts.length === 0) {
return;
}
account = accounts[0];
}
const type = 'k8s';
const connectInfo = new ConnectData();
connToken.asset['type'] = {'value': type};
connectInfo.asset = connToken.asset;
connectInfo.account = account;
connectInfo.protocol = {
'name': type,
'port': 443,
'public': true,
'setting': {}
};
connectInfo.manualAuthInfo = {
alias: account.alias,
username: account.username,
secret: undefined,
rememberAuth: false
};
connectInfo.connectMethod = {
type: type,
value: 'web_cli',
component: 'koko',
label: type,
endpoint_protocol: 'http',
disabled: false,
};
const kInfo = new K8sInfo();
kInfo.pod = idObject['pod'];
kInfo.namespace = idObject['namespace'];
kInfo.container = idObject['container'];

this._logger.debug('Connect info: ', connectInfo);
this.createWebView(connToken.asset, connectInfo, connToken, kInfo);
});
});
}

subscribeConnectEvent() {
connectEvt.asObservable().subscribe(evt => {
if (!evt.node) {
return;
}
if (evt.action === 'k8s') {
if (['asset', 'container'].indexOf(evt.node.meta.data.identity) !== -1) {
this.connectK8sAsset(evt.node.id);
return;
}
}

this._http.getAssetDetail(evt.node.id).subscribe(asset => {
switch (evt.action) {
Expand Down Expand Up @@ -194,7 +134,9 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
}

if (connToken.protocol === 'k8s') {
window.open(`/luna/k8s?token=${connToken.id}`);
const baseUrl = `${window.location.protocol}//${window.location.host}/`;
const fullUrl = `${baseUrl}koko/k8s/?token=${connToken.id}`;
window.open(fullUrl);
return;
}

Expand Down Expand Up @@ -240,13 +182,13 @@ export class ElementConnectComponent implements OnInit, OnDestroy {
}


createWebView(asset: Asset, connectInfo: any, connToken: ConnectionToken, k8sInfo?: K8sInfo) {
const view = new View(asset, connectInfo, connToken, 'node', k8sInfo);
createWebView(asset: Asset, connectInfo: any, connToken: ConnectionToken) {
const view = new View(asset, connectInfo, connToken, 'node');
this.onNewView.emit(view);
}

currentWebSubView(asset: Asset, connectInfo: any, connToken: ConnectionToken, k8sInfo?: K8sInfo) {
const view = new View(asset, connectInfo, connToken, 'node', k8sInfo);
currentWebSubView(asset: Asset, connectInfo: any, connToken: ConnectionToken) {
const view = new View(asset, connectInfo, connToken, 'node');
this.viewSrv.addSubViewToCurrentView(view);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ li {
overflow: hidden;
white-space: nowrap;
font-size: 13px;
cursor: default;
cursor: pointer;
color: #cacaca;

.view_icon {
Expand Down
12 changes: 0 additions & 12 deletions src/app/elements/content/content-window/koko/koko.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,10 @@ export class ElementConnectorKokoComponent implements OnInit {
}
}

setK8sParams(params) {
Object.keys(this.view.k8sInfo).forEach(k => {
const v = this.view.k8sInfo[k];
if (v) {
params[k] = this.view.k8sInfo[k];
}
});
}

generateNodeConnectUrl() {
const params = {};
params['disableautohash'] = this.view.getConnectOption('disableautohash');
params['token'] = this.view.connectToken.id;
if (this.view.k8sInfo) {
this.setK8sParams(params);
}

params['_'] = Date.now().toString();
const query = Object.entries(params)
Expand Down
6 changes: 3 additions & 3 deletions src/app/elements/content/content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export class ElementContentComponent implements OnInit, OnDestroy {

handleKeyDownTabChange() {
this.keyboardSubscription = fromEvent(window, 'keydown').subscribe((event: any) => {
if (event.altKey && (event.key === 'ArrowRight' || event.key === 'ArrowLeft') && this.viewList.length > 1) {
if (event.altKey && event.shiftKey && (event.key === 'ArrowRight' || event.key === 'ArrowLeft') && this.viewList.length > 1) {
let key = '';
if (event.key === 'ArrowRight') {
key = 'alt+right';
key = 'alt+shift+right';
} else if (event.key === 'ArrowLeft') {
key = 'alt+left';
key = 'alt+shift+left';
}
this.viewSrv.keyboardSwitchTab(key);
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/elements/elements.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {ElementConnectorGuideComponent} from '@app/elements/content/content-wind
import {ElementCommandDialogComponent} from '@app/elements/content/command-dialog/command-dialog.component';
import {ElementSendCommandDialogComponent} from '@app/elements/content/send-command-dialog/send-command-dialog.component';
import {ElementChatComponent} from '@app/elements/chat/chat.component';
import {ElementsPartsComponent} from './replay/parts/parts.component';


export const ElementComponents = [
ElementLeftBarComponent,
Expand Down Expand Up @@ -68,4 +70,5 @@ export const ElementComponents = [
ElementConnectorGuideComponent,
ElementCommandDialogComponent,
ElementSendCommandDialogComponent,
ElementsPartsComponent,
];
1 change: 1 addition & 0 deletions src/app/elements/iframe/iframe.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class ElementIframeComponent implements OnInit, AfterViewInit, OnDestroy
}

handleIframeEvent() {
// @ts-ignore
this.ping = setInterval(() => {
this._logger.info(`[Luna] Send PING to: ${this.id}`);
this.iframeWindow.postMessage({name: 'PING', id: this.id}, '*');
Expand Down
4 changes: 2 additions & 2 deletions src/app/elements/left-bar/left-bar.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="sidebar" fxLayout="column">
<div class="organization" [style.display]="this._settingSvc.hasXPack() ? '' : 'none'">
<elements-organization [isK8s]="isK8s"></elements-organization>
<elements-organization></elements-organization>
</div>

<div *ngIf="showTree" class="my-assets" [ngClass]="{'has-org': this._settingSvc.hasXPack()}">
<div class="overflow ngx-scroll-overlay">
<elements-asset-tree style="width: 100%" [isK8s]="this.isK8s" #assetTree></elements-asset-tree>
<elements-asset-tree style="width: 100%" #assetTree></elements-asset-tree>
</div>
</div>

Expand Down
3 changes: 1 addition & 2 deletions src/app/elements/left-bar/left-bar.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Output, Input, EventEmitter} from '@angular/core';
import {Component, Output, EventEmitter} from '@angular/core';
import {DataStore} from '@app/globals';
import {version} from '@src/environments/environment';
import {OrganizationService, SettingService} from '@app/services';
Expand All @@ -10,7 +10,6 @@ import {OrganizationService, SettingService} from '@app/services';
styleUrls: ['./left-bar.component.scss'],
})
export class ElementLeftBarComponent {
@Input() isK8s: boolean = false;
@Output() menuActive = new EventEmitter();
showTree = true;
version = version;
Expand Down
18 changes: 0 additions & 18 deletions src/app/elements/nav/nav.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,6 @@ export class ElementNavComponent implements OnInit {
name: 'View',
children: [
// 此处直接使用空串的话,在渲染时会被 nif 判断为 false 从而只有禁用效果而不展示文字内容
{
id: 'SplitVertical',
href: '/',
name: this._i18n.instant('SplitVertical'),
disable: true
},
{
id: 'CommandBar',
href: '/',
name: this._i18n.instant('CommandBar'),
disable: true
},
{
id: 'ShareSession',
href: '/',
name: this._i18n.instant('ShareSession'),
disable: true
},
{
id: 'FullScreen',
click: () => {
Expand Down
Loading

0 comments on commit 81e3fad

Please sign in to comment.