diff --git a/jupiterone/cassettes/TestResourcePermission_Basic.yaml b/jupiterone/cassettes/TestResourcePermission_Basic.yaml index 558c539..0151788 100644 --- a/jupiterone/cassettes/TestResourcePermission_Basic.yaml +++ b/jupiterone/cassettes/TestResourcePermission_Basic.yaml @@ -78,8 +78,86 @@ interactions: - "0" status: 200 OK code: 200 - duration: 664.85025ms + duration: 533.467416ms - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 544 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nquery GetResourcePermissions ($filter: GetResourcePermissionsFilter!, $cursor: String, $limit: Int) {\n\tgetResourcePermissions(filter: $filter, cursor: $cursor, limit: $limit) {\n\t\tcanCreate\n\t\tcanDelete\n\t\tcanRead\n\t\tcanUpdate\n\t\tresourceArea\n\t\tresourceId\n\t\tresourceType\n\t\tsubjectId\n\t\tsubjectType\n\t}\n}\n","variables":{"filter":{"subjectType":"group","subjectId":"example-group-id","resourceArea":"rule","resourceType":"*","resourceId":"*"},"cursor":"","limit":10},"operationName":"GetResourcePermissions"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 217 + uncompressed: false + body: | + {"data":{"getResourcePermissions":[{"canCreate":true,"canDelete":true,"canRead":true,"canUpdate":true,"resourceArea":"rule","resourceId":"*","resourceType":"*","subjectId":"example-group-id","subjectType":"group"}]}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "217" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 450.648917ms + - id: 2 request: proto: HTTP/1.1 proto_major: 1 @@ -156,4 +234,4 @@ interactions: - "0" status: 200 OK code: 200 - duration: 234.689667ms + duration: 482.037916ms diff --git a/jupiterone/cassettes/TestSmartClassQuery_Basic.yaml b/jupiterone/cassettes/TestSmartClassQuery_Basic.yaml new file mode 100644 index 0000000..ad37089 --- /dev/null +++ b/jupiterone/cassettes/TestSmartClassQuery_Basic.yaml @@ -0,0 +1,471 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 268 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation CreateSmartClass ($input: CreateSmartClassInput!) {\n\tcreateSmartClass(input: $input) {\n\t\tid\n\t\ttagName\n\t\tdescription\n\t}\n}\n","variables":{"input":{"tagName":"TfProviderTagTest","description":"xyz"}},"operationName":"CreateSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 126 + uncompressed: false + body: | + {"data":{"createSmartClass":{"id":"db268834-80f4-42b7-953d-ffde1b8770f9","tagName":"TfProviderTagTest","description":"xyz"}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "126" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 1.087211667s + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 355 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation CreateSmartClassQuery ($input: CreateSmartClassQueryInput!) {\n\tcreateSmartClassQuery(input: $input) {\n\t\tid\n\t\tquery\n\t\tsmartClassId\n\t\tdescription\n\t}\n}\n","variables":{"input":{"smartClassId":"db268834-80f4-42b7-953d-ffde1b8770f9","description":"find users","query":"FIND User"}},"operationName":"CreateSmartClassQuery"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 182 + uncompressed: false + body: | + {"data":{"createSmartClassQuery":{"id":"f656bdf2-da8a-4f89-9ec5-c4565aed641b","query":"FIND User","smartClassId":"db268834-80f4-42b7-953d-ffde1b8770f9","description":"find users"}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "182" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 814.919833ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 305 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nquery GetSmartClass ($smartClassId: ID!) {\n\tsmartClass(id: $smartClassId) {\n\t\tid\n\t\ttagName\n\t\tdescription\n\t\ttags {\n\t\t\tid\n\t\t\tname\n\t\t\ttype\n\t\t\tvalue\n\t\t}\n\t}\n}\n","variables":{"smartClassId":"db268834-80f4-42b7-953d-ffde1b8770f9"},"operationName":"GetSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 130 + uncompressed: false + body: | + {"data":{"smartClass":{"id":"db268834-80f4-42b7-953d-ffde1b8770f9","tagName":"TfProviderTagTest","description":"xyz","tags":[]}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "130" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 381.960917ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 285 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nquery GetSmartClassQuery ($smartClassQueryId: ID!) {\n\tsmartClassQuery(id: $smartClassQueryId) {\n\t\tid\n\t\tquery\n\t\tsmartClassId\n\t\tdescription\n\t}\n}\n","variables":{"smartClassQueryId":"f656bdf2-da8a-4f89-9ec5-c4565aed641b"},"operationName":"GetSmartClassQuery"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 176 + uncompressed: false + body: | + {"data":{"smartClassQuery":{"id":"f656bdf2-da8a-4f89-9ec5-c4565aed641b","query":"FIND User","smartClassId":"db268834-80f4-42b7-953d-ffde1b8770f9","description":"find users"}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "176" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 374.910708ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 259 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation DeleteSmartClassQuery ($smartClassQueryId: ID!) {\n\tdeleteSmartClassQuery(id: $smartClassQueryId) {\n\t\tsuccess\n\t}\n}\n","variables":{"smartClassQueryId":"f656bdf2-da8a-4f89-9ec5-c4565aed641b"},"operationName":"DeleteSmartClassQuery"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 52 + uncompressed: false + body: | + {"data":{"deleteSmartClassQuery":{"success":true}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "52" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 654.072959ms + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 229 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation DeleteSmartClass ($smartClassId: ID!) {\n\tdeleteSmartClass(id: $smartClassId) {\n\t\tsuccess\n\t}\n}\n","variables":{"smartClassId":"db268834-80f4-42b7-953d-ffde1b8770f9"},"operationName":"DeleteSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 47 + uncompressed: false + body: | + {"data":{"deleteSmartClass":{"success":true}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "47" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 692.91325ms diff --git a/jupiterone/cassettes/TestSmartClassTag_Basic.yaml b/jupiterone/cassettes/TestSmartClassTag_Basic.yaml new file mode 100644 index 0000000..4fb28c1 --- /dev/null +++ b/jupiterone/cassettes/TestSmartClassTag_Basic.yaml @@ -0,0 +1,471 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 268 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation CreateSmartClass ($input: CreateSmartClassInput!) {\n\tcreateSmartClass(input: $input) {\n\t\tid\n\t\ttagName\n\t\tdescription\n\t}\n}\n","variables":{"input":{"tagName":"TfProviderTagTest","description":"xyz"}},"operationName":"CreateSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 126 + uncompressed: false + body: | + {"data":{"createSmartClass":{"id":"b9f97b9b-13f3-47f4-9d5d-8e32abfdf9e7","tagName":"TfProviderTagTest","description":"xyz"}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "126" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 988.278416ms + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 334 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation CreateSmartClassTag ($input: CreateSmartClassTagInput!) {\n\tcreateSmartClassTag(input: $input) {\n\t\tid\n\t\tname\n\t\ttype\n\t\tvalue\n\t}\n}\n","variables":{"input":{"smartClassId":"b9f97b9b-13f3-47f4-9d5d-8e32abfdf9e7","name":"tagname","type":"boolean","value":"true"}},"operationName":"CreateSmartClassTag"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 128 + uncompressed: false + body: | + {"data":{"createSmartClassTag":{"id":"b7458939-c5ca-4a33-8d5b-749dd4665a95","name":"tagname","type":"boolean","value":"true"}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "128" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 711.427875ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 305 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nquery GetSmartClass ($smartClassId: ID!) {\n\tsmartClass(id: $smartClassId) {\n\t\tid\n\t\ttagName\n\t\tdescription\n\t\ttags {\n\t\t\tid\n\t\t\tname\n\t\t\ttype\n\t\t\tvalue\n\t\t}\n\t}\n}\n","variables":{"smartClassId":"b9f97b9b-13f3-47f4-9d5d-8e32abfdf9e7"},"operationName":"GetSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 224 + uncompressed: false + body: | + {"data":{"smartClass":{"id":"b9f97b9b-13f3-47f4-9d5d-8e32abfdf9e7","tagName":"TfProviderTagTest","description":"xyz","tags":[{"id":"b7458939-c5ca-4a33-8d5b-749dd4665a95","name":"tagname","type":"boolean","value":"true"}]}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "224" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 360.229667ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 305 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nquery GetSmartClass ($smartClassId: ID!) {\n\tsmartClass(id: $smartClassId) {\n\t\tid\n\t\ttagName\n\t\tdescription\n\t\ttags {\n\t\t\tid\n\t\t\tname\n\t\t\ttype\n\t\t\tvalue\n\t\t}\n\t}\n}\n","variables":{"smartClassId":"b9f97b9b-13f3-47f4-9d5d-8e32abfdf9e7"},"operationName":"GetSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 224 + uncompressed: false + body: | + {"data":{"smartClass":{"id":"b9f97b9b-13f3-47f4-9d5d-8e32abfdf9e7","tagName":"TfProviderTagTest","description":"xyz","tags":[{"id":"b7458939-c5ca-4a33-8d5b-749dd4665a95","name":"tagname","type":"boolean","value":"true"}]}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "224" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 367.938792ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 247 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation DeleteSmartClassTag ($smartClassTagId: ID!) {\n\tdeleteSmartClassTag(id: $smartClassTagId) {\n\t\tsuccess\n\t}\n}\n","variables":{"smartClassTagId":"b7458939-c5ca-4a33-8d5b-749dd4665a95"},"operationName":"DeleteSmartClassTag"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 50 + uncompressed: false + body: | + {"data":{"deleteSmartClassTag":{"success":true}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "50" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 1.356674708s + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 229 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation DeleteSmartClass ($smartClassId: ID!) {\n\tdeleteSmartClass(id: $smartClassId) {\n\t\tsuccess\n\t}\n}\n","variables":{"smartClassId":"b9f97b9b-13f3-47f4-9d5d-8e32abfdf9e7"},"operationName":"DeleteSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 47 + uncompressed: false + body: | + {"data":{"deleteSmartClass":{"success":true}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "47" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 696.425417ms diff --git a/jupiterone/cassettes/TestSmartClass_Basic.yaml b/jupiterone/cassettes/TestSmartClass_Basic.yaml index 2797c38..2e793c0 100644 --- a/jupiterone/cassettes/TestSmartClass_Basic.yaml +++ b/jupiterone/cassettes/TestSmartClass_Basic.yaml @@ -1,3 +1,237 @@ --- version: 2 -interactions: [] +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 311 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation CreateSmartClass ($input: CreateSmartClassInput!) {\n\tcreateSmartClass(input: $input) {\n\t\tid\n\t\ttagName\n\t\tdescription\n\t}\n}\n","variables":{"input":{"tagName":"TfProviderTestSmartClass","description":"description of TfProviderTestSmartClass"}},"operationName":"CreateSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 169 + uncompressed: false + body: | + {"data":{"createSmartClass":{"id":"ec6c835c-d669-41f9-9cb7-790eb29b7856","tagName":"TfProviderTestSmartClass","description":"description of TfProviderTestSmartClass"}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "169" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 1.307006708s + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 305 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nquery GetSmartClass ($smartClassId: ID!) {\n\tsmartClass(id: $smartClassId) {\n\t\tid\n\t\ttagName\n\t\tdescription\n\t\ttags {\n\t\t\tid\n\t\t\tname\n\t\t\ttype\n\t\t\tvalue\n\t\t}\n\t}\n}\n","variables":{"smartClassId":"ec6c835c-d669-41f9-9cb7-790eb29b7856"},"operationName":"GetSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 173 + uncompressed: false + body: | + {"data":{"smartClass":{"id":"ec6c835c-d669-41f9-9cb7-790eb29b7856","tagName":"TfProviderTestSmartClass","description":"description of TfProviderTestSmartClass","tags":[]}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "173" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 512.516875ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 229 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nmutation DeleteSmartClass ($smartClassId: ID!) {\n\tdeleteSmartClass(id: $smartClassId) {\n\t\tsuccess\n\t}\n}\n","variables":{"smartClassId":"ec6c835c-d669-41f9-9cb7-790eb29b7856"},"operationName":"DeleteSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 47 + uncompressed: false + body: | + {"data":{"deleteSmartClass":{"success":true}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "47" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 724.513458ms diff --git a/jupiterone/cassettes/TestSmartClass_BasicImport.yaml b/jupiterone/cassettes/TestSmartClass_BasicImport.yaml index 9fe7407..d295ba7 100644 --- a/jupiterone/cassettes/TestSmartClass_BasicImport.yaml +++ b/jupiterone/cassettes/TestSmartClass_BasicImport.yaml @@ -30,7 +30,7 @@ interactions: content_length: 161 uncompressed: false body: | - {"data":{"createSmartClass":{"id":"3f40b190-bbfc-477a-bf41-a9e8900437b2","tagName":"TfProviderTestImport","description":"description of TfProviderTestImport"}}} + {"data":{"createSmartClass":{"id":"d1e89b60-a19b-47ca-b706-f61f4d71a972","tagName":"TfProviderTestImport","description":"description of TfProviderTestImport"}}} headers: Access-Control-Allow-Credentials: - "true" @@ -78,4 +78,82 @@ interactions: - "0" status: 200 OK code: 200 - duration: 1.049610292s + duration: 1.108235791s + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 305 + transfer_encoding: [] + trailer: {} + host: graphql.dev.jupiterone.io + remote_addr: "" + request_uri: "" + body: '{"query":"\nquery GetSmartClass ($smartClassId: ID!) {\n\tsmartClass(id: $smartClassId) {\n\t\tid\n\t\ttagName\n\t\tdescription\n\t\ttags {\n\t\t\tid\n\t\t\tname\n\t\t\ttype\n\t\t\tvalue\n\t\t}\n\t}\n}\n","variables":{"smartClassId":"d1e89b60-a19b-47ca-b706-f61f4d71a972"},"operationName":"GetSmartClass"}' + form: {} + headers: + Cache-Control: + - no-cache + Content-Type: + - application/json + url: https://graphql.dev.jupiterone.io/ + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 165 + uncompressed: false + body: | + {"data":{"smartClass":{"id":"d1e89b60-a19b-47ca-b706-f61f4d71a972","tagName":"TfProviderTestImport","description":"description of TfProviderTestImport","tags":[]}}} + headers: + Access-Control-Allow-Credentials: + - "true" + Content-Length: + - "165" + Content-Security-Policy: + - 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self'' https: data:;form-action ''self'';frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src ''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests' + Content-Type: + - application/json + Cross-Origin-Embedder-Policy: + - require-corp + Cross-Origin-Opener-Policy: + - same-origin + Cross-Origin-Resource-Policy: + - same-origin + Expect-Ct: + - max-age=0 + Origin-Agent-Cluster: + - ?1 + Ratelimit-Limit: + - "1000" + Ratelimit-Remaining: + - "999" + Ratelimit-Requested: + - "1" + Ratelimit-Reset: + - "1" + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=15552000; includeSubDomains + Vary: + - Origin + X-Content-Type-Options: + - nosniff + X-Dns-Prefetch-Control: + - "off" + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Xss-Protection: + - "0" + status: 200 OK + code: 200 + duration: 372.458458ms diff --git a/jupiterone/internal/client/client.go b/jupiterone/internal/client/client.go index 702366e..fd43175 100644 --- a/jupiterone/internal/client/client.go +++ b/jupiterone/internal/client/client.go @@ -85,7 +85,10 @@ func (rt *RetryTransport) RoundTrip(req *http.Request) (*http.Response, error) { // Setting the body for the request req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) - resp, _ = rt.Transport.RoundTrip(req) + resp, err = rt.Transport.RoundTrip(req) + if err != nil { + return nil, err + } if resp.StatusCode != http.StatusTooManyRequests { updateLastNon429Response() diff --git a/jupiterone/resource_smart_class_query_test.go b/jupiterone/resource_smart_class_query_test.go new file mode 100644 index 0000000..848d405 --- /dev/null +++ b/jupiterone/resource_smart_class_query_test.go @@ -0,0 +1,109 @@ +package jupiterone + +import ( + "context" + "fmt" + "testing" + + "github.com/Khan/genqlient/graphql" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/jupiterone/terraform-provider-jupiterone/jupiterone/internal/client" +) + +func TestSmartClassQuery_Basic(t *testing.T) { + ctx := context.TODO() + + recordingClient, directClient, cleanup := setupTestClients(ctx, t) + defer cleanup(t) + + resourceName := "jupiterone_smart_class_query.test" + smartClassResourceName := "jupiterone_smart_class.test" + _query := "FIND User" + _description := "find users" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(recordingClient), + CheckDestroy: testAccCheckSmartClassQueryDestroy(ctx, directClient), + Steps: []resource.TestStep{ + { + Config: testSmartClassQueryBasicConfig(_query, _description), + Check: resource.ComposeTestCheckFunc( + testAccCheckSmartClassQueryExists(ctx, directClient), + resource.TestCheckResourceAttrSet(resourceName, "id"), + resource.TestCheckResourceAttrPair(resourceName, "smart_class_id", smartClassResourceName, "id"), + resource.TestCheckResourceAttr(resourceName, "query", _query), + resource.TestCheckResourceAttr(resourceName, "description", _description), + ), + }, + }, + }) +} + +func testAccCheckSmartClassQueryExists(ctx context.Context, qlient graphql.Client) resource.TestCheckFunc { + return func(s *terraform.State) error { + if err := smartClassQueryExistsHelper(ctx, s, qlient); err != nil { + return err + } + return nil + } +} + +func smartClassQueryExistsHelper(ctx context.Context, s *terraform.State, qlient graphql.Client) error { + if qlient == nil { + return nil + } + + for _, r := range s.RootModule().Resources { + if r.Type == "jupiterone_smart_class_query" { + id := r.Primary.ID + _, err := client.GetSmartClassQuery(ctx, qlient, id) + if err != nil { + return err + } + } + } + + return nil +} + +func testAccCheckSmartClassQueryDestroy(ctx context.Context, qlient graphql.Client) func(*terraform.State) error { + return func(s *terraform.State) error { + if err := smartClassQueryDestroyHelper(ctx, s, qlient); err != nil { + return err + } + return nil + } +} + +func smartClassQueryDestroyHelper(ctx context.Context, s *terraform.State, qlient graphql.Client) error { + if qlient == nil { + return nil + } + + err := smartClassQueryExistsHelper(ctx, s, qlient) + + if err == nil { + return fmt.Errorf("Smart class query still exists") + } + + return nil +} + +func testSmartClassQueryBasicConfig(_query string, _description string) string { + return fmt.Sprintf(` + provider "jupiterone" {} + + resource "jupiterone_smart_class" "test" { + tag_name = "TfProviderTagTest" + description = "xyz" + } + + resource "jupiterone_smart_class_query" "test" { + smart_class_id = jupiterone_smart_class.test.id + query = %q + description = %q + } + `, _query, _description) +} diff --git a/jupiterone/resource_smart_class_tag_test.go b/jupiterone/resource_smart_class_tag_test.go new file mode 100644 index 0000000..616115e --- /dev/null +++ b/jupiterone/resource_smart_class_tag_test.go @@ -0,0 +1,124 @@ +package jupiterone + +import ( + "context" + "fmt" + "testing" + + "github.com/Khan/genqlient/graphql" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/jupiterone/terraform-provider-jupiterone/jupiterone/internal/client" +) + +func TestSmartClassTag_Basic(t *testing.T) { + ctx := context.TODO() + + recordingClient, directClient, cleanup := setupTestClients(ctx, t) + defer cleanup(t) + + resourceName := "jupiterone_smart_class_tag.test" + smartClassResourceName := "jupiterone_smart_class.test" + _name := "tagname" + _type := "boolean" + _value := "true" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(recordingClient), + CheckDestroy: testAccCheckSmartClassTagDestroy(ctx, directClient), + Steps: []resource.TestStep{ + { + Config: testSmartClassTagBasicConfig(_name, _type, _value), + Check: resource.ComposeTestCheckFunc( + testAccCheckSmartClassTagExists(ctx, directClient), + resource.TestCheckResourceAttrSet(resourceName, "id"), + resource.TestCheckResourceAttrPair(resourceName, "smart_class_id", smartClassResourceName, "id"), + resource.TestCheckResourceAttr(resourceName, "name", _name), + resource.TestCheckResourceAttr(resourceName, "type", _type), + resource.TestCheckResourceAttr(resourceName, "value", _value), + ), + }, + }, + }) +} + +func testAccCheckSmartClassTagExists(ctx context.Context, qlient graphql.Client) resource.TestCheckFunc { + return func(s *terraform.State) error { + if err := smartClassTagExistsHelper(ctx, s, qlient); err != nil { + return err + } + return nil + } +} + +func smartClassTagExistsHelper(ctx context.Context, s *terraform.State, qlient graphql.Client) error { + if qlient == nil { + return nil + } + + var smartClassTag client.GetSmartClassSmartClassTagsSmartClassTag + for _, r := range s.RootModule().Resources { + if r.Type == "jupiterone_smart_class" { + id := r.Primary.ID + smartClassResponse, err := client.GetSmartClass(ctx, qlient, id) + if err != nil { + return err + } + + for _, tag := range smartClassResponse.SmartClass.Tags { + if tag.Name == "tagname" { + smartClassTag = tag + break + } + } + } + } + + if smartClassTag.Name != "tagname" { + return fmt.Errorf("Smart class tag does not exist") + } + + return nil +} + +func testAccCheckSmartClassTagDestroy(ctx context.Context, qlient graphql.Client) func(*terraform.State) error { + return func(s *terraform.State) error { + if err := smartClassTagDestroyHelper(ctx, s, qlient); err != nil { + return err + } + return nil + } +} + +func smartClassTagDestroyHelper(ctx context.Context, s *terraform.State, qlient graphql.Client) error { + if qlient == nil { + return nil + } + + err := smartClassTagExistsHelper(ctx, s, qlient) + + if err == nil { + return fmt.Errorf("Smart class tag still exists") + } + + return nil +} + +func testSmartClassTagBasicConfig(_name string, _type string, _value string) string { + return fmt.Sprintf(` + provider "jupiterone" {} + + resource "jupiterone_smart_class" "test" { + tag_name = "TfProviderTagTest" + description = "xyz" + } + + resource "jupiterone_smart_class_tag" "test" { + smart_class_id = jupiterone_smart_class.test.id + name = %q + type = %q + value = %q + } + `, _name, _type, _value) +}