apiVersion: batch/v1
kind: Job
metadata:
  name: github-subs-BBS_PROJECT_CODE
  labels:
    app: github-subs-BBS_PROJECT_CODE
spec:
  ttlSecondsAfterFinished: 100
  template:
    metadata:
      labels:
        app: github-subs-BBS_PROJECT_CODE
    spec:
      volumes:
      - name: data-volume
        hostPath: 
          path: /mnt/volume_lon1_01
          type: Directory
      containers:
      - name: github-subs-BBS_PROJECT_CODE
        image: smokingcaterpillar/bbs-osintel-github-subs
        env:
        - name: SECRET_USERNAME
          valueFrom:
            secretKeyRef:
              name: bbs-config
              key: github-token
        volumeMounts:
        - name: data-volume
          mountPath: /optdata
        command: 
        - /bin/bash
        - -c
        - |
          echo Github Subs v1
          echo Code: BBS_PROJECT_CODE
          echo Id: BBS_PROJECT_ID
          echo List: BBS_PROJECT_LIST
          echo Github Token: $SECRET_USERNAME
          
          ## BBRF SETUP ##
          echo setting up BBRF...
          cp /optdata/BBS/output/private/bbrs-config.json /root/.bbrf/config.json
          bbrf use BBS_PROJECT_CODE
          ## BBRF SETUP ##
          
          cd /opt/github-search/
          echo reading list items
          counter=0
          mkdir -p /optdata/BBS/output/project-data/BBS_PROJECT_CODE/data/osintel/github-subdomains/data/$HOSTNAME/
          input="/optdata/BBS/output/project-data/BBS_PROJECT_CODE/BBS_PROJECT_LIST"
          while IFS= read -r line
          do
            echo Running github-subdomains on "$line"
            python3 github-subdomains.py -t $SECRET_USERNAME -d $line > /optdata/BBS/output/project-data/BBS_PROJECT_CODE/data/osintel/github-subdomains/data/$HOSTNAME/$HOSTNAME.$counter.domains.txt
            counter=$((counter+1))
          done < "$input"
          
          echo adding discovered domains to BBRF
          cat /optdata/BBS/output/project-data/BBS_PROJECT_CODE/data/osintel/github-subdomains/data/$HOSTNAME/$HOSTNAME.*.domains.txt | grep -v ">>>" | bbrf domain add - -t "added_by:github-subdomains"

          echo all done
      restartPolicy: Never

