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

APP-15731 - Support rule labels #219

Merged
merged 5 commits into from
Oct 23, 2024
Merged

APP-15731 - Support rule labels #219

merged 5 commits into from
Oct 23, 2024

Conversation

jzolo22
Copy link
Member

@jzolo22 jzolo22 commented Oct 22, 2024

We are using a "Primitive" gql type for the value of labelValue - this gets translated to a type of string when the client is generated. Users will use strings for the values and rule-service will parse them into their respective primitive types if needed (PR: https://github.com/JupiterOne/rule-service/pull/556).
Note: I am not adding labels to the questionRuleInstance query because the primitive label values will be returned not as strings and terraform loses its mind.

@jzolo22 jzolo22 marked this pull request as ready for review October 23, 2024 14:51
@jzolo22 jzolo22 requested a review from a team as a code owner October 23, 2024 14:51
@jzolo22 jzolo22 changed the title App 15731 APP-15731 - Support rule labels Oct 23, 2024
@jzolo22
Copy link
Member Author

jzolo22 commented Oct 23, 2024

Note to self: tag before merge

transfer_encoding: []
trailer: {}
host: graphql.us.jupiterone.io
remote_addr: ""
request_uri: ""
body: '{"query":"\nmutation CreateInlineQuestionRuleInstance ($instance: CreateInlineQuestionRuleInstanceInput!) {\n\tcreateQuestionRuleInstance: createInlineQuestionRuleInstance(instance: $instance) {\n\t\tid\n\t\tversion\n\t\tspecVersion\n\t\tquestion {\n\t\t\tqueries {\n\t\t\t\tname\n\t\t\t\tquery\n\t\t\t\tversion\n\t\t\t\tincludeDeleted\n\t\t\t}\n\t\t}\n\t\toperations {\n\t\t\twhen\n\t\t\tactions\n\t\t}\n\t}\n}\n","variables":{"instance":{"question":{"queries":[{"query":"Find DataStore with classification=(''critical'' or ''sensitive'' or ''confidential'' or ''restricted'') and encrypted!=true","name":"query0","version":"v1","includeDeleted":false}]},"templates":null,"tags":["tf_acc:1","tf_acc:2"],"name":"tf-provider-test-rule","description":"test","specVersion":1,"operations":[],"outputs":["queries.query0.total","alertLevel"],"pollingInterval":"ONE_DAY","notifyOnFailure":false,"triggerActionsOnNewEntitiesOnly":false,"ignorePreviousResults":false,"remediationSteps":"","j1Internal":false}},"operationName":"CreateInlineQuestionRuleInstance"}'
body: '{"query":"\nmutation CreateInlineQuestionRuleInstance ($instance: CreateInlineQuestionRuleInstanceInput!) {\n\tcreateQuestionRuleInstance: createInlineQuestionRuleInstance(instance: $instance) {\n\t\tid\n\t\tversion\n\t\tspecVersion\n\t\tquestion {\n\t\t\tqueries {\n\t\t\t\tname\n\t\t\t\tquery\n\t\t\t\tversion\n\t\t\t\tincludeDeleted\n\t\t\t}\n\t\t}\n\t\toperations {\n\t\t\twhen\n\t\t\tactions\n\t\t}\n\t\tlabels {\n\t\t\tlabelName\n\t\t\tlabelValue\n\t\t}\n\t}\n}\n","variables":{"instance":{"question":{"queries":[{"query":"Find DataStore with classification=(''critical'' or ''sensitive'' or ''confidential'' or ''restricted'') and encrypted!=true","name":"query0","version":"v1","includeDeleted":false}]},"templates":null,"tags":["tf_acc:1","tf_acc:2"],"name":"tf-provider-test-rule","description":"test","specVersion":1,"operations":[],"outputs":["queries.query0.total","alertLevel"],"pollingInterval":"ONE_DAY","notifyOnFailure":false,"triggerActionsOnNewEntitiesOnly":false,"ignorePreviousResults":false,"remediationSteps":"","collectionId":"","labels":null,"j1Internal":false}},"operationName":"CreateInlineQuestionRuleInstance"}'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use a pipe for multi-line blocks in yaml to make this more readable

  {
    "query": "\nmutation CreateInlineQuestionRuleInstance ($instance: CreateInlineQuestionRuleInstanceInput!) {\n  createQuestionRuleInstance: createInlineQuestionRuleInstance(instance: $instance) {\n    id\n    version\n    specVersion\n    question {\n      queries {\n        name\n        query\n        version\n        includeDeleted\n      }\n    }\n    operations {\n      when\n      actions\n    }\n    labels {\n      labelName\n      labelValue\n    }\n  }\n}\n",
    "variables": {
      "instance": {
        "question": {
          "queries": [
            {
              "query": "Find DataStore with classification=('critical' or 'sensitive' or 'confidential' or 'restricted') and encrypted!=true",
              "name": "query0",
              "version": "v1",
              "includeDeleted": false
            }
          ]
        },
        "templates": null,
        "tags": ["tf_acc:1", "tf_acc:2"],
        "name": "tf-provider-test-rule",
        "description": "test",
        "specVersion": 1,
        "operations": [],
        "outputs": ["queries.query0.total", "alertLevel"],
        "pollingInterval": "ONE_DAY",
        "notifyOnFailure": false,
        "triggerActionsOnNewEntitiesOnly": false,
        "ignorePreviousResults": false,
        "remediationSteps": "",
        "collectionId": "",
        "labels": null,
        "j1Internal": false
      }
    },
    "operationName": "CreateInlineQuestionRuleInstance"
  }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generated!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh okeee

for i, label := range r.Labels {
labels[i] = client.RuleInstanceLabelInput{
LabelName: label.LabelName.ValueString(),
LabelValue: label.LabelValue.ValueString(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this incorrectly convert things to a string if they are an int or a bool?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will only support strings in the terraform and do parsing if needed on the rule-service side. Terraform will actually throw an error if it receives anything but a string

for i, label := range r.Labels {
labels[i] = client.RuleInstanceLabelInput{
LabelName: label.LabelName.ValueString(),
LabelValue: label.LabelValue.ValueString(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this handle empty string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll throw a tf error
image

@jzolo22 jzolo22 merged commit 9e71751 into main Oct 23, 2024
7 checks passed
@jzolo22 jzolo22 deleted the APP-15731 branch October 23, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants