MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / create_secret

Method create_secret

github/Organization.py:881–941  ·  view source on GitHub ↗

:param secret_name: string name of the secret :param unencrypted_value: string plain text value of the secret :param visibility: string options all or selected :param selected_repositories: list of repositrories that the secret will be available in :param sec

(
        self,
        secret_name: str,
        unencrypted_value: str,
        visibility: str = "all",
        selected_repositories: Opt[list[github.Repository.Repository]] = NotSet,
        secret_type: str = "actions",
    )

Source from the content-addressed store, hash-verified

879 return github.Repository.Repository(self._requester, headers, data, completed=True)
880
881 def create_secret(
882 self,
883 secret_name: str,
884 unencrypted_value: str,
885 visibility: str = "all",
886 selected_repositories: Opt[list[github.Repository.Repository]] = NotSet,
887 secret_type: str = "actions",
888 ) -> github.OrganizationSecret.OrganizationSecret:
889 """
890 :param secret_name: string name of the secret
891 :param unencrypted_value: string plain text value of the secret
892 :param visibility: string options all or selected
893 :param selected_repositories: list of repositrories that the secret will be available in
894 :param secret_type: string options actions or dependabot
895
896 :calls: `PUT /orgs/{org}/actions/secrets/{secret_name} <https://docs.github.com/rest/actions/secrets#get-an-organization-secret>`_
897 :calls: `PUT /orgs/{org}/dependabot/secrets/{secret_name} <https://docs.github.com/rest/dependabot/secrets#get-an-organization-secret>`_
898 """
899 assert isinstance(secret_name, str), secret_name
900 assert isinstance(unencrypted_value, str), unencrypted_value
901 assert isinstance(visibility, str), visibility
902 assert is_optional_list(selected_repositories, github.Repository.Repository), selected_repositories
903 assert secret_type in ["actions", "dependabot"], "secret_type should be actions or dependabot"
904
905 if visibility == "selected":
906 assert isinstance(selected_repositories, list) and all(
907 isinstance(element, github.Repository.Repository) for element in selected_repositories
908 ), selected_repositories
909 else:
910 assert selected_repositories is NotSet
911
912 public_key = self.get_public_key(secret_type=secret_type)
913 payload = public_key.encrypt(unencrypted_value)
914 put_parameters: dict[str, Any] = {
915 "key_id": public_key.key_id,
916 "encrypted_value": payload,
917 "visibility": visibility,
918 }
919 if is_defined(selected_repositories):
920 # Dependbot and Actions endpoint expects different types
921 # https://docs.github.com/en/rest/dependabot/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
922 # https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
923 if secret_type == "actions":
924 put_parameters["selected_repository_ids"] = [element.id for element in selected_repositories]
925 if secret_type == "dependabot":
926 put_parameters["selected_repository_ids"] = [str(element.id) for element in selected_repositories]
927
928 quoted_secret_name = urllib.parse.quote(secret_name, safe="")
929 url = f"{self.url}/{secret_type}/secrets/{quoted_secret_name}"
930 self._requester.requestJsonAndCheck("PUT", url, input=put_parameters)
931
932 return github.OrganizationSecret.OrganizationSecret(
933 self._requester,
934 url=url,
935 attributes={
936 "name": secret_name,
937 "visibility": visibility,
938 "selected_repositories_url": f"{url}/repositories",

Callers

nothing calls this directly

Calls 5

get_public_keyMethod · 0.95
is_optional_listFunction · 0.90
is_definedFunction · 0.90
encryptMethod · 0.80
requestJsonAndCheckMethod · 0.80

Tested by

no test coverage detected