nebius/SWE-bench-extra huggingface dataset:
Repository: zalando-stups/pierone-cli

Issue:
no basic auth credentials
Today I had an auth issue. While trying to do `docker push` I was getting the following log:

    ➜ pierone login             
    Getting OAuth2 token "pierone".. OK
    Storing Docker client configuration in /Users/whoever/.docker/config.json.. OK
    ➜ docker push myrepo/...
    The push refers to a repository [myrepo/...]
    a5f591aacc10: Preparing 
    ...
    cb11ba605400: Waiting 
    no basic auth credentials

Recreating `~/config.json` saved me.  
There was `"credsStore": "osxkeychain"` setting In the previous version of the `~/config.json` which was causing me troubles.

BTW 
mac os 10.12.3
pierone cli 1.1.27
docker 17.06.0-ce, build 02c1d87

Comments:

Patch:
diff --git a/pierone/api.py b/pierone/api.py
index 35542be..9b0c76a 100644
--- a/pierone/api.py
+++ b/pierone/api.py
@@ -71,6 +71,9 @@ def docker_login_with_token(url, access_token):
     basic_auth = codecs.encode('oauth2:{}'.format(access_token).encode('utf-8'), 'base64').strip().decode('utf-8')
     if 'auths' not in dockercfg:
         dockercfg['auths'] = {}
+    if 'credsStore' in dockercfg:
+        del dockercfg['credsStore']
+
     dockercfg['auths'][url] = {'auth': basic_auth,
                                'email': 'no-mail-required@example.org'}
     with Action('Storing Docker client configuration in {}..'.format(path)):


Test patch:
diff --git a/tests/test_api.py b/tests/test_api.py
index 62e1f0a..3ee83be 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -21,6 +21,29 @@ def test_docker_login(monkeypatch, tmpdir):
         assert {'auth': 'b2F1dGgyOjEyMzc3',
                 'email': 'no-mail-required@example.org'} == data.get('auths').get('https://pierone.example.org')
 
+def test_docker_login_with_credsstore(monkeypatch, tmpdir):
+    monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
+    monkeypatch.setattr('pierone.api.get_token', MagicMock(return_value='12377'))
+    path = os.path.expanduser('~/.docker/config.json')
+    os.makedirs(os.path.dirname(path))
+    with open(path, 'w') as fd:
+        json.dump({
+            "auths": {
+                "https://pierone.stups.zalan.do": {
+                    "auth": "xxx",
+                    "email": "no-mail-required@example.org"
+                }
+            },
+            "credsStore": "osxkeychain"
+        }, fd)
+    docker_login('https://pierone.example.org', 'services', 'mytok',
+                 'myuser', 'mypass', 'https://token.example.org', use_keyring=False)
+    with open(path) as fd:
+        data = yaml.safe_load(fd)
+        assert {'auth': 'b2F1dGgyOjEyMzc3',
+                'email': 'no-mail-required@example.org'} == data.get('auths').get('https://pierone.example.org')
+        assert 'credsStore' not in data
+
 
 def test_docker_login_service_token(monkeypatch, tmpdir):
     monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
Repository: zalando-stups/senza

Issue:
Lookup SecurityGroups by the tag "Name" rather than GroupName
Both AWS API and CloudFormation allow to refer to a security group by its name if the operation runs in EC2 Classic or the default VPC. Unfortunately it uses the `GroupName` attribute that is automatically generated by AWS if the SG is a part of CloudFormation stack.

It would be a good idea to extend Senza to lookup SG during the CF template generation phase and to use the _tag_ `Name` instead. The tag can be set by another ("system") Senza stack definition, thus allowing the cross-stack references.

Another option would be to support the new cross-stack references that are recently introduced by Amazon:  https://aws.amazon.com/blogs/aws/aws-cloudformation-update-yaml-cross-stack-references-simplified-substitution/

Comments:

Patch:
diff --git a/senza/aws.py b/senza/aws.py
index 1284ba3..c7f0468 100644
--- a/senza/aws.py
+++ b/senza/aws.py
@@ -55,13 +55,12 @@ def is_status_complete(status: str):
 def get_security_group(region: str, sg_name: str):
     ec2 = boto3.resource('ec2', region)
     try:
