bdcs-api-0.1.0: BDCS API Server

Safe HaskellNone
LanguageHaskell2010

BDCS.API.V0

Description

API v0 routes

Synopsis

Documentation

data RecipesAPIError Source #

RecipesAPIError is used to report errors with the recipes routes

This is converted to a JSON error response that is used in the API responses

{
    "recipe": "unknown-recipe",
    "msg": "unknown-recipe.toml is not present on branch master"
}

Constructors

RecipesAPIError 

Fields

v0ApiServer :: GitLock -> ConnectionPool -> Server V0API Source #

Connect the V0API type to all of the handlers

errTest :: Handler [Text] Source #

A test using ServantErr

recipesList :: GitLock -> Text -> Maybe Int -> Maybe Int -> Handler RecipesListResponse Source #

apiv0recipeslist List the names of the available recipes

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
 {
     "recipes": [
         "development",
         "glusterfs",
         "http-server",
         "jboss",
         "kubernetes",
         "octave",
     ],
     "offset": 0,
     "limit": 20,
     "total": 6
 }

recipesInfo :: GitLock -> Text -> String -> Handler RecipesInfoResponse Source #

apiv0recipesinfo/<recipes> Return the contents of the recipe, or a list of recipes

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipes_names
A comma separated list of recipe names

The errors list may be empty, or may include recipe-specific errors if there was a problem retrieving it.

