rubrikinc / rubrik-powershell-sdk

The Rubrik Security Cloud SDK
https://www.powershellgallery.com/packages/RubrikSecurityCloud
MIT License
7 stars 9 forks source link

Is this broken or me? #4

Closed Freakwncy closed 7 months ago

Freakwncy commented 1 year ago

PS C:\Users\rhobbs> (Invoke-Rsc "query {clusterConnection(sortBy:RegisteredAt){nodes{id}}}").Nodes.Id c37fa80c-f406-41b1-99e4-bf178c271677 9de0208c-8ba1-40ce-89d2-7c11f5256205 c9e29d83-8456-482b-b510-06a4ada29899 2a50fef8-443d-46b1-b086-7b26c892e697 43a5ad4c-a1c6-4150-9342-dcca2dddf2e8 dee41856-2d11-4199-94b8-907f7327f91c 9ce3af40-81df-41c3-bc7a-03562a04265a 9dd657e8-b5d7-4ce8-b4f9-1c2714e170b0 0d56a609-b1ef-4b70-8334-6514a4af03c3 3204bfc0-96da-4c2c-860a-d62cbb382841 880e7c3a-57d9-4f27-b13d-e282d270b8b8 0b660cba-ec3f-482b-a9a0-e96d74de4c80 fe243c53-0905-4f73-b9cc-fa39b9ff0a24 20cb93c5-75c3-4b8e-94b9-871f96b4aa8a f77d5092-6b61-47f0-bb6c-dfa5f3561bf9 a09fa153-9ce6-4951-9c44-13be5aa5e72f 1be8b596-dbe1-4f4f-8d4e-c6c8855947ab be0dd03f-caf9-4eae-a10e-c00cb5ba8059 b73966ce-e4a3-4b42-a605-45e44884c400 dc365f4d-8377-468d-85b9-3b5d1409e0c6 5435bbfc-1a23-41a7-b86a-51d3444681e5 9c15184d-da7b-42d4-87db-e4599bcfb213 f7662246-b3ee-407e-a466-47ff5c771794 062251af-fe85-4462-8102-3ef8da6626ab bb9c54a3-a2c6-4ced-87cd-b755ef2a0212 ab497a35-0f12-4b8e-8007-53412fa9184c 91c83123-a74a-4758-afa1-554cf26a39fc af795b91-8ac0-4ef7-bf3c-a78caf978c8c c9dd6155-e94e-43c0-9a6e-d95a7cb15570 10a24650-722c-4055-b1f9-89c86fbc57e3 5daa97df-f5a5-4890-ae0d-7122d6d34146 9fff60eb-bcbc-4988-b6fc-d5e8338b7ca2 400de370-09ce-4e4e-9443-6e4be6ac0991 5145d66d-fb22-43e8-b9d3-b7c235cad58e 315e56ea-05b5-4051-9ad6-5ec2ada1c5ec 626db60b-667f-467e-92a2-e2c328ba62bc 4daf9753-3fc5-44cf-ac62-126657c97ae4 af7d1d1b-3392-4a02-871b-d97e063fbff2 87d21c61-a79e-44f2-a32d-130e4a80e13f 8ba1e8d9-2838-48c5-b282-536656ce17c2 79f40f9f-3e63-4639-b9d1-f32a1022f6ee PS C:\Users\rhobbs> (Invoke-Rsc "query {clusterConnection(sortBy:UUID){nodes{id}}}").Nodes.Id
Invoke-Rsc: Exception has been thrown by the target of an invocation. PS C:\Users\rhobbs> (Invoke-Rsc "query {clusterConnection(sortBy:clusterUUID){nodes{id}}}").Nodes.Id Invoke-Rsc: Exception has been thrown by the target of an invocation. PS C:\Users\rhobbs> (Invoke-Rsc "query {clusterConnection(sortBy:name){nodes{id}}}").Nodes.Id
Invoke-Rsc: Exception has been thrown by the target of an invocation. PS C:\Users\rhobbs> (Invoke-Rsc "query {clusterConnection(sortBy:Name){nodes{id}}}").Nodes.Id Invoke-Rsc: Exception has been thrown by the target of an invocation. PS C:\Users\rhobbs> (Invoke-Rsc "query {clusterConnection(sortBy:Id){nodes{id}}}").Nodes.Id
Invoke-Rsc: Exception has been thrown by the target of an invocation. PS C:\Users\rhobbs> (Invoke-Rsc "query {clusterConnection(sortBy:id){nodes{id}}}").Nodes.Id
Invoke-Rsc: Exception has been thrown by the target of an invocation. PS C:\Users\rhobbs> ``

rynardtspies commented 1 year ago

@Freakwncy I've had a look at the issue. Your first query works correctly since RegisteredAt is a valid ENUM value for type ClusterSortByEnum, which is the datatype for the sortBy parameter. Looking at the API, valid values for ClusterSortByEnum are:

krobar1 commented 1 year ago

I tried these in the sort with id and it this works. I then removed the sort and wanted to see other attributes. Some of these work, others don't. Is there a list of attributes that we can request, or can you request everything in the list? Meaning, all of these?

LicensedProducts : PauseStatus : ProductType : RegisteredMode : Status : SubStatus : SystemStatus : Type : ConnectivityLastUpdated : DefaultAddress : DefaultPort : EncryptionEnabled : EstimatedRunway : Id : af795b91-8ac0-4ef7-bf3c-a78caf978c8c IsHealthy : LastConnectionTime : Name : NoSqlWorkloadCount : PassesConnectivityCheck : RegistrationTime : SnapshotCount : SystemStatusMessage : Timezone : Version : ActivitySeriesConnection : AllOrgs : AuthorizedOperations : CcprovisionInfo : CdmClusterNodeDetails : CdmUpgradeInfo : CloudInfo : ClusterDiskConnection : ClusterNodeConnection : ClusterNodeStats : ConfigProtectionInfo : DatagovAutoEnablePolicyConfig : DatagovPreviewerConfig : GeoLocation : GlobalManagerConnectivityStatus : LambdaConfig : LambdaFeatureHistory : MetadataPullScheduler : Metric : MetricTimeSeries : ReplicationSources : ReplicationTargets : RubrikSyncStatus : SnappableConnection : State : SystemStatusAffectedNodes :

PS C:\Users\jwebb6>

Some of these return an error. This works: (Invoke-Rsc "query {clusterConnection{nodes{id, name, version}}}").Nodes

These return an error: PS C:\Users\jwebb6> (Invoke-Rsc "query {clusterConnection{nodes{id, name, estimatedrunway}}}").Nodes Invoke-Rsc: Exception has been thrown by the target of an invocation. PS C:\Users\jwebb6> (Invoke-Rsc "query {clusterConnection{nodes{id, name, state}}}").Nodes
Invoke-Rsc: Exception has been thrown by the target of an invocation. PS C:\Users\jwebb6>

rynardtspies commented 1 year ago

I see your issue.

You can get the fields/members of the object or query with:

(Invoke-Rsc "query {clusterConnection{nodes{id, name, version}}}").Nodes | Get-Member

You can also use Get-RscType to do the same

Get-RscType -Name Cluster | Get-Member

Note that if you're writing for GQL queries by hand, they follow camelCase convention, and the GQL API will enforce that.

Therefore, the following will work:

Invoke-Rsc "query {clusterConnection{nodes{id, name, version, estimatedRunway}}}"

While this will fail:

Invoke-Rsc "query {clusterConnection{nodes{id, name, version, estimatedrunway}}}"

Freakwncy commented 1 year ago

The queries need to be checked, because EstimatedRunway : is the way it's listed in the column. And our normal "guesswork" was EstimatedRunway and estimatedrunway. Either all upper case or all lowercase. Having the first word not capitalized is not a normal standard.

rynardtspies commented 1 year ago

Apologies if I'm misunderstanding you, but I think you may be confusing GraphQL field name conversions with .NET type member name conversions.

All queries from the SDK client to the GQL API will be sent in a GQL compliant query, with the correct casing, i.e. id, name, estimatedRunway, etc. When the data returns in JSON format from the API, it will return exactly the same, i.e id name, estimatedRunway, etc. However, since PowerShell objects are just instantiated .NET classes, the returned JSON data is cast to .NET types, which is all defined and contained within the module. This is to conform with .NET naming conventions.

When you pipe anything through | Get-Member or | gm, you get back the members of the type piped in, and the field/property names will be displayed in a .NET convention, as defined here: Names of Type Members. So in .NET estimatedRunway is cast to a property named EstimatedRunway:

PS /Users/rynardtspies> Get-RscType -Name Cluster | Select estimatedrunway | gm

   TypeName: Selected.RubrikSecurityCloud.Types.Cluster

Name            MemberType   Definition
----            ----------   ----------
Equals          Method       bool Equals(System.Object obj)
GetHashCode     Method       int GetHashCode()
GetType         Method       type GetType()
ToString        Method       string ToString()
EstimatedRunway NoteProperty object EstimatedRunway=null

This is very much an early non-GA release and we are working on improving the SDK so that users would not need to use Invoke-Rsc in the vast majority of cases.

guirava commented 7 months ago

Scrubbing old issues ... I believe this is resolved, please re-open if not.