World Conquest Chronicles

World Conquest Chronicles

go-exercises-backend, v1.7

Back-end of the service for solving programming exercises.

Support for user updating in the utility for managing users.

Change Log

  • utilities:
    • utility for managing users:
      • commands:
        • add a user:
          • parameters:
            • flag indicating the need to generate a password;
            • flag indicating whether the user is disabled or not;
          • simplify control of password generation;
        • update a user:
          • parameters:
            • username;
            • new username;
            • password;
            • password hashing cost;
            • flag indicating the need to generate a password;
            • generated password length;
            • flag indicating whether the user is disabled or not;
            • flag indicating whether the user is enabled or not;
          • can update the user fields individually.

Features

  • RESTful API:
    • models:
      • task model:
        • storing:
          • author ID;
          • title;
          • description;
          • boilerplate code;
          • test cases:
            • all test cases are represented by a single string;
        • operations:
          • getting all tasks:
            • calculate a total correctness flag based on all solutions of a requesting author;
            • sort the results by creation time in descending order;
            • process pagination:
              • implemented using an offset and a limit;
          • getting a single task by an ID:
            • calculate a total correctness flag based on all solutions of a requesting author;
          • creating:
            • automatically format a task boilerplate code;
          • updating by an ID:
            • allowed for its author only;
            • automatically format a task boilerplate code;
          • deleting by an ID:
            • allowed for its author only;
      • solution model:
        • storing:
          • author ID;
          • task ID;
          • code;
          • correctness flag;
          • testing result:
            • represented by a string;
        • operations:
          • getting all solutions by a task ID:
            • filtered by a requesting author:
              • allow a solution task author to get solutions of other authors;
            • sort the results by creation time in descending order;
            • process pagination:
              • implemented using an offset and a limit;
          • getting a single solution by an ID:
            • allowed for:
              • solution author;
              • solution task author;
          • creating:
            • automatically format a solution code;
          • updating by an ID:
            • performed by a queue consumer only (see below);
          • formatting a solution code;
    • representing:
      • in a JSON:
        • payloads:
          • of requests;
          • of responses;
      • as a plain text:
        • errors;
  • server:
    • additional routing:
      • serving static files;
    • storing settings in environment variables;
    • supporting graceful shutdown;
    • logging:
      • logging requests;
      • logging errors;
    • panics:
      • recovering on panics;
      • logging of panics;
  • authentication:
    • use the Bearer authentication scheme based on JSON Web Tokens:
      • store in a JWT claims:
        • expiration time claim;
        • user claim:
          • contains a whole user model;
    • generate a token signing key automatically by default;
    • user model:
      • storing:
        • username (unique);
        • password hash:
          • generated using the bcrypt function;
        • flag indicating whether the user is disabled or not;
  • databases:
  • interaction with queues:
    • using the RabbitMQ message broker;
    • common properties:
      • automatic declaring of the used queues;
      • passing of a message data in JSON;
    • operations:
      • producing solutions:
        • concurrent producing;
      • consuming solution results:
        • concurrent consuming;
        • once requeue the solution on failure;
  • utilities:
    • utility for managing users:
      • commands:
        • add a user:
          • parameters:
            • username;
            • password;
            • password hashing cost;
            • flag indicating the need to generate a password;
            • generated password length;
            • flag indicating whether the user is disabled or not;
        • update a user:
          • parameters:
            • username;
            • new username;
            • password;
            • password hashing cost;
            • flag indicating the need to generate a password;
            • generated password length;
            • flag indicating whether the user is disabled or not;
            • flag indicating whether the user is enabled or not;
          • can update the user fields individually;
  • distributing:

Usage of the go-exercises-manager Tool

$ go-exercises-manager -h | --help
$ go-exercises-manager add-user [options]
$ go-exercises-manager update-user [options]

Commands:

  • add-user — add the user;
  • update-user — update the user.

Options:

  • -h, --help — show the context-sensitive help message and exit;
  • -u STRING, --username STRING — username;
  • -U STRING, --new-username STRING — new username (applies only to the update-user command);
  • -p STRING, --password STRING — user password;
  • -c INTEGER, --cost INTEGER — cost of the user password hashing (range: from 4 to 31 inclusive; default: 10);
  • -g, --generate — generate the user password;
  • -l INTEGER, --length INTEGER — length of the user password to be generated (minimum: 6; default: 6);
  • -d, --disable — disable the user;
  • -e, --enable — enable the user (applies only to the update-user command).

Environment variables:

  • STORAGE_ADDRESSPostgreSQL connection URI (default: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable).

Repository

Link: https://github.com/thewizardplusplus/go-exercises-backend/tree/v1.7.

Content: code.

License: MIT.