mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-06-13 22:32:22 +00:00
Use jsoncpp to parse AWS JSON
This commit is contained in:
parent
366f0705a0
commit
8660abaea2
10
configure.ac
10
configure.ac
|
@ -176,13 +176,13 @@ dnl
|
||||||
dnl For PKG_CONFIG before checking nss/gnutls.
|
dnl For PKG_CONFIG before checking nss/gnutls.
|
||||||
dnl this is redundant checking, but we need checking before following.
|
dnl this is redundant checking, but we need checking before following.
|
||||||
dnl
|
dnl
|
||||||
PKG_CHECK_MODULES([common_lib_checking], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6])
|
PKG_CHECK_MODULES([common_lib_checking], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 jsoncpp >= 1.7])
|
||||||
|
|
||||||
AC_MSG_CHECKING([compile s3fs with])
|
AC_MSG_CHECKING([compile s3fs with])
|
||||||
case "${auth_lib}" in
|
case "${auth_lib}" in
|
||||||
openssl)
|
openssl)
|
||||||
AC_MSG_RESULT(OpenSSL)
|
AC_MSG_RESULT(OpenSSL)
|
||||||
PKG_CHECK_MODULES([DEPS], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 libcrypto >= 0.9])
|
PKG_CHECK_MODULES([DEPS], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 libcrypto >= 0.9 jsoncpp >= 1.7])
|
||||||
;;
|
;;
|
||||||
gnutls)
|
gnutls)
|
||||||
AC_MSG_RESULT(GnuTLS-gcrypt)
|
AC_MSG_RESULT(GnuTLS-gcrypt)
|
||||||
|
@ -191,7 +191,7 @@ gnutls)
|
||||||
AS_IF([test "$gnutls_nettle" = ""], [AC_CHECK_LIB(gcrypt, gcry_control, [gnutls_nettle=0])])
|
AS_IF([test "$gnutls_nettle" = ""], [AC_CHECK_LIB(gcrypt, gcry_control, [gnutls_nettle=0])])
|
||||||
AS_IF([test $gnutls_nettle = 0],
|
AS_IF([test $gnutls_nettle = 0],
|
||||||
[
|
[
|
||||||
PKG_CHECK_MODULES([DEPS], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 gnutls >= 2.12.0 ])
|
PKG_CHECK_MODULES([DEPS], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 gnutls >= 2.12.0 jsoncpp >= 1.7 ])
|
||||||
LIBS="-lgnutls -lgcrypt $LIBS"
|
LIBS="-lgnutls -lgcrypt $LIBS"
|
||||||
AC_MSG_CHECKING([gnutls is build with])
|
AC_MSG_CHECKING([gnutls is build with])
|
||||||
AC_MSG_RESULT(gcrypt)
|
AC_MSG_RESULT(gcrypt)
|
||||||
|
@ -205,7 +205,7 @@ nettle)
|
||||||
AS_IF([test "$gnutls_nettle" = ""], [AC_CHECK_LIB(nettle, nettle_MD5Init, [gnutls_nettle=1])])
|
AS_IF([test "$gnutls_nettle" = ""], [AC_CHECK_LIB(nettle, nettle_MD5Init, [gnutls_nettle=1])])
|
||||||
AS_IF([test $gnutls_nettle = 1],
|
AS_IF([test $gnutls_nettle = 1],
|
||||||
[
|
[
|
||||||
PKG_CHECK_MODULES([DEPS], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 nettle >= 2.7.1 ])
|
PKG_CHECK_MODULES([DEPS], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 nettle >= 2.7.1 jsoncpp >= 1.7 ])
|
||||||
LIBS="-lgnutls -lnettle $LIBS"
|
LIBS="-lgnutls -lnettle $LIBS"
|
||||||
AC_MSG_CHECKING([gnutls is build with])
|
AC_MSG_CHECKING([gnutls is build with])
|
||||||
AC_MSG_RESULT(nettle)
|
AC_MSG_RESULT(nettle)
|
||||||
|
@ -214,7 +214,7 @@ nettle)
|
||||||
;;
|
;;
|
||||||
nss)
|
nss)
|
||||||
AC_MSG_RESULT(NSS)
|
AC_MSG_RESULT(NSS)
|
||||||
PKG_CHECK_MODULES([DEPS], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 nss >= 3.15.0 ])
|
PKG_CHECK_MODULES([DEPS], [fuse >= ${min_fuse_version} libcurl >= 7.0 libxml-2.0 >= 2.6 nss >= 3.15.0 jsoncpp >= 1.7 ])
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
AC_MSG_ERROR([unknown ssl library type.])
|
AC_MSG_ERROR([unknown ssl library type.])
|
||||||
|
|
32
src/curl.cpp
32
src/curl.cpp
|
@ -41,6 +41,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <json/reader.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "curl.h"
|
#include "curl.h"
|
||||||
|
@ -1414,7 +1416,6 @@ bool S3fsCurl::ParseIAMCredentialResponse(const char* response, iamcredmap_t& ke
|
||||||
}else if(string::npos != (pos = oneline.find(IAMCRED_EXPIRATION))){
|
}else if(string::npos != (pos = oneline.find(IAMCRED_EXPIRATION))){
|
||||||
key = IAMCRED_EXPIRATION;
|
key = IAMCRED_EXPIRATION;
|
||||||
}else{
|
}else{
|
||||||
S3FS_PRN_INFO3("Unknown key");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(string::npos == (pos = oneline.find(':', pos + key.length()))){
|
if(string::npos == (pos = oneline.find(':', pos + key.length()))){
|
||||||
|
@ -1428,19 +1429,44 @@ bool S3fsCurl::ParseIAMCredentialResponse(const char* response, iamcredmap_t& ke
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
val = oneline.substr(0, pos);
|
val = oneline.substr(0, pos);
|
||||||
S3FS_PRN_INFO3("keyval: %s - %s", key, val);
|
|
||||||
keyval[key] = val;
|
keyval[key] = val;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool S3fsCurl::ParseIAMCredentialResponseV2(const char* response, iamcredmap_t& keyval)
|
||||||
|
{
|
||||||
|
if(!response){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value root;
|
||||||
|
Json::Reader reader;
|
||||||
|
|
||||||
|
if (!reader.parse(response, root)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyval[string(IAMCRED_ACCESSKEYID)] = root.get(IAMCRED_ACCESSKEYID, "").asString();
|
||||||
|
keyval[string(IAMCRED_SECRETACCESSKEY)] = root.get(IAMCRED_SECRETACCESSKEY, "").asString();
|
||||||
|
keyval[string(IAMCRED_ACCESSTOKEN)] = root.get(IAMCRED_ACCESSTOKEN, "").asString();
|
||||||
|
keyval[string(IAMCRED_EXPIRATION)] = root.get(IAMCRED_EXPIRATION, "").asString();
|
||||||
|
|
||||||
|
if (S3fsCurl::is_ecs) {
|
||||||
|
keyval[string(IAMCRED_ROLEARN)] = root.get(IAMCRED_ROLEARN, "").asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool S3fsCurl::SetIAMCredentials(const char* response)
|
bool S3fsCurl::SetIAMCredentials(const char* response)
|
||||||
{
|
{
|
||||||
S3FS_PRN_INFO3("IAM credential response = \"%s\"", response);
|
S3FS_PRN_INFO3("IAM credential response = \"%s\"", response);
|
||||||
|
|
||||||
iamcredmap_t keyval;
|
iamcredmap_t keyval;
|
||||||
|
|
||||||
if(!ParseIAMCredentialResponse(response, keyval)){
|
if(!ParseIAMCredentialResponseV2(response, keyval)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
S3FS_PRN_INFO3("Parsed");
|
S3FS_PRN_INFO3("Parsed");
|
||||||
|
|
|
@ -299,6 +299,7 @@ class S3fsCurl
|
||||||
static S3fsCurl* ParallelGetObjectRetryCallback(S3fsCurl* s3fscurl);
|
static S3fsCurl* ParallelGetObjectRetryCallback(S3fsCurl* s3fscurl);
|
||||||
|
|
||||||
static bool ParseIAMCredentialResponse(const char* response, iamcredmap_t& keyval);
|
static bool ParseIAMCredentialResponse(const char* response, iamcredmap_t& keyval);
|
||||||
|
static bool ParseIAMCredentialResponseV2(const char* response, iamcredmap_t& keyval);
|
||||||
static bool SetIAMCredentials(const char* response);
|
static bool SetIAMCredentials(const char* response);
|
||||||
static bool ParseIAMRoleFromMetaDataResponse(const char* response, std::string& rolename);
|
static bool ParseIAMRoleFromMetaDataResponse(const char* response, std::string& rolename);
|
||||||
static bool SetIAMRoleFromMetaData(const char* response);
|
static bool SetIAMRoleFromMetaData(const char* response);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user