|
1 | 1 | from app.app_instance import app |
2 | 2 | from app.gpt_services import gpt_service |
| 3 | +from fastapi.responses import FileResponse |
3 | 4 | from app.services import ( |
4 | 5 |
|
5 | 6 | edit_directory_generator,execute_pythonfile) |
@@ -58,74 +59,85 @@ async def IaC_install_generation(request:IaCInstallationInput) -> Output: |
58 | 59 |
|
59 | 60 | @app.post("/api/IaC-template/docker") |
60 | 61 | async def IaC_template_generation_docker(request:IaCTemplateGenerationDocker) -> Output: |
61 | | - if os.environ.get("TEST"): |
62 | | - return Output(output='output (nothing special)') |
63 | | - generated_prompt = IaC_template_generator_docker(request) |
64 | | - output = gpt_service(generated_prompt) |
65 | | - edit_directory_generator("terraform_generator",output) |
66 | | - execute_pythonfile("MyTerraform","terraform_generator") |
67 | | - return Output(output='output') |
| 62 | + |
| 63 | + dir = 'app/media/terraform.tfvars' |
| 64 | + |
| 65 | + file_response = IaC_template_generator_docker(request) |
| 66 | + with open(dir,'w')as f: |
| 67 | + f.write(file_response) |
| 68 | + |
| 69 | + return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars") |
68 | 70 |
|
69 | 71 | @app.post("/api/IaC-template/aws/ec2") |
70 | 72 | async def IaC_template_generation_aws_ec2(request:IaCTemplateGenerationEC2) -> Output: |
71 | | - if os.environ.get("TEST"): |
72 | | - return Output(output='output (nothing special)') |
| 73 | + |
| 74 | + dir = 'app/media/terraform.tfvars' |
| 75 | + |
| 76 | + file_response = IaC_template_generator_ec2(request) |
| 77 | + with open(dir,'w')as f: |
| 78 | + f.write(file_response) |
| 79 | + |
| 80 | + return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars") |
73 | 81 |
|
74 | | - generated_prompt = IaC_template_generator_ec2(request) |
75 | | - output = gpt_service(generated_prompt) |
76 | | - edit_directory_generator("terraform_generator",output) |
77 | | - execute_pythonfile("MyTerraform","terraform_generator") |
78 | | - return Output(output='output') |
79 | 82 |
|
80 | 83 | @app.post("/api/IaC-template/aws/s3") |
81 | 84 | async def IaC_template_generation_aws_s3(request:IaCTemplateGenerationS3) -> Output: |
82 | | - if os.environ.get("TEST"): |
83 | | - return Output(output='output (nothing special)') |
84 | | - generated_prompt = IaC_template_generator_s3(request) |
85 | | - output = gpt_service(generated_prompt) |
86 | | - edit_directory_generator("terraform_generator",output) |
87 | | - execute_pythonfile("MyTerraform","terraform_generator") |
88 | | - return Output(output='output') |
| 85 | + |
| 86 | + dir = 'app/media/terraform.tfvars' |
| 87 | + |
| 88 | + file_response = IaC_template_generator_s3(request) |
| 89 | + with open(dir,'w')as f: |
| 90 | + f.write(file_response) |
| 91 | + |
| 92 | + return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars") |
| 93 | + |
89 | 94 |
|
90 | 95 | @app.post("/api/IaC-template/aws/iam") |
91 | 96 | async def IaC_template_generation_aws_iam(request:IaCTemplateGenerationIAM) -> Output: |
92 | | - if os.environ.get("TEST"): |
93 | | - return Output(output='output (nothing special)') |
94 | | - generated_prompt = IaC_template_generator_iam(request) |
95 | | - output = gpt_service(generated_prompt) |
96 | | - edit_directory_generator("terraform_generator",output) |
97 | | - execute_pythonfile("MyTerraform","terraform_generator") |
98 | | - return Output(output='output') |
| 97 | + |
| 98 | + dir = 'app/media/terraform.tfvars' |
| 99 | + |
| 100 | + file_response = IaC_template_generator_iam(request) |
| 101 | + with open(dir,'w')as f: |
| 102 | + f.write(file_response) |
| 103 | + |
| 104 | + return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars") |
| 105 | + |
99 | 106 |
|
100 | 107 |
|
101 | 108 | @app.post("/api/IaC-template/argocd") |
102 | 109 | async def IaC_template_generation_argocd(request:IaCTemplateGenerationArgoCD) -> Output: |
103 | | - if os.environ.get("TEST"): |
104 | | - return Output(output='output (nothing special)') |
105 | | - generated_prompt = IaC_template_generator_argocd(request) |
106 | | - output = gpt_service(generated_prompt) |
107 | | - edit_directory_generator("terraform_generator",output) |
108 | | - execute_pythonfile("MyTerraform","terraform_generator") |
109 | | - return Output(output='output') |
| 110 | + |
| 111 | + dir = 'app/media/terraform.tfvars' |
| 112 | + |
| 113 | + file_response = IaC_template_generator_argocd(request) |
| 114 | + with open(dir,'w')as f: |
| 115 | + f.write(file_response) |
| 116 | + |
| 117 | + return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars") |
110 | 118 |
|
111 | 119 |
|
112 | 120 |
|
113 | 121 | @app.post("/api/IaC-template/aws/elb") |
114 | 122 | async def IaC_template_generation_aws_elb(request:IaCTemplateGenerationELB) -> Output: |
115 | | - if os.environ.get("TEST"): |
116 | | - return Output(output='output (nothing special)') |
117 | | - generated_prompt = IaC_template_generator_elb(request) |
118 | | - output = gpt_service(generated_prompt) |
119 | | - edit_directory_generator("terraform_generator",output) |
120 | | - execute_pythonfile("MyTerraform","terraform_generator") |
121 | | - return Output(output='output') |
| 123 | + |
| 124 | + dir = 'app/media/terraform.tfvars' |
| 125 | + |
| 126 | + file_response = IaC_template_generator_elb(request) |
| 127 | + with open(dir,'w')as f: |
| 128 | + f.write(file_response) |
| 129 | + |
| 130 | + return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars") |
| 131 | + |
122 | 132 |
|
123 | 133 | @app.post("/api/IaC-template/aws/efs") |
124 | 134 | async def IaC_template_generation_aws_efs(request:IaCTemplateGenerationEFS) -> Output: |
125 | | - if os.environ.get("TEST"): |
126 | | - return Output(output='output (nothing special)') |
127 | | - generated_prompt = IaC_template_generator_efs(request) |
128 | | - output = gpt_service(generated_prompt) |
129 | | - edit_directory_generator("terraform_generator",output) |
130 | | - execute_pythonfile("MyTerraform","terraform_generator") |
131 | | - return Output(output='output') |
| 135 | + |
| 136 | + dir = 'app/media/terraform.tfvars' |
| 137 | + |
| 138 | + file_response = IaC_template_generator_efs(request) |
| 139 | + with open(dir,'w')as f: |
| 140 | + f.write(file_response) |
| 141 | + |
| 142 | + return FileResponse(dir, media_type='application/zip', filename=f"terraform.tfvars") |
| 143 | + |
0 commit comments