Giter Site home page Giter Site logo

Comments (4)

ADRFranklin avatar ADRFranklin commented on June 8, 2024

Well you should instead make use of .env files which sampctl autoloads and use the pawn-env plugin https://github.com/dakyskye/pawn-env

Because pawn.json files are generally uploaded to git repositories, we don't recommend storing sensitive information such as database information within them, this is why there exists a system like .env files which are designed to not be uploaded to repositories and are generally excluded in git repos.

from sampctl.

pedropapa avatar pedropapa commented on June 8, 2024

@ADRFranklin Thanks for your reply, correct, in my real codebase I don't have these constants in the pawn.json file, but rather as docker env vars, in my pawn.json I just have:

{
      "name": "main",
      "includes": ["../../legacy"],
      "args": ["-;+", "-(+", "-O1", "-Z+"],
      "compiler": {},
      "constants": {
        "MYSQL_HOST": "$MYSQL_HOST",
        "MYSQL_PORT": "$MYSQL_PORT",
        "MYSQL_USER": "$MYSQL_USER",
        "MYSQL_PASS": "$MYSQL_PASS",
        "MYSQL_DB": "$MYSQL_DB"
      }
    },

The snippet I posted was just a reproducible example of the issue with sampctl constants. To be fair I couldn't make it work using pawn compiler directly passing the constants as compiler options.

Using env variables also doesn't work. I'll check out the library you provided, cheers.

Also about having database connection configuration versioned: It actually depends on the use case right? I assume you're talking about production environment which I obviously agree, but if I have an integration tests setup on my ci workflow where the database schema is short-lived (created/destroyed during the workflow run) and only accessible from the CI tool (i.e. Github Actions), I don't see any harm or potential security issues, I would end up having something like:

{
....
  "builds": [
    {
      "name": "live",
      "includes": ["../../legacy"],
      "args": ["-;+", "-(+", "-O1", "-Z+"],
      "compiler": {},
      "constants": {
        "MYSQL_HOST": "$MYSQL_HOST",
        "MYSQL_PORT": "$MYSQL_PORT",
        "MYSQL_USER": "$MYSQL_USER",
        "MYSQL_PASS": "$MYSQL_PASS",
        "MYSQL_DB": "$MYSQL_DB"
      }
    },
    {
      "name": "tests",
      "includes": ["../../legacy"],
      "args": ["-;+", "-(+", "-O1", "-Z+", "-d3"],
      "compiler": {},
      "constants": {
        "MYSQL_HOST": "127.0.0.1",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "integration_tests",
        "MYSQL_PASS": "integration_tests",
        "MYSQL_DB": "integration_tests"
      }
    }
  ]
}

from sampctl.

ADRFranklin avatar ADRFranklin commented on June 8, 2024

The stuff in constants are passed to the compiler using the symbol params. I use constants all the time specifically for passing the environment, so I only build specific code. Never had a problem doing this or detecting if one exists, so I am not sure what doesn't work for you?

from sampctl.

pedropapa avatar pedropapa commented on June 8, 2024

@ADRFranklin I have no issues when the constant value is a number, however when it's a string it's defined as empty.

"constants": {
  "MY_CONSTANT_NUMBER": "300", // works
  "MY_CONSTANT_STRING": "test" // will output an empty string when running printf("%s", MY_CONSTANT_STRING);
},

from sampctl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.