GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — rules_python/python/private/auth.bzl at main · kcon-stackav/rules_python Expand file tree/ Copy pathauth.bzlMore file actions 106 lines (86 loc) · 4.06 KB / Copy pathauth.bzlFile metadata and controls106 lines (86 loc) · 4.06 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 # Copyright 2022 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Helpers copied from http_file source to be reused here. The implementation below is copied directly from Bazel's implementation of `http_archive`. Accordingly, the return value of this function should be used identically as the `auth` parameter of `http_archive`. Reference: https://github.com/bazelbuild/bazel/blob/6.3.2/tools/build_defs/repo/http.bzl#L109 The helpers were further modified to support module_ctx. """ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_netrc", "read_user_netrc", "use_netrc") # Copied from https://sourcegraph.com/github.com/bazelbuild/bazel@26c6add3f9809611ad3795bce1e5c0fb37902902/-/blob/tools/build_defs/repo/http.bzl _AUTH_PATTERN_DOC = """An optional dict mapping host names to custom authorization patterns. If a URL's host name is present in this dict the value will be used as a pattern when generating the authorization header for the http request. This enables the use of custom authorization schemes used in a lot of common cloud storage providers. The pattern currently supports 2 tokens: <code><login></code> and <code><password></code>, which are replaced with their equivalent value in the netrc file for the same host name. After formatting, the result is set as the value for the <code>Authorization</code> field of the HTTP request. Example attribute and netrc for a http download to an oauth2 enabled API using a bearer token: <pre> auth_patterns = { "storage.cloudprovider.com": "Bearer <password>" } </pre> netrc: <pre> machine storage.cloudprovider.com password RANDOM-TOKEN </pre> The final HTTP request would have the following header: <pre> Authorization: Bearer RANDOM-TOKEN </pre> """ # AUTH_ATTRS are used within whl_library and pip bzlmod extension. AUTH_ATTRS = { "auth_patterns": attr.string_dict( doc = _AUTH_PATTERN_DOC, ), "netrc": attr.string( doc = "Location of the .netrc file to use for authentication", ), } def get_auth(ctx, urls, ctx_attr = None): """Utility for retrieving netrc-based authentication parameters for repository download rules used in python_repository. Args: ctx(repository_ctx or module_ctx): The extension module_ctx or repository rule's repository_ctx object. urls: A list of URLs from which assets will be downloaded. ctx_attr(struct): The attributes to get the netrc from. When ctx is repository_ctx, then we will attempt to use repository_ctx.attr if this is not specified, otherwise we will use the specified field. The module_ctx attributes are located in the tag classes so it cannot be retrieved from the context. Returns: dict: A map of authentication parameters by URL. """ # module_ctx does not have attributes, as they are stored in tag classes. Whilst # the correct behaviour should be to pass the `attr` to the ctx_attr = ctx_attr or getattr(ctx, "attr", None) ctx_attr = struct( netrc = getattr(ctx_attr, "netrc", None), auth_patterns = getattr(ctx_attr, "auth_patterns", ""), ) if ctx_attr.netrc: netrc = read_netrc(ctx, ctx_attr.netrc) elif "NETRC" in ctx.os.environ: # This can be used on newer bazel versions if hasattr(ctx, "getenv"): netrc = read_netrc(ctx, ctx.getenv("NETRC")) else: netrc = read_netrc(ctx, ctx.os.environ["NETRC"]) else: netrc = read_user_netrc(ctx) return use_netrc(netrc, urls, ctx_attr.auth_patterns) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |