Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move auth to http module (#6502)
- Loading branch information
Showing
4 changed files
with
37 additions
and
42 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import got from 'got'; | ||
import auth from './auth'; | ||
import { mergeInstances } from './util'; | ||
import { create, mergeInstances } from './util'; | ||
|
||
export * from './common'; | ||
|
||
/* | ||
* This is the default got instance for Renovate. | ||
* - Cache all GET requests for the lifetime of the repo | ||
* | ||
*/ | ||
export const api = mergeInstances(got, auth); | ||
const dummy = create({ | ||
options: {}, | ||
handler: (options, next) => { | ||
return next(options); | ||
}, | ||
}); | ||
|
||
export const api = mergeInstances(got, dummy); | ||
|
||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
PLATFORM_TYPE_GITEA, | ||
PLATFORM_TYPE_GITHUB, | ||
PLATFORM_TYPE_GITLAB, | ||
} from '../../constants/platforms'; | ||
|
||
export function applyAuthorization(inOptions: any): any { | ||
const options = { ...inOptions }; | ||
if (options.auth || options.headers?.authorization) { | ||
return options; | ||
} | ||
if (options.token) { | ||
if ( | ||
options.hostType === PLATFORM_TYPE_GITHUB || | ||
options.hostType === PLATFORM_TYPE_GITEA | ||
) { | ||
options.headers.authorization = `token ${options.token}`; | ||
} else if (options.hostType === PLATFORM_TYPE_GITLAB) { | ||
options.headers['Private-token'] = options.token; | ||
} else { | ||
options.headers.authorization = `Bearer ${options.token}`; | ||
} | ||
delete options.token; | ||
} | ||
return options; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters