Skip to content
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
2 changes: 2 additions & 0 deletions src/cli/Baseten.CLI/Commands/DefaultApiGroupCommand.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static Command Create()
command.Subcommands.Add(EditRoutesConnectionsByConnectionIdCommandApiCommand.Create());
command.Subcommands.Add(EditRoutesSettingsTeamsByTeamIdCommandApiCommand.Create());
command.Subcommands.Add(EditRoutesSettingsTeamsByTeamIdUsersByUserIdCommandApiCommand.Create());
command.Subcommands.Add(EditRoutesTeamSettingsCommandApiCommand.Create());
command.Subcommands.Add(EditTeamsByTeamIdEnvironmentGroupsByEnvNameCommandApiCommand.Create());
command.Subcommands.Add(EditTrainingCapacityCommandApiCommand.Create());
command.Subcommands.Add(EditTrainingProjectsByTrainingProjectIdJobsByTrainingJobIdCommandApiCommand.Create());
Expand Down Expand Up @@ -204,6 +205,7 @@ public static Command Create()
command.Subcommands.Add(GetRoutesSettingsTeamsByTeamIdUsersCommandApiCommand.Create());
command.Subcommands.Add(GetRoutesSettingsTeamsByTeamIdUsersByUserIdCommandApiCommand.Create());
command.Subcommands.Add(GetRoutesSettingsUsersByUserIdTeamsCommandApiCommand.Create());
command.Subcommands.Add(GetRoutesTeamSettingsCommandApiCommand.Create());
command.Subcommands.Add(GetRoutesUsageCommandApiCommand.Create());
command.Subcommands.Add(GetSecretsCommandApiCommand.Create());
command.Subcommands.Add(GetTeamsCommandApiCommand.Create());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ internal static partial class EditRoutesSettingsTeamsByTeamIdCommandApiCommand
{
Description = @"Harnesses to change; harnesses left out are unchanged. Pass null to clear every harness, so each role uses the team's default.",
};

