11/**
22 * @license
3- * Copyright (c) 2021, 2023 , Oracle and/or its affiliates.
3+ * Copyright (c) 2021, 2024 , Oracle and/or its affiliates.
44 * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55 */
66const CredentialEncryptor = require ( './credentialEncryptor' ) ;
@@ -9,7 +9,6 @@ const { getLogger } = require('./wktLogging');
99
1010const DECRYPTION_FAILED_STRING = 'Unsupported state or unable to authenticate data' ;
1111
12- /* global Buffer */
1312class CredentialManager {
1413 constructor ( credentialStorePolicy ) {
1514 this . credentialStorePolicy = credentialStorePolicy ;
@@ -57,63 +56,17 @@ class CredentialManager {
5756 refObj . reference = { } ;
5857 }
5958 const cipherText = refObj . reference [ refObj . field ] ;
60- refObj . reference [ refObj . field ] = await this . manager . loadCredential ( jsonPath , cipherText ) ;
59+ if ( cipherText ) {
60+ refObj . reference [ refObj . field ] = await this . manager . loadCredential ( jsonPath , cipherText ) ;
61+ } else {
62+ logger . debug ( 'Failed to load credential from %s so skipping it' , jsonPath ) ;
63+ }
6164 }
6265 }
6366 return Promise . resolve ( loadedProject ) ;
6467 }
6568}
6669
67- class CredentialStoreManager extends CredentialManager {
68- constructor ( projectGuid ) {
69- super ( 'native' ) ;
70- const CredentialStore = require ( './credentialStore' ) ;
71-
72- this . projectGuid = projectGuid ;
73- this . credentialStore = new CredentialStore ( ) ;
74- super . credentialManager = this ;
75- }
76-
77- get credentialStoreType ( ) {
78- return super . credentialStoreType ;
79- }
80-
81- async storeCredentials ( project ) {
82- return super . storeCredentials ( project ) ;
83- }
84-
85- async loadCredentials ( project ) {
86- return super . loadCredentials ( project ) ;
87- }
88-
89- async storeCredential ( jsonPath , clearText ) {
90- return new Promise ( ( resolve , reject ) => {
91- if ( clearText ) {
92- this . credentialStore . storeCredential ( this . _getCredentialName ( jsonPath ) , clearText )
93- . then ( ( ) => resolve ( ) )
94- . catch ( err => reject ( new Error ( `Failed to save credential for ${ jsonPath } : ${ err } ` ) ) ) ;
95- } else {
96- this . credentialStore . deleteCredential ( this . _getCredentialName ( jsonPath ) )
97- . then ( ( ) => resolve ( ) )
98- . catch ( err => reject ( new Error ( `Failed to delete empty credential for ${ jsonPath } : ${ err } ` ) ) ) ;
99- }
100- } ) ;
101- }
102-
103- // eslint-disable-next-line no-unused-vars
104- async loadCredential ( jsonPath , cipherText ) {
105- return new Promise ( ( resolve , reject ) => {
106- this . credentialStore . getCredential ( this . _getCredentialName ( jsonPath ) )
107- . then ( clearText => resolve ( clearText ) )
108- . catch ( err => reject ( new Error ( `Failed to load credential for ${ jsonPath } : ${ err } ` ) ) ) ;
109- } ) ;
110- }
111-
112- _getCredentialName ( jsonPath ) {
113- return Buffer . from ( `${ this . projectGuid } :${ jsonPath } ` , 'utf8' ) . toString ( 'base64' ) ;
114- }
115- }
116-
11770class EncryptedCredentialManager extends CredentialManager {
11871 static BAD_PASSPHRASE_KEY = 'Incorrect passphrase' ;
11972
@@ -199,6 +152,5 @@ class CredentialNoStoreManager extends CredentialManager {
199152
200153module . exports = {
201154 CredentialNoStoreManager,
202- CredentialStoreManager,
203155 EncryptedCredentialManager
204156} ;
0 commit comments