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

Enable logging in PowerShell sub-sessions #124

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private async Task<T> InvokeGraphQLQuery<T>(

HttpClient apiClient = new HttpClient(loggingHandler)
{
BaseAddress = new Uri($"{_polarisUrlScheme}://{_polarisBaseUrl}")
BaseAddress = this.ServerBaseAddress()
};
apiClient.Timeout = TimeSpan.FromMinutes(
RubrikSecurityCloud.Config.ApiClientTimeOutMinutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,29 @@ protected override void ProcessRecord()
RscOp op = SchemaMeta.RscOpLookupByGqlRootField(this.gqlRootField);
_logger?.Debug($"Gql root field {this.gqlRootField} maps to {op}. cmdletName={op.CmdletName}, cmdletSwitchName={op.CmdletSwitchName}, gqlRootFieldName={op.GqlRootFieldName}, gqlReturnTypeName={op.GqlReturnTypeName}, gqlReturnTypeName={op.GqlReturnTypeName},DomainName={op.DomainName()},OpName={op.OpName()}");
ProcessDomainOp(op.DomainName(), op.OpName());
return;
}

if (this.ApiDomainName() == SchemaMeta.ApiDomainName.Unknown)
else
{
throw new Exception("Operation not supported");
}
if (this.ApiDomainName() == SchemaMeta.ApiDomainName.Unknown)
{
throw new Exception("Operation not supported");
}

string operation = "";
string? dynOp = this.GetStringDynParam("Operation");
if (!string.IsNullOrEmpty(dynOp))
{
operation = (dynOp ?? "").Trim();
_logger?.Debug("Operation from -Operation: " + operation);
}
else if (this.Copy != null && this.Copy.rscOp != null)
{
operation = this.Copy.rscOp.OpName();
_logger?.Debug("Operation from Copy: " + operation);
string operation = "";
string? dynOp = this.GetStringDynParam("Operation");
if (!string.IsNullOrEmpty(dynOp))
{
operation = (dynOp ?? "").Trim();
_logger?.Debug("Operation from -Operation: " + operation);
}
else if (this.Copy != null && this.Copy.rscOp != null)
{
operation = this.Copy.rscOp.OpName();
_logger?.Debug("Operation from Copy: " + operation);
}
operation = this.ValidateOperation(operation, unknownOk: false);
ProcessDomainOp(this.ApiDomainName().ToString(), operation);
}
operation = this.ValidateOperation(operation, unknownOk: false);
ProcessDomainOp(this.ApiDomainName().ToString(), operation);
}

protected void ProcessDomainOp(string domain, string op)
Expand Down Expand Up @@ -176,7 +177,7 @@ protected void ProcessDomainOp(string domain, string op)
}
if (r is RscQuery query)
{
_query = query;
this._query = query;
// RscGqlPSCmdlet.EndProcessing()
// will write the object to the pipeline
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,25 @@ protected override void EndProcessing()
return;
}

if (_config.SendQueryOnExitIfAny && _query != null)
if (this._query != null)
{
RscGqlRequest gqlReq = _query.GqlRequest();
if (gqlReq != null && _rbkClient != null)
if (this.MyInvocation.BoundParameters.ContainsKey("Verbose"))
{
this.SendGqlRequest(gqlReq);
this._query.InvokedWithVerboseFlag = true;
}
}
else
{
if (_query != null)
if (this.MyInvocation.BoundParameters.ContainsKey("Debug"))
{
this._query.InvokedWithDebugFlag = true;
}
if (_config.SendQueryOnExitIfAny)
{
RscGqlRequest gqlReq = _query.GqlRequest();
if (gqlReq != null && _rbkClient != null)
{
this.SendGqlRequest(gqlReq);
}
}
else
{
//InterfaceHelper.ConvertListsToRscInterfaces(_query.Field);
this.WriteObject(_query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class RscQuery
internal IRscLogger Logger = null;
internal string OperationsDir = null;
internal string CustomOperationsDir = null;
internal bool InvokedWithDebugFlag = false;
internal bool InvokedWithVerboseFlag = false;

// temporary until Op becomes an RscOp
internal RscOp? rscOp { get; set; } = null;
Expand Down Expand Up @@ -113,6 +115,18 @@ public object Invoke()
{
powerShell.AddCommand("Invoke-Rsc")
.AddParameter("Query", this);

// Check if the parent cmdlet is called with -Verbose and/or -Debug
if (this.InvokedWithVerboseFlag)
{
powerShell.AddParameter("Verbose", true);
}

if (this.InvokedWithDebugFlag)
{
powerShell.AddParameter("Debug", true);
}

var result = powerShell.Invoke();
return result;
}
Expand Down
Loading