nextstrain / nextstrain.org

The Nextstrain website
https://nextstrain.org
GNU Affero General Public License v3.0
88 stars 49 forks source link

[dev only] explain configuration settings in server start up message #685

Closed jameshadfield closed 5 months ago

jameshadfield commented 1 year ago

The nextstrain.org server has conditional logic to change certain features into a "testing" / "development" mode. There are a few different (overlapping) concepts of testing/development, and it would be great to say up-front what the server is using. The logic to choose different modes is quite flexible -- environment variables, server configuration files, local aws configuration files etc, and it can be hard to keep track of what's being used! As an example of the kind of start-up message I would find really useful:

  -------------------------------------------------------------------------

  Nextstrain is an open-source project to harness the scientific and public
  health potential of pathogen genome data.

  This is the server behind nextstrain.org.
  See https://github.com/nextstrain/nextstrain.org for more.

  Server listening at http://localhost:5000
  Running in testing mode:
    Cognito user pool: nextstrain.org-testing
    Server knows about 3 groups (see ./env/testing/groups.json)
    Charon API requests may be made to localhost:8000
  Authorization is via IAM user nextstrain.org
  -------------------------------------------------------------------------

(I'm not sure the IAM user name is knowable, but if it's not we could at least say via env variables $... and $... or via ./aws/config etc.)

There are other things we could include here (perhaps GITHUB_TOKEN) but the above would be the most useful

jameshadfield commented 5 months ago

I'm not sure the IAM user name is knowable

Via an unrelated slack comment by @victorlin this is pretty simple to obtain:

// <https://www.npmjs.com/package/@aws-sdk/client-sts>
// <https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sts/command/GetCallerIdentityCommand/>
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
const client = new STSClient({ region: "us-east-1" });
const command = new GetCallerIdentityCommand({});
try {
  const data = await client.send(command);
  if (!data.Arn.startsWith('arn:aws:iam::')) throw new Error("Identity is not an IAM user")
  console.log(`IAM user: ${data.Arn.replace(/^.+user\//, '')}`)
} catch (error) {
  console.log(error)
}