• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 18505123992

14 Oct 2025 05:30PM UTC coverage: 86.888% (-0.01%) from 86.899%
18505123992

push

github

web-flow
S3: fix `aws-global` validation in CreateBucket (#13250)

10 of 10 new or added lines in 4 files covered. (100.0%)

831 existing lines in 40 files now uncovered.

68028 of 78294 relevant lines covered (86.89%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/localstack-core/localstack/cli/profiles.py
1
import argparse
1✔
2
import os
1✔
3
import sys
1✔
4

5
# important: this needs to be free of localstack imports
6

7

8
def set_and_remove_profile_from_sys_argv():
1✔
9
    """
10
    Performs the following steps:
11

12
    1. Use argparse to parse the command line arguments for the --profile flag.
13
       All occurrences are removed from the sys.argv list, and the value from
14
       the last occurrence is used.  This allows the user to specify a profile
15
       at any point on the command line.
16

17
    2. If a --profile flag is not found, check for the -p flag.  The first
18
       occurrence of the -p flag is used and it is not removed from sys.argv.
19
       The reasoning for this is that at least one of the CLI subcommands has
20
       a -p flag, and we want to keep it in sys.argv for that command to
21
       pick up.  An existing bug means that if a -p flag is used with a
22
       subcommand, it could erroneously be used as the profile value as well.
23
       This behaviour is undesired, but we must maintain back-compatibility of
24
       allowing the profile to be specified using -p.
25

26
    3. If a profile is found, the 'CONFIG_PROFILE' os variable is set
27
       accordingly. This is later picked up by ``localstack.config``.
28

29
    WARNING:  Any --profile options are REMOVED from sys.argv, so that they are
30
              not passed to the localstack CLI. This allows the profile option
31
              to be set at any point on the command line.
32
    """
33
    parser = argparse.ArgumentParser(add_help=False)
1✔
34
    parser.add_argument("--profile")
1✔
35
    namespace, sys.argv = parser.parse_known_args(sys.argv)
1✔
36
    profile = namespace.profile
1✔
37

38
    if not profile:
1✔
39
        # if no profile is given, check for the -p argument
40
        profile = parse_p_argument(sys.argv)
1✔
41

42
    if profile:
1✔
43
        os.environ["CONFIG_PROFILE"] = profile.strip()
1✔
44

45

46
def parse_p_argument(args) -> str | None:
1✔
47
    """
48
    Lightweight arg parsing to find the first occurrence of ``-p <config>``, or ``-p=<config>`` and return the value of
49
    ``<config>`` from the given arguments.
50

51
    :param args: list of CLI arguments
52
    :returns: the value of ``-p``.
53
    """
54
    for i, current_arg in enumerate(args):
1✔
55
        if current_arg.startswith("-p="):
1✔
56
            # if using the "<arg>=<value>" notation, we remove the "-p=" prefix to get the value
57
            return current_arg[3:]
1✔
58
        if current_arg == "-p":
1✔
59
            # otherwise use the next arg in the args list as value
60
            try:
1✔
61
                return args[i + 1]
1✔
62
            except IndexError:
1✔
63
                return None
1✔
64

UNCOV
65
    return None
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc