Skip to content

Commit

Permalink
#10 keyring secured password + update Rdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Aug 5, 2020
1 parent 691b606 commit 01a1bea
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 44 deletions.
24 changes: 18 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", comment = c(ORCID = "0000-0002-5870-5762")))
Maintainer: Emmanuel Blondel <[email protected]>
Description: Provides an R interface to the 'GeoNetwork' API (<https://geonetwork-opensource.org/#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)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export(GNVersion)
import(XML)
import(geometa)
import(httr)
import(keyring)
importFrom(R6,R6Class)
importFrom(openssl,base64_encode)
46 changes: 31 additions & 15 deletions R/GNManager.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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)){
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -294,10 +306,6 @@ GNManager <- R6Class("GNManager",
return(private$token)
},

getUserPwd = function(){
return(paste0(private$user,":", private$pwd))
},

#getClassName
#---------------------------------------------------------------------------
getClassName = function(){
Expand All @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions R/geonapi.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#' @aliases geonapi
#' @docType package
#'
#' @import geometa
#'
#' @title 'GeoNetwork' API R Interface
#' @description Provides an R interface to the 'GeoNetwork' API (<https://geonetwork-opensource.org/#api>)
#' allowing to upload and publish metadata in a 'GeoNetwork' web-application and exposte it to OGC CSW
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions man/GNManager.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/GNPrivConfiguration.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/GNRESTRequest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/GNUtils.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/GNVersion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01a1bea

Please sign in to comment.