-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat(update): add update attributes handler and Cobra CLI cmd #4
Changes from all commits
5136a9c
c654b0b
49b8907
4d27926
007df32
754740c
c4df4ae
fe6e5bc
20b5fff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ const ( | |
) | ||
|
||
type Attribute struct { | ||
Id int32 | ||
Name string | ||
Rule string | ||
Values []string | ||
|
@@ -41,12 +42,13 @@ func GetAttribute(id int) (Attribute, error) { | |
} | ||
|
||
return Attribute{ | ||
Id: resp.Definition.Descriptor_.Id, | ||
Name: resp.Definition.Name, | ||
Rule: GetAttributeRuleFromAttributeType(resp.Definition.Rule), | ||
Values: values, | ||
Namespace: resp.Definition.Descriptor_.Namespace, | ||
Description: resp.Definition.Descriptor_.Description, | ||
Fqn: GetAttributeFqn(resp.Definition), | ||
Fqn: GetAttributeFqn(resp.Definition.Descriptor_.Namespace, resp.Definition.Name), | ||
}, nil | ||
} | ||
|
||
|
@@ -64,6 +66,7 @@ func ListAttributes() ([]Attribute, error) { | |
values = append(values, v.Value) | ||
} | ||
attrs = append(attrs, Attribute{ | ||
Id: attr.Descriptor_.Id, | ||
Name: attr.Name, | ||
Rule: GetAttributeRuleFromAttributeType(attr.Rule), | ||
Values: values, | ||
|
@@ -110,6 +113,62 @@ func CreateAttribute(name string, rule string, values []string, namespace string | |
}, nil | ||
} | ||
|
||
func UpdateAttribute( | ||
id int32, | ||
name string, | ||
rule string, | ||
values []string, | ||
groupBy []string, | ||
resourceId int32, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can I get greater clarity on which of these are generated at the server/db layer and which are truly required by a User of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is looking at the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, but this is good feedback for the team and a issue is ideal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
resourceVersion int32, | ||
resourceName string, | ||
resourceNamespace string, | ||
resourceDescription string, | ||
resourceDependencies []string, | ||
) (*attributesv1.UpdateAttributeResponse, error) { | ||
var attrValues []*attributesv1.AttributeDefinitionValue | ||
for _, v := range values { | ||
if v != "" { | ||
attrValues = append(attrValues, &attributesv1.AttributeDefinitionValue{Value: v}) | ||
} | ||
} | ||
|
||
var attrGroupBy []*attributesv1.AttributeDefinitionValue | ||
for _, v := range groupBy { | ||
if v != "" { | ||
attrGroupBy = append(attrGroupBy, &attributesv1.AttributeDefinitionValue{Value: v}) | ||
} | ||
} | ||
|
||
var dependencies []*commonv1.ResourceDependency | ||
for _, v := range resourceDependencies { | ||
if v != "" { | ||
dependencies = append(dependencies, &commonv1.ResourceDependency{Namespace: v}) | ||
} | ||
} | ||
|
||
client := attributesv1.NewAttributesServiceClient(grpc.Conn) | ||
return client.UpdateAttribute(grpc.Context, &attributesv1.UpdateAttributeRequest{ | ||
Id: id, | ||
Definition: &attributesv1.AttributeDefinition{ | ||
Name: name, | ||
Rule: GetAttributeRuleFromReadableString(rule), | ||
Values: attrValues, | ||
GroupBy: attrGroupBy, | ||
Descriptor_: &commonv1.ResourceDescriptor{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If some of these values are optional, should we be careful of zero values in the grpc calls (i.e. nil instead of an empty string slice) or is that handled elegantly in the service when lengths are zero? Looking at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update, looks like resource dependencies ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I think this is relevant opentdf/platform#33 |
||
Type: commonv1.PolicyResourceType_POLICY_RESOURCE_TYPE_ATTRIBUTE_DEFINITION, | ||
Id: resourceId, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the |
||
Version: resourceVersion, | ||
Name: resourceName, | ||
Namespace: resourceNamespace, | ||
Fqn: GetAttributeFqn(resourceNamespace, resourceName), | ||
Description: resourceDescription, | ||
Dependencies: dependencies, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func DeleteAttribute(id int) error { | ||
client := attributesv1.NewAttributesServiceClient(grpc.Conn) | ||
|
||
|
@@ -120,8 +179,8 @@ func DeleteAttribute(id int) error { | |
return err | ||
} | ||
|
||
func GetAttributeFqn(resp *attributesv1.AttributeDefinition) string { | ||
return fmt.Sprintf("https://%s/attr/%s", resp.Descriptor_.Namespace, resp.Name) | ||
func GetAttributeFqn(namespace string, name string) string { | ||
return fmt.Sprintf("https://%s/attr/%s", namespace, name) | ||
} | ||
|
||
func GetAttributeRuleOptions() []string { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we ever allow zero's as our
int32
values passed by users? For example, I ran into an issue here withresource-version
. If that value must be defined by aUser
in anAttribute - Update
flow, the version should currently be truly 0, but 0 is also the Go zero-value for theint32
type, so if we want to require an int32 flag, we'd want to gracefully handle these zero values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if the user has to apply the version that is a problem. It seems like the version should iterate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opentdf/platform#38