Skip to content

Commit

Permalink
Metrics properly watch with new delimiter (#25)
Browse files Browse the repository at this point in the history
* feat: todo

* refactor: DomainRoleSplitter

* feat: metrics watch the correct role cert

* fix: limitation

* fix: header

* fix: return err instead as it was before

* fix: use athenz directly with import instead

* feat: logger

* delete: unncessary comments

Co-authored-by: Windz <WindzCUHK@users.noreply.github.com>
Signed-off-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>

---------

Signed-off-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
Co-authored-by: Windz <WindzCUHK@users.noreply.github.com>
Signed-off-by: taniwa <taniwa@yahoo-corp.jp>
  • Loading branch information
2 people authored and taniwa committed Jul 31, 2023
1 parent c66f858 commit 75efe68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 4 additions & 7 deletions pkg/identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/AthenZ/k8s-athenz-sia/v3/third_party/util"

"github.com/AthenZ/athenz/clients/go/zts"
athenz "github.com/AthenZ/athenz/libs/go/sia/util"
extutil "github.com/AthenZ/k8s-athenz-sia/v3/pkg/util"
)

Expand Down Expand Up @@ -405,14 +406,10 @@ func PrepareRoleCsrOptions(cfg *config.IdentityConfig, domain, service string) (
}

for _, domainrole := range strings.Split(cfg.TargetDomainRoles, ",") {
// referred to SplitRoleName()
// https://github.com/AthenZ/athenz/blob/73b25572656f289cce501b4c2fe78f86656082e7/libs/go/sia/util/util.go#L69-L78
dr := strings.Split(domainrole, ":role.")
if len(dr) != 2 || len(dr[0]) == 0 || len(dr[1]) == 0 {
return nil, fmt.Errorf("Invalid role name: '%s', expected format {domain}:role.{role}", domainrole)
targetDomain, targetRole, err := athenz.SplitRoleName(domainrole)
if err != nil {
return nil, err
}
targetDomain := dr[0]
targetRole := dr[1]

domainDNSPart := extutil.DomainToDNSPart(domain)

Expand Down
9 changes: 8 additions & 1 deletion pkg/identity/metricsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"
"time"

athenz "github.com/AthenZ/athenz/libs/go/sia/util"
"github.com/AthenZ/k8s-athenz-sia/v3/pkg/config"
"github.com/AthenZ/k8s-athenz-sia/v3/third_party/log"

Expand Down Expand Up @@ -72,7 +73,13 @@ func Metricsd(idConfig *config.IdentityConfig, stopChan <-chan struct{}) (error,

if idConfig.TargetDomainRoles != "" && idConfig.RoleCertDir != "" {
for _, domainrole := range strings.Split(idConfig.TargetDomainRoles, ",") {
exporter.Files = append(exporter.Files, strings.TrimSuffix(idConfig.RoleCertDir, "/")+"/"+domainrole+".cert.pem")
targetDomain, targetRole, err := athenz.SplitRoleName(domainrole)
if err != nil {
log.Warnf("Failed to read element '%s' of given TARGET_DOMAIN_ROLES: %s, err: %s", domainrole, idConfig.TargetDomainRoles, err.Error())
continue
}
fileName := targetDomain + idConfig.RoleCertFilenameDelimiter + targetRole + ".cert.pem"
exporter.Files = append(exporter.Files, strings.TrimSuffix(idConfig.RoleCertDir, "/")+"/"+fileName)
}
}

Expand Down

0 comments on commit 75efe68

Please sign in to comment.