]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: adds a commom method to remove prefix(www, http and https)
authorPritha Srivastava <prsrivas@redhat.com>
Sun, 29 Mar 2020 10:20:32 +0000 (15:50 +0530)
committerPritha Srivastava <prsrivas@redhat.com>
Mon, 12 Oct 2020 15:41:07 +0000 (21:11 +0530)
from a url.

Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
(cherry picked from commit ca96ae806f79063922f27c3b4628026b9930fd89)

src/rgw/rgw_auth.cc
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_oidc_provider.cc
src/rgw/rgw_rest_oidc_provider.cc

index 6c4d544d35d14871d63e0a220647636e965dd235..705d3e81cea5c68b710b314de8a7c1f82fc00e08 100644 (file)
@@ -350,15 +350,7 @@ void rgw::auth::WebIdentityApplier::to_str(std::ostream& out) const
 string rgw::auth::WebIdentityApplier::get_idp_url() const
 {
   string idp_url = token_claims.iss;
-  auto pos = idp_url.find("http://");
-  if (pos == std::string::npos) {
-      pos = idp_url.find("https://");
-      if (pos != std::string::npos) {
-        idp_url.erase(pos, 8);
-    }
-  } else {
-    idp_url.erase(pos, 7);
-  }
+  idp_url = url_remove_prefix(idp_url);
   return idp_url;
 }
 
index 64e77708c8652f75bc31f609c4ca6329149dc7b4..618b9f9fdde59357d5b8b932251c23176bf68d87 100644 (file)
@@ -1594,6 +1594,27 @@ std::string url_encode(const std::string& src, bool encode_slash)
   return dst;
 }
 
+std::string url_remove_prefix(const std::string& url)
+{
+  std::string dst = url;
+  auto pos = dst.find("http://");
+  if (pos == std::string::npos) {
+    pos = dst.find("https://");
+    if (pos != std::string::npos) {
+      dst.erase(pos, 8);
+    } else {
+      pos = dst.find("www.");
+      if (pos != std::string::npos) {
+        dst.erase(pos, 4);
+      }
+    }
+  } else {
+    dst.erase(pos, 7);
+  }
+
+  return dst;
+}
+
 string rgw_trim_whitespace(const string& src)
 {
   if (src.empty()) {
index 390e0e04b1ee0d8103733bfc351fc6cbec4f68dd..7ce379b0dda63bac12f75cfb54831d7a1c5eec7f 100644 (file)
@@ -2281,6 +2281,7 @@ extern std::string url_decode(const boost::string_view& src_str,
 extern void url_encode(const std::string& src, string& dst,
                        bool encode_slash = true);
 extern std::string url_encode(const std::string& src, bool encode_slash = true);
+extern std::string url_remove_prefix(const std::string& url); // Removes hhtp, https and www from url
 /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */
 extern void calc_hmac_sha1(const char *key, int key_len,
                           const char *msg, int msg_len, char *dest);
index ee28d2cd162d742356ca9e6ab69d50e1a4583cdc..14eea2f76f8fd9b7e5c9f32790104d1966a02c42 100644 (file)
@@ -64,21 +64,7 @@ int RGWOIDCProvider::create(bool exclusive)
     return -EINVAL;
   }
 
-  string idp_url = provider_url;
-  auto pos = idp_url.find("http://");
-  if (pos == std::string::npos) {
-    pos = idp_url.find("https://");
-    if (pos != std::string::npos) {
-      idp_url.erase(pos, 8);
-    } else {
-      pos = idp_url.find("www.");
-      if (pos != std::string::npos) {
-        idp_url.erase(pos, 4);
-      }
-    }
-  } else {
-    idp_url.erase(pos, 7);
-  }
+  string idp_url = url_remove_prefix(provider_url);
 
   /* check to see the name is not used */
   ret = read_url(idp_url, tenant);
index e2f6ddc00d6b003f3ee05c7f8876316e31104f69..a72e3c64b78b1bc4a24c23e9ef7bbc072f22fb15 100644 (file)
@@ -79,21 +79,7 @@ int RGWCreateOIDCProvider::verify_permission()
     return ret;
   }
 
-  string idp_url = provider_url;
-  auto pos = idp_url.find("http://");
-  if (pos == std::string::npos) {
-    pos = idp_url.find("https://");
-    if (pos != std::string::npos) {
-      idp_url.erase(pos, 8);
-    } else {
-      pos = idp_url.find("www.");
-      if (pos != std::string::npos) {
-        idp_url.erase(pos, 4);
-      }
-    }
-  } else {
-    idp_url.erase(pos, 7);
-  }
+  string idp_url = url_remove_prefix(provider_url);
   if (!verify_user_permission(this,
                               s,
                               rgw::ARN(idp_url,