private static Option<global::Baseten.UpdateRouteTeamSpendLimitSettingV1?> SpendLimit { get; } = new(
name: @"--spend-limit")
{
Description = @"Spend limit fields to change. Pass null to remove the team's limits; omit to leave them unchanged.",
};
private static readonly UpdateRouteTeamSpendLimitSettingV1OptionSet SpendLimitOptions = UpdateRouteTeamSpendLimitSettingV1OptionSet.Create(@"spend-limit");
private static Option<string?> Input { get; } = new(@"--input")
{
Description = "Load request JSON from a file path, '-' for stdin, or an inline JSON object/array string.",
Expand Down Expand Up @@ -68,8 +63,8 @@ public static Command Create(string? commandName = null)
var command = new Command(commandName ?? @"edit-routes-settings-teams-by-team-id", @"Updates a team's route settings
Changes only the fields in the request, all or nothing. Requires team admin, and organization admin to change the team-wide spend limit.");
command.Arguments.Add(TeamId);
command.Options.Add(HarnessDefaults);
command.Options.Add(SpendLimit);
command.Options.Add(HarnessDefaults); command.Options.Add(SpendLimitOptions.PerMemberMonthlyLimitUsd);
command.Options.Add(SpendLimitOptions.TeamWideMonthlyLimitUsd);
command.Options.Add(Input);
command.Options.Add(RequestJson);
command.Options.Add(RequestFile);
Expand Down Expand Up @@ -97,7 +92,19 @@ await CliRuntime.RunAsync(async () =>
cancellationToken).ConfigureAwait(false);
var teamId = parseResult.GetRequiredValue(TeamId);
var harnessDefaults = CliRuntime.WasSpecified(parseResult, HarnessDefaults) ? parseResult.GetValue(HarnessDefaults) : (__requestBase is { } __HarnessDefaultsBaseValue ? __HarnessDefaultsBaseValue.HarnessDefaults : default);
var spendLimit = CliRuntime.WasSpecified(parseResult, SpendLimit) ? parseResult.GetValue(SpendLimit) : (__requestBase is { } __SpendLimitBaseValue ? __SpendLimitBaseValue.SpendLimit : default);

var __SpendLimitBase = __requestBase is { } __SpendLimitBaseValue ? __SpendLimitBaseValue.SpendLimit : default; var spendLimitPerMemberMonthlyLimitUsd = CliRuntime.WasSpecified(parseResult, SpendLimitOptions.PerMemberMonthlyLimitUsd) ? parseResult.GetValue(SpendLimitOptions.PerMemberMonthlyLimitUsd) : (__SpendLimitBase is { } __SpendLimitperMemberMonthlyLimitUsdBaseValue ? __SpendLimitperMemberMonthlyLimitUsdBaseValue.PerMemberMonthlyLimitUsd : default);
var spendLimitTeamWideMonthlyLimitUsd = CliRuntime.WasSpecified(parseResult, SpendLimitOptions.TeamWideMonthlyLimitUsd) ? parseResult.GetValue(SpendLimitOptions.TeamWideMonthlyLimitUsd) : (__SpendLimitBase is { } __SpendLimitteamWideMonthlyLimitUsdBaseValue ? __SpendLimitteamWideMonthlyLimitUsdBaseValue.TeamWideMonthlyLimitUsd : default);
var __SpendLimitSpecified = CliRuntime.WasSpecified(parseResult, SpendLimitOptions.PerMemberMonthlyLimitUsd) || CliRuntime.WasSpecified(parseResult, SpendLimitOptions.TeamWideMonthlyLimitUsd);
var spendLimit =
__SpendLimitSpecified || __SpendLimitBase is not null
? new global::Baseten.UpdateRouteTeamSpendLimitSettingV1
{
PerMemberMonthlyLimitUsd = spendLimitPerMemberMonthlyLimitUsd,
TeamWideMonthlyLimitUsd = spendLimitTeamWideMonthlyLimitUsd,

}
: __SpendLimitBase;
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace Baseten.CLI.Commands;

internal static partial class EditRoutesTeamSettingsCommandApiCommand
{
private static Option<global::Baseten.UpdateRouteHarnessDefaultsV1?> HarnessDefaults { get; } = new(
name: @"--harness-defaults")
{
Description = @"Harnesses to change; harnesses left out are unchanged. Pass null to clear every harness, so each role uses the team's default.",
};

private static Option<string?> TeamId { get; } = new(
name: @"--team-id")
{
Description = @"ID of the team. When omitted, the team you belong to; required when you belong to several.",
};
private static readonly UpdateRouteTeamSpendLimitSettingV1OptionSet SpendLimitOptions = UpdateRouteTeamSpendLimitSettingV1OptionSet.Create(@"spend-limit");
private static Option<string?> Input { get; } = new(@"--input")
{
Description = "Load request JSON from a file path, '-' for stdin, or an inline JSON object/array string.",
};

private static Option<string?> RequestJson { get; } = new(@"--request-json")
{
Description = "Request body as JSON.",
Hidden = true,
};

private static Option<string?> RequestFile { get; } = new(@"--request-file")
{
Description = "Path to a JSON request file, or '-' for stdin.",
Hidden = true,
};

private static string FormatResponse(ParseResult parseResult, global::Baseten.RouteTeamSettingsV1 value, global::System.Text.Json.Serialization.JsonSerializerContext context, bool truncateLongStrings)
{
string? text = null;
CustomizeResponseText(parseResult, value, ref text);
if (!string.IsNullOrWhiteSpace(text))
{
return text;
}

var hints = new Dictionary<string, CliFormatHint>(StringComparer.OrdinalIgnoreCase)
{
};
CustomizeResponseFormatHints(hints);
return CliRuntime.FormatHumanReadable(value, context, truncateLongStrings, hints);
}

static partial void CustomizeResponseText(ParseResult parseResult, global::Baseten.RouteTeamSettingsV1 value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


static partial void CustomizeCommand(ref Command command);

public static Command Create(string? commandName = null)
{
var command = new Command(commandName ?? @"edit-routes-team-settings", @"Updates a team's route settings by team ID or your only team
Changes only the fields in the request, all or nothing. Requires team admin, and organization admin to change the team-wide spend limit. The team comes from `team_id` instead of the path. Omit it to use the team you belong to; when you belong to several, the request fails with a 400.");
command.Options.Add(HarnessDefaults);
command.Options.Add(TeamId); command.Options.Add(SpendLimitOptions.PerMemberMonthlyLimitUsd);
command.Options.Add(SpendLimitOptions.TeamWideMonthlyLimitUsd);
command.Options.Add(Input);
command.Options.Add(RequestJson);
command.Options.Add(RequestFile);
command.Validators.Add(result =>
{
var hasInput = result.GetResult(Input) is not null;
var hasRequestJson = result.GetResult(RequestJson) is not null;
var hasRequestFile = result.GetResult(RequestFile) is not null;
var specifiedCount = (hasInput ? 1 : 0) + (hasRequestJson ? 1 : 0) + (hasRequestFile ? 1 : 0);
if (specifiedCount > 1)
{
result.AddError(@"Specify at most one of --input, --request-json, or --request-file.");
}
});

command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var __requestBase = await CliRuntime.ReadRequestOrDefaultAsync<global::Baseten.UpdateResolvedRouteTeamSettingsRequestV1>(
parseResult,
Input,
RequestJson,
RequestFile,
global::Baseten.SourceGenerationContext.Default,
cancellationToken).ConfigureAwait(false);
var harnessDefaults = CliRuntime.WasSpecified(parseResult, HarnessDefaults) ? parseResult.GetValue(HarnessDefaults) : (__requestBase is { } __HarnessDefaultsBaseValue ? __HarnessDefaultsBaseValue.HarnessDefaults : default);
var teamId = CliRuntime.WasSpecified(parseResult, TeamId) ? parseResult.GetValue(TeamId) : (__requestBase is { } __TeamIdBaseValue ? __TeamIdBaseValue.TeamId : default);

var __SpendLimitBase = __requestBase is { } __SpendLimitBaseValue ? __SpendLimitBaseValue.SpendLimit : default; var spendLimitPerMemberMonthlyLimitUsd = CliRuntime.WasSpecified(parseResult, SpendLimitOptions.PerMemberMonthlyLimitUsd) ? parseResult.GetValue(SpendLimitOptions.PerMemberMonthlyLimitUsd) : (__SpendLimitBase is { } __SpendLimitperMemberMonthlyLimitUsdBaseValue ? __SpendLimitperMemberMonthlyLimitUsdBaseValue.PerMemberMonthlyLimitUsd : default);
var spendLimitTeamWideMonthlyLimitUsd = CliRuntime.WasSpecified(parseResult, SpendLimitOptions.TeamWideMonthlyLimitUsd) ? parseResult.GetValue(SpendLimitOptions.TeamWideMonthlyLimitUsd) : (__SpendLimitBase is { } __SpendLimitteamWideMonthlyLimitUsdBaseValue ? __SpendLimitteamWideMonthlyLimitUsdBaseValue.TeamWideMonthlyLimitUsd : default);
var __SpendLimitSpecified = CliRuntime.WasSpecified(parseResult, SpendLimitOptions.PerMemberMonthlyLimitUsd) || CliRuntime.WasSpecified(parseResult, SpendLimitOptions.TeamWideMonthlyLimitUsd);
var spendLimit =
__SpendLimitSpecified || __SpendLimitBase is not null
? new global::Baseten.UpdateRouteTeamSpendLimitSettingV1
{
PerMemberMonthlyLimitUsd = spendLimitPerMemberMonthlyLimitUsd,
TeamWideMonthlyLimitUsd = spendLimitTeamWideMonthlyLimitUsd,

}
: __SpendLimitBase;
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.EditRoutesTeamSettingsAsync(
harnessDefaults: harnessDefaults,
teamId: teamId,
spendLimit: spendLimit,
cancellationToken: cancellationToken).ConfigureAwait(false);


await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::Baseten.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false));
CustomizeCommand(ref command);
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#nullable enable
#pragma warning disable CS0618

using System.CommandLine;

namespace Baseten.CLI.Commands;

internal static partial class GetRoutesTeamSettingsCommandApiCommand
{
private static Option<string?> TeamId { get; } = new(
name: @"--team-id")
{
Description = @"ID of the team. When omitted, the team you belong to; required when you belong to several.",
};

private static string FormatResponse(ParseResult parseResult, global::Baseten.RouteTeamSettingsV1 value, global::System.Text.Json.Serialization.JsonSerializerContext context, bool truncateLongStrings)
{
string? text = null;
CustomizeResponseText(parseResult, value, ref text);
if (!string.IsNullOrWhiteSpace(text))
{
return text;
}

var hints = new Dictionary<string, CliFormatHint>(StringComparer.OrdinalIgnoreCase)
{
};
CustomizeResponseFormatHints(hints);
return CliRuntime.FormatHumanReadable(value, context, truncateLongStrings, hints);
}

static partial void CustomizeResponseText(ParseResult parseResult, global::Baseten.RouteTeamSettingsV1 value, ref string? text);
static partial void CustomizeResponseFormatHints(Dictionary<string, CliFormatHint> hints);


static partial void CustomizeCommand(ref Command command);

public static Command Create(string? commandName = null)
{
var command = new Command(commandName ?? @"get-routes-team-settings", @"Gets a team's route settings by team ID or your only team
Returns the settings that apply to the team, including the default models for each coding harness and the team's spend limits. Any member who can invoke the team's routes can read them. The team comes from `team_id` instead of the path. Omit it to use the team you belong to; when you belong to several, the request fails with a 400.");
command.Options.Add(TeamId);


command.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
await CliRuntime.RunAsync(async () =>
{
var teamId = parseResult.GetValue(TeamId);
using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);


var response = await client.GetRoutesTeamSettingsAsync(
teamId: teamId,
cancellationToken: cancellationToken).ConfigureAwait(false);


await CliRuntime.WriteResponseAsync(
parseResult,
response,
global::Baseten.SourceGenerationContext.Default,
FormatResponse,
cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false));
CustomizeCommand(ref command);
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#nullable enable

using System.CommandLine;

namespace Baseten.CLI.Commands;

internal sealed record UpdateRouteTeamSpendLimitSettingV1OptionSet(
Option<string?> PerMemberMonthlyLimitUsd,
Option<string?> TeamWideMonthlyLimitUsd)
{
public static UpdateRouteTeamSpendLimitSettingV1OptionSet Create(string? prefix = null)
{
var normalizedPrefix = string.IsNullOrWhiteSpace(prefix)
? string.Empty
: prefix.Trim().Trim('-') + "-";
return new UpdateRouteTeamSpendLimitSettingV1OptionSet(
PerMemberMonthlyLimitUsd: new Option<string?>($"--{normalizedPrefix}per-member-monthly-limit-usd")
{
Description = @"Spend limit in USD for each UTC calendar month that applies to each member's Grid spend in this team, unless the member has a limit of their own. Send null to remove it; omit to leave it unchanged.",
},
TeamWideMonthlyLimitUsd: new Option<string?>($"--{normalizedPrefix}team-wide-monthly-limit-usd")
{
Description = @"Spend limit in USD for each UTC calendar month on the Grid spend of all members in this team together. Send null to remove it; omit to leave it unchanged.",
}
);
}
}
Loading
Loading