Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding resource ownership support for MSD API #2744

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions clients/go/msd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,11 @@ func (client MSDClient) GetTransportPolicyRulesByDomain(domainName DomainName, m
}
}

func (client MSDClient) PutTransportPolicy(domainName DomainName, serviceName EntityName, auditRef string, payload *TransportPolicyRequest) (*TransportPolicyRules, error) {
func (client MSDClient) PutTransportPolicy(domainName DomainName, serviceName EntityName, auditRef string, resourceOwner string, payload *TransportPolicyRequest) (*TransportPolicyRules, error) {
var data *TransportPolicyRules
headers := map[string]string{
"Y-Audit-Ref": auditRef,
"Athenz-Resource-Owner": resourceOwner,
"Y-Audit-Ref": auditRef,
}
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/transportpolicy"
contentBytes, err := json.Marshal(payload)
Expand Down Expand Up @@ -515,9 +516,10 @@ func (client MSDClient) GetTransportPolicyRulesByService(domainName DomainName,
}
}

func (client MSDClient) DeleteTransportPolicy(domainName DomainName, serviceName EntityName, id int64, auditRef string) error {
func (client MSDClient) DeleteTransportPolicy(domainName DomainName, serviceName EntityName, id int64, auditRef string, resourceOwner string) error {
headers := map[string]string{
"Y-Audit-Ref": auditRef,
"Athenz-Resource-Owner": resourceOwner,
"Y-Audit-Ref": auditRef,
}
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/transportpolicy/" + fmt.Sprint(id)
resp, err := client.httpDelete(url, headers)
Expand Down Expand Up @@ -621,13 +623,16 @@ func (client MSDClient) GetWorkloadsByIP(ip string, matchingTag string) (*Worklo
}
}

func (client MSDClient) PutDynamicWorkload(domainName DomainName, serviceName EntityName, options *WorkloadOptions) error {
func (client MSDClient) PutDynamicWorkload(domainName DomainName, serviceName EntityName, options *WorkloadOptions, resourceOwner string) error {
headers := map[string]string{
"Athenz-Resource-Owner": resourceOwner,
}
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/workload/dynamic"
contentBytes, err := json.Marshal(options)
if err != nil {
return err
}
resp, err := client.httpPut(url, nil, contentBytes)
resp, err := client.httpPut(url, headers, contentBytes)
if err != nil {
return err
}
Expand All @@ -652,9 +657,12 @@ func (client MSDClient) PutDynamicWorkload(domainName DomainName, serviceName En
}
}

func (client MSDClient) DeleteDynamicWorkload(domainName DomainName, serviceName EntityName, instanceId PathElement) error {
func (client MSDClient) DeleteDynamicWorkload(domainName DomainName, serviceName EntityName, instanceId PathElement, resourceOwner string) error {
headers := map[string]string{
"Athenz-Resource-Owner": resourceOwner,
}
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/instanceId/" + fmt.Sprint(instanceId) + "/workload/dynamic"
resp, err := client.httpDelete(url, nil)
resp, err := client.httpDelete(url, headers)
if err != nil {
return err
}
Expand All @@ -679,13 +687,16 @@ func (client MSDClient) DeleteDynamicWorkload(domainName DomainName, serviceName
}
}

func (client MSDClient) PutStaticWorkload(domainName DomainName, serviceName EntityName, staticWorkload *StaticWorkload) error {
func (client MSDClient) PutStaticWorkload(domainName DomainName, serviceName EntityName, staticWorkload *StaticWorkload, resourceOwner string) error {
headers := map[string]string{
"Athenz-Resource-Owner": resourceOwner,
}
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/workload/static"
contentBytes, err := json.Marshal(staticWorkload)
if err != nil {
return err
}
resp, err := client.httpPut(url, nil, contentBytes)
resp, err := client.httpPut(url, headers, contentBytes)
if err != nil {
return err
}
Expand All @@ -710,9 +721,12 @@ func (client MSDClient) PutStaticWorkload(domainName DomainName, serviceName Ent
}
}

func (client MSDClient) DeleteStaticWorkload(domainName DomainName, serviceName EntityName, name StaticWorkloadName) error {
func (client MSDClient) DeleteStaticWorkload(domainName DomainName, serviceName EntityName, name StaticWorkloadName, resourceOwner string) error {
headers := map[string]string{
"Athenz-Resource-Owner": resourceOwner,
}
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/name/" + fmt.Sprint(name) + "/workload/static"
resp, err := client.httpDelete(url, nil)
resp, err := client.httpDelete(url, headers)
if err != nil {
return err
}
Expand Down Expand Up @@ -851,13 +865,16 @@ func (client MSDClient) GetWorkloadsByDomainAndService(request *BulkWorkloadRequ
}
}

func (client MSDClient) PutCompositeInstance(domainName DomainName, serviceName EntityName, instance *CompositeInstance) error {
func (client MSDClient) PutCompositeInstance(domainName DomainName, serviceName EntityName, instance *CompositeInstance, resourceOwner string) error {
headers := map[string]string{
"Athenz-Resource-Owner": resourceOwner,
}
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/workload/discover/instance"
contentBytes, err := json.Marshal(instance)
if err != nil {
return err
}
resp, err := client.httpPut(url, nil, contentBytes)
resp, err := client.httpPut(url, headers, contentBytes)
if err != nil {
return err
}
Expand All @@ -882,9 +899,12 @@ func (client MSDClient) PutCompositeInstance(domainName DomainName, serviceName
}
}

func (client MSDClient) DeleteCompositeInstance(domainName DomainName, serviceName EntityName, instance SimpleName) error {
func (client MSDClient) DeleteCompositeInstance(domainName DomainName, serviceName EntityName, instance SimpleName, resourceOwner string) error {
headers := map[string]string{
"Athenz-Resource-Owner": resourceOwner,
}
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/workload/discover/instance/" + fmt.Sprint(instance)
resp, err := client.httpDelete(url, nil)
resp, err := client.httpDelete(url, headers)
if err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions clients/go/msd/msd_schema.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ public Workloads getWorkloadsByService(String domain, String service, String mat
* @param options options for the new workload
* @return WorkloadOptions
*/
public WorkloadOptions putDynamicWorkload(String domain, String service, WorkloadOptions options) {
public WorkloadOptions putDynamicWorkload(String domain, String service, WorkloadOptions options, String resourceOwner) {
try {
return client.putDynamicWorkload(domain, service, options);
return client.putDynamicWorkload(domain, service, options, resourceOwner);
} catch (ResourceException ex) {
throw new MSDClientException(ex.getCode(), ex.getData());
} catch (Exception ex) {
Expand All @@ -218,9 +218,9 @@ public WorkloadOptions putDynamicWorkload(String domain, String service, Workloa
* @param service name of the service
* @param instanceId instanceId of the host
*/
public void deleteDynamicWorkload(String domain, String service, String instanceId) {
public void deleteDynamicWorkload(String domain, String service, String instanceId, String resourceOwner) {
try {
client.deleteDynamicWorkload(domain, service, instanceId);
client.deleteDynamicWorkload(domain, service, instanceId, resourceOwner);
} catch (ResourceException ex) {
throw new MSDClientException(ex.getCode(), ex.getData());
} catch (Exception ex) {
Expand All @@ -236,9 +236,9 @@ public void deleteDynamicWorkload(String domain, String service, String instance
* @param staticWorkload StaticWorkload object
* @return WorkloadOptions
*/
public StaticWorkload putStaticWorkload(String domain, String service, StaticWorkload staticWorkload) {
public StaticWorkload putStaticWorkload(String domain, String service, StaticWorkload staticWorkload, String resourceOwner) {
try {
return client.putStaticWorkload(domain, service, staticWorkload);
return client.putStaticWorkload(domain, service, staticWorkload, resourceOwner);
} catch (ResourceException ex) {
throw new MSDClientException(ex.getCode(), ex.getData());
} catch (Exception ex) {
Expand All @@ -253,9 +253,9 @@ public StaticWorkload putStaticWorkload(String domain, String service, StaticWor
* @param service name of the service
* @param name name of the static workload
*/
public void deleteStaticWorkload(String domain, String service, String name) {
public void deleteStaticWorkload(String domain, String service, String name, String resourceOwner) {
try {
client.deleteStaticWorkload(domain, service, name);
client.deleteStaticWorkload(domain, service, name, resourceOwner);
} catch (ResourceException ex) {
throw new MSDClientException(ex.getCode(), ex.getData());
} catch (Exception ex) {
Expand Down
Loading