aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/AwsRole.java
blob: 204e6e236070196ac5b33f52730dc1bece48c669 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.api;

import java.net.URLEncoder;
import java.util.Objects;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
 * @author mortent
 */
public class AwsRole {

    private final String name;
    private final String encodedName;

    public AwsRole(String awsRoleName) {
        this.name = awsRoleName;
        // Encoded twice for zts compatibility
        this.encodedName = URLEncoder.encode(URLEncoder.encode(this.name, UTF_8), UTF_8);
    }

    public String encodedName() {
        return encodedName;
    }

    public String name() {
        return name;
    }

    public static AwsRole from(AthenzIdentity identity) {
        return new AwsRole(identity.getFullName());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AwsRole awsRole = (AwsRole) o;
        return Objects.equals(name, awsRole.name) &&
               Objects.equals(encodedName, awsRole.encodedName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, encodedName);
    }
}