Skip to content

Commit

Permalink
Adding resource ownership support for MSD API
Browse files Browse the repository at this point in the history
Signed-off-by: yosrixp <yosrixp@yahooinc.com>
  • Loading branch information
yosrixp committed Sep 27, 2024
1 parent 515c5fa commit 3b2d878
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 24 deletions.
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.

Loading

0 comments on commit 3b2d878

Please sign in to comment.