-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swift backend support #207
Open
constantinius
wants to merge
14
commits into
MapServer:main
Choose a base branch
from
constantinius:swift
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bb0db52
Adding OpenStack Swift cache backend using modified keystone-client a…
constantinius 4ca952c
Improved error handling. Cleanup.
constantinius 44c4e91
Adding bindings to enable debugging
constantinius 530afe6
keystone v3 authentication
constantinius daa7276
Adding support for keystone v3 authorization
constantinius 9bac975
Fixes to be able to use json-c 0.12
constantinius a54efe7
Fixing typo: allocating container instead of object
constantinius c0be54c
Fixes for object existence check. Additional return codes for HTTP st…
constantinius 813c6ec
Special handling of 404 responses in the backend
constantinius e1a74fa
Trying to fix segfaults in cache retrieval
constantinius f3597e1
Adding source reference in comments
constantinius a1c3931
Fixing buffer overflow in swift_set_object and swift_set_container
constantinius 6173b17
Making comment to state why a byte was added in allocation
constantinius 34d1c64
Fixing build error when Swift is disabled
constantinius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Try to find json-c | ||
# Once done, this will define | ||
# | ||
# JSONC_FOUND - system has jsonc | ||
# JSONC__INCLUDE_DIRS - the jsonc include directories | ||
# JSONC__LIBRARIES - jsonc libraries directories | ||
|
||
if(JSONC_INCLUDE_DIRS AND JSONC_LIBRARIES) | ||
set(JSONC_FIND_QUIETLY TRUE) | ||
endif(JSONC_INCLUDE_DIRS AND JSONC_LIBRARIES) | ||
|
||
find_path(JSONC_INCLUDE_DIR json.h | ||
HINTS | ||
/usr/include/json-c/ | ||
/usr/local/include/json-c/ | ||
) | ||
find_library(JSONC_LIBRARY json-c | ||
HINTS | ||
/usr/lib/ | ||
/usr/local/lib | ||
) | ||
|
||
set(JSONC_INCLUDE_DIRS ${JSONC_INCLUDE_DIR}) | ||
set(JSONC_LIBRARIES ${JSONC_LIBRARY}) | ||
|
||
# handle the QUIETLY and REQUIRED arguments and set JSONC_FOUND to TRUE if | ||
# all listed variables are TRUE | ||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(jsonc DEFAULT_MSG JSONC_INCLUDE_DIRS JSONC_LIBRARIES) | ||
|
||
mark_as_advanced(JSONC_INCLUDE_DIRS JSONC_LIBRARIES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
/* | ||
* Based on https://github.com/ukyg9e5r6k7gubiekd6/keystone-client | ||
*/ | ||
|
||
#ifndef KEYSTONE_CLIENT_H_ | ||
#define KEYSTONE_CLIENT_H_ | ||
|
||
#include <stdio.h> | ||
#include <curl/curl.h> | ||
#include <json-c/json.h> | ||
|
||
/** | ||
* Keystone version to be used. | ||
* Currently supported are V1 and V3. | ||
*/ | ||
enum keystone_auth_version { | ||
KS_AUTH_V1 = 1, | ||
KS_AUTH_V3 = 3 | ||
}; | ||
|
||
/** | ||
* High-level types of errors which can occur while attempting to use Keystone. | ||
* More detail is available from lower-level libraries (such as curl and libjson) | ||
* using error callbacks specific to those libraries. | ||
*/ | ||
enum keystone_error { | ||
KSERR_SUCCESS = 0, /* Success */ | ||
KSERR_INIT_FAILED = 1, /* Initialisation of this library failed */ | ||
KSERR_INVARG = 2, /* Invalid argument */ | ||
KSERR_ALLOC_FAILED = 3, /* Memory allocation failed */ | ||
KSERR_URL_FAILED = 4, /* Network operation on a URL failed */ | ||
KSERR_AUTH_REJECTED = 5, /* Authentication attempt rejected */ | ||
KSERR_NOTFOUND = 6, /* Requested service(s) not found in service catalog */ | ||
KSERR_PARSE = 7 /* Failed to parse Keystone response */ | ||
}; | ||
|
||
/** | ||
* Types of OpenStack service. | ||
*/ | ||
enum openstack_service { | ||
OS_SERVICE_KEYSTONE = 0, /* Keystone authentication and service catalog */ | ||
OS_SERVICE_NOVA = 1, /* Nova compute */ | ||
OS_SERVICE_NOVA_EC2 = 2, /* Nova compute, EC2 API */ | ||
OS_SERVICE_SWIFT = 3, /* Swift object storage */ | ||
OS_SERVICE_SWIFT_S3 = 4, /* Swift object storage, S3 API */ | ||
OS_SERVICE_CINDER = 5, /* Cinder block storage */ | ||
OS_SERVICE_GLANCE = 6 /* Glance image storage */ | ||
}; | ||
#define OS_SERVICE_MAX OS_SERVICE_GLANCE | ||
|
||
/** | ||
* Types of OpenStack service endpoint. | ||
*/ | ||
enum openstack_service_endpoint_url_type { | ||
OS_ENDPOINT_URL_PUBLIC = 0, /* Service's public endpoint */ | ||
OS_ENDPOINT_URL_PRIVATE = 1, /* Service's private endpoint */ | ||
OS_ENDPOINT_URL_INTERNAL = 2, /* Service's internal endpoint */ | ||
}; | ||
#define OS_ENDPOINT_URL_MAX OS_ENDPOINT_URL_INTERNAL | ||
|
||
/* keystone client library's per-thread private context */ | ||
struct keystone_context_private { | ||
CURL *curl; /* Handle to curl library's easy interface */ | ||
unsigned int debug; | ||
struct json_tokener *json_tokeniser; /* libjson0 library's JSON tokeniser */ | ||
struct json_object *services; /* service catalog JSON array */ | ||
enum keystone_auth_version version; | ||
unsigned int verify_cert_trusted; /* True if the peer's certificate must chain to a trusted CA, false otherwise */ | ||
unsigned int verify_cert_hostname; /* True if the peer's certificate's hostname must be correct, false otherwise */ | ||
char *auth_payload; /* Authentication POST payload, containing credentials */ | ||
char *auth_token; /* Authentication token previously obtained from Keystone */ | ||
}; | ||
|
||
typedef struct keystone_context_private keystone_context_private_t; | ||
|
||
/* A function which allocates, re-allocates or de-allocates memory */ | ||
typedef void *(*keystone_allocator_func_t)(void *ptr, size_t newsize); | ||
|
||
/* A function which receives curl errors */ | ||
typedef void (*curl_error_callback_t)(const char *curl_funcname, CURLcode res); | ||
|
||
/* A function which receives libjson errors */ | ||
typedef void (*json_error_callback_t)(const char *json_funcname, enum json_tokener_error json_err); | ||
|
||
/* A function which receives Keystone errors */ | ||
typedef void (*keystone_error_callback_t)(const char *keystone_operation, enum keystone_error keystone_err); | ||
|
||
/** | ||
* All use of this library is performed within a 'context'. | ||
* Contexts cannot be shared among threads; each thread must have its own context. | ||
* Your program is responsible for allocating and freeing context structures. | ||
* Contexts should be zeroed out prior to use. | ||
*/ | ||
struct keystone_context { | ||
|
||
/* These members are 'public'; your program can (and should) set them at will */ | ||
|
||
/** | ||
* Called when a libcurl error occurs. | ||
* Your program may set this function pointer in order to perform custom error handling. | ||
* If this is NULL at the time keystone_start is called, a default handler will be used. | ||
*/ | ||
curl_error_callback_t curl_error; | ||
/** | ||
* Called when a libjson error occurs. | ||
* Your program may set this function in order to perform custom error handling. | ||
* If this is NULL at the time keystone_start is called, a default handler will be used. | ||
*/ | ||
json_error_callback_t json_error; | ||
/** | ||
* Called when a Keystone error occurs. | ||
* Your program may set this function in order to perform custom error handling. | ||
* If this is NULL at the time keystone_start is called, a default handler will be used. | ||
*/ | ||
keystone_error_callback_t keystone_error; | ||
/** | ||
* Called when this library needs to allocate, re-allocate or free memory. | ||
* If size is zero and ptr is NULL, nothing is done. | ||
* If size is zero and ptr is non-NULL, the previously-allocated memory at ptr is to be freed. | ||
* If size is non-zero and ptr is NULL, memory of the given size is to be allocated. | ||
* If size is non-zero and ptr is non-NULL, the previously-allocated memory at ptr | ||
* is to be re-allocated to be the given size. | ||
* If this function pointer is NULL at the time keystone_start is called, a default re-allocator will be used. | ||
*/ | ||
keystone_allocator_func_t allocator; | ||
/* This member (and its members, recursively) are 'private'. */ | ||
/* They should not be modified by your program unless you *really* know what you're doing. */ | ||
keystone_context_private_t pvt; | ||
}; | ||
|
||
typedef struct keystone_context keystone_context_t; | ||
|
||
/** | ||
* Begin using this library. | ||
* The context passed must be zeroed out, except for the public part, | ||
* in which you may want to over-ride the function pointers. | ||
* Function pointers left NULL will be given meaningful defaults. | ||
* This must be called early in the execution of your program, | ||
* before additional threads (if any) are created. | ||
* This must be called before any other use of this library by your program. | ||
* These restrictions are imposed by libcurl, and the libcurl restrictions are in turn | ||
* imposed by the libraries that libcurl uses. | ||
* If your program is a library, it will need to expose a similar API to, | ||
* and expose similar restrictions on, its users. | ||
*/ | ||
enum keystone_error keystone_global_init(void); | ||
|
||
/** | ||
* Cease using this library. | ||
* This must be called late in the execution of your program, | ||
* after all secondary threads (if any) have exited, | ||
* so that there is precisely one thread in your program at the time of the call. | ||
* This library must not be used by your program after this function is called. | ||
* This function must be called exactly once for each successful prior call to keystone_global_init | ||
* by your program. | ||
* These restrictions are imposed by libcurl, and the libcurl restrictions are in turn | ||
* imposed by the libraries that libcurl uses. | ||
* If your program is a library, it will need to expose a similar API to, | ||
* and expose similar restrictions on, its users. | ||
*/ | ||
void keystone_global_cleanup(void); | ||
|
||
/** | ||
* Begin using this library for a single thread of your program. | ||
* This must be called by each thread of your program in order to use this library. | ||
*/ | ||
enum keystone_error keystone_start(keystone_context_t *context); | ||
|
||
/** | ||
* Cease using this library for a single thread. | ||
* This must be called by each thread of your program after it is finished using this library. | ||
* Each thread in your program must call this function precisely once for each successful prior call | ||
* to keystone_start by that thread. | ||
* After this call, the context is invalid. | ||
*/ | ||
void keystone_end(keystone_context_t *context); | ||
|
||
/** | ||
* Control whether a proxy (eg HTTP or SOCKS) is used to access the Keystone server. | ||
* Argument must be a URL, or NULL if no proxy is to be used. | ||
*/ | ||
enum keystone_error keystone_set_proxy(keystone_context_t *context, const char *proxy_url); | ||
|
||
/** | ||
* Control verbose logging to stderr of the actions of this library and the libraries it uses. | ||
* Currently this enables logging to standard error of libcurl's actions. | ||
*/ | ||
enum keystone_error keystone_set_debug(keystone_context_t *context, unsigned int enable_debugging); | ||
|
||
const char *service_name(unsigned int service); | ||
const char *endpoint_url_name(unsigned int endpoint); | ||
|
||
/** | ||
* Set the auth version to be used. Default is v1. | ||
*/ | ||
enum keystone_error keystone_set_auth_version(keystone_context_t *context, enum keystone_auth_version version); | ||
|
||
/** | ||
* Authenticate against a Keystone authentication service with the given tenant and user names and password. | ||
* This yields an authorisation token, which is then used to access all Swift services. | ||
*/ | ||
enum keystone_error keystone_authenticate(keystone_context_t *context, const char *url, const char *tenant_name, const char *username, const char *password); | ||
|
||
/** | ||
* Return the previously-acquired Keystone authentication token, if any. | ||
* If no authentication token has previously been acquired, return NULL. | ||
*/ | ||
const char *keystone_get_auth_token(keystone_context_t *context); | ||
|
||
/** | ||
* Given a desired service type and version and type of URL, find a service of the given type in Keystone's catalog of services, | ||
* then find an endpoint of that service with the given API version, then return its URL of the given type. | ||
* Return NULL if the service cannot be found, or if no endpoint of the given version can be found, | ||
* or if the service endpoint of the given version has no URL of the given type. | ||
*/ | ||
const char *keystone_get_service_url(keystone_context_t *context, enum openstack_service desired_service_type, unsigned int desired_api_version, enum openstack_service_endpoint_url_type endpoint_url_type); | ||
|
||
#endif /* KEYSTONE_CLIENT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing licence on imported files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right!
Besides: Do you think that it is alright to include a source file like that? The repo says it is GPL v3.