{
    "changes": [
        {
            "name": "recipe-test",
            "changed": true
        },
    ],
    "recipes": [
        {
            "name": "http-server",
            "description": "An example http server with PHP and MySQL support.",
            "version": "0.0.1",
            "modules": [
                {
                    "name": "httpd",
                    "version": "2.4.*"
                },
                {
                    "name": "mod_auth_kerb",
                    "version": "5.4"
                },
                {
                    "name": "mod_ssl",
                    "version": "2.4.*"
                },
                {
                    "name": "php",
                    "version": "5.4.*"
                },
                {
                    "name": "php-mysql",
                    "version": "5.4.*"
                }
            ],
            "packages": [
                {
                    "name": "tmux",
                    "version": "2.2"
                },
                {
                    "name": "openssh-server",
                    "version": "6.6.*"
                },
                {
                    "name": "rsync",
                    "version": "3.0.*"
                }
            ]
        },
    "errors": [
        {
            "recipe": "a-missing-recipe",
            "msg": "Error retrieving a-missing-recipe"
        }
    ]
}

getRecipeInfo :: GitLock -> Text -> Text -> IO (Either String (Bool, Recipe)) Source #

Get the recipe from the workspace or from git If there is neither workspace or git recipes then an error is returned.

recipesChanges :: GitLock -> Text -> String -> Maybe Int -> Maybe Int -> Handler RecipesChangesResponse Source #

apiv0recipeschanges/<recipes> Return the commit history of the recipes

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipes_name
The recipe name
moffset
The offset from the start of the results. Defaults to 0
mlimit
Limit to the number of results to be returned. Defaults to 20

The changes for each listed recipe will have offset and limit applied to them. This means that there will be cases where changes will be empty, when offset > total for the recipe.

If a recipe commit has been tagged as a new revision the changes will include a revision field set to the revision number. If the commit has not been tagged it will not have this field included.

{
    "recipes": [
        {
            "name": "nfs-server",
            "changes": [
                {
                    "commit": "97d483e8dd0b178efca9a805e5fd8e722c48ac8e",
                    "time": "Wed,  1 Mar 2017 13:29:37 -0800",
                    "summary": "Recipe nfs-server saved"
                },
                {
                    "commit": "857e1740f983bf033345c3242204af0ed7b81f37",
                    "time": "Wed,  1 Mar 2017 09:28:53 -0800",
                    "summary": "Recipe nfs-server saved",
                    "revision" : 1
                }
            ],
            "total": 2
        },
        {
            "name": "ruby",
            "changes": [
                {
                    "commit": "4b84f072befc3f4debbe1348d6f4b166f7c83d78",
                    "time": "Wed,  1 Mar 2017 13:32:09 -0800",
                    "summary": "Recipe ruby saved"
                },
                {
                    "commit": "85999253c1790367a860a344ea622971b7e0a050",
                    "time": "Wed,  1 Mar 2017 13:31:19 -0800",
                    "summary": "Recipe ruby saved"
                }
            ],
            "total": 2
        }
    ],
    "errors": [
        {
            "recipe": "a-missing-recipe",
            "msg": "Error retrieving a-missing-recipe"
        }
    ]
    "offset": 0,
    "limit": 20
}

recipesNew :: GitLock -> Text -> Recipe -> Handler RecipesStatusResponse Source #

POST apiv0recipesnew Create or update a recipe.

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipe
The Recipe record

The body of the post is a JSON or TOML representation of the recipe. If Conten-Type is application/json it uses the same format received from apiv0recipesinfo<recipes>, and if it is textx-toml it uses the recipe's TOML format for the body.

The response for a successful POST is:

{
    "status": true,
    "errors": []
}

recipesDelete :: GitLock -> Text -> String -> Handler RecipesStatusResponse Source #

DELETE apiv0recipesdelete/<recipe> Delete the named recipe from the repository branch

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipe_name
The recipe name

The response for a successful DELETE is:

{
    "status": true,
    "errors": []
}

recipesUndo :: GitLock -> Text -> String -> String -> Handler RecipesStatusResponse Source #

POST apiv0recipesundo<recipe><commit> Revert a recipe to a previous commit

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipe_name
The recipe name
commit
The commit to revert to

The response for a successful POST is:

{
    "status": true,
    "errors": []
}

recipesWorkspace :: GitLock -> Text -> Recipe -> Handler RecipesStatusResponse Source #

POST apiv0recipesworkspace Update the temporary recipe workspace

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipe
The Recipe record

The body of the post is the same as recipesnew/. For more details on the workspace see BDCS.API.Workspace

The response for a successful POST is:

{
    "status": true,
    "errors": []
}

recipesTag :: GitLock -> Text -> String -> Handler RecipesStatusResponse Source #

POST apiv0recipestag/recipe Tag the most recent recipe commit as the next revision

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipe_name
The recipe name

If the commit is already tagged it will return False.

The response for a successful POST is:

{
    "status": true,
    "errors": []
}

recipesDiff :: GitLock -> Text -> String -> String -> String -> Handler RecipesDiffResponse Source #

apiv0recipesdiffrecipefrom_commit/to_commit Return the diff between the two recipe commits.

repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipe_name
The recipe name
from_commit
The older commit to caclulate the difference from, can also be NEWEST
to_commit
The newer commit to calculate the diff. to, can also be NEWEST or WORKSPACE

If there is an error retrieving a commit (eg. it cannot find the hash), it will use HEAD instead and log an error.

In addition to the commit hashes listed by a call to recipeschanges/<recipe-name> you can use NEWEST to compare the latest commit, and WORKSPACE to compare it with the current temporary workspace version of the recipe. eg. to see what the differences are between the current workspace and most recent commit of http-server you would call:

/recipes/diff/http-server/NEWEST/WORKSPACE

Each entry in the response's diff object contains the old recipe value and the new one. If old is null and new is set, then it was added. If new is null and old is set, then it was removed. If both are set, then it was changed.

The old/new entries will have the name of the recipe field that was changed. This can be one of: Name, Description, Version, Module, or Package. The contents for these will be the old/new values for them.

In the example below the description and version were changed. The php module's version was changed, the rsync package was removed, and the vim-enhanced package was added.

# Examples

{
    "diff": [
        {
            "old": {
                "Description": "An example http server with PHP and MySQL support."
            },
            "new": {
                "Description": "Apache HTTP Server"
            }
        },
        {
            "old": {
                "Version": "0.0.1"
            },
            "new": {
                "Version": "0.1.1"
            }
        },
        {
            "old": {
                "Module": {
                    "name": "php",
                    "version": "5.4.*"
                }
            },
            "new": {
                "Module": {
                    "name": "php",
                    "version": "5.6.*"
                }
            }
        },
        {
            "old": null,
            "new": {
                "Package": {
                    "name": "vim-enhanced",
                    "version": "8.0.*"
                }
            }
        },
        {
            "old": {
                "Package": {
                    "name": "rsync",
                    "version": "3.0.*"
                }
            },
            "new": null
        }
    ]
}

recipesDepsolve :: ConnectionPool -> GitLock -> Text -> String -> Handler RecipesDepsolveResponse Source #

apiv0recipesdepsolve/recipes Return the recipe and summary information about all of its modules and packages.

pool
The sqlite connection pool object
repoLock
The git repositories ReadWriteLock and Repository object
branch
The branch name
recipe_names
The recipe names to depsolve, comma-separated if there is more than one

If a workspace version of the recipe is found it will be used for the depsolve. If there are any errors reading the recipe, or depsolving it, they will be returned in the errors object.

# Error example

{
    "errors": [
        {
            "msg": "nfs-server.toml is not present on branch master",
            "recipe": "nfs-server"
        }
    ],
    "recipes": []
}

A successful result will include 3 items. dependencies will be the NEVRAs of all of the projects needed to satisfy the recipe's dependencies. modules will be the project NEVRAs for the modules and packages explicitly listed in the recipe, and recipe will be a copy of the recipe that was depsolved.

# Abbreviated successful example

{
    "errors": [],
    "recipes": [
        {
            "dependencies": [
                {
                    "arch": "x86_64",
                    "epoch": "0",
                    "name": "apr",
                    "release": "3.el7",
                    "version": "1.4.8"
                },
                {
                    "arch": "x86_64",
                    "epoch": "0",
                    "name": "apr-util",
                    "release": "6.el7",
                    "version": "1.5.2"
                },
                ...
            ],
            "modules": [
                {
                    "arch": "x86_64",
                    "epoch": "0",
                    "name": "httpd",
                    "release": "67.el7",
                    "version": "2.4.6"
                },
                {
                    "arch": "x86_64",
                    "epoch": "0",
                    "name": "mod_auth_kerb",
                    "release": "28.el7",
                    "version": "5.4"
                },
                ...
            ],
           "recipe": {
                "description": "An example http server with PHP and MySQL support.",
                "modules": [
                    {
                        "name": "httpd",
                        "version": "2.4.*"
                    },
                    {
                        "name": "mod_auth_kerb",
                        "version": "5.4"
                    },
                    {
                        "name": "mod_ssl",
                        "version": "2.4.*"
                    },
                    {
                        "name": "php",
                        "version": "5.4.*"
                    },
                    {
                        "name": "php-mysql",
                        "version": "5.4.*"
                    }
                ],
                "name": "http-server",
                "packages": [
                    {
                        "name": "tmux",
                        "version": "2.2"
                    },
                    {
                        "name": "openssh-server",
                        "version": "6.6.*"
                    },
                    {
                        "name": "rsync",
                        "version": "3.0.*"
                    }
                ],
                "version": "0.2.0"
            }
        }
    ]
}

recipesFreeze :: ConnectionPool -> GitLock -> Text -> String -> Handler RecipesFreezeResponse Source #

apiv0recipesfreeze/recipes Return the contents of the recipe with frozen dependencies instead of expressions.

This depsolves the recipe, and then replaces the modules and packages versions with the EVR found by the depsolve, returning a frozen recipe.

# Examples

{
    "errors": [],
    "recipes": [
        {
            "description": "An example http server with PHP and MySQL support.",
            "modules": [
                {
                    "name": "httpd",
                    "version": "2.4.6-67.el7"
                },
                {
                    "name": "mod_auth_kerb",
                    "version": "5.4-28.el7"
                },
                {
                    "name": "mod_ssl",
                    "version": "1:2.4.6-67.el7"
                },
                {
                    "name": "php",
                    "version": "5.4.16-42.el7"
                },
                {
                    "name": "php-mysql",
                    "version": "5.4.16-42.el7"
                }
            ],
            "name": "http-server",
            "packages": [
                {
                    "name": "tmux",
                    "version": "1.8-4.el7"
                },
                {
                    "name": "openssh-server",
                    "version": "7.4p1-11.el7"
                },
                {
                    "name": "rsync",
                    "version": "3.0.9-18.el7"
                }
            ],
            "version": "0.2.0"
        }
    ]
}

projectsList :: ConnectionPool -> Maybe Int -> Maybe Int -> Handler ProjectsListResponse Source #

apiv0projectslist Return the list of available projects

# Example

{
    "limit": 20,
    "offset": 0,
    "projects": [
        {
            "description": "389 Directory Server is an LDAPv3 compliant server. ...",
            "homepage": "https://www.port389.org/",
            "name": "389-ds-base",
            "summary": "389 Directory Server (base)",
            "upstream_vcs": "UPSTREAM_VCS"
        },
        }
    ],
    "total": 2117
}

projectsInfo :: ConnectionPool -> String -> Handler ProjectsInfoResponse Source #

apiv0projectsinfo/projects Return information about the comma-separated list of projects

# Example

{
    "projects": [
        {
            "description": "The GNU tar program saves many files ...",
            "homepage": "http://www.gnu.org/software/tar/",
            "name": "tar",
            "summary": "A GNU file archiving program",
            "upstream_vcs": "UPSTREAM_VCS"
        }
    ]
}

projectsDepsolve :: ConnectionPool -> String -> Handler ProjectsDepsolveResponse Source #

apiv0projectsdepsolve/projects Return the dependencies of a comma separated list of projects

depsolveProjects :: ConnectionPool -> [Text] -> IO (Either String [PackageNEVRA]) Source #

Depsolve a list of project names, returning a list of PackageNEVRA If there is an error it returns an empty list