in server/aws-lsp-identity/src/language-server/profiles/profileService.ts [86:156]
async updateProfile(params: UpdateProfileParams, token?: CancellationToken): Promise<UpdateProfileResult> {
// Currently only supports non-legacy SSO profiles with sso-sessions
const result: UpdateProfileResult = {}
const options = { ...updateProfileOptionsDefaults, ...params.options }
// Validate params, this will change as more profile kinds are added
// Validate profile
this.throwOnInvalidProfile(!params.profile, 'Profile required.')
const profile = params.profile!
this.throwOnInvalidProfile(
!profile.kinds.includes(ProfileKind.SsoTokenProfile),
'Profile must be non-legacy sso-session type.'
)
this.throwOnInvalidProfile(!profile.name, 'Profile name required.')
this.throwOnInvalidProfile(!profile.settings, 'Settings required on profile.')
const profileSettings = profile.settings!
this.throwOnInvalidProfile(!profileSettings.sso_session, 'Sso-session name required on profile.')
// Validate sso-session
this.throwOnInvalidSsoSession(!params.ssoSession, 'Sso-session required.')
const ssoSession: SsoSession = params.ssoSession!
this.throwOnInvalidSsoSession(!ssoSession.name, 'Sso-session name required.')
this.throwOnInvalidSsoSession(!ssoSession.settings, 'Settings required on sso-session.')
const ssoSessionSettings = ssoSession.settings!
this.throwOnInvalidSsoSession(!ssoSessionSettings.sso_region, 'Sso-session region required.')
this.throwOnInvalidSsoSession(!ssoSessionSettings.sso_start_url, 'Sso-session start URL required.')
this.throwOnInvalidProfile(
profileSettings.sso_session !== ssoSession.name,
'Profile sso-session name must be the same as provided sso-session.'
)
const { profiles, ssoSessions } = await this.profileStore.load().catch(reason => {
throw AwsError.wrap(reason, AwsErrorCodes.E_CANNOT_READ_SHARED_CONFIG)
})
// Enforce options
if (!options.createNonexistentProfile && !profiles.some(p => p.name === profile.name)) {
this.observability.logging.log(`Cannot create profile. options: ${JSON.stringify(options)}`)
throw new AwsError('Cannot create profile.', AwsErrorCodes.E_CANNOT_CREATE_PROFILE)
}
if (!options.createNonexistentSsoSession && !ssoSessions.some(s => s.name === ssoSession.name)) {
this.observability.logging.log(`Cannot create sso-session. options: ${JSON.stringify(options)}`)
throw new AwsError('Cannot create sso-session.', AwsErrorCodes.E_CANNOT_CREATE_SSO_SESSION)
}
if (
!options.updateSharedSsoSession &&
this.isSharedSsoSession(ssoSession.name, profiles, profile.name) &&
this.willUpdateExistingSsoSession(ssoSession, ssoSessions)
) {
this.observability.logging.log(`Cannot update shared sso-session. options: ${JSON.stringify(options)}`)
throw new AwsError('Cannot update shared sso-session.', AwsErrorCodes.E_CANNOT_OVERWRITE_SSO_SESSION)
}
await this.profileStore
.save({
profiles: [params.profile],
ssoSessions: params.ssoSession ? [params.ssoSession] : [],
})
.catch(reason => {
throw AwsError.wrap(reason, AwsErrorCodes.E_CANNOT_WRITE_SHARED_CONFIG)
})
return result
}