Skip to content

Commit

Permalink
Nexus Cloud API enum and oneof changes. (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikki-dag authored Aug 23, 2024
1 parent 23343d2 commit 5fbbd58
Show file tree
Hide file tree
Showing 4 changed files with 480 additions and 154 deletions.
40 changes: 24 additions & 16 deletions app/nexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ func (c *NexusClient) createEndpoint(
policySpecs := make([]*nexus.EndpointPolicySpec, len(allowedNamespaceIDs))
for i, ns := range allowedNamespaceIDs {
policySpecs[i] = &nexus.EndpointPolicySpec{
AllowedCloudNamespacePolicySpec: &nexus.AllowedCloudNamespacePolicySpec{
NamespaceId: ns,
Variant: &nexus.EndpointPolicySpec_AllowedCloudNamespacePolicySpec{
AllowedCloudNamespacePolicySpec: &nexus.AllowedCloudNamespacePolicySpec{
NamespaceId: ns,
},
},
}
}
Expand All @@ -83,9 +85,11 @@ func (c *NexusClient) createEndpoint(
Name: endpointName,
Description: endpointDescription,
TargetSpec: &nexus.EndpointTargetSpec{
WorkerTargetSpec: &nexus.WorkerTargetSpec{
NamespaceId: targetNamespaceID,
TaskQueue: targetTaskQueue,
Variant: &nexus.EndpointTargetSpec_WorkerTargetSpec{
WorkerTargetSpec: &nexus.WorkerTargetSpec{
NamespaceId: targetNamespaceID,
TaskQueue: targetTaskQueue,
},
},
},
PolicySpecs: policySpecs,
Expand Down Expand Up @@ -116,12 +120,12 @@ func (c *NexusClient) patchEndpoint(
existingEndpoint.Spec.Description = description
hasChanges = true
}
if targetNamespaceID != "" && targetNamespaceID != existingEndpoint.Spec.TargetSpec.WorkerTargetSpec.NamespaceId {
existingEndpoint.Spec.TargetSpec.WorkerTargetSpec.NamespaceId = targetNamespaceID
if targetNamespaceID != "" && targetNamespaceID != existingEndpoint.Spec.TargetSpec.GetWorkerTargetSpec().NamespaceId {
existingEndpoint.Spec.TargetSpec.GetWorkerTargetSpec().NamespaceId = targetNamespaceID
hasChanges = true
}
if targetTaskQueue != "" && targetTaskQueue != existingEndpoint.Spec.TargetSpec.WorkerTargetSpec.TaskQueue {
existingEndpoint.Spec.TargetSpec.WorkerTargetSpec.TaskQueue = targetTaskQueue
if targetTaskQueue != "" && targetTaskQueue != existingEndpoint.Spec.TargetSpec.GetWorkerTargetSpec().TaskQueue {
existingEndpoint.Spec.TargetSpec.GetWorkerTargetSpec().TaskQueue = targetTaskQueue
hasChanges = true
}

Expand Down Expand Up @@ -158,7 +162,7 @@ func (c *NexusClient) addAllowedNamespaces(
existingPolicySpecs := existingEndpoint.Spec.PolicySpecs
existingAllowedNamespaceIDMap := make(map[string]struct{}, len(existingPolicySpecs))
for _, policySpec := range existingPolicySpecs {
existingAllowedNamespaceIDMap[policySpec.AllowedCloudNamespacePolicySpec.NamespaceId] = struct{}{}
existingAllowedNamespaceIDMap[policySpec.GetAllowedCloudNamespacePolicySpec().NamespaceId] = struct{}{}
}

updatedPolicySpecs := make([]*nexus.EndpointPolicySpec, len(existingPolicySpecs))
Expand All @@ -168,8 +172,10 @@ func (c *NexusClient) addAllowedNamespaces(
if _, ok := existingAllowedNamespaceIDMap[namespaceID]; !ok {
hasChange = true
updatedPolicySpecs = append(updatedPolicySpecs, &nexus.EndpointPolicySpec{
AllowedCloudNamespacePolicySpec: &nexus.AllowedCloudNamespacePolicySpec{
NamespaceId: namespaceID,
Variant: &nexus.EndpointPolicySpec_AllowedCloudNamespacePolicySpec{
AllowedCloudNamespacePolicySpec: &nexus.AllowedCloudNamespacePolicySpec{
NamespaceId: namespaceID,
},
},
})
}
Expand All @@ -191,8 +197,10 @@ func (c *NexusClient) setAllowedNamespaces(
updatedPolicySpecs := make([]*nexus.EndpointPolicySpec, len(namespaceIDs))
for i, namespaceID := range namespaceIDs {
updatedPolicySpecs[i] = &nexus.EndpointPolicySpec{
AllowedCloudNamespacePolicySpec: &nexus.AllowedCloudNamespacePolicySpec{
NamespaceId: namespaceID,
Variant: &nexus.EndpointPolicySpec_AllowedCloudNamespacePolicySpec{
AllowedCloudNamespacePolicySpec: &nexus.AllowedCloudNamespacePolicySpec{
NamespaceId: namespaceID,
},
},
}
}
Expand All @@ -215,7 +223,7 @@ func (c *NexusClient) removeAllowedNamespaces(

var updatedPolicySpecs []*nexus.EndpointPolicySpec
for _, existingPolicySpec := range existingPolicySpecs {
if _, ok := namespaceIDsToRemoveMap[existingPolicySpec.AllowedCloudNamespacePolicySpec.NamespaceId]; !ok {
if _, ok := namespaceIDsToRemoveMap[existingPolicySpec.GetAllowedCloudNamespacePolicySpec().NamespaceId]; !ok {
updatedPolicySpecs = append(updatedPolicySpecs, existingPolicySpec)
}
}
Expand Down Expand Up @@ -522,7 +530,7 @@ func NewNexusCommand(getNexusClientFn GetNexusClientFn) (CommandOut, error) {
existingPolicySpecs := existingEndpoint.Spec.PolicySpecs
existingAllowedNamespaceIDs := make([]string, len(existingPolicySpecs))
for i, policySpec := range existingPolicySpecs {
existingAllowedNamespaceIDs[i] = policySpec.AllowedCloudNamespacePolicySpec.NamespaceId
existingAllowedNamespaceIDs[i] = policySpec.GetAllowedCloudNamespacePolicySpec().NamespaceId
}
return PrintObj(existingAllowedNamespaceIDs)
},
Expand Down
Loading

0 comments on commit 5fbbd58

Please sign in to comment.