|
172 | 172 | (println (prepare-key-value "body" (:body release-data)))))) |
173 | 173 |
|
174 | 174 | (defn validate-subscription! [context] |
175 | | - (let [repo (:repo context) |
176 | | - url (str "https://agent.api.stepsecurity.io/v1/github/" repo "/actions/subscription")] |
177 | | - (try |
178 | | - (curl/get url {:timeout 3000}) |
179 | | - (catch clojure.lang.ExceptionInfo e |
180 | | - (let [status (-> e ex-data :status)] |
181 | | - (if (= status 403) |
182 | | - (do |
183 | | - (println "::error::Subscription is not valid. Reach out to support@stepsecurity.io") |
184 | | - (System/exit 1)) |
185 | | - (println "INFO: Timeout or API not reachable. Continuing to next step.")))) |
186 | | - (catch Exception _ |
187 | | - ;; handle unexpected error types (network issues, DNS, etc.) |
188 | | - (println "INFO: Timeout or API not reachable. Continuing to next step."))))) |
| 175 | + (let [event-path (System/getenv "GITHUB_EVENT_PATH") |
| 176 | + repo-private (when (and event-path (.exists (io/file event-path))) |
| 177 | + (try |
| 178 | + (get-in (json/parse-string (slurp event-path) true) |
| 179 | + [:repository :private]) |
| 180 | + (catch Exception _ nil))) |
| 181 | + upstream "rymndhng/release-on-push-action" |
| 182 | + action (System/getenv "GITHUB_ACTION_REPOSITORY") |
| 183 | + docs-url "https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions"] |
| 184 | + (println "") |
| 185 | + (println "[1;36mStepSecurity Maintained Action[0m") |
| 186 | + (println (str "Secure drop-in replacement for " upstream)) |
| 187 | + (when (false? repo-private) |
| 188 | + (println "[32m✓ Free for public repositories[0m")) |
| 189 | + (println (str "[36mLearn more:[0m " docs-url)) |
| 190 | + (println "") |
| 191 | + (when-not (false? repo-private) |
| 192 | + (let [server-url (or (System/getenv "GITHUB_SERVER_URL") "https://github.com") |
| 193 | + body (cond-> {:action (or action "")} |
| 194 | + (not= server-url "https://github.com") (assoc :ghes_server server-url)) |
| 195 | + url (str "https://agent.api.stepsecurity.io/v1/github/" |
| 196 | + (:repo context) |
| 197 | + "/actions/maintained-actions-subscription")] |
| 198 | + (try |
| 199 | + (curl/post url {:body (json/generate-string body) |
| 200 | + :headers {"Content-Type" "application/json"} |
| 201 | + :timeout 3000}) |
| 202 | + (catch clojure.lang.ExceptionInfo e |
| 203 | + (let [status (-> e ex-data :status)] |
| 204 | + (if (= status 403) |
| 205 | + (do |
| 206 | + (println "::error::[1;31mThis action requires a StepSecurity subscription for private repositories.[0m") |
| 207 | + (println (str "::error::[31mLearn how to enable a subscription: " docs-url "[0m")) |
| 208 | + (System/exit 1)) |
| 209 | + (println "Timeout or API not reachable. Continuing to next step.")))) |
| 210 | + (catch Exception _ |
| 211 | + (println "Timeout or API not reachable. Continuing to next step."))))))) |
189 | 212 |
|
190 | 213 |
|
191 | 214 | (defn -main [& args] |
|
0 commit comments