8000 client-go/rest/url_utils.go at v0.34.1 · kubernetes/client-go · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"allShortcutsEnabled":false,"fileTree":{"rest":{"items":[{"name":"fake","path":"rest/fake","contentType":"directory"},{"name":"testdata","path":"rest/testdata","contentType":"directory"},{"name":"watch","path":"rest/watch","contentType":"directory"},{"name":".mockery.yaml","path":"rest/.mockery.yaml","contentType":"file"},{"name":"OWNERS","path":"rest/OWNERS","contentType":"file"},{"name":"client.go","path":"rest/client.go","contentType":"file"},{"name":"client_test.go","path":"rest/client_test.go","contentType":"file"},{"name":"config.go","path":"rest/config.go","contentType":"file"},{"name":"config_test.go","path":"rest/config_test.go","contentType":"file"},{"name":"connection_test.go","path":"rest/connection_test.go","contentType":"file"},{"name":"exec.go","path":"rest/exec.go","contentType":"file"},{"name":"exec_test.go","path":"rest/exec_test.go","contentType":"file"},{"name":"mock_backoff_manager_test.go","path":"rest/mock_backoff_manager_test.go","contentType":"file"},{"name":"plugin.go","path":"rest/plugin.go","contentType":"file"},{"name":"plugin_test.go","path":"rest/plugin_test.go","contentType":"file"},{"name":"request.go","path":"rest/request.go","contentType":"file"},{"name":"request_test.go","path":"rest/request_test.go","contentType":"file"},{"name":"transport.go","path":"rest/transport.go","contentType":"file"},{"name":"transport_test.go","path":"rest/transport_test.go","contentType":"file"},{"name":"url_utils.go","path":"rest/url_utils.go","contentType":"file"},{"name":"url_utils_test.go","path":"rest/url_utils_test.go","contentType":"file"},{"name":"urlbackoff.go","path":"rest/urlbackoff.go","contentType":"file"},{"name":"urlbackoff_test.go","path":"rest/urlbackoff_test.go","contentType":"file"},{"name":"warnings.go","path":"rest/warnings.go","contentType":"file"},{"name":"warnings_test.go","path":"rest/warnings_test.go","contentType":"file"},{"name":"with_retry.go","path":"rest/with_retry.go","contentType":"file"},{"name":"with_retry_test.go","path":"rest/with_retry_test.go","contentType":"file"},{"name":"zz_generated.deepcopy.go","path":"rest/zz_generated.deepcopy.go","contentType":"file"}],"totalCount":28},"":{"items":[{"name":".github","path":".github","contentType":"directory"},{"name":"applyconfigurations","path":"applyconfigurations","contentType":"directory"},{"name":"discovery","path":"discovery","contentType":"directory"},{"name":"dynamic","path":"dynamic","contentType":"directory"},{"name":"examples","path":"examples","contentType":"directory"},{"name":"features","path":"features","contentType":"directory"},{"name":"gentype","path":"gentype","contentType":"directory"},{"name":"informers","path":"informers","contentType":"directory"},{"name":"kubernetes","path":"kubernetes","contentType":"directory"},{"name":"kubernetes_test","path":"kubernetes_test","contentType":"directory"},{"name":"listers","path":"listers","contentType":"directory"},{"name":"metadata","path":"metadata","contentType":"directory"},{"name":"openapi","path":"openapi","contentType":"directory"},{"name":"openapi3","path":"openapi3","contentType":"directory"},{"name":"pkg","path":"pkg","contentType":"directory"},{"name":"plugin","path":"plugin","contentType":"directory"},{"name":"rest","path":"rest","contentType":"directory"},{"name":"restmapper","path":"restmapper","contentType":"directory"},{"name":"scale","path":"scale","contentType":"directory"},{"name":"testing","path":"testing","contentType":"directory"},{"name":"third_party","path":"third_party","contentType":"directory"},{"name":"tools","path":"tools","contentType":"directory"},{"name":"transport","path":"transport","contentType":"directory"},{"name":"util","path":"util","contentType":"directory"},{"name":"CHANGELOG.md","path":"CHANGELOG.md","contentType":"file"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","contentType":"file"},{"name":"INSTALL.md","path":"INSTALL.md","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"OWNERS","path":"OWNERS","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"SECURITY_CONTACTS","path":"SECURITY_CONTACTS","contentType":"file"},{"name":"code-of-conduct.md","path":"code-of-conduct.md","contentType":"file"},{"name":"doc.go","path":"doc.go","contentType":"file"},{"name":"go.mod","path":"go.mod","contentType":"file"},{"name":"go.sum","path":"go.sum","contentType":"file"}],"totalCount":35}},"fileTreeProcessingTime":39.926993,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":66509131,"defaultBranch":"master","name":"client-go","ownerLogin":"kubernetes","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2016-08-25T00:19:38.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/13629408?v=4","public":true,"private":false,"isOrgOwned":true},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"v0.34.1","listCacheKey":"v0:1759950348.0","canEdit":false,"refType":"tag","currentOid":"d033c497ffef47be9b4f81abde5c3d94dd78089a","canEditOnDefaultBranch":false,"fileExistsOnDefault":true},"path":"rest/url_utils.go","currentUser":null,"blob":{"rawLines":["/*","Copyright 2016 The Kubernetes Authors.","","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.","*/","","package rest","","import (","\t\"fmt\"","\t\"net/url\"","\t\"path\"","","\t\"k8s.io/apimachinery/pkg/runtime/schema\"",")","","// DefaultServerURL converts a host, host:port, or URL string to the default base server API path","// to use with a Client at a given API version following the standard conventions for a","// Kubernetes API.","func DefaultServerURL(host, apiPath string, groupVersion schema.GroupVersion, defaultTLS bool) (*url.URL, string, error) {","\tif host == \"\" {","\t\treturn nil, \"\", fmt.Errorf(\"host must be a URL or a host:port pair\")","\t}","\tbase := host","\thostURL, err := url.Parse(base)","\tif err != nil || hostURL.Scheme == \"\" || hostURL.Host == \"\" {","\t\tscheme := \"http://\"","\t\tif defaultTLS {","\t\t\tscheme = \"https://\"","\t\t}","\t\thostURL, err = url.Parse(scheme + base)","\t\tif err != nil {","\t\t\treturn nil, \"\", err","\t\t}","\t\tif hostURL.Path != \"\" \u0026\u0026 hostURL.Path != \"/\" {","\t\t\treturn nil, \"\", fmt.Errorf(\"host must be a URL or a host:port pair: %q\", base)","\t\t}","\t}","","\t// hostURL.Path is optional; a non-empty Path is treated as a prefix that is to be applied to","\t// all URIs used to access the host. this is useful when there's a proxy in front of the","\t// apiserver that has relocated the apiserver endpoints, forwarding all requests from, for","\t// example, /a/b/c to the apiserver. in this case the Path should be /a/b/c.","\t//","\t// if running without a frontend proxy (that changes the location of the apiserver), then","\t// hostURL.Path should be blank.","\t//","\t// versionedAPIPath, a path relative to baseURL.Path, points to a versioned API base","\tversionedAPIPath := DefaultVersionedAPIPath(apiPath, groupVersion)","","\treturn hostURL, versionedAPIPath, nil","}","","// DefaultVersionedAPIPath constructs the default path for the given group version, assuming the given","// API path, following the standard conventions of the Kubernetes API.","func DefaultVersionedAPIPath(apiPath string, groupVersion schema.GroupVersion) string {","\tversionedAPIPath := path.Join(\"/\", apiPath)","","\t// Add the version to the end of the path","\tif len(groupVersion.Group) \u003e 0 {","\t\tversionedAPIPath = path.Join(versionedAPIPath, groupVersion.Group, groupVersion.Version)","","\t} else {","\t\tversionedAPIPath = path.Join(versionedAPIPath, groupVersion.Version)","\t}","","\treturn versionedAPIPath","}","","// DefaultServerUrlFor is shared between IsConfigTransportTLS and RESTClientFor. It","// requires Host and Version to be set prior to being called.","func DefaultServerUrlFor(config *Config) (*url.URL, string, error) {","\t// TODO: move the default to secure when the apiserver supports TLS by default","\t// config.Insecure is taken to mean \"I want HTTPS but don't bother checking the certs against a CA.\"","\thasCA := len(config.CAFile) != 0 || len(config.CAData) != 0","\thasCert := len(config.CertFile) != 0 || len(config.CertData) != 0","\tdefaultTLS := hasCA || hasCert || config.Insecure","\thost := config.Host","\tif host == \"\" {","\t\thost = \"localhost\"","\t}","","\tif config.GroupVersion != nil {","\t\treturn DefaultServerURL(host, config.APIPath, *config.GroupVersion, defaultTLS)","\t}","\treturn DefaultServerURL(host, config.APIPath, schema.GroupVersion{}, defaultTLS)","}"],"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"copilotSWEAgentEnabled":false,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/kubernetes/client-go/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"url_utils.go","displayUrl":"https://github.com/kubernetes/client-go/blob/v0.34.1/rest/url_utils.go?raw=true","headerInfo":{"blobSize":"3.52 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":null,"isGitLfs":false,"onBranch":false,"shortPath":"0a0ab79","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fkubernetes%2Fclient-go%2Fblob%2Fv0.34.1%2Frest%2Furl_utils.go","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"97","truncatedSloc":"82"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"Go","languageID":132,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/kubernetes/client-go/blob/v0.34.1/rest/url_utils.go","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/kubernetes/client-go/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/kubernetes/client-go/raw/refs/tags/v0.34.1/rest/url_utils.go","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":4,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"isMarketplaceEnabled":true,"csrf_tokens":{"/kubernetes/client-go/branches":{"post":"pO4C5icEcycqqbZBmbhDOiAOYguHuGU6YIrDR4t3FDeITLUPV5FY-wGr9wGDFsz2_E6vT0NfmqESlLiMsgG2xg"},"/repos/preferences":{"post":"SASlpl_ayW7kzpc-IpZPtNol23sDhDzrdBSGEZTr0aE9LxutANzqSGxX6uIYmLDeNxUAFXXbA5-xa9ZQ-RqY4w"}}},"title":"client-go/rest/url_utils.go at v0.34.1 · kubernetes/client-go","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-9bd411a8e273.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-410714137fc9.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0