-        sec_groups = list(ec2.security_groups.filter(
-            Filters=[{'Name': 'group-name', 'Values': [sg_name]}]
-        ))
-        if not sec_groups:
-            return None
-        # FIXME: What if we have 2 VPC, with a SG with the same name?!
-        return sec_groups[0]
+        # first try by tag name then by group-name (cannot be changed)
+        for _filter in [{'Name': 'tag:Name', 'Values': [sg_name]}, {'Name': 'group-name', 'Values': [sg_name]}]:
+            sec_groups = list(ec2.security_groups.filter(Filters=[_filter]))
+            if sec_groups:
+                # FIXME: What if we have 2 VPC, with a SG with the same name?!
+                return sec_groups[0]
     except ClientError as e:
         error_code = extract_client_error_code(e)
         if error_code == 'InvalidGroup.NotFound':


Test patch:
diff --git a/tests/test_aws.py b/tests/test_aws.py
index 4ca762a..8dd5b44 100644
--- a/tests/test_aws.py
+++ b/tests/test_aws.py
@@ -14,6 +14,21 @@ def test_get_security_group(monkeypatch):
     assert results == get_security_group('myregion', 'group_inexistant')
 
 
+def test_get_security_group_by_tag_name(monkeypatch):
+
+    def mock_filter(Filters):
+        if Filters[0]['Name'] == 'tag:Name' and Filters[0]['Values'] == ['my-sg']:
+            sg = MagicMock()
+            sg.id = 'sg-123'
+            return [sg]
+
+    ec2 = MagicMock()
+    ec2.security_groups.filter = mock_filter
+    monkeypatch.setattr('boto3.resource', MagicMock(return_value=ec2))
+
+    assert get_security_group('myregion', 'my-sg').id == 'sg-123'
+
+
 def test_resolve_security_groups(monkeypatch):
     ec2 = MagicMock()
     ec2.security_groups.filter = MagicMock(side_effect=[
Repository: zalando-stups/senza

Issue:
Discrepancy between README and error messages
README.md states:
`sudo pip3 install --upgrade stups-senza`

But if you have an old version of senza installed, the reported message is:
`...Please install the new one using 'sudo pip install --upgrade stups-senza'`

Note that `pip3` is specified in README and `pip` is specified in the error message.


Comments:

Patch:
diff --git a/senza/subcommands/root.py b/senza/subcommands/root.py
index a121009..e163658 100644
--- a/senza/subcommands/root.py
+++ b/senza/subcommands/root.py
@@ -99,9 +99,9 @@ def check_senza_version(current_version: str):
     if latest_version is not None and current_version < latest_version:
         if __file__.startswith('/home'):
             # if it's installed in the user folder
-            cmd = "pip install --upgrade stups-senza"
+            cmd = "pip3 install --upgrade stups-senza"
         else:
-            cmd = "sudo pip install --upgrade stups-senza"
+            cmd = "sudo pip3 install --upgrade stups-senza"
         warning("Your senza version ({current}) is outdated. "
                 "Please install the new one using '{cmd}'".format(current=current_version,
                                                                   cmd=cmd))


Test patch:
diff --git a/tests/test_subcommands/test_root.py b/tests/test_subcommands/test_root.py
index 86f5a4f..c16be12 100644
--- a/tests/test_subcommands/test_root.py
+++ b/tests/test_subcommands/test_root.py
@@ -71,7 +71,7 @@ def test_check_senza_version(monkeypatch,
         check_senza_version("0.40")
         mock_warning.assert_called_once_with(
             "Your senza version (0.40) is outdated. "
-            "Please install the new one using 'pip install --upgrade stups-senza'"
+            "Please install the new one using 'pip3 install --upgrade stups-senza'"
         )
 
     with TemporaryDirectory() as temp_dir_4:
@@ -83,7 +83,7 @@ def test_check_senza_version(monkeypatch,
         mock_warning.assert_called_once_with(
             "Your senza version (0.40) is outdated. "
             "Please install the new one using "
-            "'sudo pip install --upgrade stups-senza'"
+            "'sudo pip3 install --upgrade stups-senza'"
         )
 
 
@@ -115,7 +115,7 @@ def test_check_senza_version_outdated_cache(monkeypatch,  # noqa: F811
         mock_warning.assert_called_once_with(
             "Your senza version (0.40) is outdated. "
             "Please install the new one using "
-            "'sudo pip install --upgrade stups-senza'"
+            "'sudo pip3 install --upgrade stups-senza'"
         )
Repository: zalando-stups/senza

Issue:
Spotinst elastigroup adds "Config" to resource name
This invalidates many existing Senza templates. It should keep the original name

Comments:

Patch:
diff --git a/senza/components/elastigroup.py b/senza/components/elastigroup.py
index 7d39d6b..301359a 100644
--- a/senza/components/elastigroup.py
+++ b/senza/components/elastigroup.py
@@ -64,7 +64,7 @@ def component_elastigroup(definition, configuration, args, info, force, account_
     extract_instance_profile(args, definition, configuration, elastigroup_config)
     # cfn definition
     access_token = _extract_spotinst_access_token(definition)
-    config_name = configuration["Name"] + "Config"
+    config_name = configuration["Name"]
     definition["Resources"][config_name] = {
         "Type": "Custom::elastigroup",
         "Properties": {


Test patch:
diff --git a/tests/test_elastigroup.py b/tests/test_elastigroup.py
index 339bf4e..b98621e 100644
--- a/tests/test_elastigroup.py
+++ b/tests/test_elastigroup.py
@@ -44,7 +44,7 @@ def test_component_elastigroup_defaults(monkeypatch):
 
     result = component_elastigroup(definition, configuration, args, info, False, mock_account_info)
 
-    properties = result["Resources"]["eg1Config"]["Properties"]
+    properties = result["Resources"]["eg1"]["Properties"]
     assert properties["accountId"] == 'act-12345abcdef'
     assert properties["group"]["capacity"] == {"target": 1, "minimum": 1, "maximum": 1}
     instance_types = properties["group"]["compute"]["instanceTypes"]
Repository: zalando-stups/zign

Issue:
--refresh doesn't do anything useful
The `--refresh` flag doesn't do anything for named tokens.

```
$ ztoken token --refresh -n postman | md5sum
34e6b2a7a14439271f077690eba31fa3  -
$ ztoken token --refresh -n postman | md5sum
34e6b2a7a14439271f077690eba31fa3  -
```

I expected this to request a new token using the existing refresh token.

Interestingly it also does weird things when requesting an unnamed token (`ztoken token --refresh`). Then a browser window is always opened and after successful authentication you get

```
{
"error": "invalid_client",
"error_description": "invalid client"
}
```

The reason for that seems to be wrong creation of the URL. It points to `.../oauth2/authorize?business_partner_id=True&client_id=ztoken&redirect_uri=http://localhost:8081&response_type=token` (True as business_partner_id).

---

There is also the general weirdness of different behavior of when new tokens are created. Creating an unnamed token just records the refresh token but not the token and no lifetime. This way every run of `ztoken` has to create a new token and so `--refresh` would be pointless there. Creating a named token records the lifetime and seems to return the same token every time as long as it is valid. Even if the `--refresh` thing were fixed, this dichotomy would not go away.

Comments:

Patch:
diff --git a/zign/cli.py b/zign/cli.py
index 2fabfb2..b6cd3e0 100644
--- a/zign/cli.py
+++ b/zign/cli.py
@@ -87,7 +87,8 @@ def token(name, authorize_url, client_id, business_partner_id, refresh):
     '''Create a new Platform IAM token or use an existing one.'''
 
     try:
-        token = get_token_implicit_flow(name, authorize_url, client_id, business_partner_id, refresh)
+        token = get_token_implicit_flow(name, authorize_url=authorize_url, client_id=client_id,
+                                        business_partner_id=business_partner_id, refresh=refresh)
     except AuthenticationFailed as e:
         raise click.UsageError(e)
     access_token = token.get('access_token')


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
new file mode 100644
index 0000000..8b23802
--- /dev/null
+++ b/tests/test_cli.py
@@ -0,0 +1,19 @@
+from click.testing import CliRunner
+from unittest.mock import MagicMock
+from zign.cli import cli
+
+
+def test_token(monkeypatch):
+    token = 'abc-123'
+
+    get_token_implicit_flow = MagicMock()
+    get_token_implicit_flow.return_value = {'access_token': token, 'expires_in': 1, 'token_type': 'test'}
+    monkeypatch.setattr('zign.cli.get_token_implicit_flow', get_token_implicit_flow)
+
+    runner = CliRunner()
+
+    with runner.isolated_filesystem():
+        result = runner.invoke(cli, ['token', '-n', 'mytok', '--refresh'], catch_exceptions=False)
+
+        assert token == result.output.rstrip().split('\n')[-1]
+        get_token_implicit_flow.assert_called_with('mytok', authorize_url=None, business_partner_id=None, client_id=None, refresh=True)