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

Draft: add protos and generate code #4

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

r-n-o
Copy link
Contributor

@r-n-o r-n-o commented May 24, 2024

This PR is a draft for codegen in the Rust SDK: internally Turnkey uses proto3 to define all types and interfaces so it seems like a waste to force our users to manually write types. We can generate it all!

The proto folder now contains the source protos, and src/gen contains generated code. I haven't yet tried to use this with a Rust project hence why this is still a draft PR.

@joshhchun joshhchun force-pushed the rno/add-protos-and-gen-code branch from ec4d751 to 59dee42 Compare May 26, 2024 02:39
Copy link

@andrewkmin andrewkmin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏅 looking good!! just some minor comments to address

Ok(BASE64_URL_SAFE_NO_PAD.encode(json_stamp.as_bytes()))
}

#[cfg(test)]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to retain some semblance of a test suite with the rewrite :)

Some(input_headers) => {
for (_, value) in input_headers.iter() {
if let Ok(val_header) = HeaderValue::try_from(value) {
headers.insert("test keyname", val_header);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this in the case that there are other headers the user would like to include? or purely for testing?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: Might need to check if path starts with "/", not sure how its called
let mut url = format!("{}{}", self.base_url, path);

// TODO: This can all be cleaned up/simplified with Url crate if needed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to using a URL crate if it simplifies thing. any potential reason it'd be a bad idea?

@mountainpath9
Copy link

If this is intended to be a general purpose SDK, I'd suggest that accessing environment variables directly (and the use of .env files) should be up to the SDK user, and not baked into the SDK itself. My personal use case is likely to see these values coming from other rust code.

If you really want this for convenience, then env variable access should be optional, ie something like this this:

impl Turnkey {
    pub fn new(base_url: String, stamper: TurnkeyApiKey) -> Self {
        Self {
            base_url,
            stamper,
            client: Client::new(),
        })
    }

    pub fn new_from_env() -> TurnkeyResult<Self>  {
        Self::new(
           base_url: env::var("TURNKEY_BASE_URL")
                .map_err(|e| TurnkeyError::OtherError(e.to_string()))?,
            stamper: TurnkeyApiKey::new_from_env()?,
        )
    }

mountainpath9 added a commit to mountainpath9/tkhq-rust-sdk that referenced this pull request Jun 17, 2024
The code is based up existing stamping and request code in

tkhq#4

and leverages the generated proto types
mountainpath9 added a commit to mountainpath9/tkhq-rust-sdk that referenced this pull request Jun 17, 2024
The code is based up existing stamping and request code in

tkhq#4

and leverages the generated proto types
mountainpath9 added a commit to mountainpath9/tkhq-rust-sdk that referenced this pull request Jun 17, 2024
The code is based up existing stamping and request code in

tkhq#4

and leverages the generated proto types
mountainpath9 added a commit to mountainpath9/tkhq-rust-sdk that referenced this pull request Jun 17, 2024
The code is based up existing stamping and request code in

tkhq#4

and leverages the generated proto types
mountainpath9 added a commit to mountainpath9/tkhq-rust-sdk that referenced this pull request Jun 17, 2024
The code is based up existing stamping and request code in

tkhq#4

and leverages the generated proto types
mountainpath9 added a commit to mountainpath9/tkhq-rust-sdk that referenced this pull request Jun 17, 2024
The code is based up existing stamping and request code in

tkhq#4

and leverages the generated proto types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants