33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import * as nls from 'vscode-nls'
7- import { DefaultCloudWatchLogsClient } from '../../../shared/clients/cloudWatchLogsClient'
8- import { createBackButton , createExitButton , createHelpButton } from '../../../shared/ui/buttons'
9- import { createInputBox } from '../../../shared/ui/inputPrompter'
10- import { DataQuickPickItem } from '../../../shared/ui/pickerPrompter'
11- import { Wizard } from '../../../shared/wizards/wizard'
12- import { CloudWatchLogsGroupInfo } from '../registry/logDataRegistry'
13- import { RegionSubmenu , RegionSubmenuResponse } from '../../../shared/ui/common/regionSubmenu'
6+ import { TailLogGroupWizard } from '../wizard/tailLogGroupWizard'
7+ import { getLogger } from '../../../shared'
148import { CancellationError } from '../../../shared/utilities/timeoutUtils'
15- import { LogStreamFilterResponse , LogStreamFilterSubmenu } from '../liveTailLogStreamSubmenu'
16- import { getLogger , ToolkitError } from '../../../shared'
17- import { cwlFilterPatternHelpUrl } from '../../../shared/constants'
18-
19- const localize = nls . loadMessageBundle ( )
20-
21- export interface TailLogGroupWizardResponse {
22- regionLogGroupSubmenuResponse : RegionSubmenuResponse < string >
23- logStreamFilter : LogStreamFilterResponse
24- filterPattern : string
25- }
269
2710export async function tailLogGroup ( logData ?: { regionName : string ; groupName : string } ) : Promise < void > {
2811 const wizard = new TailLogGroupWizard ( logData )
@@ -34,75 +17,3 @@ export async function tailLogGroup(logData?: { regionName: string; groupName: st
3417 //TODO: Remove Log. For testing while we aren't yet consuming the wizardResponse.
3518 getLogger ( ) . info ( JSON . stringify ( wizardResponse ) )
3619}
37-
38- export class TailLogGroupWizard extends Wizard < TailLogGroupWizardResponse > {
39- public constructor ( logGroupInfo ?: CloudWatchLogsGroupInfo ) {
40- super ( {
41- initState : {
42- regionLogGroupSubmenuResponse : logGroupInfo
43- ? {
44- data : logGroupInfo . groupName ,
45- region : logGroupInfo . regionName ,
46- }
47- : undefined ,
48- } ,
49- } )
50- this . form . regionLogGroupSubmenuResponse . bindPrompter ( createRegionLogGroupSubmenu )
51- this . form . logStreamFilter . bindPrompter ( ( state ) => {
52- if ( ! state . regionLogGroupSubmenuResponse ?. data ) {
53- throw new ToolkitError ( 'LogGroupName is null' )
54- }
55- return new LogStreamFilterSubmenu (
56- state . regionLogGroupSubmenuResponse . data ,
57- state . regionLogGroupSubmenuResponse . region
58- )
59- } )
60- this . form . filterPattern . bindPrompter ( ( state ) => createFilterPatternPrompter ( ) )
61- }
62- }
63-
64- export function createRegionLogGroupSubmenu ( ) : RegionSubmenu < string > {
65- return new RegionSubmenu (
66- getLogGroupQuickPickOptions ,
67- {
68- title : localize ( 'AWS.cwl.tailLogGroup.logGroupPromptTitle' , 'Select Log Group to tail' ) ,
69- buttons : [ createExitButton ( ) ] ,
70- } ,
71- { title : localize ( 'AWS.cwl.tailLogGroup.regionPromptTitle' , 'Select Region for Log Group' ) } ,
72- 'LogGroups'
73- )
74- }
75-
76- async function getLogGroupQuickPickOptions ( regionCode : string ) : Promise < DataQuickPickItem < string > [ ] > {
77- const client = new DefaultCloudWatchLogsClient ( regionCode )
78- const logGroups = client . describeLogGroups ( )
79-
80- const logGroupsOptions : DataQuickPickItem < string > [ ] = [ ]
81-
82- for await ( const logGroupObject of logGroups ) {
83- if ( ! logGroupObject . arn || ! logGroupObject . logGroupName ) {
84- throw new ToolkitError ( 'LogGroupObject name or arn undefined' )
85- }
86-
87- logGroupsOptions . push ( {
88- label : logGroupObject . logGroupName ,
89- data : formatLogGroupArn ( logGroupObject . arn ) ,
90- } )
91- }
92-
93- return logGroupsOptions
94- }
95-
96- function formatLogGroupArn ( logGroupArn : string ) : string {
97- return logGroupArn . endsWith ( ':*' ) ? logGroupArn . substring ( 0 , logGroupArn . length - 2 ) : logGroupArn
98- }
99-
100- export function createFilterPatternPrompter ( ) {
101- const helpUri = cwlFilterPatternHelpUrl
102- return createInputBox ( {
103- title : 'Provide log event filter pattern' ,
104- placeholder : 'filter pattern (case sensitive; empty matches all)' ,
105- prompt : 'Optional pattern to use to filter the results to include only log events that match the pattern.' ,
106- buttons : [ createHelpButton ( helpUri ) , createBackButton ( ) , createExitButton ( ) ] ,
107- } )
108- }
0 commit comments