npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

env-manage

v0.1.17

Published

A-lock env manager

Downloads

8

Readme

🗒 Env-manage


env-manage

사내 env 데이터를 가져와서 파일로 사용할 수 있도록 만들어본 툴입니다.

개발 시 env를 번거롭게 초기화하지 않고 커맨드로 재생성하여 업데이트 할 수 있도록 구현하였습니다.

개발 후기와 관련하여 정리한 내용은 개인 블로그에서 확인하실 수 있습니다.

Quick Features

  • CLI 명령어를 이용해 초기 설정
  • CLI 명령어를 이용해 env 생성 및 업데이트

Prerequisite

  • 해당 버전은 REST 통신을 기반으로 합니다
  • 기본 워크플로우는 아래와 같습니다

해당 구조에 따라, 보안적으로 필요되는 서버 및 데이터베이스 구조는 아래와 같습니다.

  1. access token을 JWT로 생성하기 위해 필요한 secret 값. 해당 secret은 개발자들이 대외비로 알고 있어야 하며, 서버 측은 이 secret을 저장하고 이것과 jwt 라이브러리를 이용하여 access token을 생성 및 검증하는 로직을 만들어야 합니다.

  2. access token 발급을 위한 Init Endpoint(-sve) (POST/Body 내에 secret 값 검증 후 일치하면 jwt토큰을 생성하여 전달)

  3. database 조회 후 해당 데이터를 전달해줄 Generate Endpoint (POST/Body 내에 repo 값으로 데이터 필터링)

    • 해당 endpoint는 init 때 발급받은 access token을 검증하는 로직 필요 (미들웨어 구조 추천)

    • 토큰 검증 미들웨어를 작성할 때, access token은 Authorization Header을 통해 전달되므로, 검증 middleware에서 해당 header의 access token을 검증하도록 구현해야 함

    • generate endpoint는 body에서 전달받는 "repo" 값을 기준으로 데이터베이스를 필터링하여 Env 값을 조회하는 것을 권장함

    • generate endpoint에서 response로 전달해줘야 할 env 리스트는 그 값 자체를 Json으로 보내주어야 함

  4. "repo" 라는 컬럼명을 지닌 env 관리 테이블. (repo 컬럼은 예를 들어, 웹개발 환경인지, 앱개발 환경인지, 서버인지 등등을 구분하여 env 데이터를 저장합니다. 자세 사항은 gen 커맨드 설명 내용 참조.)


Commands

📖 init : 초기 환경 설정을 실행합니다

init이 진행방향은 아래와 같습니다.

a. command 입력 b. origin 입력(개발, 운영) c. mode 입력(access token 발급받을 서버 환경 선택) d. secret 입력

args

  1. -sve (토큰 발급주소) : 서버의 어떤 Endpoint를 통해 secret 값을 검증하고 access token을 발행받을 지를 작성하여 data.json에 저장합니다.

  2. -gee (env 발급주소) : 서버의 어떤 Endpoint를 통해 DB의 env 값을 조회하고, 사용자에게 전달해줄 지를 작성하여 data.json에 저장합니다.

# init command 예시

npx env-manage init -sve v1/env-init -gee v1/env-generate

init이 완료되면, 초기설정에 대한 값이 data.json이라는 파일에 저장되어 해당 모듈의 폴더 아래에 저장됩니다.


📖 gen : evn 파일을 생성합니다

args

  1. mode ("-d" or "-p") : 환경을 설정합니다. 설정된 환경의 서버로부터 env 데이터를 발급받습니다.

  2. -repo (env 필터링 쿼리) : env가 관리되는 데이터베이스 테이블에서 예를 들어 "afun-wallet-app"이라는 장소의 env만 필요할 경우, 해당 데이터만 필터링하여 조회할 수 있도록 전달되어야 하는 값잆니다.

  3. -filename (env 이름, optional) : env를 생성할 시, 어떤 이름으로 설정할 것인지를 결정합니다. 만약 입력하지 않는다면 ".env"로 자동 설정됩니다.

# gen command 예시

npx env-manage gen -d -repo afun-wallet-app -filename .env.development

📖 refresh : init시에 저장되어 있던 access token이 만료될 경우, 해당 토큰을 업데이트하는 데 사용합니다. (generate를 위해서는 만료가 지나지 않은 access token이 필요합니다.)

해당 refresh 커맨드를 사용하기 위해서는 먼저 init 커맨드를 이용하여 초기 설정을 저장해 두어야 합니다.

초기 설정이 완료된 이후에는, 해당 데이터를 기반으로 access token을 업데이트합니다.

# gen command 예시

npx env-manage refresh