Skip to content

Commit

Permalink
buckets: remove transform tags from create bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
rewitt94 committed May 20, 2024
1 parent 639135d commit b8fc245
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 99 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Breaking

- The `create bucket` flag `--transform-tag` is now removed.

# v0.25.0
- Fixes issue when getting streams that have multiple filters on single user property
- Fixes issue where upper case file names would not be matched in `parse`
Expand Down
4 changes: 2 additions & 2 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub use crate::{
resources::{
bucket::{
Bucket, BucketType, FullName as BucketFullName, Id as BucketId,
Identifier as BucketIdentifier, Name as BucketName, NewBucket, TransformTag,
Identifier as BucketIdentifier, Name as BucketName, NewBucket,
},
comment::{
AnnotatedComment, Comment, CommentFilter, CommentsIterPage, Continuation,
Expand Down Expand Up @@ -120,7 +120,7 @@ pub use crate::{
project::{NewProject, Project, ProjectName, UpdateProject},
source::{
FullName as SourceFullName, Id as SourceId, Identifier as SourceIdentifier,
Name as SourceName, NewSource, Source, SourceKind, UpdateSource,
Name as SourceName, NewSource, Source, SourceKind, TransformTag, UpdateSource,
},
statistics::Statistics as CommentStatistics,
stream::{
Expand Down
14 changes: 0 additions & 14 deletions api/src/resources/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ pub struct Bucket {
pub name: Name,
pub owner: Username,
pub created_at: DateTime<Utc>,
#[serde(default)]
pub transform_tag: Option<TransformTag>,
}

impl Bucket {
Expand All @@ -41,17 +39,6 @@ pub struct Id(pub String);
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
pub struct ModelFamily(pub String);

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
pub struct TransformTag(pub String);

impl FromStr for TransformTag {
type Err = Error;

fn from_str(string: &str) -> Result<Self> {
Ok(Self(string.to_owned()))
}
}

// TODO(mcobzarenco)[3963]: Make `Identifier` into a trait (ensure it still implements
// `FromStr` so we can take T: Identifier as a clap command line argument).
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -114,7 +101,6 @@ pub struct NewBucket<'request> {
pub bucket_type: BucketType,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<&'request str>,
pub transform_tag: &'request TransformTag,
}

#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
Expand Down
12 changes: 11 additions & 1 deletion api/src/resources/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ use std::{
use crate::{
error::{Error, Result},
resources::bucket::Id as BucketId,
resources::bucket::TransformTag,
resources::user::Username,
CommentFilter,
};

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
pub struct TransformTag(pub String);

impl FromStr for TransformTag {
type Err = Error;

fn from_str(string: &str) -> Result<Self> {
Ok(Self(string.to_owned()))
}
}

#[derive(Debug, Clone, Serialize, Default)]
pub struct StatisticsRequestParams {
pub comment_filter: CommentFilter,
Expand Down
17 changes: 3 additions & 14 deletions cli/src/commands/create/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{commands::DEFAULT_TRANSFORM_TAG, printer::Printer};
use crate::printer::Printer;
use anyhow::{Context, Result};
use log::info;
use reinfer_client::{BucketFullName, BucketType, Client, NewBucket, TransformTag};
use reinfer_client::{BucketFullName, BucketType, Client, NewBucket};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
Expand All @@ -17,39 +17,28 @@ pub struct CreateBucketArgs {
#[structopt(default_value, long = "type")]
/// Set the type of the new bucket. Currently, this must be "emails".
bucket_type: BucketType,

#[structopt(long = "transform-tag")]
/// Set the transform tag of the new bucket. You will be given this value
/// by a Re:infer engineer.
transform_tag: Option<TransformTag>,
}

pub fn create(client: &Client, args: &CreateBucketArgs, printer: &Printer) -> Result<()> {
let CreateBucketArgs {
name,
title,
bucket_type,
transform_tag,
} = args;

let transform_tag = transform_tag
.clone()
.unwrap_or(DEFAULT_TRANSFORM_TAG.clone());

let bucket = client
.create_bucket(
name,
NewBucket {
title: title.as_deref(),
bucket_type: *bucket_type,
transform_tag: &transform_tag,
},
)
.context("Operation to create a bucket has failed")?;
info!(
"New bucket `{}` [id: {}] created successfully",
bucket.full_name(),
bucket.id
bucket.id,
);
printer.print_resources(&[bucket])?;
Ok(())
Expand Down
12 changes: 2 additions & 10 deletions cli/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl DisplayTable for Integration {
}
impl DisplayTable for Bucket {
fn to_table_headers() -> Row {
row![bFg => "Name", "ID", "Created (UTC)", "Transform Tag"]
row![bFg => "Name", "ID", "Created (UTC)"]
}

fn to_table_row(&self) -> Row {
Expand All @@ -88,10 +88,6 @@ impl DisplayTable for Bucket {
full_name,
self.id.0,
self.created_at.format("%Y-%m-%d %H:%M:%S"),
match &self.transform_tag {
Some(transform_tag) => transform_tag.0.as_str().into(),
None => "missing".dimmed(),
}
]
}
}
Expand Down Expand Up @@ -201,7 +197,7 @@ pub struct PrintableBucket {
}
impl DisplayTable for PrintableBucket {
fn to_table_headers() -> Row {
row![bFg => "Name", "ID", "Created (UTC)", "Transform Tag", "Num Emails"]
row![bFg => "Name", "ID", "Created (UTC)", "Num Emails"]
}

fn to_table_row(&self) -> Row {
Expand All @@ -215,10 +211,6 @@ impl DisplayTable for PrintableBucket {
full_name,
self.bucket.id.0,
self.bucket.created_at.format("%Y-%m-%d %H:%M:%S"),
match &self.bucket.transform_tag {
Some(transform_tag) => transform_tag.0.as_str().into(),
None => "missing".dimmed(),
},
if let Some(stats) = &self.stats {
stats.count.to_string().as_str().into()
} else {
Expand Down
63 changes: 5 additions & 58 deletions cli/tests/test_buckets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ fn test_bucket_lifecycle() {
let new_bucket_name = format!("{}/test-source-{}", owner, Uuid::new_v4());

// Create bucket
let output = cli.run([
"create",
"bucket",
&new_bucket_name,
"--transform-tag",
"generic_simple.0.QR5PW4VZ",
]);
let output = cli.run(["create", "bucket", &new_bucket_name]);
assert!(output.contains(&new_bucket_name), "{}", output);

let output = cli.run(["get", "buckets"]);
Expand All @@ -29,40 +23,11 @@ fn test_bucket_lifecycle() {
assert!(!output.contains(&new_bucket_name), "{}", output);
}

#[test]
fn test_bucket_with_invalid_transform_tag_fails() {
let cli = TestCli::get();
let owner = TestCli::project();

let new_bucket_name = format!("{}/test-source-{}", owner, Uuid::new_v4());

let output = cli.run_and_error([
"create",
"bucket",
&new_bucket_name,
"--transform-tag",
"not-a-valid-transform-tag.0.ABCDEFGH",
]);
assert!(
output.contains(
"422 Unprocessable Entity: The value 'not-a-valid-transform-tag.0.ABCDEFGH' is not a valid transform tag."
),
"{}",
output,
);
}

#[test]
fn test_create_without_org_fails() {
let cli = TestCli::get();

let output = cli.run_and_error([
"create",
"bucket",
"bucket-name-without-org",
"--transform-tag",
"generic_simple.0.QR5PW4VZ",
]);
let output = cli.run_and_error(["create", "bucket", "bucket-name-without-org"]);
assert!(
output.contains("Expected <owner>/<name>, got: bucket-name-without-org"),
"{}",
Expand All @@ -74,13 +39,7 @@ fn test_create_without_org_fails() {
fn test_create_with_empty_org_fails() {
let cli = TestCli::get();

let output = cli.run_and_error([
"create",
"bucket",
"/bucket-name-with-empty-org",
"--transform-tag",
"generic_simple.0.QR5PW4VZ",
]);
let output = cli.run_and_error(["create", "bucket", "/bucket-name-with-empty-org"]);
assert!(
output.contains("Expected <owner>/<name>, got: /bucket-name-with-empty-org"),
"{}",
Expand All @@ -92,13 +51,7 @@ fn test_create_with_empty_org_fails() {
fn test_create_with_empty_bucket_name_fails() {
let cli = TestCli::get();

let output = cli.run_and_error([
"create",
"bucket",
"org-without-bucket-name/",
"--transform-tag",
"generic_simple.0.QR5PW4VZ",
]);
let output = cli.run_and_error(["create", "bucket", "org-without-bucket-name/"]);
assert!(
output.contains("Expected <owner>/<name>, got: org-without-bucket-name/"),
"{}",
Expand All @@ -110,13 +63,7 @@ fn test_create_with_empty_bucket_name_fails() {
fn test_create_with_too_many_seperators_fails() {
let cli = TestCli::get();

let output = cli.run_and_error([
"create",
"bucket",
"Bucket/Name/with/too/many/seperators/",
"--transform-tag",
"generic_simple.0.QR5PW4VZ",
]);
let output = cli.run_and_error(["create", "bucket", "Bucket/Name/with/too/many/seperators/"]);
assert!(
output.contains("Expected <owner>/<name>, got: Bucket/Name/with/too/many/seperators"),
"{}",
Expand Down

0 comments on commit b8fc245

Please sign in to comment.