Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
61ff2d55
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
61ff2d55
编写于
8月 29, 2017
作者:
C
Christof Marti
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove filter by resource group from API (#33431)
上级
956c5de4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
109 deletion
+41
-109
extensions/azure-account/src/azure-account.ts
extensions/azure-account/src/azure-account.ts
+36
-104
extensions/azure-account/src/extension.ts
extensions/azure-account/src/extension.ts
+4
-2
extensions/azure-account/src/typings/azure-account.api.d.ts
extensions/azure-account/src/typings/azure-account.api.d.ts
+1
-3
未找到文件。
extensions/azure-account/src/azure-account.ts
浏览文件 @
61ff2d55
...
...
@@ -10,12 +10,12 @@ const CacheDriver = require('adal-node/lib/cache-driver');
const
createLogContext
=
require
(
'
adal-node/lib/log
'
).
createLogContext
;
import
{
DeviceTokenCredentials
,
AzureEnvironment
}
from
'
ms-rest-azure
'
;
import
{
SubscriptionClient
,
ResourceManagementClient
,
SubscriptionModels
}
from
'
azure-arm-resource
'
;
import
{
SubscriptionClient
,
SubscriptionModels
}
from
'
azure-arm-resource
'
;
import
*
as
opn
from
'
opn
'
;
import
*
as
copypaste
from
'
copy-paste
'
;
import
*
as
nls
from
'
vscode-nls
'
;
import
{
window
,
commands
,
credentials
,
EventEmitter
,
MessageItem
,
ExtensionContext
,
workspace
,
ConfigurationTarget
}
from
'
vscode
'
;
import
{
window
,
commands
,
credentials
,
EventEmitter
,
MessageItem
,
ExtensionContext
,
workspace
,
ConfigurationTarget
,
WorkspaceConfiguration
}
from
'
vscode
'
;
import
{
AzureAccount
,
AzureSession
,
AzureLoginStatus
,
AzureResourceFilter
}
from
'
./typings/azure-account.api
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -198,69 +198,47 @@ export class AzureLoginHelper {
}
const
{
session
,
subscription
}
=
subscriptionResult
.
subscription
;
// const client = new ResourceManagementClient(session.credentials, subscription.subscriptionId!);
// const resourceGroups = await listAll(client.resourceGroups, client.resourceGroups.list());
// const resourceGroupFilters: AzureResourceFilter[] = [
// {
// ...subscriptionResult.subscription,
// allResourceGroups: true,
// resourceGroups
// }
// ];
// resourceGroupFilters.push(...resourceGroups.filter(resourceGroup => resourceFilter.indexOf(`${session.tenantId}/${subscription.subscriptionId}/${resourceGroup.name}`) === -1)
// .map(resourceGroup => ({
// session,
// subscription,
// allResourceGroups: false,
// resourceGroups: [resourceGroup]
// })));
// resourceGroupFilters.sort((a, b) => (!a.allResourceGroups ? a.resourceGroups[0].name! : '').localeCompare(!b.allResourceGroups ? b.resourceGroups[0].name! : ''));
// const resourceGroupResult = await window.showQuickPick(resourceGroupFilters.map(resourceGroup => (!resourceGroup.allResourceGroups ? {
// label: resourceGroup.resourceGroups[0].name!,
// description: resourceGroup.resourceGroups[0].location,
// resourceGroup
// } : {
// label: localize('azure-account.entireSubscription', "Entire Subscription"),
// description: '',
// resourceGroup
// })));
// if (!resourceGroupResult) {
// return;
// }
// const resourceGroup = resourceGroupResult.resourceGroup;
// if (!resourceGroup.allResourceGroups) {
// resourceFilter.push(`${resourceGroup.session.tenantId}/${resourceGroup.subscription.subscriptionId}/${resourceGroup.resourceGroups[0].name}`);
// } else {
resourceFilter
.
splice
(
0
,
resourceFilter
.
length
,
...
resourceFilter
.
filter
(
c
=>
!
c
.
startsWith
(
`
${
session
.
tenantId
}
/
${
subscription
.
subscriptionId
}
/`
)));
resourceFilter
.
push
(
`
${
session
.
tenantId
}
/
${
subscription
.
subscriptionId
}
`
);
// }
const
resourceFilterConfig
=
azureConfig
.
inspect
<
string
[]
>
(
'
resourceFilter
'
);
let
target
=
ConfigurationTarget
.
Global
;
if
(
resourceFilterConfig
)
{
if
(
resourceFilterConfig
.
workspaceFolderValue
)
{
target
=
ConfigurationTarget
.
WorkspaceFolder
;
}
else
if
(
resourceFilterConfig
.
workspaceValue
)
{
target
=
ConfigurationTarget
.
Workspace
;
}
else
if
(
resourceFilterConfig
.
globalValue
)
{
target
=
ConfigurationTarget
.
Global
;
}
await
this
.
updateConfiguration
(
azureConfig
,
resourceFilter
);
}
private
async
removeFilter
()
{
if
(
!
(
await
this
.
waitForLogin
()))
{
return
commands
.
executeCommand
(
'
azure-account.askForLogin
'
);
}
const
azureConfig
=
workspace
.
getConfiguration
(
'
azure
'
);
let
resourceFilter
=
azureConfig
.
get
<
string
[]
>
(
'
resourceFilter
'
)
||
[];
const
subscriptionItems
=
this
.
loadSubscriptionItems
(
resourceFilter
,
false
);
const
subscriptionResult
=
await
window
.
showQuickPick
(
subscriptionItems
);
if
(
!
subscriptionResult
)
{
return
;
}
await
azureConfig
.
update
(
'
resourceFilter
'
,
resourceFilter
,
target
);
const
{
session
,
subscription
}
=
subscriptionResult
.
subscription
;
const
remove
=
`
${
session
.
tenantId
}
/
${
subscription
.
subscriptionId
}
`
;
resourceFilter
=
resourceFilter
.
filter
(
e
=>
e
!==
remove
);
await
this
.
updateConfiguration
(
azureConfig
,
resourceFilter
);
}
private
async
loadSubscriptionItems
(
resourceFilter
:
string
[])
{
private
async
loadSubscriptionItems
(
resourceFilter
:
string
[],
exclude
=
true
)
{
if
(
!
resourceFilter
.
length
&&
!
exclude
)
{
return
[];
}
const
subscriptionItems
:
{
session
:
AzureSession
;
subscription
:
SubscriptionModels
.
Subscription
}[]
=
[];
for
(
const
session
of
this
.
api
.
sessions
)
{
const
credentials
=
session
.
credentials
;
const
client
=
new
SubscriptionClient
(
credentials
);
const
subscriptions
=
await
listAll
(
client
.
subscriptions
,
client
.
subscriptions
.
list
());
subscriptionItems
.
push
(...
subscriptions
.
filter
(
subscription
=>
resourceFilter
.
indexOf
(
`
${
session
.
tenantId
}
/
${
subscription
.
subscriptionId
}
`
)
===
-
1
)
const
items
=
subscriptions
.
filter
(
subscription
=>
exclude
!==
(
resourceFilter
.
indexOf
(
`
${
session
.
tenantId
}
/
${
subscription
.
subscriptionId
}
`
)
!==
-
1
)
)
.
map
(
subscription
=>
({
session
,
subscription
})));
}));
subscriptionItems
.
push
(...
items
);
}
subscriptionItems
.
sort
((
a
,
b
)
=>
a
.
subscription
.
displayName
!
.
localeCompare
(
b
.
subscription
.
displayName
!
));
return
subscriptionItems
.
map
(
subscription
=>
({
...
...
@@ -270,45 +248,7 @@ export class AzureLoginHelper {
}));
}
private
async
removeFilter
()
{
if
(
!
(
await
this
.
waitForLogin
()))
{
return
commands
.
executeCommand
(
'
azure-account.askForLogin
'
);
}
const
azureConfig
=
workspace
.
getConfiguration
(
'
azure
'
);
let
resourceFilter
=
azureConfig
.
get
<
string
[]
>
(
'
resourceFilter
'
)
||
[];
const
filters
=
resourceFilter
.
length
?
this
.
api
.
filters
.
reduce
((
list
,
filter
)
=>
{
if
(
filter
.
allResourceGroups
)
{
list
.
push
(
filter
);
}
else
{
list
.
push
(...
filter
.
resourceGroups
.
map
(
resourceGroup
=>
({
...
filter
,
resourceGroups
:
[
resourceGroup
]
})));
}
return
list
;
},
<
AzureResourceFilter
[]
>
[])
:
[];
filters
.
sort
((
a
,
b
)
=>
(
!
a
.
allResourceGroups
?
a
.
resourceGroups
[
0
].
name
!
:
`/
${
a
.
subscription
.
displayName
}
`
).
localeCompare
(
!
b
.
allResourceGroups
?
b
.
resourceGroups
[
0
].
name
!
:
`/
${
b
.
subscription
.
displayName
}
`
));
const
filterResult
=
await
window
.
showQuickPick
(
filters
.
map
(
filter
=>
(
!
filter
.
allResourceGroups
?
{
label
:
filter
.
resourceGroups
[
0
].
name
!
,
description
:
filter
.
subscription
.
displayName
!
,
filter
}
:
{
label
:
filter
.
subscription
.
displayName
!
,
description
:
filter
.
subscription
.
subscriptionId
!
,
filter
})));
if
(
!
filterResult
)
{
return
;
}
const
filter
=
filterResult
.
filter
;
const
remove
=
!
filter
.
allResourceGroups
?
`
${
filter
.
session
.
tenantId
}
/
${
filter
.
subscription
.
subscriptionId
}
/
${
filter
.
resourceGroups
[
0
].
name
}
`
:
`
${
filter
.
session
.
tenantId
}
/
${
filter
.
subscription
.
subscriptionId
}
`
;
resourceFilter
=
resourceFilter
.
filter
(
e
=>
e
!==
remove
);
private
async
updateConfiguration
(
azureConfig
:
WorkspaceConfiguration
,
resourceFilter
:
string
[])
{
const
resourceFilterConfig
=
azureConfig
.
inspect
<
string
[]
>
(
'
resourceFilter
'
);
let
target
=
ConfigurationTarget
.
Global
;
if
(
resourceFilterConfig
)
{
...
...
@@ -334,14 +274,11 @@ export class AzureLoginHelper {
resourceFilter
=
[];
}
const
filters
=
resourceFilter
&&
resourceFilter
.
map
(
s
=>
typeof
s
===
'
string
'
?
s
.
split
(
'
/
'
)
:
[])
.
filter
(
s
=>
s
.
length
===
2
||
s
.
length
===
3
)
.
map
(([
tenantId
,
subscriptionId
,
resourceGroup
])
=>
({
tenantId
,
subscriptionId
,
resourceGroup
}));
const
tenantIds
=
filters
&&
filters
.
reduce
<
Record
<
string
,
Record
<
string
,
Record
<
string
,
boolean
>
|
boolean
>>>
((
result
,
filter
)
=>
{
.
filter
(
s
=>
s
.
length
===
2
)
.
map
(([
tenantId
,
subscriptionId
])
=>
({
tenantId
,
subscriptionId
}));
const
tenantIds
=
filters
&&
filters
.
reduce
<
Record
<
string
,
Record
<
string
,
boolean
>>>
((
result
,
filter
)
=>
{
const
tenant
=
result
[
filter
.
tenantId
]
||
(
result
[
filter
.
tenantId
]
=
{});
const
resourceGroups
=
tenant
[
filter
.
subscriptionId
]
||
(
tenant
[
filter
.
subscriptionId
]
=
(
filter
.
resourceGroup
?
{}
:
true
));
if
(
typeof
resourceGroups
===
'
object
'
&&
filter
.
resourceGroup
)
{
resourceGroups
[
filter
.
resourceGroup
]
=
true
;
}
tenant
[
filter
.
subscriptionId
]
=
true
;
return
result
;
},
{});
...
...
@@ -353,12 +290,7 @@ export class AzureLoginHelper {
const
subscriptions
=
await
listAll
(
client
.
subscriptions
,
client
.
subscriptions
.
list
());
const
filteredSubscriptions
=
subscriptionIds
?
subscriptions
.
filter
(
subscription
=>
subscriptionIds
[
subscription
.
subscriptionId
!
])
:
subscriptions
;
for
(
const
subscription
of
filteredSubscriptions
)
{
const
client
=
new
ResourceManagementClient
(
session
.
credentials
,
subscription
.
subscriptionId
!
);
const
resourceGroupNames
=
subscriptionIds
&&
subscriptionIds
[
subscription
.
subscriptionId
!
];
const
allResourceGroups
=
!
(
resourceGroupNames
&&
typeof
resourceGroupNames
===
'
object
'
);
const
unfilteredResourceGroups
=
await
listAll
(
client
.
resourceGroups
,
client
.
resourceGroups
.
list
());
const
resourceGroups
=
allResourceGroups
?
unfilteredResourceGroups
:
unfilteredResourceGroups
.
filter
(
resourceGroup
=>
(
<
Record
<
string
,
boolean
>>
resourceGroupNames
!
)[
resourceGroup
.
name
!
]);
newFilters
.
push
({
session
,
subscription
,
allResourceGroups
,
resourceGroups
});
newFilters
.
push
({
session
,
subscription
});
}
}
this
.
api
.
filters
.
splice
(
0
,
this
.
api
.
filters
.
length
,
...
newFilters
);
...
...
extensions/azure-account/src/extension.ts
浏览文件 @
61ff2d55
...
...
@@ -35,8 +35,10 @@ function createStatusBarItem(api: AzureAccount) {
statusBarItem
.
show
();
break
;
case
'
LoggedIn
'
:
statusBarItem
.
text
=
localize
(
'
azure-account.loggedIn
'
,
"
Azure: {0}
"
,
api
.
sessions
[
0
].
userId
);
statusBarItem
.
show
();
if
(
api
.
sessions
.
length
)
{
statusBarItem
.
text
=
localize
(
'
azure-account.loggedIn
'
,
"
Azure: {0}
"
,
api
.
sessions
[
0
].
userId
);
statusBarItem
.
show
();
}
break
;
default
:
statusBarItem
.
hide
();
...
...
extensions/azure-account/src/typings/azure-account.api.d.ts
浏览文件 @
61ff2d55
...
...
@@ -6,7 +6,7 @@
import
{
Event
}
from
'
vscode
'
;
import
{
ServiceClientCredentials
}
from
'
ms-rest
'
;
import
{
AzureEnvironment
}
from
'
ms-rest-azure
'
;
import
{
SubscriptionModels
,
ResourceModels
}
from
'
azure-arm-resource
'
;
import
{
SubscriptionModels
}
from
'
azure-arm-resource
'
;
export
type
AzureLoginStatus
=
'
Initializing
'
|
'
LoggingIn
'
|
'
LoggedIn
'
|
'
LoggedOut
'
;
...
...
@@ -30,8 +30,6 @@ export interface AzureSession {
export
interface
AzureResourceFilter
{
readonly
session
:
AzureSession
;
readonly
subscription
:
SubscriptionModels
.
Subscription
;
readonly
allResourceGroups
:
boolean
;
readonly
resourceGroups
:
ResourceModels
.
ResourceGroup
[];
}
export
interface
Credentials
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录