@@ -711,6 +711,85 @@ version() {
711
711
printf " %s\\ n" " ${_VERSION} "
712
712
}
713
713
714
+ # revoke ######################################################################
715
+
716
+ describe " revoke" << HEREDOC
717
+ Usage:
718
+ ${_ME} revoke [-t|-h|<options>]
719
+
720
+ Options:
721
+ -t | --token <token> Access token to revoke. (Required)
722
+ -h | --hostname <hostname> The API URL of GitHub. (Default = api.github.com)
723
+
724
+ Description:
725
+ Revoke the provided access token
726
+ HEREDOC
727
+ revoke () {
728
+ local _token=
729
+ local _hostname=" api.github.com"
730
+
731
+ for __arg in " ${@:- } "
732
+ do
733
+ case ${__arg} in
734
+ -t|--token)
735
+ _token=${2:- }
736
+ shift
737
+ shift
738
+ ;;
739
+ -h|--hostname)
740
+ _hostname=${2:- }
741
+ shift
742
+ shift
743
+ ;;
744
+ -* )
745
+ _exit_1 printf " Unexpected option: %s\\ n" " ${__arg} "
746
+ ;;
747
+ * )
748
+ esac
749
+ done
750
+
751
+ if [[ -z " ${_token} " ]]
752
+ then
753
+ _exit_1 echo " -t | --token <token> is required"
754
+ fi
755
+
756
+ if [[ " ${_hostname} " == " api.github.com" ]]
757
+ then
758
+
759
+ # ;-------------------------------------
760
+ # ; Get installation id from GitHub.com
761
+ # ;-------------------------------------
762
+ _api_url=" https://${_hostname} "
763
+
764
+ else
765
+ # ;-------------------------------------
766
+ # ; Get installation id from GHES
767
+ # ;-------------------------------------
768
+ _api_url=" https://${_hostname} /api/v3"
769
+
770
+ fi
771
+
772
+ # Revoke the token
773
+ local _response=
774
+ _response=$( curl --write-out ' %{http_code}' \
775
+ --output /dev/null \
776
+ --silent \
777
+ -X DELETE \
778
+ -H " Authorization: Token " " ${_token} " \
779
+ -H " Accept: application/vnd.github.v3+json" \
780
+ " ${_api_url} " /installation/token | \
781
+ jq)
782
+
783
+ if [[ " ${_response} " == 204 ]]
784
+ then
785
+ echo ${_response} " : Token revoked successfully"
786
+ else
787
+ echo ${_response} " : Failed to revoke token. Maybe it expired already?"
788
+ fi
789
+ }
790
+
791
+
792
+
714
793
# installations ###############################################################
715
794
716
795
describe " installations" << HEREDOC
@@ -755,7 +834,7 @@ installations() {
755
834
shift
756
835
shift
757
836
;;
758
- -h |--hostname)
837
+ -o |--hostname)
759
838
_hostname=${2:- }
760
839
shift
761
840
shift
@@ -923,7 +1002,7 @@ generate() {
923
1002
shift
924
1003
shift
925
1004
;;
926
- -h |--hostname)
1005
+ -o |--hostname)
927
1006
_hostname=${2:- }
928
1007
shift
929
1008
shift
0 commit comments