call-credentials.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Metadata } from './metadata';
  2. export interface CallMetadataOptions {
  3. method_name: string;
  4. service_url: string;
  5. }
  6. export type CallMetadataGenerator = (options: CallMetadataOptions, cb: (err: Error | null, metadata?: Metadata) => void) => void;
  7. export interface OldOAuth2Client {
  8. getRequestMetadata: (url: string, callback: (err: Error | null, headers?: {
  9. [index: string]: string;
  10. }) => void) => void;
  11. }
  12. export interface CurrentOAuth2Client {
  13. getRequestHeaders: (url?: string) => Promise<{
  14. [index: string]: string;
  15. }>;
  16. }
  17. export type OAuth2Client = OldOAuth2Client | CurrentOAuth2Client;
  18. /**
  19. * A class that represents a generic method of adding authentication-related
  20. * metadata on a per-request basis.
  21. */
  22. export declare abstract class CallCredentials {
  23. /**
  24. * Asynchronously generates a new Metadata object.
  25. * @param options Options used in generating the Metadata object.
  26. */
  27. abstract generateMetadata(options: CallMetadataOptions): Promise<Metadata>;
  28. /**
  29. * Creates a new CallCredentials object from properties of both this and
  30. * another CallCredentials object. This object's metadata generator will be
  31. * called first.
  32. * @param callCredentials The other CallCredentials object.
  33. */
  34. abstract compose(callCredentials: CallCredentials): CallCredentials;
  35. /**
  36. * Check whether two call credentials objects are equal. Separate
  37. * SingleCallCredentials with identical metadata generator functions are
  38. * equal.
  39. * @param other The other CallCredentials object to compare with.
  40. */
  41. abstract _equals(other: CallCredentials): boolean;
  42. /**
  43. * Creates a new CallCredentials object from a given function that generates
  44. * Metadata objects.
  45. * @param metadataGenerator A function that accepts a set of options, and
  46. * generates a Metadata object based on these options, which is passed back
  47. * to the caller via a supplied (err, metadata) callback.
  48. */
  49. static createFromMetadataGenerator(metadataGenerator: CallMetadataGenerator): CallCredentials;
  50. /**
  51. * Create a gRPC credential from a Google credential object.
  52. * @param googleCredentials The authentication client to use.
  53. * @return The resulting CallCredentials object.
  54. */
  55. static createFromGoogleCredential(googleCredentials: OAuth2Client): CallCredentials;
  56. static createEmpty(): CallCredentials;
  57. }