Skip to content

Instantly share code, notes, and snippets.

@dvu4
Last active February 10, 2023 00:17
Show Gist options
  • Save dvu4/98bf636f3ef612962226a8bcfa5e4f8c to your computer and use it in GitHub Desktop.
Save dvu4/98bf636f3ef612962226a8bcfa5e4f8c to your computer and use it in GitHub Desktop.

search for "service" using the grep

alias grep="grep --color=auto" 
grep -rn . -e "service"  

Here's what each of the options and arguments mean:

  • -r: Recursively search all files in the specified directory and its subdirectories.

  • -n: Prefix each line of output with the line number within its input file.

  • -e "service": Specify the pattern to search for. In this case, the pattern is the string "service".

  • . : Specifies the directory to search. A single dot (.) is used to represent the current working directory.

Result

./src/dai_identity_api/api/service_principals.py:243:    with servicebus_sender:
./src/dai_identity_api/api/service_principals.py:244:        servicebus_sender.send_messages(message)
./src/dai_identity_api/api/service_principals.py:257:    sp_details = list_service_principals(
./src/dai_identity_api/api/service_principals.py:285:def list_my_service_principals(
./src/dai_identity_api/api/service_principals.py:310:        f"/oneidazure/identity/{owner_id}/serviceprincipals/?page={page-1}&size={limit}",
./src/dai_identity_api/api/service_principals.py:325:def list_service_principals(
./src/dai_identity_api/api/service_principals.py:349:        f"/oneidazure/serviceprincipals/?cursor={limit*(page-1) + 1}&limit={limit}",
./src/dai_identity_api/api/service_principals.py:364:def list_service_principal_names(
./src/dai_identity_api/api/service_principals.py:372:    sp_details = list_service_principals(
./src/dai_identity_api/api/service_principals.py:400:    sp_details = list_service_principals(
./src/dai_identity_api/api/service_principals.py:410:        f"/oneidazure/serviceprincipals/{app_id}/owners",
./src/dai_identity_api/api/service_principals.py:432:    sp_details = list_service_principals(
./src/dai_identity_api/api/service_principals.py:444:        f"/oneidazure/serviceprincipals/{app_id}/owners",
./src/dai_identity_api/api/service_principals.py:472:        my_sp_details = list_my_service_principals(
./src/dai_identity_api/api/service_principals.py:480:            msg = "No service principal is found"
./src/dai_identity_api/api/service_principals.py:485:            msg = f"There are more than one service principal with name {display_name}. Please provide app_object_id"
./src/dai_identity_api/api/service_principals.py:507:def filter_my_service_principals(
./src/dai_identity_api/api/service_principals.py:524:        response = list_my_service_principals(
Binary file ./src/dai_identity_api/api/__pycache__/service_principals.cpython-310.pyc matches
./src/dai_identity_api/exceptions.py:2:    """Exception raised when service principal already exists in the azure."""
./src/dai_identity_api/exceptions.py:7:    """Exception raised when there is more than one service principal in the azure."""
./src/dai_identity_api/exceptions.py:37:    """Exception raised when no service principal is found with a provided display name."""
./src/dai_identity_api/exceptions.py:42:    """Exception raised when two secrets associated with a service principal with a provided display name."""
./src/dai_identity_api/exceptions.py:47:    """Exception raised when no secret is created for the service principal with a provided display name."""

search for "service" or "secret" using the grep

grep -rn . -e "service\|secret"

This command searches for either the string "service" or "secret" in all files under the current directory (indicated by .) and outputs the line numbers and filenames where either of the strings was found.

  • The -e option is used to specify the pattern to search for
  • \| is used as the OR operator. This means that the command will search for lines that contain either "service" or "secret".
  • The -r option is used to search the pattern recursively in all subdirectories under the current directory
  • The -n option is used to show the line number for each match.

Result

./src/dai_identity_api/cli/service_principals/secrets.py:82:        response = rotate_secret(
./src/dai_identity_api/cli/service_principals/main.py:4:from . import secrets
./src/dai_identity_api/cli/service_principals/main.py:6:from ...api.service_principals import (
./src/dai_identity_api/cli/service_principals/main.py:7:    list_service_principals,
./src/dai_identity_api/cli/service_principals/main.py:8:    list_my_service_principals,
./src/dai_identity_api/cli/service_principals/main.py:9:    create_service_principal,
./src/dai_identity_api/cli/service_principals/main.py:10:    delete_service_principal,
./src/dai_identity_api/cli/service_principals/main.py:11:    filter_my_service_principals,
./src/dai_identity_api/cli/service_principals/main.py:38:    response = create_service_principal(
./src/dai_identity_api/cli/service_principals/main.py:73:        delete_service_principal(
./src/dai_identity_api/cli/service_principals/main.py:104:        response = list_service_principals(
./src/dai_identity_api/cli/service_principals/main.py:113:        filename = "service-principals"
./src/dai_identity_api/cli/service_principals/main.py:115:        response = list_my_service_principals(
./src/dai_identity_api/cli/service_principals/main.py:125:        filename = "my-service-principals"
./src/dai_identity_api/cli/service_principals/main.py:137:app.add_typer(secrets.app, name="secrets")
./src/dai_identity_api/cli/service_principals/main.py:158:    response = filter_my_service_principals(
./src/dai_identity_api/cli/service_principals/main.py:165:    filename = "my-expired-service-principals"
./src/dai_identity_api/cli/__init__.py:7:from dai_identity_api.cli.service_principals import main
./src/dai_identity_api/cli/__init__.py:27:app.add_typer(main.app, name="service-principals")
Binary file ./src/dai_identity_api/cli/__pycache__/__init__.cpython-310.pyc matches
./src/dai_identity_api/api/service_principals.py:39:from azure.keyvault.secrets import SecretClient
./src/dai_identity_api/api/service_principals.py:40:from azure.servicebus import ServiceBusClient, ServiceBusMessage
./src/dai_identity_api/api/service_principals.py:43:TOPIC_NAME = "ds-service-principal-events"
./src/dai_identity_api/api/service_principals.py:53:def create_service_principal(
./src/dai_identity_api/api/service_principals.py:79:        display_names = list_service_principal_names(token)
./src/dai_identity_api/api/service_principals.py:97:        "/oneidazure/serviceprincipals",
./src/dai_identity_api/api/service_principals.py:106:def delete_service_principal(
./src/dai_identity_api/api/service_principals.py:120:    sp_details = list_service_principals(token, display_name=display_name, app_object_id=app_object_id)
./src/dai_identity_api/api/service_principals.py:123:        msg = f"There are more than one service principal with name {display_name}. Please provide app_object_id"
./src/dai_identity_api/api/service_principals.py:127:    my_sp_details = list_my_service_principals(
./src/dai_identity_api/api/service_principals.py:135:    secret_name = f"{display_name}-secret"
./src/dai_identity_api/api/service_principals.py:143:        f"/oneidazure/serviceprincipals/{sp_object_id}",
./src/dai_identity_api/api/service_principals.py:148:        msg = f"No secret is created for service principal {display_name}."
./src/dai_identity_api/api/service_principals.py:156:        deleted_secret = client.begin_delete_secret(secret_name).result()
./src/dai_identity_api/api/service_principals.py:157:        deleted_client_id = client.begin_delete_secret(client_id_name).result()
./src/dai_identity_api/api/service_principals.py:158:        logger.info(f"Deleted Secret value : {deleted_secret.name, }")
./src/dai_identity_api/api/service_principals.py:159:        logger.info(f"Date of Secret value is deleted on : {deletedsecret.deleted_date}")
./src/dai_identity_api/api/service_principals.py:164:def create_secret(
./src/dai_identity_api/api/service_principals.py:171:    sp_details = list_service_principals(token, app_object_id=app_object_id, display_name=display_name)
./src/dai_identity_api/api/service_principals.py:174:        msg = "No service principal is found"
./src/dai_identity_api/api/service_principals.py:178:        msg = f"There are more than one service principal with name {display_name}. Please provide app_object_id"
./src/dai_identity_api/api/service_principals.py:187:        f"{sp_details.azureSPDetails[0].appName}-secret-{expire_date.strftime('%Y%m%d')}"
./src/dai_identity_api/api/service_principals.py:196:        f"/oneidazure/applications/{app_object_id}/secret",
./src/dai_identity_api/api/service_principals.py:212:    secret_value = result.secret["secretText"]
./src/dai_identity_api/api/service_principals.py:213:    secret_name = f"{display_name}-secret"
./src/dai_identity_api/api/service_principals.py:218:    client.set_secret(client_id_name, client_id)
./src/dai_identity_api/api/service_principals.py:219:    client.set_secret(secret_name, secret_value)
./src/dai_identity_api/api/service_principals.py:224:    key_id = result.secret["keyId"]
./src/dai_identity_api/api/service_principals.py:225:    creation_date = result.secret["startDateTime"]
./src/dai_identity_api/api/service_principals.py:226:    expiry_date = result.secret["endDateTime"]
./src/dai_identity_api/api/service_principals.py:240:    servicebus_client = ServiceBusClient(fully_qualified_namespace=fully_qualified_namespace,
./src/dai_identity_api/api/service_principals.py:242:    servicebus_sender = servicebus_client.get_topic_sender(topic_name=TOPIC_NAME)
./src/dai_identity_api/api/service_principals.py:243:    with servicebus_sender:
./src/dai_identity_api/api/service_principals.py:244:        servicebus_sender.send_messages(message)
./src/dai_identity_api/api/service_principals.py:249:def delete_secret(
./src/dai_identity_api/api/service_principals.py:257:    sp_details = list_service_principals(
./src/dai_identity_api/api/service_principals.py:269:        f"/oneidazure/applications/{app_object_id}/secret",
./src/dai_identity_api/api/service_principals.py:285:def list_my_service_principals(
./src/dai_identity_api/api/service_principals.py:310:        f"/oneidazure/identity/{owner_id}/serviceprincipals/?page={page-1}&size={limit}",
./src/dai_identity_api/api/service_principals.py:325:def list_service_principals(
./src/dai_identity_api/api/service_principals.py:349:        f"/oneidazure/serviceprincipals/?cursor={limit*(page-1) + 1}&limit={limit}",
./src/dai_identity_api/api/service_principals.py:364:def list_service_principal_names(
./src/dai_identity_api/api/service_principals.py:372:    sp_details = list_service_principals(
./src/dai_identity_api/api/service_principals.py:400:    sp_details = list_service_principals(
./src/dai_identity_api/api/service_principals.py:410:        f"/oneidazure/serviceprincipals/{app_id}/owners",
./src/dai_identity_api/api/service_principals.py:432:    sp_details = list_service_principals(
./src/dai_identity_api/api/service_principals.py:444:        f"/oneidazure/serviceprincipals/{app_id}/owners",
./src/dai_identity_api/api/service_principals.py:458:def rotate_secret(
./src/dai_identity_api/api/service_principals.py:472:        my_sp_details = list_my_service_principals(
./src/dai_identity_api/api/service_principals.py:480:            msg = "No service principal is found"
./src/dai_identity_api/api/service_principals.py:485:            msg = f"There are more than one service principal with name {display_name}. Please provide app_object_id"
./src/dai_identity_api/api/service_principals.py:490:            msg = "No secret is found. Creating a new secret"
./src/dai_identity_api/api/service_principals.py:492:            response = create_secret(token, keyvault_name, app_object_id=app_object_id, display_name=display_name)
./src/dai_identity_api/api/service_principals.py:495:            msg = f"Two secrets associated with {display_name} are found"
./src/dai_identity_api/api/service_principals.py:501:            response = create_secret(token, keyvault_name, app_object_id=app_object_id, display_name=display_name)
./src/dai_identity_api/api/service_principals.py:502:            delete_secret(token, key_id, app_object_id=app_object_id, display_name=display_name)
./src/dai_identity_api/api/service_principals.py:507:def filter_my_service_principals(
./src/dai_identity_api/api/service_principals.py:524:        response = list_my_service_principals(
Binary file ./src/dai_identity_api/api/__pycache__/service_principals.cpython-310.pyc matches
./src/dai_identity_api/exceptions.py:2:    """Exception raised when service principal already exists in the azure."""
./src/dai_identity_api/exceptions.py:7:    """Exception raised when there is more than one service principal in the azure."""
./src/dai_identity_api/exceptions.py:22:    """Exception raised when creating secret fails."""
./src/dai_identity_api/exceptions.py:27:    """Exception raised when deleting secret fails."""
./src/dai_identity_api/exceptions.py:37:    """Exception raised when no service principal is found with a provided display name."""
./src/dai_identity_api/exceptions.py:42:    """Exception raised when two secrets associated with a service principal with a provided display name."""
./src/dai_identity_api/exceptions.py:47:    """Exception raised when no secret is created for the service principal with a provided display name."""

search for both "service" and "secret" using the grep

grep -rn . -e "service.*service\|secret.*secret"

This command searches for lines that contain both the strings "service" and "secret" in all files under the current directory (indicated by .) and outputs the line numbers and filenames where both strings were found.

The -e option is used to specify the pattern to search for. The pattern uses the regular expression offer.*give to match lines that contain "service" followed by "secret", and give.*offer to match lines that contain "secret" followed by "service".

  • The .* regular expression matches any characters between the two strings.
  • The -r option is used to search the pattern recursively in all subdirectories under the current directory
  • The -n option is used to show the line number for each match.

-->

./tests/test_service_principals.py:22:            service_principals.create_service_principal(
./tests/test_service_principals.py:28:            service_principals.create_service_principal(
./tests/test_service_principals.py:32:        """Test to check if service principal already exists in list of service principals"""
./tests/test_service_principals.py:34:        when(service_principals).list_service_principal_names(...).thenReturn(existed_service_principals)
./tests/test_service_principals.py:36:            service_principals.create_service_principal(
./tests/test_service_principals.py:42:        when(service_principals).list_service_principal_names(...).thenReturn(existed_service_principals)
./tests/test_service_principals.py:44:            service_principals.create_service_principal(
./tests/test_service_principals.py:51:    def test_service_principal_empty_and_create_new_service_principal(self):
./tests/test_service_principals.py:52:        """Test to check if there is no service principal, then create a service principal"""
./tests/test_service_principals.py:54:        when(service_principals).list_service_principal_names(token).thenReturn([])
./tests/test_service_principals.py:63:        assert service_principals.create_service_principal(
./tests/test_service_principals.py:67:    def test_display_name_not_in_service_principal_and_create_new_service_principal(self):
./tests/test_service_principals.py:68:        """Test to check if there is no duplicate service principal, then create a service principal"""
./tests/test_service_principals.py:70:        when(service_principals).list_service_principal_names(token, ...).thenReturn(["abc", "cde", "fgh"])
./tests/test_service_principals.py:79:        assert service_principals.create_service_principal(
./tests/test_service_principals.py:96:        result = service_principals.list_service_principals(token, ...)
./tests/test_service_principals.py:116:        result = service_principals.list_service_principals(token, None, None, None, None, False, page, limit)
./tests/test_service_principals.py:120:    def test_creating_secret_when_there_are_more_than_two_secrets(self):
./tests/test_service_principals.py:127:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:144:    def test_deleting_secret_when_there_is_no_secret(self):
./tests/test_service_principals.py:148:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:168:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:184:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:203:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:220:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:251:        when(service_principals).list_my_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:323:        when(service_principals).list_my_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:338:    def test_rotating_secret_when_two_secrets_are_found(self):
./tests/test_service_principals.py:382:        when(service_principals).list_my_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:418:        result = service_principals.list_my_service_principals(
./tests/test_service_principals.py:445:        result = service_principals.list_my_service_principals(
./tests/test_service_principals.py:472:        result = service_principals.list_my_service_principals(
./tests/test_service_principals.py:478:    def test_listing_my_service_principal_when_no_more_service_principal_is_found(self):
./tests/test_service_principals.py:494:            service_principals.list_my_service_principals(
./tests/test_service_principals.py:515:            service_principals.list_service_principals(token, None, None, None, None, False, page, limit)
./tests/test_service_principals.py:535:            service_principals.list_service_principals(token, None, None, None, None, False, page, limit)
./tests/test_service_principals.py:546:            service_principals.filter_my_service_principals(token, "name@walgreens.com", False, expires_within)
./tests/test_service_principals.py:612:        when(service_principals).list_my_service_principals(token, ...).thenReturn(response)
./tests/test_service_principals.py:613:        result = service_principals.filter_my_service_principals(token, "name@walgreens.com", False, expires_within)
./tests/test_service_principals.py:678:        when(service_principals).list_my_service_principals(token, ...).thenReturn(response)
./tests/test_service_principals.py:679:        result = service_principals.filter_my_service_principals(token, "name@walgreens.com", False, expires_within)
./tests/test_service_principals.py:691:            service_principals.delete_service_principal(
./tests/test_service_principals.py:698:    def test_deleting_service_principal_when_there_are_two_service_principals_with_same_display_name(self):
./tests/test_service_principals.py:707:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:710:            service_principals.delete_service_principal(
./tests/test_service_principals.py:726:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:739:        when(service_principals).list_service_principals(token, ...).thenReturn(sp_detail)
./tests/test_service_principals.py:827:        when(service_principals).list_my_service_principals(token, ...).thenReturn(response)
./tests/test_service_principals.py:828:        result = service_principals.filter_my_service_principals(token, "name@walgreens.com", False, expires_within)
./README.md:156:- `cursor` (Default value = 1) : specify the pointer to a specific service principals (the first service principal in each page).
./scripts/storage_table_service_principals.py:5:from dai_identity_api.api.service_principals import filter_my_service_principals, list_my_service_principals
./scripts/storage_table_service_principals.py:85:            secret_names = [secret_property.name for secret_property in secret_client.list_properties_of_secres()
./scripts/storage_table_service_principals.py:87:            keyvault_secrets[vault.name] = secret_names
./scripts/storage_table_service_principals.py:97:    for secret_name in secret_names:
./scripts/storage_table_service_principals.py:110:    service_principals = get_service_principals()
./scripts/storage_table_service_principals.py:115:    for service_principal in service_principals:
./scripts/storage_table_service_principals.py:120:        keyvaults_for_sps[service_principal] = list(filter(get_keyvaults_sp_is_in, keyvaults_with_service_principals))
./scripts/storage_table_service_principals.py:124:            entity = create_expiry_service_principal_entity(keyvault_name=kv, display_name=service_principal)
./scripts/storage_table_service_principals.py:127:            typer.echo(f"{service_principal} is in {len(keyvaults_for_sps[service_principal])} KeyVaults")
./scripts/storage_table_service_principals.py:133:    keyvault_secrets = get_keyvault_secrets()
./scripts/expiring_service_principals.py:10:from dai_identity_api.api.service_principals import filter_my_service_principals
./scripts/expiring_service_principals.py:47:        servicebus_sender = servicebus_client.get_topic_sender(topic_name=TOPIC_NAME)
./scripts/create_service_principals.py:9:from dai_identity_api.api.service_principals import create_service_principal, create_secret
./scripts/create_service_principals.py:47:        secret_response: SetSecretResponse = create_secret(access_token, app_object_id=app_object_id, display_name=display_name)
./scripts/create_service_principals.py:48:        secret_name = secret_response.secret["displayName"]
./scripts/create_service_principals.py:49:        secret_file = open(f"{secret_name}.json", "w")
./scripts/create_service_principals.py:50:        json.dump(secret_response.dict(), secret_file, indent=2)
Binary file ./.git/index matches
Binary file ./src/dai_identity_api/__pycache__/config.cpython-310.pyc matches
Binary file ./src/dai_identity_api/cli/service_principals/__pycache__/main.cpython-310.pyc matches
Binary file ./src/dai_identity_api/cli/service_principals/__pycache__/secrets.cpython-310.pyc matches
./src/dai_identity_api/cli/service_principals/secrets.py:4:from dai_identity_api.api.service_principals import create_secret, delete_secret, rotate_secret
./src/dai_identity_api/cli/service_principals/main.py:137:app.add_typer(secrets.app, name="secrets")
Binary file ./src/dai_identity_api/cli/__pycache__/__init__.cpython-310.pyc matches
./src/dai_identity_api/api/service_principals.py:135:    secret_name = f"{display_name}-secret"
./src/dai_identity_api/api/service_principals.py:156:        deleted_secret = client.begin_delete_secret(secret_name).result()
./src/dai_identity_api/api/service_principals.py:212:    secret_value = result.secret["secretText"]
./src/dai_identity_api/api/service_principals.py:213:    secret_name = f"{display_name}-secret"
./src/dai_identity_api/api/service_principals.py:219:    client.set_secret(secret_name, secret_value)
./src/dai_identity_api/api/service_principals.py:242:    servicebus_sender = servicebus_client.get_topic_sender(topic_name=TOPIC_NAME)
./src/dai_identity_api/api/service_principals.py:490:            msg = "No secret is found. Creating a new secret"
Binary file ./src/dai_identity_api/api/__pycache__/service_principals.cpython-310.pyc matches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment