mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2025-08-16 22:46:02 +08:00

* fixing audit failures * replacing lerna bootstrap with npm command * audit fix for cache and tool-cache * updating tunnel * upgrading core packages * re-adding tunnel as prod dep * updating dependencies * updating exec deps * updating exec io package * . * Revert * updating packages * adding core as dep * updating learna config * updating lerna commands * Removing audit failing packages in cache + tool-cache * updating contribution bootstrap description * updating libraries * prettier lint * hiding stricter rules * updating prettier command * Removing unknown flag * Adding eslint prettier * ignoring sym links * updating ignore path * updating prettier rules * changing prettier + github ver * updating ts and ignores * Revert ts * Adding unknown ignores * downgrading lerna * . * adding nx * Adding lint auto lint rules * updating eslint ignore for glob packages * Adding subdirs to ignore * adding flag for ignore pattern in linter * Expanding ignore regex * Adding ignore rules * adding another ignore pattern to tsconfig eslint * adding ignore pattern to eslintrc * syncing package-json * updating traverse * . * test adding core and http client to base package * running npm ci * adding tsconfig paths * adding base URL * Adding explicit path to core and http-client * editing tsc call * updating artifact packages * force build * updating lock file version * updating lock file version * upgrading node version * Adding babel traverse back * fixing build issue * fixing typescript ver * updating package json * Adding ignore for artifact test * adding ignore to flags * unlink after test completes * cleanup * merge + package edit
88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import * as http from 'http'
|
|
import * as ifm from './interfaces'
|
|
import {HttpClientResponse} from './index'
|
|
|
|
export class BasicCredentialHandler implements ifm.RequestHandler {
|
|
username: string
|
|
password: string
|
|
|
|
constructor(username: string, password: string) {
|
|
this.username = username
|
|
this.password = password
|
|
}
|
|
|
|
prepareRequest(options: http.RequestOptions): void {
|
|
if (!options.headers) {
|
|
throw Error('The request has no headers')
|
|
}
|
|
options.headers['Authorization'] = `Basic ${Buffer.from(
|
|
`${this.username}:${this.password}`
|
|
).toString('base64')}`
|
|
}
|
|
|
|
// This handler cannot handle 401
|
|
canHandleAuthentication(): boolean {
|
|
return false
|
|
}
|
|
|
|
async handleAuthentication(): Promise<HttpClientResponse> {
|
|
throw new Error('not implemented')
|
|
}
|
|
}
|
|
|
|
export class BearerCredentialHandler implements ifm.RequestHandler {
|
|
token: string
|
|
|
|
constructor(token: string) {
|
|
this.token = token
|
|
}
|
|
|
|
// currently implements pre-authorization
|
|
// TODO: support preAuth = false where it hooks on 401
|
|
prepareRequest(options: http.RequestOptions): void {
|
|
if (!options.headers) {
|
|
throw Error('The request has no headers')
|
|
}
|
|
options.headers['Authorization'] = `Bearer ${this.token}`
|
|
}
|
|
|
|
// This handler cannot handle 401
|
|
canHandleAuthentication(): boolean {
|
|
return false
|
|
}
|
|
|
|
async handleAuthentication(): Promise<HttpClientResponse> {
|
|
throw new Error('not implemented')
|
|
}
|
|
}
|
|
|
|
export class PersonalAccessTokenCredentialHandler
|
|
implements ifm.RequestHandler
|
|
{
|
|
token: string
|
|
|
|
constructor(token: string) {
|
|
this.token = token
|
|
}
|
|
|
|
// currently implements pre-authorization
|
|
// TODO: support preAuth = false where it hooks on 401
|
|
prepareRequest(options: http.RequestOptions): void {
|
|
if (!options.headers) {
|
|
throw Error('The request has no headers')
|
|
}
|
|
options.headers['Authorization'] = `Basic ${Buffer.from(
|
|
`PAT:${this.token}`
|
|
).toString('base64')}`
|
|
}
|
|
|
|
// This handler cannot handle 401
|
|
canHandleAuthentication(): boolean {
|
|
return false
|
|
}
|
|
|
|
async handleAuthentication(): Promise<HttpClientResponse> {
|
|
throw new Error('not implemented')
|
|
}
|
|
}
|