forked from badtuxx/giropops-senhas
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Melange, APKO e GitHub Container Registry
- Loading branch information
nataliagranato
committed
Aug 26, 2024
1 parent
d934069
commit 914ae3f
Showing
40 changed files
with
3,366 additions
and
112 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,4 +117,3 @@ jobs: | |
with: | ||
sarif_file: 'trivy-results.sarif' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Melange, APKO e GitHub Container Registry | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
|
||
jobs: | ||
build: | ||
name: Build e Distribuição de Pacotes | ||
runs-on: ubuntu-20.04 | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
steps: | ||
# Checkout do código | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
# Configurar Docker Buildx | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
# Instalar Melange | ||
- name: Install Melange | ||
run: | | ||
wget https://github.com/chainguard-dev/melange/releases/download/v0.11.2/melange_0.11.2_linux_386.tar.gz | ||
tar -xzf melange_0.11.2_linux_386.tar.gz | ||
cd melange_0.11.2_linux_386 | ||
sudo mv melange /usr/local/bin/ | ||
melange version | ||
# Instalar APKO | ||
- name: Install APKO | ||
run: | | ||
wget https://github.com/chainguard-dev/apko/releases/download/v0.14.7/apko_0.14.7_linux_386.tar.gz | ||
tar -xzf apko_0.14.7_linux_386.tar.gz | ||
cd apko_0.14.7_linux_386 | ||
sudo mv apko /usr/local/bin/ | ||
apko version | ||
# Gerar chaves com Melange | ||
- name: Generate keys with Melange | ||
run: | | ||
cd chainguard/environments/prd | ||
melange keygen | ||
# Construir pacotes com Melange | ||
- name: Build packages with Melange | ||
run: | | ||
cd chainguard/environments/prd | ||
melange build melange.yaml --runner docker --signing-key melange.rsa --arch amd64 | ||
# Construir imagem de container com APKO | ||
- name: Build container image with APKO | ||
run: | | ||
cd chainguard/environments/prd | ||
apko build apko.yaml senhas senhas-prd.tar -k melange.rsa.pub --arch amd64 | ||
# Load da imagem Docker | ||
- name: Load Docker image | ||
run: | | ||
cd chainguard/environments/prd | ||
docker load < senhas-prd.tar | ||
docker images | ||
docker tag senhas-prd:latest-amd64 ghcr.io/nataliagranato/senhas-prd:$(date +%s) | ||
export CR_PAT=$PERSONAL_ACCESS_TOKEN | ||
echo $CR_PAT | docker login ghcr.io -u nataliagranato --password-stdin | ||
docker push ghcr.io/nataliagranato/senhas-prd:$(date +%s) |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from flask import Flask, render_template, request, jsonify | ||
import redis | ||
import string | ||
import random | ||
import os | ||
from prometheus_client import Counter, generate_latest # Adicionando a importação necessária | ||
|
||
app = Flask(__name__) | ||
|
||
redis_host = os.environ.get("REDIS_HOST") | ||
redis_port = os.environ.get("REDIS_PORT") | ||
redis_user = os.environ.get("REDIS_USER") | ||
redis_pass = os.environ.get("REDIS_PASS") | ||
|
||
r = redis.StrictRedis(host=redis_host, port=redis_port, password="", decode_responses=True) | ||
|
||
senha_gerada_counter = Counter('senha_gerada', 'Contador de senhas geradas') | ||
|
||
|
||
def criar_senha(tamanho, incluir_numeros, incluir_caracteres_especiais): | ||
caracteres = string.ascii_letters | ||
|
||
if incluir_numeros: | ||
caracteres += string.digits | ||
|
||
if incluir_caracteres_especiais: | ||
caracteres += string.punctuation | ||
|
||
senha = ''.join(random.choices(caracteres, k=tamanho)) | ||
|
||
return senha | ||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def index(): | ||
if request.method == 'POST': | ||
tamanho = int(request.form.get('tamanho', 8)) | ||
incluir_numeros = request.form.get('incluir_numeros') == 'on' | ||
incluir_caracteres_especiais = request.form.get('incluir_caracteres_especiais') == 'on' | ||
senha = criar_senha(tamanho, incluir_numeros, incluir_caracteres_especiais) | ||
|
||
r.lpush("senhas", senha) | ||
senha_gerada_counter.inc() | ||
senhas = r.lrange("senhas", 0, 9) | ||
if senhas: | ||
senhas_geradas = [{"id": index + 1, "senha": senha} for index, senha in enumerate(senhas)] | ||
return render_template('index.html', senhas_geradas=senhas_geradas, senha=senhas_geradas[0]['senha'] or '' ) | ||
return render_template('index.html') | ||
|
||
|
||
@app.route('/api/gerar-senha', methods=['POST']) | ||
def gerar_senha_api(): | ||
dados = request.get_json() | ||
|
||
tamanho = int(dados.get('tamanho', 8)) | ||
incluir_numeros = dados.get('incluir_numeros', False) | ||
incluir_caracteres_especiais = dados.get('incluir_caracteres_especiais', False) | ||
|
||
senha = criar_senha(tamanho, incluir_numeros, incluir_caracteres_especiais) | ||
r.lpush("senhas", senha) | ||
senha_gerada_counter.inc() | ||
|
||
return jsonify({"senha": senha}) | ||
|
||
@app.route('/api/senhas', methods=['GET']) | ||
def listar_senhas(): | ||
senhas = r.lrange("senhas", 0, 9) | ||
|
||
resposta = [{"id": index + 1, "senha": senha} for index, senha in enumerate(senhas)] | ||
return jsonify(resposta) | ||
|
||
@app.route('/metrics') | ||
def metrics(): | ||
return generate_latest() | ||
|
||
@app.route('/health') | ||
def ping(): | ||
return jsonify({"status": "healthy"}), 200 | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=False, host='0.0.0.0', port=5000) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Flask==3.0.3 | ||
redis==5.1.0b7 | ||
prometheus-client==0.16.0 | ||
Werkzeug==3.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
README.md | ||
LICENSE | ||
Dockerfile | ||
.github | ||
.dockerignore |
Oops, something went wrong.