1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

feature: added wf_credentials_set_type and wf_credentials_add

This commit is contained in:
Falk Werner 2020-06-10 22:42:26 +02:00
parent f60079dadb
commit 81fd41f46a
8 changed files with 106 additions and 55 deletions

View File

@ -1,28 +0,0 @@
#ifndef WF_ADAPTER_CLIENT_CREDENTIALS_H
#define WF_ADAPTER_CLIENT_CREDENTIALS_H
#include "webfuse/adapter/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_client_credentials;
extern WF_API void
wf_client_credentials_set_type(
struct wf_client_credentials * credentials,
char const * type);
extern WF_API void
wf_client_credentials_add(
struct wf_client_credentials * credentials,
char const * key,
char const * value);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -65,6 +65,28 @@ extern WF_API char const * wf_credentials_get(
struct wf_credentials const * credentials,
char const * key);
//------------------------------------------------------------------------------
/// \brief Sets the type of the credentials.
///
/// \param credentials Pointer to credentials object.
/// \param type Type of credentials.
//------------------------------------------------------------------------------
extern WF_API void wf_credentials_set_type(
struct wf_credentials * credentials,
char const * type);
//------------------------------------------------------------------------------
/// \brief Adds an item to credentials
///
/// \param credentials Pointer to credentials object.
/// \param key String to identify the item.
/// \param key Value of the item.
//------------------------------------------------------------------------------
extern WF_API void wf_credentials_add(
struct wf_credentials * credentials,
char const * key,
char const * value);
#ifdef __cplusplus
}
#endif

View File

@ -18,7 +18,6 @@
#include <webfuse/adapter/mountpoint.h>
#include <webfuse/adapter/client.h>
#include <webfuse/adapter/client_credentials.h>
#endif

View File

@ -147,6 +147,21 @@ char const * wf_credentials_get(
return wf_impl_credentials_get(credentials, key);
}
void wf_credentials_set_type(
struct wf_credentials * credentials,
char const * type)
{
wf_impl_credentials_set_type(credentials, type);
}
void wf_credentials_add(
struct wf_credentials * credentials,
char const * key,
char const * value)
{
wf_impl_credentials_add(credentials, key, value);
}
// mountpoint
struct wf_mountpoint *
@ -255,24 +270,3 @@ wf_client_add_filesystem(
(void) name;
}
// client credentials
void
wf_client_credentials_set_type(
struct wf_client_credentials * credentials,
char const * type)
{
(void) credentials;
(void) type;
}
void
wf_client_credentials_add(
struct wf_client_credentials * credentials,
char const * key,
char const * value)
{
(void) credentials;
(void) key;
(void) value;
}

View File

@ -1,6 +1,13 @@
#include "webfuse/adapter/impl/credentials.h"
#include <string.h>
void wf_impl_credentials_init_default(
struct wf_credentials * credentials)
{
credentials->type = NULL;
credentials->data = json_object();
}
void wf_impl_credentials_init(
struct wf_credentials * credentials,
char const * type,
@ -38,3 +45,20 @@ char const * wf_impl_credentials_get(
return result;
}
void wf_impl_credentials_set_type(
struct wf_credentials * credentials,
char const * type)
{
free(credentials->type);
credentials->type = strdup(type);
}
void wf_impl_credentials_add(
struct wf_credentials * credentials,
char const * key,
char const * value)
{
json_object_set_new(credentials->data, key, json_string(value));
}

View File

@ -19,6 +19,9 @@ extern void wf_impl_credentials_init(
char const * type,
json_t * data);
extern void wf_impl_credentials_init_default(
struct wf_credentials * credentials);
extern void wf_impl_credentials_cleanup(
struct wf_credentials * credentials);
@ -29,6 +32,15 @@ extern char const * wf_impl_credentials_get(
struct wf_credentials const * credentials,
char const * key);
extern void wf_impl_credentials_set_type(
struct wf_credentials * credentials,
char const * type);
extern void wf_impl_credentials_add(
struct wf_credentials * credentials,
char const * key,
char const * value);
#ifdef __cplusplus
}
#endif

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "webfuse/adapter/client.h"
#include "webfuse/adapter/client_credentials.h"
#include "webfuse/adapter/credentials.h"
namespace
{
@ -43,10 +43,10 @@ void callback(
break;
case WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS:
{
auto * credentials = reinterpret_cast<wf_client_credentials*>(args);
wf_client_credentials_set_type(credentials, "username");
wf_client_credentials_add(credentials, "user", "bob");
wf_client_credentials_add(credentials, "password", "secret");
auto * credentials = reinterpret_cast<wf_credentials*>(args);
wf_credentials_set_type(credentials, "username");
wf_credentials_add(credentials, "user", "bob");
wf_credentials_add(credentials, "password", "secret");
}
break;
case WF_CLIENT_FILESYSTEM_ADDED:

View File

@ -83,3 +83,31 @@ TEST(Credentials, FailedToGetWrongElementDataType)
wf_impl_credentials_cleanup(&creds);
json_decref(data);
}
TEST(Credentials, SetType)
{
struct wf_credentials creds;
wf_impl_credentials_init_default(&creds);
wf_credentials_set_type(&creds, "username");
ASSERT_STREQ("username", wf_credentials_type(&creds));
wf_impl_credentials_cleanup(&creds);
}
TEST(Credentials, Add)
{
struct wf_credentials creds;
wf_impl_credentials_init_default(&creds);
wf_credentials_add(&creds, "a.value", "a");
ASSERT_STREQ("a", wf_credentials_get(&creds, "a.value"));
wf_credentials_add(&creds, "b.value", "b");
ASSERT_STREQ("b", wf_credentials_get(&creds, "b.value"));
wf_credentials_add(&creds, "a.value", "A");
ASSERT_STREQ("A", wf_credentials_get(&creds, "a.value"));
wf_impl_credentials_cleanup(&creds);
}