@@ -25,6 +25,90 @@ app.get('/async-status', async (req, res) => {
25
25
message : status
26
26
} ) ;
27
27
} ) ;
28
+ app . post ( '/whitelist-secret' , async ( req , res ) => {
29
+ let secret = req . body . secret ;
30
+ if ( ! secret ) {
31
+ res . status ( 400 ) . json ( {
32
+ message : "Please provide a secret" ,
33
+ } ) ;
34
+ }
35
+ try {
36
+ // first check if the secret already exists, if not then add it
37
+ const client = await db ;
38
+ let secretObj = await client . collection ( "secrets" ) . findOne ( {
39
+ secret :
40
+ { $eq : secret }
41
+ } ) ;
42
+ if ( secretObj ) {
43
+ res . status ( 200 ) . json ( {
44
+ message : "Secret already exists" ,
45
+ } ) ;
46
+ }
47
+ else {
48
+ await client . collection ( "secrets" ) . insertOne ( { secret : secret } ) ;
49
+ res . status ( 200 ) . json ( {
50
+ message : "Secret added successfully" ,
51
+ } ) ;
52
+ }
53
+ }
54
+ catch ( err ) {
55
+ console . log ( err ) ;
56
+ res . status ( 500 ) . json ( {
57
+ message : "Failed to add secret" ,
58
+ } ) ;
59
+ }
60
+ } ) ;
61
+
62
+ app . post ( '/remove-secret' , async ( req , res ) => {
63
+ let secret = req . body . secret ;
64
+ if ( ! secret ) {
65
+ res . status ( 400 ) . json ( {
66
+ message : "Please provide a secret" ,
67
+ } ) ;
68
+ }
69
+ try {
70
+ const client = await db ;
71
+ let secretObj = await client . collection ( "secrets" ) . findOne ( {
72
+ secret :
73
+ { $eq : secret }
74
+ } ) ;
75
+ if ( ! secretObj ) {
76
+ res . status ( 200 ) . json ( {
77
+ message : "Secret doesn't exist" ,
78
+ } ) ;
79
+ }
80
+ else {
81
+ await client . collection ( "secrets" ) . deleteOne ( { secret : secret } ) ;
82
+ res . status ( 200 ) . json ( {
83
+ message : "Secret removed successfully" ,
84
+ } ) ;
85
+ }
86
+ }
87
+ catch ( err ) {
88
+ console . log ( err ) ;
89
+ res . status ( 500 ) . json ( {
90
+ message : "Failed to remove secret" ,
91
+ } ) ;
92
+ }
93
+ }
94
+ ) ;
95
+
96
+ app . get ( '/list-secrets' , async ( req , res ) => {
97
+ try {
98
+ const client = await db ;
99
+ const secrets = await client . collection ( "secrets" ) . find ( { } ) . toArray ( ) ;
100
+ res . status ( 200 ) . json ( {
101
+ secrets : secrets
102
+ } ) ;
103
+ }
104
+ catch ( err ) {
105
+ console . log ( err ) ;
106
+ res . status ( 500 ) . json ( {
107
+ message : "Failed to fetch secrets" ,
108
+ } ) ;
109
+ }
110
+ }
111
+ ) ;
28
112
29
113
app . post ( '/git-scan/' , async ( req , res ) => {
30
114
let job_name = `scanjob${ generateRandomString ( 5 ) . toLowerCase ( ) } ` ;
0 commit comments