Decomposition #2

Merged
Ghost merged 4 commits from :master into master 2021-11-12 11:22:23 +02:00

API changes

  • /systemVersion is now /system/version
  • /getDKIM is now /services/mailserver/dkim
  • /pythonVersion is now /system/pythonVersion
  • /users/create is now POST on /users
  • /users/deleteUser is now DELETE on /users
  • /services/SERVICE_NAME/enable and /services/SERVICE_NAME/disable now also return message in their responses.
  • /services/ssh/key/send: response field result renamed to status.

Other changes

  • Moved to Python 3.9
  • Moved to flask_restful's Resource objects.
  • distutils is deprecated, moved to setuptools.
  • Bumped version 1.0.1 → 1.1.0

Code formatting

Black is used for code formatting, let's use it.

No linting rules applied yet.

Known issues

  • Nix kills api service when running rebuild

Nix files changes

api-package.nix

  • Moved to Python 3.9
  • Removed Pandas
  • Added setuptools
  • Bumped version
{ nixpkgs ? import <nixpkgs> {}, pythonPkgs ? nixpkgs.pkgs.python39Packages }:

let
  inherit (nixpkgs) pkgs;
  inherit pythonPkgs;

  selfprivacy-api = { buildPythonPackage, flask, flask-restful, setuptools }:
    buildPythonPackage rec {
      pname = "selfprivacy-api";
      version = "1.1";
      src = {TODO} };
      propagatedBuildInputs = [ flask flask-restful setuptools ];
      meta = {
        description = ''
          SelfPrivacy Server Management API
        '';
      };
    };
  drv = pythonPkgs.callPackage selfprivacy-api {};
in
  if pkgs.lib.inNixShell then drv.env else drv

api-module.nix

  • main.py now app.py
  • added restic and mkpasswd to PATH
{ config, lib, pkgs, ... }:

with lib;

let
  selfprivacy-api = pkgs.callPackage ./api-package.nix {};
  cfg = config.services.selfprivacy-api;
  directionArg = if cfg.direction == ""
    then ""
    else "--direction=${cfg.direction}";
in 
{
  options.services.selfprivacy-api = {
    enable = mkOption {
      default = false;
      type = types.bool;
      description = ''
        Enable SelfPrivacy API service
      '';
    };
  };
  config = lib.mkIf cfg.enable {

    systemd.services.selfprivacy-api = {
      description = "API Server used to control system from the mobile application";
      environment = config.nix.envVars // {
        inherit (config.environment.sessionVariables) NIX_PATH;
        HOME = "/root";
        PYTHONUNBUFFERED = "1";
      } // config.networking.proxy.envVars;
      path = [ "/var/" "/var/dkim/" pkgs.coreutils pkgs.gnutar pkgs.xz.bin pkgs.gzip pkgs.gitMinimal config.nix.package.out pkgs.nixos-rebuild pkgs.restic pkgs.mkpasswd ];
      after = [ "network-online.target" ];
      wantedBy = [ "network-online.target" ];
      serviceConfig = {
        User = "root";
        ExecStart = "${selfprivacy-api}/bin/app.py";
        Restart = "always";
        RestartSec = "5";
      };
    };
  };
}

# API changes * `/systemVersion` is now `/system/version` * `/getDKIM` is now `/services/mailserver/dkim` * `/pythonVersion` is now `/system/pythonVersion` * `/users/create` is now `POST` on `/users` * `/users/deleteUser` is now `DELETE` on `/users` * `/services/SERVICE_NAME/enable` and `/services/SERVICE_NAME/disable` now also return message in their responses. * `/services/ssh/key/send`: response field `result` renamed to `status`. # Other changes * Moved to Python 3.9 * Moved to `flask_restful`'s `Resource` objects. * `distutils` is [deprecated](https://docs.python.org/3/whatsnew/3.10.html#distutils-deprecated), moved to `setuptools`. * Bumped version 1.0.1 → 1.1.0 # Code formatting [Black](https://github.com/psf/black) is used for code *formatting*, let's use it. No *linting* rules applied yet. # Known issues * Nix kills api service when running rebuild # Nix files changes ## api-package.nix * Moved to Python 3.9 * Removed Pandas * Added setuptools * Bumped version ```nix { nixpkgs ? import <nixpkgs> {}, pythonPkgs ? nixpkgs.pkgs.python39Packages }: let inherit (nixpkgs) pkgs; inherit pythonPkgs; selfprivacy-api = { buildPythonPackage, flask, flask-restful, setuptools }: buildPythonPackage rec { pname = "selfprivacy-api"; version = "1.1"; src = {TODO} }; propagatedBuildInputs = [ flask flask-restful setuptools ]; meta = { description = '' SelfPrivacy Server Management API ''; }; }; drv = pythonPkgs.callPackage selfprivacy-api {}; in if pkgs.lib.inNixShell then drv.env else drv ``` ## api-module.nix * main.py now app.py * added restic and mkpasswd to PATH ```nix { config, lib, pkgs, ... }: with lib; let selfprivacy-api = pkgs.callPackage ./api-package.nix {}; cfg = config.services.selfprivacy-api; directionArg = if cfg.direction == "" then "" else "--direction=${cfg.direction}"; in { options.services.selfprivacy-api = { enable = mkOption { default = false; type = types.bool; description = '' Enable SelfPrivacy API service ''; }; }; config = lib.mkIf cfg.enable { systemd.services.selfprivacy-api = { description = "API Server used to control system from the mobile application"; environment = config.nix.envVars // { inherit (config.environment.sessionVariables) NIX_PATH; HOME = "/root"; PYTHONUNBUFFERED = "1"; } // config.networking.proxy.envVars; path = [ "/var/" "/var/dkim/" pkgs.coreutils pkgs.gnutar pkgs.xz.bin pkgs.gzip pkgs.gitMinimal config.nix.package.out pkgs.nixos-rebuild pkgs.restic pkgs.mkpasswd ]; after = [ "network-online.target" ]; wantedBy = [ "network-online.target" ]; serviceConfig = { User = "root"; ExecStart = "${selfprivacy-api}/bin/app.py"; Restart = "always"; RestartSec = "5"; }; }; }; } ```
inex added 1 commit 2021-11-11 20:34:21 +02:00
inex added 1 commit 2021-11-11 20:48:49 +02:00
inex added 2 commits 2021-11-11 20:50:11 +02:00
Ghost merged commit dbb4c10956 into master 2021-11-12 11:22:23 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: SelfPrivacy/selfprivacy-rest-api#2
There is no content yet.