@@ -29,9 +29,9 @@ export class ProfileManager implements IProfileManager {
29
29
* @param {string } profileName profile to look up
30
30
* @returns {string } returns the activation to be performed
31
31
*/
32
- public async getActivationMode ( profileName : string , tenantId : string ) : Promise < string > {
32
+ public async getActivationMode ( profileName : string , tenantId : string ) : Promise < string | null > {
33
33
const profile = await this . getAmtProfile ( profileName , tenantId )
34
- let activation : string
34
+ let activation : string | null = null
35
35
36
36
if ( profile ?. activation ) {
37
37
this . logger . debug ( `found activation for profile ${ profileName } ` )
@@ -48,15 +48,19 @@ export class ProfileManager implements IProfileManager {
48
48
* @param {string } profile of cira config
49
49
* @returns {string } returns the config for CIRA for a given profile
50
50
*/
51
- public async getCiraConfiguration ( profileName : string , tenantId : string ) : Promise < CIRAConfig > {
51
+ public async getCiraConfiguration ( profileName : string | null , tenantId : string ) : Promise < CIRAConfig | null > {
52
52
const profile = await this . getAmtProfile ( profileName , tenantId )
53
- let ciraConfig : CIRAConfig
53
+ let ciraConfig : CIRAConfig | null = null
54
54
55
- if ( profile ?. ciraConfigName && profile . ciraConfigObject ) {
56
- this . logger . debug ( `found CIRAConfigObject for profile: ${ profile . profileName } ` )
57
- ciraConfig = profile . ciraConfigObject
55
+ if ( profile ) {
56
+ if ( profile . ciraConfigName && profile . ciraConfigObject ) {
57
+ this . logger . debug ( `found CIRAConfigObject for profile: ${ profile . profileName } ` )
58
+ ciraConfig = profile . ciraConfigObject
59
+ } else {
60
+ this . logger . debug ( `unable to find CIRAConfig for profile ${ profile . profileName } ` )
61
+ }
58
62
} else {
59
- this . logger . debug ( `unable to find CIRAConfig for profile ${ profile . profileName } ` )
63
+ this . logger . debug ( `unable to find CIRAConfig for profile ${ profileName } ` )
60
64
}
61
65
62
66
return ciraConfig
@@ -67,9 +71,9 @@ export class ProfileManager implements IProfileManager {
67
71
* @param {string } profileName profile name of amt password
68
72
* @returns {string } returns the amt password for a given profile
69
73
*/
70
- public async getAmtPassword ( profileName : string , tenantId : string ) : Promise < string > {
71
- const profile : AMTConfiguration = await this . getAmtProfile ( profileName , tenantId )
72
- let amtPassword : string
74
+ public async getAmtPassword ( profileName : string , tenantId : string ) : Promise < string | null > {
75
+ const profile : AMTConfiguration | null = await this . getAmtProfile ( profileName , tenantId )
76
+ let amtPassword : string | null = null
73
77
if ( profile ) {
74
78
if ( profile . generateRandomPassword ) {
75
79
amtPassword = PasswordHelper . generateRandomPassword ( )
@@ -82,27 +86,30 @@ export class ProfileManager implements IProfileManager {
82
86
} else if ( this . secretsManager ) {
83
87
amtPassword = await this . secretsManager . getSecretFromKey ( `profiles/${ profileName } ` , 'AMT_PASSWORD' )
84
88
} else {
85
- amtPassword = profile . amtPassword
89
+ if ( profile . amtPassword ) {
90
+ amtPassword = profile . amtPassword
91
+ }
86
92
}
87
- this . logger . debug ( `found amtPassword for profile ${ profileName } ` )
88
93
if ( ! amtPassword ) {
89
94
this . logger . error ( 'password cannot be blank' )
90
95
throw new Error ( 'password cannot be blank' )
91
96
}
97
+ this . logger . debug ( `found amtPassword for profile ${ profileName } ` )
92
98
return amtPassword
93
99
} else {
94
100
this . logger . error ( `unable to find amtPassword for profile ${ profileName } ` )
95
101
}
102
+ return null
96
103
}
97
104
98
105
/**
99
106
* @description Retrieves the amt password set in the configuration or generates a nonstatic password
100
107
* @param {string } profileName profile name of amt password
101
108
* @returns {string } returns the amt password for a given profile
102
109
*/
103
- public async getMEBxPassword ( profileName : string , tenantId : string ) : Promise < string > {
104
- const profile : AMTConfiguration = await this . getAmtProfile ( profileName , tenantId )
105
- let mebxPassword : string
110
+ public async getMEBxPassword ( profileName : string , tenantId : string ) : Promise < string | null > {
111
+ const profile : AMTConfiguration | null = await this . getAmtProfile ( profileName , tenantId )
112
+ let mebxPassword : string | null = null
106
113
if ( profile ) {
107
114
if ( profile . generateRandomMEBxPassword ) {
108
115
mebxPassword = PasswordHelper . generateRandomPassword ( )
@@ -115,18 +122,20 @@ export class ProfileManager implements IProfileManager {
115
122
} else if ( this . secretsManager ) {
116
123
mebxPassword = await this . secretsManager . getSecretFromKey ( `profiles/${ profileName } ` , 'MEBX_PASSWORD' )
117
124
} else {
118
- mebxPassword = profile . mebxPassword
125
+ if ( profile . mebxPassword ) {
126
+ mebxPassword = profile . mebxPassword
127
+ }
119
128
}
120
-
121
- this . logger . debug ( `found amtPassword for profile ${ profileName } ` )
122
129
if ( ! mebxPassword ) {
123
130
this . logger . error ( 'mebx password cannot be blank' )
124
131
throw new Error ( 'mebx password cannot be blank' )
125
132
}
133
+ this . logger . debug ( `found amtPassword for profile ${ profileName } ` )
126
134
return mebxPassword
127
135
} else {
128
136
this . logger . error ( `unable to find mebxPassword for profile ${ profileName } ` )
129
137
}
138
+ return null
130
139
}
131
140
132
141
/**
@@ -136,8 +145,8 @@ export class ProfileManager implements IProfileManager {
136
145
* @returns {string } returns the MPS password for a given profile
137
146
*/
138
147
public async getMPSPassword ( profileName : string , tenantId : string ) : Promise < string > {
139
- const profile : AMTConfiguration = await this . getAmtProfile ( profileName , tenantId )
140
- let mpsPassword : string
148
+ const profile : AMTConfiguration | null = await this . getAmtProfile ( profileName , tenantId )
149
+ let mpsPassword : string | null = null
141
150
142
151
if ( profile ?. ciraConfigObject ) {
143
152
mpsPassword = PasswordHelper . generateRandomPassword ( )
@@ -164,14 +173,17 @@ export class ProfileManager implements IProfileManager {
164
173
* @param {string } profile
165
174
* @returns {AMTConfiguration } returns AMTConfig object if profile exists otherwise null.
166
175
*/
167
- public async getAmtProfile ( profile : string , tenantId : string ) : Promise < AMTConfiguration > {
176
+ public async getAmtProfile ( profile : string | null , tenantId : string ) : Promise < AMTConfiguration | null > {
168
177
try {
169
178
if ( ! profile ) {
170
179
return null
171
180
}
172
- const amtProfile : AMTConfiguration = await this . amtConfigurations . getByName ( profile , tenantId )
181
+ const amtProfile : AMTConfiguration | null = await this . amtConfigurations . getByName ( profile , tenantId )
182
+ if ( ! amtProfile ) {
183
+ return null
184
+ }
173
185
// If the CIRA Config associated with profile, retrieves from DB
174
- if ( amtProfile ? .ciraConfigName != null ) {
186
+ if ( amtProfile . ciraConfigName != null ) {
175
187
amtProfile . ciraConfigObject = await this . amtConfigurations . getCiraConfigForProfile ( amtProfile . ciraConfigName , tenantId )
176
188
}
177
189
// If the TLS Config associated with profile, retrieves from DB
@@ -182,7 +194,7 @@ export class ProfileManager implements IProfileManager {
182
194
}
183
195
}
184
196
// If the CIRA Config associated with profile, retrieves from DB
185
- if ( amtProfile ? .ieee8021xProfileName != null ) {
197
+ if ( amtProfile . ieee8021xProfileName != null ) {
186
198
amtProfile . ieee8021xProfileObject = await this . amtConfigurations . get8021XConfigForProfile ( amtProfile . ieee8021xProfileName , tenantId )
187
199
}
188
200
this . logger . debug ( `AMT Profile returned from db: ${ amtProfile ?. profileName } ` )
0 commit comments