R/organizations.R

Defines functions uo_delete_organization_users_delete uo_patch_organization_users_update uo_get_organization_users_get uo_post_organization_users_create uo_get_organization_users_list uo_get_organization_usage_details_get uo_get_organization_usage_get uo_get_organizations_resource_usage uo_patch_organizations_update uo_get_organizations uo_get_organizations_get

# (autogenerated content from swagger API)


#' Get details of an organization
#'
#'
#'  ### Description
#'  Get the details of an organization
#'
#'  ### Response Structure
#'  Details of the organization
#'  - `id`: Unique identifier for the organization (UUID)
#'
#'  - `name`: Name of the organization
#'
#'  - `creation_date`: Time the organization was created
#'
#'  - `subscription`: Name of the subscription
#'
#'
#'  #### Response Examples
#'  ```
#'  {
#'    "id": "abe2e406-fae5-4bcf-a3bc-956d756e4ecb",
#'    "name": "test-organization",
#'    "creation_date": "2020-03-25T15:43:46.101877Z",
#'    "subscription": "free"
#'  }
#'  ```
#'
#' @param organization_name descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_get_organizations_get <- function(organization_name, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::GET(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' Get organizations overview
#'
#'
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_get_organizations <- function(UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/")
    tk <- check_ubiobstoken(UBIOPS_TOKEN)
    h  <- create_headers(tk)
    res <- httr::GET(url=endpoint,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' Update details of an organization
#'
#'
#'  ### Description
#'  Update an organization. The user making the request must be admin of the organization. Users are able to update the name of the organization, but changes to the subscription can only be done by Dutch Analytics.
#'  To delete the end date of the current subscription, give the 'subscription_end_date' parameter with value null.
#'
#'  ### Optional Parameters
#'  - `name`: New organization name
#'  - `subscription`: New subscription
#'  - `subscription_agreed`: A boolean field indicating whether the Services Agreement and Terms & Conditions are accepted upon upgrading the subscription
#'  - `subscription_end_date`: End date of the new subscription. The required format is `YYYY-MM-DD`. The subscription will be cancelled on this date. If the subscription_end_date was previously set, but should be removed, give a null value for this field.
#'
#'  #### Request Examples
#'
#'
#'  ```
#'  {
#'    "name": "new-organization-name"
#'  }
#'  ```
#'  ```
#'  {
#'    "subscription": "professional",
#'    "subscription_agreed": true
#'  }
#'  ```
#'  ```
#'  {
#'    "subscription_end_date": "2020-08-30",
#'    "subscription_agreed": true
#'  }
#'  ```
#'
#'  ### Response Structure
#'  Details of the organization
#'  - `id`: Unique identifier for the organization (UUID)
#'
#'  - `name`: Name of the organization
#'
#'  - `creation_date`: Time the organization was created
#'
#'  - `subscription`: Name of the subscription
#'
#'
#'  #### Response Examples
#'  ```
#'  {
#'    "id": "abe2e406-fae5-4bcf-a3bc-956d756e4ecb",
#'    "name": "test-organization",
#'    "creation_date": "2020-03-25T15:43:46.101877Z",
#'    "subscription": "free"
#'  }
#'  ```
#'
#' @param organization_name descriptionhere
#' @param name descriptionhere
#' @param subscription descriptionhere
#' @param subscription_agreed descriptionhere
#' @param subscription_end_date descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_patch_organizations_update <- function(organization_name, name, subscription, subscription_agreed, subscription_end_date, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::PATCH(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' List resource usage of an organization
#'
#'
#'  ### Description
#'  List the total number of resources used by this organization
#'
#'  ### Response Structure
#'  A list containing the number of
#'  - projects
#'
#'  - users
#'
#'  - deployments
#'
#'  - versions
#'
#'  - pipelines
#'
#'  currently used by the organization.
#'
#'  #### Response Examples
#'  ```
#'  {
#'    "projects": 5,
#'    "users": 3,
#'    "deployments": 30,
#'    "versions": 47,
#'    "pipelines": 2
#'  }
#'  ```
#'
#' @param organization_name descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_get_organizations_resource_usage <- function(organization_name, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}/resources")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::GET(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' Get resource usage
#'
#'
#'  ### Description
#'  Get resource usage for the organization. This returns a list of metrics that are used for billing, aggregated per month.
#'
#'  ### Optional Parameters
#'  - `start_month`: date indicating the start month to fetch usage data from, formatted `YYYY-MM`. If omitted results are generated from one year ago.
#'
#'  ### Response Structure
#'   - `metric`: The metric that was measured
#'   - `object_type`: Type of object the metric was measured for (version or pipeline)
#'   - `usage`: an array of objects each containing the following:
#'       - `month`: Timestamp denoting the start of the month
#'       - `value`: Aggregated metric value for the given unit over the given month
#'
#'  #### Response Examples
#'  ```
#'  [
#'    {
#'      "object_type": "pipeline",
#'      "metric": "input_volume",
#'      "usage": [
#'        {
#'          "month": "2019-08-01T00:00:00Z",
#'          "value": 1840
#'        },
#'        {
#'          "month": "2019-09-01T00:00:00Z",
#'          "value": 400
#'        },
#'        {
#'          "month": "2019-10-01T00:00:00Z",
#'          "value": 1204
#'        },
#'        {
#'          "month": "2019-11-01T00:00:00Z",
#'          "value": 1598
#'        },
#'        {
#'          "month": "2019-12-01T00:00:00Z",
#'          "value": 824
#'        },
#'        {
#'          "month": "2020-01-01T00:00:00Z",
#'          "value": 2036
#'        },
#'        {
#'          "month": "2020-02-01T00:00:00Z",
#'          "value": 1438
#'        },
#'        {
#'          "month": "2020-03-01T00:00:00Z",
#'          "value": 932
#'        },
#'        {
#'          "month": "2020-04-01T00:00:00Z",
#'          "value": 528
#'        },
#'        {
#'          "month": "2020-05-01T00:00:00Z",
#'          "value": 1484
#'        },
#'        {
#'          "month": "2020-06-01T00:00:00Z",
#'          "value": 1942
#'        },
#'        {
#'          "month": "2020-07-01T00:00:00Z",
#'          "value": 1332
#'        }
#'      ]
#'    }
#'  ]
#'
#'  ```
#'
#' @param organization_name descriptionhere
#' @param start_month descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_get_organization_usage_get <- function(organization_name, start_month, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}/usage")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::GET(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' Get resource usage details
#'
#'
#'  ### Description
#'  Get resource usage for the organization. This returns a list of metrics that are used for billing, aggregated per day.
#'
#'  ### Optional Parameters
#'  - `month`: date indicating the month to fetch usage data for, formatted `YYYY-MM`. If omitted defaults to the current month
#'
#'  ### Response Structure
#'   - `metric`: The metric that was measured
#'   - `object_type`: Type of object the metric was measured for (version or pipeline)
#'   - `usage`: an array of objects each containing the following:
#'       - `day`: Timestamp denoting the start of the day
#'       - `value`: Aggregated metric value for the given unit over the given day
#'
#'  #### Response Examples
#'  ```
#'  [
#'    {
#'      "object_type": "version",
#'      "metric": "gb_seconds",
#'      "usage": [
#'        {
#'          "day": "2020-07-29T00:00:00Z",
#'          "value": 4200
#'        },
#'        {
#'          "day": "2020-07-28T00:00:00Z",
#'          "value": 840
#'        },
#'        {
#'          "day": "2020-07-30T00:00:00Z",
#'          "value": 960
#'        }
#'      ]
#'    },
#'    {
#'      "object_type": "pipeline",
#'      "metric": "input_volume",
#'      "usage": [
#'        {
#'          "day": "2020-07-28T00:00:00Z",
#'          "value": 1098
#'        },
#'        {
#'          "day": "2020-07-06T00:00:00Z",
#'          "value": 18
#'        },
#'        {
#'          "day": "2020-07-16T00:00:00Z",
#'          "value": 9
#'        },
#'        {
#'          "day": "2020-07-15T00:00:00Z",
#'          "value": 117
#'        },
#'        {
#'          "day": "2020-07-08T00:00:00Z",
#'          "value": 90
#'        }
#'      ]
#'    }
#'  ]
#'
#'  ```
#'
#' @param organization_name descriptionhere
#' @param month descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_get_organization_usage_details_get <- function(organization_name, month, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}/usage/details")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::GET(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' List the users in an organization
#'
#'
#'  ### Description
#'  List users and their details in an organization
#'
#'  ### Response Structure
#'  List of details of users
#'  - `id`: Unique identifier for the user (UUID)
#'
#'  - `email`: Email of the user
#'
#'  - `name`: Name of the user
#'
#'  - `surname`: Surname of the user
#'
#'  - `admin`: Boolean value indicating whether the user is an admin of the organization or not
#'
#'
#'  #### Response Examples
#'  ```
#'  [
#'    {
#'      "id": "54977bc3-2c3b-4d8f-97c7-aff89a95bf21",
#'      "email": "user@example.com",
#'      "name": "user",
#'      "surname": "name",
#'      "admin": true
#'    },
#'    {
#'      "id": "abe2e406-fae5-4bcf-a3bc-956d756e4ecb",
#'      "email": "user2@example.com",
#'      "name": "user",
#'      "surname": "name",
#'      "admin": false
#'    }
#'  ]
#'  ```
#'
#' @param organization_name descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_get_organization_users_list <- function(organization_name, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}/users")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::GET(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' Add a user to an organization
#'
#'
#'  ### Description
#'  Add a user to an organization as admin or normal user. The user making the request must be admin of the organization.
#'  The user can later be assigned roles in the projects defined in the scope the organization, such as project-admin, project-viewer etc.
#'
#'  ### Required Parameters
#'  - `email`: Email of the user
#'
#'  - `admin`: Boolean value indicating whether the user is added as an admin of the organization or not
#'
#'
#'  #### Request Examples
#'  ```
#'  {
#'    "email": "test@example.com",
#'    "admin": false
#'  }
#'  ```
#'
#'  ### Response Structure
#'  Details of the added user
#'  - `id`: Unique identifier for the user (UUID)
#'
#'  - `email`: Email of the user
#'
#'  - `name`: Name of the user
#'
#'  - `surname`: Surname of the user
#'
#'  - `admin`: Boolean value indicating whether the user is an admin of the organization or not
#'
#'
#'  #### Response Examples
#'  ```
#'  {
#'    "id": "332d7432-2742-4177-99a9-139e91e0110c",
#'    "email": "test@example.com",
#'    "name": "user",
#'    "surname": "name",
#'    "admin": false
#'  }
#'  ```
#'
#' @param organization_name descriptionhere
#' @param email descriptionhere
#' @param admin descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_post_organization_users_create <- function(organization_name, email, admin, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}/users")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::POST(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' Get details of a user in an organization
#'
#'
#'  ### Description
#'  Get the details of a user in an organization. The user making the request must be admin of the organization.
#'
#'  ### Response Structure
#'  Details of the user
#'  - `id`: Unique identifier for the user (UUID)
#'
#'  - `email`: Email of the user
#'
#'  - `name`: Name of the user
#'
#'  - `surname`: Surname of the user
#'
#'  - `admin`: Boolean value indicating whether the user is an admin of the organization or not
#'
#'
#'  #### Response Examples
#'  ```
#'  {
#'    "id": "332d7432-2742-4177-99a9-139e91e0110c",
#'    "email": "test@example.com",
#'    "name": "user",
#'    "surname": "name",
#'    "admin": false
#'  }
#'  ```
#'
#' @param organization_name descriptionhere
#' @param user_id descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_get_organization_users_get <- function(organization_name, user_id, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}/users/{user_id}")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::GET(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' Update details of a user in an organization
#'
#'
#'  ### Description
#'  Update the admin status of a user in an organization. The user making the request must be admin of the organization.
#'  It is not possible to change the last admin of an organization to a regular user.
#'
#'  ### Required Parameters
#'  - `admin`: Boolean value indicating whether the user is added as an admin of the organization or not
#'
#'
#'  #### Request Examples
#'  ```
#'  {
#'    "admin": true
#'  }
#'  ```
#'
#'  ### Response Structure
#'  Details of the user
#'  - `id`: Unique identifier for the user (UUID)
#'
#'  - `email`: Email of the user
#'
#'  - `name`: Name of the user
#'
#'  - `surname`: Surname of the user
#'
#'  - `admin`: Boolean value indicating whether the user is an admin of the organization or not
#'
#'
#'  #### Response Examples
#'  ```
#'  {
#'    "id": "332d7432-2742-4177-99a9-139e91e0110c",
#'    "email": "test@example.com",
#'    "name": "user",
#'    "surname": "name",
#'    "admin": true
#'  }
#'  ```
#'
#' @param organization_name descriptionhere
#' @param user_id descriptionhere
#' @param admin descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_patch_organization_users_update <- function(organization_name, user_id, admin, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}/users/{user_id}")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::PATCH(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}

#' Delete a user from an organization
#'
#'
#'  ### Description
#'  Delete a user from an organization. The user making the request must be admin of the organization.
#'  It is not possible to delete the last admin of an organization.
#'
#'  **When a user is deleted from an organization, all his roles from all projects defined in the scope of the organization are also deleted.**
#'
#' @param organization_name descriptionhere
#' @param user_id descriptionhere
#' @param UBIOPS_TOKEN default NULL will search for token in environment
#' @return descriptionhere
#' @export
uo_delete_organization_users_delete <- function(organization_name, user_id, UBIOPS_TOKEN=NULL){
    endpoint=glue::glue("{base}/organizations/{organization_name}/users/{user_id}")
        tk <- check_ubiobstoken(UBIOPS_TOKEN)
        h  <- create_headers(tk)
    body<-'somethinghere'
    res <- httr::DELETE(url=endpoint,body=body,encode = "json",h)
    httr::stop_for_status(res)
    httr::content(res)
}
RMHogervorst/ubiopscontroller documentation built on May 25, 2021, 5:26 p.m.