Skip to content

Commit

Permalink
provide useful utility to fetch domain attrs (#2803)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Avetisyan <[email protected]>
  • Loading branch information
havetisyan authored Nov 26, 2024
1 parent 8161f55 commit 3c51ddd
Show file tree
Hide file tree
Showing 10 changed files with 407 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ utils/zts-svccert/src/
utils/zts-accesstoken/bin/
utils/zts-accesstoken/pkg/
utils/zts-accesstoken/src/
utils/zms-domainattrs/bin/
utils/zms-domainattrs/pkg/
utils/zms-domainattrs/src/
utils/zts-idtoken/bin/
utils/zts-idtoken/pkg/
utils/zts-idtoken/src/
Expand Down
4 changes: 4 additions & 0 deletions assembly/utils/utils.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<directory>${basedir}/../../utils/zms-svctoken/target</directory>
<outputDirectory>bin</outputDirectory>
</fileSet>
<fileSet>
<directory>${basedir}/../../utils/zms-domainattrs/target</directory>
<outputDirectory>bin</outputDirectory>
</fileSet>
<fileSet>
<directory>${basedir}/../../utils/zts-roletoken/target</directory>
<outputDirectory>bin</outputDirectory>
Expand Down
7 changes: 7 additions & 0 deletions clients/go/zms/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/go/zms/zms_schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
<module>provider/harness/sia-harness</module>
<module>utils/zms-cli</module>
<module>utils/athenz-conf</module>
<module>utils/zms-domainattrs</module>
<module>utils/zms-svctoken</module>
<module>utils/zpe-updater</module>
<module>utils/zts-roletoken</module>
Expand Down Expand Up @@ -499,6 +500,7 @@
<module>libs/go/athenzconf</module>
<module>utils/zms-cli</module>
<module>utils/athenz-conf</module>
<module>utils/zms-domainattrs</module>
<module>utils/zms-svctoken</module>
<module>utils/zpe-updater</module>
<module>utils/zts-roletoken</module>
Expand Down
58 changes: 58 additions & 0 deletions utils/zms-domainattrs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Makefile to build ZMS Domain Attributes utility
# Prerequisite: Go development environment
#
# Copyright The Athenz Authors
# Licensed under the Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0
#

GOPKGNAME = github.com/AthenZ/athenz/utils/zms-domainattrs
PKG_DATE=$(shell date '+%Y-%m-%dT%H:%M:%S')
BINARY=zms-domainattrs
SRC=zms-domainattrs.go

# check to see if go utility is installed
GO := $(shell command -v go 2> /dev/null)
GOPATH := $(shell pwd)
export $(GOPATH)

ifdef GO

# we need to make sure we have go 1.19+
# the output for the go version command is:
# go version go1.19 darwin/amd64

GO_VER_GTEQ := $(shell expr `go version | cut -f 3 -d' ' | cut -f2 -d.` \>= 19)
ifneq "$(GO_VER_GTEQ)" "1"
all:
@echo "Please install 1.19.x or newer version of golang"
else

.PHONY: vet fmt linux darwin
all: vet fmt linux darwin

endif

else

all:
@echo "go is not available please install golang"

endif

vet:
go vet .

fmt:
go fmt .

darwin:
@echo "Building darwin client..."
GOOS=darwin go build -ldflags "-X main.VERSION=$(PKG_VERSION) -X main.BUILD_DATE=$(PKG_DATE)" -o target/darwin/$(BINARY) $(SRC)

linux:
@echo "Building linux client..."
GOOS=linux go build -ldflags "-X main.VERSION=$(PKG_VERSION) -X main.BUILD_DATE=$(PKG_DATE)" -o target/linux/$(BINARY) $(SRC)

clean:
rm -rf target
58 changes: 58 additions & 0 deletions utils/zms-domainattrs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
zms-domainattrs
===============

The utility looks at the domains specified in a given file (one domain per line) and
for each domain, it retrieves and displays the requested attributes associated with
the domain.

The utility supports the following list of attributes:

- businessService
- productId
- account
- gcpProject
- gcpProjectNumber
- azureSubscription
- azureTenant
- azureClient
- org
- slackChannel
- environment

For businessService and productId attributes, if the given domain does not have the
attribute set, the utility will look at the parent domain to see if the attribute
is set there. If the attribute is set in the parent domain, the utility will display
the value from the parent domain. It will continue to look at the parent domains until
it finds the attribute set, or it reaches the top level domain.

## Usage

```
zms-domainattrs -svc-key-file ./key.pem -svc-cert-file ./cert.pem -zms https://athenz.io:4443/zms/v1 -domain-file ./domain.txt -attrs businessService,account
```

where domain.txt might contain:

```
weather
sports.prod
sports.nhl
sys.auth
```

And the output might look like ('weather' domain does not have a businessService attribute and
'sports.prod' domain does not have an account attribute):

```
Domain,businessService,account
weather,,123456
sports.prod,sports-service,
sports.nhl,sports-service,123456
sys.auth,athenz,456789
```

## License

Copyright The Athenz Authors

Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
7 changes: 7 additions & 0 deletions utils/zms-domainattrs/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright The Athenz Authors
// Licensed under the terms of the Apache version 2.0 license. See LICENSE file for terms.

// The utility looks at the domains specified in a given file (one domain per line) and
// for each domain, it retrieves and displays the requested attributes associated with
// the domain.
package main
73 changes: 73 additions & 0 deletions utils/zms-domainattrs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright The Athenz Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.yahoo.athenz</groupId>
<artifactId>athenz</artifactId>
<version>1.12.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>zms-domainattrs</artifactId>
<packaging>jar</packaging>
<name>zms-domainattrs</name>
<description>ZMS Domain Attribute Lookup Utility</description>

<properties>
<maven.install.skip>true</maven.install.skip>
<checkstyle.skip>true</checkstyle.skip>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${maven-exec-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<executable>make</executable>
<arguments>
<argument>PKG_VERSION=${project.parent.version}</argument>
<argument>clean</argument>
<argument>all</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<id>default-jar</id>
<phase />
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit 3c51ddd

Please sign in to comment.