diff --git a/.travis.yml b/.travis.yml index a4e1317..03e9bad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,9 @@ matrix: - name: "GeoNetwork 3.8.2" os: linux services: docker - apt_packages: libxml2-dev + apt_packages: + - libxml2-dev + - libsodium-dev env: - GN_VERSION=3.8.2 before_install: @@ -47,7 +49,9 @@ matrix: - name: "GeoNetwork 3.6.0" os: linux services: docker - apt_packages: libxml2-dev + apt_packages: + - libxml2-dev + - libsodium-dev env: - GN_VERSION=3.6.0 before_install: @@ -65,7 +69,9 @@ matrix: - name: "GeoNetwork 3.4.4" os: linux services: docker - apt_packages: libxml2-dev + apt_packages: + - libxml2-dev + - libsodium-dev env: - GN_VERSION=3.4.4 before_install: @@ -83,7 +89,9 @@ matrix: - name: "GeoNetwork 3.2.2" os: linux services: docker - apt_packages: libxml2-dev + apt_packages: + - libxml2-dev + - libsodium-dev env: - GN_VERSION=3.2.2 before_install: @@ -101,7 +109,9 @@ matrix: - name: "GeoNetwork 3.0.5" os: linux services: docker - apt_packages: libxml2-dev + apt_packages: + - libxml2-dev + - libsodium-dev env: - GN_VERSION=3.0.5 before_install: @@ -115,7 +125,9 @@ matrix: - name: "GeoNetwork 2.6.4" os: linux services: docker - apt_packages: libxml2-dev + apt_packages: + - libxml2-dev + - libsodium-dev env: - GN_VERSION=2.6.4 before_install: diff --git a/DESCRIPTION b/DESCRIPTION index fde1c5f..77ec973 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,16 +1,17 @@ Package: geonapi Type: Package Title: 'GeoNetwork' API R Interface -Version: 0.3-1 -Date: 2020-01-20 +Version: 0.4 +Date: 2020-08-05 Authors@R: c(person("Emmanuel", "Blondel", role = c("aut", "cre"), email = "emmanuel.blondel1@gmail.com", comment = c(ORCID = "0000-0002-5870-5762"))) Maintainer: Emmanuel Blondel Description: Provides an R interface to the 'GeoNetwork' API () allowing to upload and publish metadata in a 'GeoNetwork' web-application and exposte it to OGC CSW. -Depends: R (>= 3.1.0), geometa +Depends: R (>= 3.1.0), geometa, keyring Imports: R6, openssl, httr, XML Suggests: testthat, roxygen2 License: MIT + file LICENSE URL: https://github.com/eblondel/geonapi/wiki, https://geonetwork-opensource.org BugReports: https://github.com/eblondel/geonapi/issues LazyLoad: yes -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.0 +Roxygen: list(r6 = FALSE) diff --git a/NAMESPACE b/NAMESPACE index 169648c..82ca990 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,5 +9,6 @@ export(GNVersion) import(XML) import(geometa) import(httr) +import(keyring) importFrom(R6,R6Class) importFrom(openssl,base64_encode) diff --git a/R/GNManager.R b/R/GNManager.R index 9057380..ec98517 100644 --- a/R/GNManager.R +++ b/R/GNManager.R @@ -6,6 +6,9 @@ #' @import httr #' @import XML #' @importFrom openssl base64_encode +#' @import keyring +#' @import geometa +#' #' @export #' @keywords geonetwork rest api #' @return Object of \code{\link{R6Class}} with methods for communication with @@ -55,9 +58,18 @@ #' This methods attempts a connection to GeoNetwork REST API. User internally #' during initialization of \code{GNManager}. #' } +#' \item{\code{getCookies()}}{ +#' Get user session cookies +#' } +#' \item{\code{getToken()}}{ +#' Get user session token +#' } #' \item{\code{getClassName()}}{ #' Retrieves the name of the class instance #' } +#' \item{\code{getGroups()}}{ +#' Retrives the list of user groups available in Geonetwork +#' } #' \item{\code{insertMetadata(xml, file, geometa, group, category, stylesheet, validate, geometa_validate, geometa_inspire)}}{ #' Inserts a metadata by file, XML object or \pkg{geometa} object of class #' \code{ISOMetadata} or \code{ISOFeatureCatalogue}. If successful, returns the Geonetwork @@ -108,8 +120,8 @@ GNManager <- R6Class("GNManager", #TODO provider specific formatter to prevent these fields to be printable private = list( + keyring_service = NULL, user = NULL, - pwd = NULL, token = NULL, cookies = NULL, @@ -194,7 +206,7 @@ GNManager <- R6Class("GNManager", #baseUrl self$url = sprintf("%s/srv/%s", url, self$lang) - + private$keyring_service <- paste0("geonapi@", url) #try to login if(!is.null(user) && !is.null(pwd)){ @@ -245,7 +257,7 @@ GNManager <- R6Class("GNManager", } private$user <- user - private$pwd <- pwd + keyring::key_set_with_value(private$keyring_service, username = user, password = pwd) req_cookies <- cookies(req) cookies <- as.list(req_cookies$value) @@ -294,10 +306,6 @@ GNManager <- R6Class("GNManager", return(private$token) }, - getUserPwd = function(){ - return(paste0(private$user,":", private$pwd)) - }, - #getClassName #--------------------------------------------------------------------------- getClassName = function(){ @@ -313,7 +321,8 @@ GNManager <- R6Class("GNManager", url = self$getUrl(), path = "/xml.info", token = private$token, cookies = private$cookies, - user = private$user, pwd = private$pwd, + user = private$user, + pwd = keyring::key_get(private$keyring_service, username = private$user), query = list(type = "groups"), verbose = self$verbose.debug ) @@ -379,7 +388,8 @@ GNManager <- R6Class("GNManager", url = self$getUrl(), path = "/xml.metadata.insert", token = private$token, cookies = private$cookies, - user = private$user, pwd = private$pwd, + user = private$user, + pwd = keyring::key_get(private$keyring_service, username = private$user), content = gnRequest$encode(), contentType = "text/xml", verbose = self$verbose.debug @@ -421,7 +431,8 @@ GNManager <- R6Class("GNManager", url = self$getUrl(), path = ifelse(self$version$value$major < 3, "/metadata.admin", "md.privileges.update"), token = private$token, cookies = private$cookies, - user = private$user, pwd = private$pwd, + user = private$user, + pwd = keyring::key_get(private$keyring_service, username = private$user), query = queryParams, verbose = self$verbose.debug ) @@ -460,7 +471,8 @@ GNManager <- R6Class("GNManager", url = self$getUrl(), path = "/xml.metadata.get", token = private$token, cookies = private$cookies, - user = private$user, pwd = private$pwd, + user = private$user, + pwd = keyring::key_get(private$keyring_service, username = private$user), content = gnRequest$encode(), contentType = "text/xml", verbose = self$verbose.debug @@ -566,7 +578,8 @@ GNManager <- R6Class("GNManager", url = self$getUrl(), path = "/metadata.update.finish", token = private$token, cookies = private$cookies, - user = private$user, pwd = private$pwd, + user = private$user, + pwd = keyring::key_get(private$keyring_service, username = private$user), content = gnRequest$encode(), contentType = "text/xml", verbose = self$verbose.debug @@ -593,7 +606,8 @@ GNManager <- R6Class("GNManager", url = self$getUrl(), path = "/xml.metadata.delete", token = private$token, cookies = private$cookies, - user = private$user, pwd = private$pwd, + user = private$user, + pwd = keyring::key_get(private$keyring_service, username = private$user), content = gnRequest$encode(), contentType = "text/xml", verbose = self$verbose.debug @@ -625,7 +639,8 @@ GNManager <- R6Class("GNManager", url = self$getUrl(), path = "/xml.metadata.select", token = private$token, cookies = private$cookies, - user = private$user, pwd = private$pwd, + user = private$user, + pwd = keyring::key_get(private$keyring_service, username = private$user), content = gnSelectRequest$encode(), contentType = "text/xml", verbose = self$verbose.debug @@ -636,7 +651,8 @@ GNManager <- R6Class("GNManager", url = self$getUrl(), path = "/xml.metadata.batch.delete", token = private$token, cookies = private$cookies, - user = private$user, pwd = private$pwd, + user = private$user, + pwd = keyring::key_get(private$keyring_service, username = private$user), content = gnDeleteRequest$encode(), contentType = "text/xml", verbose = self$verbose.debug diff --git a/R/geonapi.R b/R/geonapi.R index b89f0e8..2ece490 100644 --- a/R/geonapi.R +++ b/R/geonapi.R @@ -3,8 +3,6 @@ #' @aliases geonapi #' @docType package #' -#' @import geometa -#' #' @title 'GeoNetwork' API R Interface #' @description Provides an R interface to the 'GeoNetwork' API () #' allowing to upload and publish metadata in a 'GeoNetwork' web-application and exposte it to OGC CSW diff --git a/README.md b/README.md index 2dd5b6c..60e0372 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build Status](https://travis-ci.org/eblondel/geonapi.svg?branch=master)](https://travis-ci.org/eblondel/geonapi) [![codecov.io](http://codecov.io/github/eblondel/geonapi/coverage.svg?branch=master)](http://codecov.io/github/eblondel/geonapi?branch=master) -[![Github_Status_Badge](https://img.shields.io/badge/Github-0.3--1-blue.svg)](https://github.com/eblondel/geonapi) +[![Github_Status_Badge](https://img.shields.io/badge/Github-0.4-blue.svg)](https://github.com/eblondel/geonapi) [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/geonapi)](https://cran.r-project.org/package=geonapi) [![CRAN checks](https://cranchecks.info/badges/worst/geonapi)](https://cran.r-project.org/web/checks/check_results_geonapi.html) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1345012.svg)](https://doi.org/10.5281/zenodo.1345012) diff --git a/man/GNManager.Rd b/man/GNManager.Rd index 4d9a161..95f1747 100644 --- a/man/GNManager.Rd +++ b/man/GNManager.Rd @@ -4,9 +4,8 @@ \name{GNManager} \alias{GNManager} \title{GeoNetwork REST API Manager} -\format{\code{\link{R6Class}} object.} -\usage{ -GNManager +\format{ +\code{\link{R6Class}} object. } \value{ Object of \code{\link{R6Class}} with methods for communication with @@ -63,9 +62,18 @@ GeoNetwork REST API Manager This methods attempts a connection to GeoNetwork REST API. User internally during initialization of \code{GNManager}. } + \item{\code{getCookies()}}{ + Get user session cookies + } + \item{\code{getToken()}}{ + Get user session token + } \item{\code{getClassName()}}{ Retrieves the name of the class instance } + \item{\code{getGroups()}}{ + Retrives the list of user groups available in Geonetwork + } \item{\code{insertMetadata(xml, file, geometa, group, category, stylesheet, validate, geometa_validate, geometa_inspire)}}{ Inserts a metadata by file, XML object or \pkg{geometa} object of class \code{ISOMetadata} or \code{ISOFeatureCatalogue}. If successful, returns the Geonetwork diff --git a/man/GNPrivConfiguration.Rd b/man/GNPrivConfiguration.Rd index ae4af0c..59cfe1a 100644 --- a/man/GNPrivConfiguration.Rd +++ b/man/GNPrivConfiguration.Rd @@ -5,11 +5,10 @@ \alias{GNPrivConfiguration} \alias{GNPriv} \title{A GeoNetwork privilege configuration} -\format{\code{\link{R6Class}} object.} -\usage{ -GNPriv +\format{ +\code{\link{R6Class}} object. -GNPrivConfiguration +\code{\link{R6Class}} object. } \value{ Object of \code{\link{R6Class}} for modelling a GeoNetwork Privilege configuration diff --git a/man/GNRESTRequest.Rd b/man/GNRESTRequest.Rd index d1419d7..21cb4b4 100644 --- a/man/GNRESTRequest.Rd +++ b/man/GNRESTRequest.Rd @@ -4,9 +4,8 @@ \name{GNRESTRequest} \alias{GNRESTRequest} \title{GeoNetwork REST API REST Request} -\format{\code{\link{R6Class}} object.} -\usage{ -GNRESTRequest +\format{ +\code{\link{R6Class}} object. } \value{ Object of \code{\link{R6Class}} for modelling a GeoNetwork REST request diff --git a/man/GNUtils.Rd b/man/GNUtils.Rd index 9ba71e2..00bf1d6 100644 --- a/man/GNUtils.Rd +++ b/man/GNUtils.Rd @@ -4,9 +4,8 @@ \name{GNUtils} \alias{GNUtils} \title{GeoNetwork REST API Manager Utils} -\format{\code{\link{R6Class}} object.} -\usage{ -GNUtils +\format{ +\code{\link{R6Class}} object. } \value{ Object of \code{\link{R6Class}} with static util methods for communication diff --git a/man/GNVersion.Rd b/man/GNVersion.Rd index 0be738f..cd6d640 100644 --- a/man/GNVersion.Rd +++ b/man/GNVersion.Rd @@ -4,9 +4,8 @@ \name{GNVersion} \alias{GNVersion} \title{A GeoNetwork version} -\format{\code{\link{R6Class}} object.} -\usage{ -GNVersion +\format{ +\code{\link{R6Class}} object. } \value{ Object of \code{\link{R6Class}} for modelling a GeoNetwork version