Skip to content

Commit

Permalink
make API type safe
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean committed Oct 7, 2023
1 parent 4f483d2 commit 32f9828
Show file tree
Hide file tree
Showing 17 changed files with 854 additions and 678 deletions.
1,294 changes: 677 additions & 617 deletions api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service.pb.go

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions api/golang/core/lib/binding_constructors/binding_constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func NewRunStarlarkScriptArgs(
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
cloudInstanceId string,
cloudUserId string,
imageDownloadMode string,
imageDownloadMode kurtosis_core_rpc_api_bindings.ImageDownloadMode,
) *kurtosis_core_rpc_api_bindings.RunStarlarkScriptArgs {
cloudInstanceIdCopy := new(string)
*cloudInstanceIdCopy = cloudInstanceId
cloudUserIdCopy := new(string)
*cloudUserIdCopy = cloudUserId
imageDownloadModeCopy := new(string)
*imageDownloadModeCopy = cloudUserId
imageDownloadModeCopy := new(kurtosis_core_rpc_api_bindings.ImageDownloadMode)
*imageDownloadModeCopy = imageDownloadMode
parallelismCopy := new(int32)
*parallelismCopy = parallelism
return &kurtosis_core_rpc_api_bindings.RunStarlarkScriptArgs{
Expand All @@ -74,16 +74,16 @@ func NewRunStarlarkPackageArgs(
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
cloudInstanceId string,
cloudUserId string,
imageDownloadMode string,
imageDownloadMode kurtosis_core_rpc_api_bindings.ImageDownloadMode,
) *kurtosis_core_rpc_api_bindings.RunStarlarkPackageArgs {
parallelismCopy := new(int32)
*parallelismCopy = parallelism
cloudInstanceIdCopy := new(string)
*cloudInstanceIdCopy = cloudInstanceId
cloudUserIdCopy := new(string)
*cloudUserIdCopy = cloudUserId
imageDownloadModeCopy := new(string)
*imageDownloadModeCopy = cloudUserId
imageDownloadModeCopy := new(kurtosis_core_rpc_api_bindings.ImageDownloadMode)
*imageDownloadModeCopy = imageDownloadMode
clonePackage := false
return &kurtosis_core_rpc_api_bindings.RunStarlarkPackageArgs{
PackageId: packageId,
Expand Down Expand Up @@ -111,15 +111,15 @@ func NewRunStarlarkRemotePackageArgs(
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
cloudInstanceId string,
cloudUserId string,
imageDownloadMode string,
imageDownloadMode kurtosis_core_rpc_api_bindings.ImageDownloadMode,
) *kurtosis_core_rpc_api_bindings.RunStarlarkPackageArgs {
parallelismCopy := new(int32)
*parallelismCopy = parallelism
cloudInstanceIdCopy := new(string)
*cloudInstanceIdCopy = cloudInstanceId
cloudUserIdCopy := new(string)
*cloudUserIdCopy = cloudUserId
imageDownloadModeCopy := new(string)
imageDownloadModeCopy := new(kurtosis_core_rpc_api_bindings.ImageDownloadMode)
*imageDownloadModeCopy = imageDownloadMode
clonePackage := true
return &kurtosis_core_rpc_api_bindings.RunStarlarkPackageArgs{
Expand Down
2 changes: 1 addition & 1 deletion api/golang/core/lib/enclaves/enclave_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (enclaveCtx *EnclaveContext) assembleRunStartosisPackageArg(
experimentalFeatures []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag,
cloudInstanceId string,
cloudUserId string,
imageDownloadMode string,
imageDownloadMode kurtosis_core_rpc_api_bindings.ImageDownloadMode,
) (*kurtosis_core_rpc_api_bindings.RunStarlarkPackageArgs, error) {
kurtosisYamlFilepath := path.Join(packageRootPath, kurtosisYamlFilename)

Expand Down
7 changes: 7 additions & 0 deletions api/golang/core/lib/shared_utils/proto_default_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ func GetOrDefaultString(optionalValue *string, defaultValue string) string {
}
return *optionalValue
}

func GetOrDefault[T any](optionalValue *T, defaultValue T) T {
if optionalValue == nil {
return defaultValue
}
return *optionalValue
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
defaultParallelism = 4
defaultCloudInstanceId = ""
defaultCloudUserId = ""
defaultImageDownload = "missing"
defaultImageDownload = kurtosis_core_rpc_api_bindings.ImageDownloadMode_missing
)

var defaultExperimentalFeatureFlags = []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag(nil)
Expand All @@ -24,7 +24,7 @@ type StarlarkRunConfig struct {
ExperimentalFeatureFlags []kurtosis_core_rpc_api_bindings.KurtosisFeatureFlag
CloudInstanceId string
CloudUserId string
ImageDownload string
ImageDownload kurtosis_core_rpc_api_bindings.ImageDownloadMode
}

type starlarkRunConfigOption func(*StarlarkRunConfig)
Expand Down Expand Up @@ -97,7 +97,7 @@ func WithCloudUserId(cloudUserId string) starlarkRunConfigOption {
}
}

func WithImageDownloadMode(imageDownloadMode string) starlarkRunConfigOption {
func WithImageDownloadMode(imageDownloadMode kurtosis_core_rpc_api_bindings.ImageDownloadMode) starlarkRunConfigOption {
return func(config *StarlarkRunConfig) {
config.ImageDownload = imageDownloadMode
}
Expand Down
10 changes: 8 additions & 2 deletions api/protobuf/core/api_container_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ enum ServiceStatus {
UNKNOWN = 2;
}

enum ImageDownloadMode {
never = 0;
always = 1;
missing = 2;
}

message ServiceInfo {
// UUID of the service
string service_uuid = 1;
Expand Down Expand Up @@ -161,7 +167,7 @@ message RunStarlarkScriptArgs {
optional string cloud_user_id = 8;

// Defaults to empty
optional string image_download_mode = 9;
optional ImageDownloadMode image_download_mode = 9;
}

message RunStarlarkPackageArgs {
Expand Down Expand Up @@ -206,7 +212,7 @@ message RunStarlarkPackageArgs {
optional string cloud_user_id = 13;

// Defaults to empty
optional string image_download_mode = 14;
optional ImageDownloadMode image_download_mode = 14;
}

enum KurtosisFeatureFlag {
Expand Down
37 changes: 33 additions & 4 deletions api/rust/src/api_container_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ pub struct RunStarlarkScriptArgs {
#[prost(string, optional, tag = "8")]
pub cloud_user_id: ::core::option::Option<::prost::alloc::string::String>,
/// Defaults to empty
#[prost(string, optional, tag = "9")]
pub image_download_mode: ::core::option::Option<::prost::alloc::string::String>,
#[prost(enumeration = "ImageDownloadMode", optional, tag = "9")]
pub image_download_mode: ::core::option::Option<i32>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -218,8 +218,8 @@ pub struct RunStarlarkPackageArgs {
#[prost(string, optional, tag = "13")]
pub cloud_user_id: ::core::option::Option<::prost::alloc::string::String>,
/// Defaults to empty
#[prost(string, optional, tag = "14")]
pub image_download_mode: ::core::option::Option<::prost::alloc::string::String>,
#[prost(enumeration = "ImageDownloadMode", optional, tag = "14")]
pub image_download_mode: ::core::option::Option<i32>,
/// Deprecated: If the package is local, it should have been uploaded with UploadStarlarkPackage prior to calling
/// RunStarlarkPackage. If the package is remote and must be cloned within the APIC, use the standalone boolean flag
/// clone_package below
Expand Down Expand Up @@ -676,6 +676,35 @@ impl ServiceStatus {
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum ImageDownloadMode {
Never = 0,
Always = 1,
Missing = 2,
}
impl ImageDownloadMode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
ImageDownloadMode::Never => "never",
ImageDownloadMode::Always => "always",
ImageDownloadMode::Missing => "missing",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"never" => Some(Self::Never),
"always" => Some(Self::Always),
"missing" => Some(Self::Missing),
_ => None,
}
}
}
/// User services port forwarding
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export class RunStarlarkScriptArgs extends jspb.Message {
hasCloudUserId(): boolean;
clearCloudUserId(): RunStarlarkScriptArgs;

getImageDownloadMode(): string;
setImageDownloadMode(value: string): RunStarlarkScriptArgs;
getImageDownloadMode(): ImageDownloadMode;
setImageDownloadMode(value: ImageDownloadMode): RunStarlarkScriptArgs;
hasImageDownloadMode(): boolean;
clearImageDownloadMode(): RunStarlarkScriptArgs;

Expand All @@ -193,7 +193,7 @@ export namespace RunStarlarkScriptArgs {
experimentalFeaturesList: Array<KurtosisFeatureFlag>,
cloudInstanceId?: string,
cloudUserId?: string,
imageDownloadMode?: string,
imageDownloadMode?: ImageDownloadMode,
}

export enum DryRunCase {
Expand Down Expand Up @@ -273,8 +273,8 @@ export class RunStarlarkPackageArgs extends jspb.Message {
hasCloudUserId(): boolean;
clearCloudUserId(): RunStarlarkPackageArgs;

getImageDownloadMode(): string;
setImageDownloadMode(value: string): RunStarlarkPackageArgs;
getImageDownloadMode(): ImageDownloadMode;
setImageDownloadMode(value: ImageDownloadMode): RunStarlarkPackageArgs;
hasImageDownloadMode(): boolean;
clearImageDownloadMode(): RunStarlarkPackageArgs;

Expand Down Expand Up @@ -302,7 +302,7 @@ export namespace RunStarlarkPackageArgs {
experimentalFeaturesList: Array<KurtosisFeatureFlag>,
cloudInstanceId?: string,
cloudUserId?: string,
imageDownloadMode?: string,
imageDownloadMode?: ImageDownloadMode,
}

export enum StarlarkPackageContentCase {
Expand Down Expand Up @@ -1254,6 +1254,11 @@ export enum ServiceStatus {
RUNNING = 1,
UNKNOWN = 2,
}
export enum ImageDownloadMode {
NEVER = 0,
ALWAYS = 1,
MISSING = 2,
}
export enum Connect {
CONNECT = 0,
NO_CONNECT = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ goog.exportSymbol('proto.api_container_api.FilesArtifactNameAndUuid', null, glob
goog.exportSymbol('proto.api_container_api.GetExistingAndHistoricalServiceIdentifiersResponse', null, global);
goog.exportSymbol('proto.api_container_api.GetServicesArgs', null, global);
goog.exportSymbol('proto.api_container_api.GetServicesResponse', null, global);
goog.exportSymbol('proto.api_container_api.ImageDownloadMode', null, global);
goog.exportSymbol('proto.api_container_api.InspectFilesArtifactContentsRequest', null, global);
goog.exportSymbol('proto.api_container_api.InspectFilesArtifactContentsResponse', null, global);
goog.exportSymbol('proto.api_container_api.KurtosisFeatureFlag', null, global);
Expand Down Expand Up @@ -1913,7 +1914,7 @@ proto.api_container_api.RunStarlarkScriptArgs.toObject = function(includeInstanc
experimentalFeaturesList: (f = jspb.Message.getRepeatedField(msg, 6)) == null ? undefined : f,
cloudInstanceId: jspb.Message.getFieldWithDefault(msg, 7, ""),
cloudUserId: jspb.Message.getFieldWithDefault(msg, 8, ""),
imageDownloadMode: jspb.Message.getFieldWithDefault(msg, 9, "")
imageDownloadMode: jspb.Message.getFieldWithDefault(msg, 9, 0)
};

if (includeInstance) {
Expand Down Expand Up @@ -1985,7 +1986,7 @@ proto.api_container_api.RunStarlarkScriptArgs.deserializeBinaryFromReader = func
msg.setCloudUserId(value);
break;
case 9:
var value = /** @type {string} */ (reader.readString());
var value = /** @type {!proto.api_container_api.ImageDownloadMode} */ (reader.readEnum());
msg.setImageDownloadMode(value);
break;
default:
Expand Down Expand Up @@ -2073,9 +2074,9 @@ proto.api_container_api.RunStarlarkScriptArgs.serializeBinaryToWriter = function
f
);
}
f = /** @type {string} */ (jspb.Message.getField(message, 9));
f = /** @type {!proto.api_container_api.ImageDownloadMode} */ (jspb.Message.getField(message, 9));
if (f != null) {
writer.writeString(
writer.writeEnum(
9,
f
);
Expand Down Expand Up @@ -2319,16 +2320,16 @@ proto.api_container_api.RunStarlarkScriptArgs.prototype.hasCloudUserId = functio


/**
* optional string image_download_mode = 9;
* @return {string}
* optional ImageDownloadMode image_download_mode = 9;
* @return {!proto.api_container_api.ImageDownloadMode}
*/
proto.api_container_api.RunStarlarkScriptArgs.prototype.getImageDownloadMode = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 9, ""));
return /** @type {!proto.api_container_api.ImageDownloadMode} */ (jspb.Message.getFieldWithDefault(this, 9, 0));
};


/**
* @param {string} value
* @param {!proto.api_container_api.ImageDownloadMode} value
* @return {!proto.api_container_api.RunStarlarkScriptArgs} returns this
*/
proto.api_container_api.RunStarlarkScriptArgs.prototype.setImageDownloadMode = function(value) {
Expand Down Expand Up @@ -2431,7 +2432,7 @@ proto.api_container_api.RunStarlarkPackageArgs.toObject = function(includeInstan
experimentalFeaturesList: (f = jspb.Message.getRepeatedField(msg, 11)) == null ? undefined : f,
cloudInstanceId: jspb.Message.getFieldWithDefault(msg, 12, ""),
cloudUserId: jspb.Message.getFieldWithDefault(msg, 13, ""),
imageDownloadMode: jspb.Message.getFieldWithDefault(msg, 14, "")
imageDownloadMode: jspb.Message.getFieldWithDefault(msg, 14, 0)
};

if (includeInstance) {
Expand Down Expand Up @@ -2519,7 +2520,7 @@ proto.api_container_api.RunStarlarkPackageArgs.deserializeBinaryFromReader = fun
msg.setCloudUserId(value);
break;
case 14:
var value = /** @type {string} */ (reader.readString());
var value = /** @type {!proto.api_container_api.ImageDownloadMode} */ (reader.readEnum());
msg.setImageDownloadMode(value);
break;
default:
Expand Down Expand Up @@ -2635,9 +2636,9 @@ proto.api_container_api.RunStarlarkPackageArgs.serializeBinaryToWriter = functio
f
);
}
f = /** @type {string} */ (jspb.Message.getField(message, 14));
f = /** @type {!proto.api_container_api.ImageDownloadMode} */ (jspb.Message.getField(message, 14));
if (f != null) {
writer.writeString(
writer.writeEnum(
14,
f
);
Expand Down Expand Up @@ -3031,16 +3032,16 @@ proto.api_container_api.RunStarlarkPackageArgs.prototype.hasCloudUserId = functi


/**
* optional string image_download_mode = 14;
* @return {string}
* optional ImageDownloadMode image_download_mode = 14;
* @return {!proto.api_container_api.ImageDownloadMode}
*/
proto.api_container_api.RunStarlarkPackageArgs.prototype.getImageDownloadMode = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 14, ""));
return /** @type {!proto.api_container_api.ImageDownloadMode} */ (jspb.Message.getFieldWithDefault(this, 14, 0));
};


/**
* @param {string} value
* @param {!proto.api_container_api.ImageDownloadMode} value
* @return {!proto.api_container_api.RunStarlarkPackageArgs} returns this
*/
proto.api_container_api.RunStarlarkPackageArgs.prototype.setImageDownloadMode = function(value) {
Expand Down Expand Up @@ -9663,6 +9664,15 @@ proto.api_container_api.ServiceStatus = {
UNKNOWN: 2
};

/**
* @enum {number}
*/
proto.api_container_api.ImageDownloadMode = {
NEVER: 0,
ALWAYS: 1,
MISSING: 2
};

/**
* @enum {number}
*/
Expand Down
Loading

0 comments on commit 32f9828

Please sign in to comment.