mirror of
				https://kkgithub.com/actions/setup-node.git
				synced 2025-11-01 03:01:53 +08:00 
			
		
		
		
	Add auth support (#21)
* Updates * Update * Update * Update * Update * Yarn sometimes prefers npmrc, so use same token * Description * Update readme * Feedback * Add type * new toolkit and scoped registries * npmrc in RUNNER_TEMP * Dont always auth * Try exporting blank token * Get auth working for now pending runner changes * Fix string interpolation for auth token. * Don't export both userconfigs * Update authutil.js * Add single quotes for authString * Fix the registry string. * Use userconfig and append trailing slash * Keep in root of repo * Try just adding auth token * Remove auth token * Try changes again * Add tests * Npm and GPR samples * Add types
This commit is contained in:
		
							
								
								
									
										88
									
								
								node_modules/@octokit/request/dist-src/fetch-wrapper.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								node_modules/@octokit/request/dist-src/fetch-wrapper.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,88 @@ | ||||
| import isPlainObject from "is-plain-object"; | ||||
| import nodeFetch from "node-fetch"; | ||||
| import { RequestError } from "@octokit/request-error"; | ||||
| import getBuffer from "./get-buffer-response"; | ||||
| export default function fetchWrapper(requestOptions) { | ||||
|     if (isPlainObject(requestOptions.body) || | ||||
|         Array.isArray(requestOptions.body)) { | ||||
|         requestOptions.body = JSON.stringify(requestOptions.body); | ||||
|     } | ||||
|     let headers = {}; | ||||
|     let status; | ||||
|     let url; | ||||
|     const fetch = (requestOptions.request && requestOptions.request.fetch) || nodeFetch; | ||||
|     return fetch(requestOptions.url, Object.assign({ | ||||
|         method: requestOptions.method, | ||||
|         body: requestOptions.body, | ||||
|         headers: requestOptions.headers, | ||||
|         redirect: requestOptions.redirect | ||||
|     }, requestOptions.request)) | ||||
|         .then(response => { | ||||
|         url = response.url; | ||||
|         status = response.status; | ||||
|         for (const keyAndValue of response.headers) { | ||||
|             headers[keyAndValue[0]] = keyAndValue[1]; | ||||
|         } | ||||
|         if (status === 204 || status === 205) { | ||||
|             return; | ||||
|         } | ||||
|         // GitHub API returns 200 for HEAD requsets | ||||
|         if (requestOptions.method === "HEAD") { | ||||
|             if (status < 400) { | ||||
|                 return; | ||||
|             } | ||||
|             throw new RequestError(response.statusText, status, { | ||||
|                 headers, | ||||
|                 request: requestOptions | ||||
|             }); | ||||
|         } | ||||
|         if (status === 304) { | ||||
|             throw new RequestError("Not modified", status, { | ||||
|                 headers, | ||||
|                 request: requestOptions | ||||
|             }); | ||||
|         } | ||||
|         if (status >= 400) { | ||||
|             return response | ||||
|                 .text() | ||||
|                 .then(message => { | ||||
|                 const error = new RequestError(message, status, { | ||||
|                     headers, | ||||
|                     request: requestOptions | ||||
|                 }); | ||||
|                 try { | ||||
|                     Object.assign(error, JSON.parse(error.message)); | ||||
|                 } | ||||
|                 catch (e) { | ||||
|                     // ignore, see octokit/rest.js#684 | ||||
|                 } | ||||
|                 throw error; | ||||
|             }); | ||||
|         } | ||||
|         const contentType = response.headers.get("content-type"); | ||||
|         if (/application\/json/.test(contentType)) { | ||||
|             return response.json(); | ||||
|         } | ||||
|         if (!contentType || /^text\/|charset=utf-8$/.test(contentType)) { | ||||
|             return response.text(); | ||||
|         } | ||||
|         return getBuffer(response); | ||||
|     }) | ||||
|         .then(data => { | ||||
|         return { | ||||
|             status, | ||||
|             url, | ||||
|             headers, | ||||
|             data | ||||
|         }; | ||||
|     }) | ||||
|         .catch(error => { | ||||
|         if (error instanceof RequestError) { | ||||
|             throw error; | ||||
|         } | ||||
|         throw new RequestError(error.message, 500, { | ||||
|             headers, | ||||
|             request: requestOptions | ||||
|         }); | ||||
|     }); | ||||
| } | ||||
							
								
								
									
										3
									
								
								node_modules/@octokit/request/dist-src/get-buffer-response.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								node_modules/@octokit/request/dist-src/get-buffer-response.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| export default function getBufferResponse(response) { | ||||
|     return response.arrayBuffer(); | ||||
| } | ||||
							
								
								
									
										9
									
								
								node_modules/@octokit/request/dist-src/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								node_modules/@octokit/request/dist-src/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| import { endpoint } from "@octokit/endpoint"; | ||||
| import getUserAgent from "universal-user-agent"; | ||||
| import { VERSION } from "./version"; | ||||
| import withDefaults from "./with-defaults"; | ||||
| export const request = withDefaults(endpoint, { | ||||
|     headers: { | ||||
|         "user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}` | ||||
|     } | ||||
| }); | ||||
							
								
								
									
										0
									
								
								node_modules/@octokit/request/dist-src/types.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								node_modules/@octokit/request/dist-src/types.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								node_modules/@octokit/request/dist-src/version.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								node_modules/@octokit/request/dist-src/version.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| export const VERSION = "0.0.0-development"; | ||||
							
								
								
									
										22
									
								
								node_modules/@octokit/request/dist-src/with-defaults.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								node_modules/@octokit/request/dist-src/with-defaults.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| import fetchWrapper from "./fetch-wrapper"; | ||||
| export default function withDefaults(oldEndpoint, newDefaults) { | ||||
|     const endpoint = oldEndpoint.defaults(newDefaults); | ||||
|     const newApi = function (route, parameters) { | ||||
|         const endpointOptions = endpoint.merge(route, parameters); | ||||
|         if (!endpointOptions.request || !endpointOptions.request.hook) { | ||||
|             return fetchWrapper(endpoint.parse(endpointOptions)); | ||||
|         } | ||||
|         const request = (route, parameters) => { | ||||
|             return fetchWrapper(endpoint.parse(endpoint.merge(route, parameters))); | ||||
|         }; | ||||
|         Object.assign(request, { | ||||
|             endpoint, | ||||
|             defaults: withDefaults.bind(null, endpoint) | ||||
|         }); | ||||
|         return endpointOptions.request.hook(request, endpointOptions); | ||||
|     }; | ||||
|     return Object.assign(newApi, { | ||||
|         endpoint, | ||||
|         defaults: withDefaults.bind(null, endpoint) | ||||
|     }); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Danny McCormick
					Danny McCormick