]> git.apps.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>
Fri, 5 Jun 2020 16:01:58 +0000 (21:31 +0530)
from a url.

Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
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 46eddfcb08accb8f429aa7fdac0ce1614974a4b3..a949ed10eed0e4a3f01f2f3d72e675ae84b730de 100644 (file)
@@ -346,15 +346,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 8e482e2144a47a6ca5041f026646c9b217445a0d..a6df0e947e5cc646f1fdce4161199f947d3da709 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 d0cbcd1eb82d35f264306b2416e9a4821f96e4aa..56b0d1590ddf027ac1382e9107167d78f67cdd16 100644 (file)
@@ -2261,6 +2261,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,