Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-julialib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-julialib
Commits
49ef5188
Commit
49ef5188
authored
Jul 14, 2021
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
DOC: Add docstrings
parent
e0826e1b
No related branches found
No related tags found
2 merge requests
!3
TST: Add CI infrastructure for integration testing
,
!2
ENH: Add minimal wrapping of libcaosdb's C interface
Pipeline
#10300
passed with warnings
Jul 14, 2021
Stage: code-style
Stage: setup
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/CaosDB.jl
+130
-62
130 additions, 62 deletions
src/CaosDB.jl
with
130 additions
and
62 deletions
src/CaosDB.jl
+
130
−
62
View file @
49ef5188
...
@@ -26,9 +26,12 @@ module CaosDB
...
@@ -26,9 +26,12 @@ module CaosDB
module
Info
module
Info
"""
"""
Struct containing version information of the CaosDB server.
Struct containing version information of the CaosDB server. Meant
mainly for internal usage; use `CaosDB.Connection.get_version_info` or
`CaosDB.Connection.print_version_info` to retrieve the version of the
connected CaosDB server.
"""
"""
mutable struct
VersionInfo
mutable struct
_
VersionInfo
major
::
Cint
major
::
Cint
minor
::
Cint
minor
::
Cint
...
@@ -36,7 +39,7 @@ mutable struct VersionInfo
...
@@ -36,7 +39,7 @@ mutable struct VersionInfo
pre_release
::
Cstring
pre_release
::
Cstring
build
::
Cstring
build
::
Cstring
VersionInfo
()
=
new
()
_
VersionInfo
()
=
new
()
end
end
...
@@ -70,12 +73,15 @@ end # Utility
...
@@ -70,12 +73,15 @@ end # Utility
module
Authentication
module
Authentication
"""
"""
Struct containing a pointer to the wrapped cpp authenticator class.
Struct containing a pointer to the wrapped cpp authenticator
class. Meant for internal use; call a
`CaosDB.Authentication.create_<authenticator>` function to create an
authenticator object from a configuration.
"""
"""
mutable struct
Authenticator
mutable struct
_
Authenticator
wrapped_authenticator
::
Ptr
{
Cvoid
}
wrapped_authenticator
::
Ptr
{
Cvoid
}
function
Authenticator
()
function
_
Authenticator
()
auth
=
new
()
auth
=
new
()
# force this to point to C_NULL after initialization
# force this to point to C_NULL after initialization
auth
.
wrapped_authenticator
=
C_NULL
auth
.
wrapped_authenticator
=
C_NULL
...
@@ -85,8 +91,8 @@ mutable struct Authenticator
...
@@ -85,8 +91,8 @@ mutable struct Authenticator
ccall
(
ccall
(
(
:
caosdb_authentication_delete_authenticator
,
"libccaosdb"
),
(
:
caosdb_authentication_delete_authenticator
,
"libccaosdb"
),
Cint
,
Cint
,
(
Ref
{
Authenticator
},),
(
Ref
{
_
Authenticator
},),
Ref
{
Authenticator
}(
t
),
Ref
{
_
Authenticator
}(
t
),
)
)
end
end
end
end
...
@@ -94,17 +100,27 @@ mutable struct Authenticator
...
@@ -94,17 +100,27 @@ mutable struct Authenticator
end
end
end
end
"""
create_plain_password_authenticator(
username::AbstractString,
password::AbstractString,
)
Return an authenticator object that contains a wrapped cpp
plain-password authenticator configured with `username` and
`password`.
"""
function
create_plain_password_authenticator
(
function
create_plain_password_authenticator
(
username
::
AbstractString
,
username
::
AbstractString
,
password
::
AbstractString
,
password
::
AbstractString
,
)
)
auth
=
Ref
{
Authenticator
}(
Authenticator
())
auth
=
Ref
{
_
Authenticator
}(
_
Authenticator
())
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_authentication_create_plain_password_authenticator
,
"libccaosdb"
),
(
:
caosdb_authentication_create_plain_password_authenticator
,
"libccaosdb"
),
Cint
,
Cint
,
(
Ref
{
Authenticator
},
Cstring
,
Cstring
),
(
Ref
{
_
Authenticator
},
Cstring
,
Cstring
),
auth
,
auth
,
username
,
username
,
password
,
password
,
...
@@ -126,13 +142,17 @@ module Connection
...
@@ -126,13 +142,17 @@ module Connection
using
..
CaosDB
using
..
CaosDB
export
connect
"""
"""
Struct containing the actual connection to a CaosDB server.
Struct containing the actual connection to a CaosDB server. Meant for
internal use; call a `CaosDB.Connection.create_<connection>` function
to create an connection object from a configuration.
"""
"""
mutable struct
CaosDB
Connection
mutable struct
_
Connection
wrapped_connection
::
Ptr
{
Cvoid
}
wrapped_connection
::
Ptr
{
Cvoid
}
function
CaosDB
Connection
()
function
_
Connection
()
conn
=
new
()
conn
=
new
()
conn
.
wrapped_connection
=
C_NULL
conn
.
wrapped_connection
=
C_NULL
function
f
(
t
)
function
f
(
t
)
...
@@ -140,8 +160,8 @@ mutable struct CaosDBConnection
...
@@ -140,8 +160,8 @@ mutable struct CaosDBConnection
ccall
(
ccall
(
(
:
caosdb_connection_delete_connection
,
"libccaosdb"
),
(
:
caosdb_connection_delete_connection
,
"libccaosdb"
),
Cint
,
Cint
,
(
Ref
{
CaosDB
Connection
},),
(
Ref
{
_
Connection
},),
Ref
{
CaosDB
Connection
}(
t
),
Ref
{
_
Connection
}(
t
),
)
)
end
end
end
end
...
@@ -151,12 +171,14 @@ end
...
@@ -151,12 +171,14 @@ end
"""
"""
Struct containing a pointer to the wrapped cpp class providing the
Struct containing a pointer to the wrapped cpp class providing the
certificate provider.
certificate provider. Meant for internal use; call a
`CaosDB.Connection.create_<certificate_provider>` function to create
an certificate-provider object from a configuration.
"""
"""
mutable struct
CertificateProvider
mutable struct
_
CertificateProvider
wrapped_certificate_provider
::
Ptr
{
Cvoid
}
wrapped_certificate_provider
::
Ptr
{
Cvoid
}
function
CertificateProvider
()
function
_
CertificateProvider
()
prov
=
new
()
prov
=
new
()
prov
.
wrapped_certificate_provider
=
C_NULL
prov
.
wrapped_certificate_provider
=
C_NULL
function
f
(
t
)
function
f
(
t
)
...
@@ -164,8 +186,8 @@ mutable struct CertificateProvider
...
@@ -164,8 +186,8 @@ mutable struct CertificateProvider
ccall
(
ccall
(
(
:
caosdb_connection_delete_certificate_provider
,
"libccaosdb"
),
(
:
caosdb_connection_delete_certificate_provider
,
"libccaosdb"
),
Cint
,
Cint
,
(
Ref
{
CertificateProvider
},),
(
Ref
{
_
CertificateProvider
},),
Ref
{
CertificateProvider
}(
t
),
Ref
{
_
CertificateProvider
}(
t
),
)
)
end
end
end
end
...
@@ -175,12 +197,14 @@ end
...
@@ -175,12 +197,14 @@ end
"""
"""
Struct containing a pointer to the wrapped cpp class for storing the
Struct containing a pointer to the wrapped cpp class for storing the
connection configuration.
connection configuration. Meant for internal use; call a
`CaosDB.Connection.create_<configuration>` function to create
an connection-configuration object from a configuration.
"""
"""
mutable struct
Configuration
mutable struct
_
Configuration
wrapped_connection_configuration
::
Ptr
{
Cvoid
}
wrapped_connection_configuration
::
Ptr
{
Cvoid
}
function
Configuration
()
function
_
Configuration
()
config
=
new
()
config
=
new
()
config
.
wrapped_connection_configuration
=
C_NULL
config
.
wrapped_connection_configuration
=
C_NULL
function
f
(
t
)
function
f
(
t
)
...
@@ -188,8 +212,8 @@ mutable struct Configuration
...
@@ -188,8 +212,8 @@ mutable struct Configuration
ccall
(
ccall
(
(
:
caosdb_connection_delete_connection_configuration
,
"libcaosdb"
),
(
:
caosdb_connection_delete_connection_configuration
,
"libcaosdb"
),
Cint
,
Cint
,
(
Ref
{
Configuration
},),
(
Ref
{
_
Configuration
},),
Ref
{
Configuration
}(
t
),
Ref
{
_
Configuration
}(
t
),
)
)
end
end
end
end
...
@@ -200,17 +224,17 @@ end
...
@@ -200,17 +224,17 @@ end
"""
"""
create_pem_file_certificate_provider(path::AbstractString)
create_pem_file_certificate_provider(path::AbstractString)
Return a `CertificateProvider` for the pem certificate located at
Return a `
_
CertificateProvider` for the pem certificate located at
`path`.
`path`.
"""
"""
function
create_pem_file_certificate_provider
(
path
::
AbstractString
)
function
create_pem_file_certificate_provider
(
path
::
AbstractString
)
cert_provider
=
Ref
{
CertificateProvider
}(
CertificateProvider
())
cert_provider
=
Ref
{
_
CertificateProvider
}(
_
CertificateProvider
())
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_create_pem_file_certificate_provider
,
"libccaosdb"
),
(
:
caosdb_connection_create_pem_file_certificate_provider
,
"libccaosdb"
),
Cint
,
Cint
,
(
Ref
{
CertificateProvider
},
Cstring
),
(
Ref
{
_
CertificateProvider
},
Cstring
),
cert_provider
,
cert_provider
,
path
,
path
,
)
)
...
@@ -229,8 +253,8 @@ end
...
@@ -229,8 +253,8 @@ end
create_tls_connection_configuration(
create_tls_connection_configuration(
host::AbstractString,
host::AbstractString,
port::Cint,
port::Cint,
authenticator::Ref{CaosDB.Authentication.Authenticator},
authenticator::Ref{CaosDB.Authentication.
_
Authenticator},
provider::Ref{CertificateProvider}
provider::Ref{
_
CertificateProvider}
)
)
Return a TLS connection configuration with authentication.
Return a TLS connection configuration with authentication.
...
@@ -238,21 +262,21 @@ Return a TLS connection configuration with authentication.
...
@@ -238,21 +262,21 @@ Return a TLS connection configuration with authentication.
function
create_tls_connection_configuration
(
function
create_tls_connection_configuration
(
host
::
AbstractString
,
host
::
AbstractString
,
port
::
Cint
,
port
::
Cint
,
authenticator
::
Ref
{
CaosDB
.
Authentication
.
Authenticator
},
authenticator
::
Ref
{
CaosDB
.
Authentication
.
_
Authenticator
},
provider
::
Ref
{
CertificateProvider
},
provider
::
Ref
{
_
CertificateProvider
},
)
)
config
=
Ref
{
Configuration
}(
Configuration
())
config
=
Ref
{
_
Configuration
}(
_
Configuration
())
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_create_tls_connection_configuration
,
"libccaosdb"
),
(
:
caosdb_connection_create_tls_connection_configuration
,
"libccaosdb"
),
Cint
,
Cint
,
(
(
Ref
{
Configuration
},
Ref
{
_
Configuration
},
Cstring
,
Cstring
,
Cint
,
Cint
,
Ref
{
CaosDB
.
Authentication
.
Authenticator
},
Ref
{
CaosDB
.
Authentication
.
_
Authenticator
},
Ref
{
CertificateProvider
},
Ref
{
_
CertificateProvider
},
),
),
config
,
config
,
host
,
host
,
...
@@ -273,12 +297,12 @@ end
...
@@ -273,12 +297,12 @@ end
function
create_insecure_connection_configuration
(
host
::
AbstractString
,
port
::
Cint
)
function
create_insecure_connection_configuration
(
host
::
AbstractString
,
port
::
Cint
)
config
=
Ref
{
Configuration
}(
Configuration
())
config
=
Ref
{
_
Configuration
}(
_
Configuration
())
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_create_insecure_connection_configuration
,
"libccaosdb"
),
(
:
caosdb_connection_create_insecure_connection_configuration
,
"libccaosdb"
),
Cint
,
Cint
,
(
Ref
{
Configuration
},
Cstring
,
Cint
),
(
Ref
{
_
Configuration
},
Cstring
,
Cint
),
config
,
config
,
host
,
host
,
port
,
port
,
...
@@ -294,18 +318,18 @@ function create_insecure_connection_configuration(host::AbstractString, port::Ci
...
@@ -294,18 +318,18 @@ function create_insecure_connection_configuration(host::AbstractString, port::Ci
end
end
"""
"""
create_connection(config::Ref{Configuration})
create_connection(config::Ref{
_
Configuration})
Return a connection based on the given `config`.
Return a connection based on the given `config`.
"""
"""
function
create_connection
(
config
::
Ref
{
Configuration
})
function
create_connection
(
config
::
Ref
{
_
Configuration
})
connection
=
Ref
{
CaosDB
Connection
}(
CaosDB
Connection
())
connection
=
Ref
{
_
Connection
}(
_
Connection
())
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_create_connection
,
"libccaosdb"
),
(
:
caosdb_connection_create_connection
,
"libccaosdb"
),
Cint
,
Cint
,
(
Ref
{
CaosDB
Connection
},
Ref
{
Configuration
}),
(
Ref
{
_
Connection
},
Ref
{
_
Configuration
}),
connection
,
connection
,
config
,
config
,
)
)
...
@@ -321,19 +345,19 @@ function create_connection(config::Ref{Configuration})
...
@@ -321,19 +345,19 @@ function create_connection(config::Ref{Configuration})
end
end
"""
"""
get_version_info(con::Ref{
CaosDB
Connection})
get_version_info(con::Ref{
_
Connection})
Return the version of the CaosDB server that `con` is connected
Return the version of the CaosDB server that `con` is connected
to.
to.
"""
"""
function
get_version_info
(
con
::
Ref
{
CaosDB
Connection
})
function
get_version_info
(
con
::
Ref
{
_
Connection
})
info
=
Ref
{
CaosDB
.
Info
.
VersionInfo
}(
CaosDB
.
Info
.
VersionInfo
())
info
=
Ref
{
CaosDB
.
Info
.
_
VersionInfo
}(
CaosDB
.
Info
.
_
VersionInfo
())
err_code
=
ccall
(
err_code
=
ccall
(
(
:
caosdb_connection_get_version_info
,
"libccaosdb"
),
(
:
caosdb_connection_get_version_info
,
"libccaosdb"
),
Cint
,
Cint
,
(
Ref
{
CaosDB
.
Info
.
VersionInfo
},
Ref
{
CaosDB
Connection
}),
(
Ref
{
CaosDB
.
Info
.
_
VersionInfo
},
Ref
{
_
Connection
}),
info
,
info
,
con
,
con
,
)
)
...
@@ -350,12 +374,12 @@ function get_version_info(con::Ref{CaosDBConnection})
...
@@ -350,12 +374,12 @@ function get_version_info(con::Ref{CaosDBConnection})
end
end
"""
"""
print_version_info(con::Ref{
CaosDB
Connection})
print_version_info(con::Ref{
_
Connection})
Retrieve the version info for the CaosDB server `con` is connected to,
Retrieve the version info for the CaosDB server `con` is connected to,
and print the version in a nice message.
and print the version in a nice message.
"""
"""
function
print_version_info
(
con
::
Ref
{
CaosDB
Connection
})
function
print_version_info
(
con
::
Ref
{
_
Connection
})
# Dereference to access the fields
# Dereference to access the fields
info
=
get_version_info
(
con
)[]
info
=
get_version_info
(
con
)[]
...
@@ -372,41 +396,87 @@ function print_version_info(con::Ref{CaosDBConnection})
...
@@ -372,41 +396,87 @@ function print_version_info(con::Ref{CaosDBConnection})
end
end
function
connect
(
"""
host
::
AbstractString
=
nothing
,
function connect([;
port_str
::
AbstractString
=
nothing
,
host::AbstractString="",
cacert
::
AbstractString
=
nothing
,
port_str::AbstractString="
undefined
",
username
::
AbstractString
=
nothing
,
cacert::AbstractString="",
password
::
AbstractString
=
nothing
,
username::AbstractString="",
password::AbstractString="
undefined
"]
)
)
if
host
==
nothing
Return a connection object created for the given `host`:`port` with an
SSL certificate located at `cacert` with the given credentials.
# Extended help
!!! info
Because of type-stability, and since an empty string may be a
valid password, the value of `password`, for which it is fetched
from an environmental variable, is "
undefined
". This means that if
you absolutely must use "
undefined
" as your password, you have to
specify it via the `CAOSDB_PASSWORD` variable.
# Arguments
- `host::AbstractString=""`: The hostname of the CaosDB server. If
none is provided, the `CAOSDB_SERVER_HOST` environmental variable is
used instead. If that's not defined, "
localhost
" is used.
- `port_str::AbstractString="
undefined
"`: The port of the CaosDB
server, given as string. If none is provided, the
`CAOSDB_SERVER_GRPC_PORT_HTTPS` environmental variable is used
instead. If that's not defined, "
8443
" is used. The default value is
"
undefined
" rather than an empty string because an empty string
could be a valid port, too, i.e. the CaosDB server is available at
`host` without a port.
- `cacert::AbstractString=""`: The path to the SSL certificate of the
CaosDB server. If none is provided, the `CAOSDB_SERVER_CERT`
environmental variable is used instead.
- `username::AbstractString=""`: The username with which to log in
into the CaosDB server. If none is provided, the `CAOSDB_USER`
environmental variable is used instead. If that's not defined,
"
admin
" is used.
- `password::AbstractString="
undefined
"`: The password with which to
log in into the CaosDB server. If none is provided, the
`CAOSDB_PASSWORD` environmental variable is used instead. If that's
not defined, "
caosdb
" is used. The default value is "
undefined
"
rather than an empty string to allow an empty password.
"""
function
connect
(;
host
::
AbstractString
=
""
,
port_str
::
AbstractString
=
"undefined"
,
cacert
::
AbstractString
=
""
,
username
::
AbstractString
=
""
,
password
::
AbstractString
=
"undefined"
)
if
host
==
""
host
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
)
host
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_SERVER_HOST"
,
"localhost"
)
end
end
if
port_str
==
nothing
if
port_str
==
"undefined"
port
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_SERVER_GRPC_PORT_HTTPS"
,
"8443"
)
port
_str
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_SERVER_GRPC_PORT_HTTPS"
,
"8443"
)
end
end
port
=
parse
(
Cint
,
port_str
)
port
=
parse
(
Cint
,
port_str
)
if
cacert
==
nothing
if
cacert
==
""
cacert
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_SERVER_CERT"
)
cacert
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_SERVER_CERT"
)
end
end
if
username
==
nothing
if
username
==
""
username
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_USER"
,
"admin"
)
username
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_USER"
,
"admin"
)
end
end
if
password
==
nothing
if
password
==
"undefined"
password
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_PASSWORD"
,
"caosdb"
)
password
=
CaosDB
.
Utility
.
get_env_var
(
"CAOSDB_PASSWORD"
,
"caosdb"
)
...
@@ -423,8 +493,6 @@ function connect(
...
@@ -423,8 +493,6 @@ function connect(
end
end
export
connect
end
# Connection
end
# Connection
module
Entity
end
module
Entity
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment