Class: RailsTemplate18f::Generators::AuditreeGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Base
Defined in:
lib/generators/rails_template18f/auditree/auditree_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_binObject



21
22
23
24
# File 'lib/generators/rails_template18f/auditree/auditree_generator.rb', line 21

def copy_bin
  template "bin/auditree"
  chmod "bin/auditree", 0o755
end

#copy_github_actionsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/generators/rails_template18f/auditree/auditree_generator.rb', line 26

def copy_github_actions
  if file_exists? ".github/workflows"
    directory "github", ".github"

    # insert plant-helper calls in rspec
    insert_into_file ".github/workflows/rspec.yml", <<PLANT_HELPER_STEPS, after: /^\s*run: bundle exec rspec$/


- name: Plant assessment plan in evidence locker
  uses: ./.github/actions/auditree-cmd
  env:
    GITHUB_TOKEN: ${{ secrets.AUDITREE_GITHUB_TOKEN }}
  with:
    volume: "tmp/oscal/assessment-plans/rspec/assessment-plan.json:/tmp/rspec.json:ro"
    cmd:
      plant-helper -f /tmp/rspec.json -c assessment-plans -d "RSpec run assessment plan"
        -t 31536000 -l #{auditree_evidence_locker}

- name: Plant assessment results in evidence locker
  uses: ./.github/actions/auditree-cmd
  env:
    GITHUB_TOKEN: ${{ secrets.AUDITREE_GITHUB_TOKEN }}
  with:
    volume: "tmp/oscal/assessment-results/rspec/assessment-results.json:/tmp/rspec.json:ro"
    cmd:
      plant-helper -f /tmp/rspec.json -c assessment-results -d "RSpec run assessment results"
        -t 31536000 -l #{auditree_evidence_locker}
PLANT_HELPER_STEPS
  end
end

#copy_gitlab_actionsObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/generators/rails_template18f/auditree/auditree_generator.rb', line 57

def copy_gitlab_actions
  if file_exists? ".gitlab-ci.yml"
    directory "gitlab", ".gitlab"
    insert_into_file ".gitlab-ci.yml", "  - local: \".gitlab/auditree.yml\"\n", after: /^include:\n/
    insert_into_file ".gitlab-ci.yml", "  AUDITREE_VERSION: #{docker_auditree_tag}\n", after: /^variables:\n/
    insert_into_file ".gitlab-ci.yml", <<EOY, after: /^\s+- bundle exec rspec\n/
  artifacts:
    paths:
- tmp/oscal/**/*
EOY
  end
end

#update_component_listObject



78
79
80
81
82
# File 'lib/generators/rails_template18f/auditree/auditree_generator.rb', line 78

def update_component_list
  if oscal_dir_exists?
    insert_into_file "doc/compliance/oscal/trestle-config.yaml", "  - devtools_cloud_gov\n"
  end
end

#update_readmeObject



70
71
72
73
74
75
76
# File 'lib/generators/rails_template18f/auditree/auditree_generator.rb', line 70

def update_readme
  if file_content("README.md").match?("## Documentation")
    insert_into_file "README.md", readme_contents, after: "## Documentation\n"
  else
    append_to_file "README.md", "\n## Documentation\n#{readme_contents}"
  end
end