Skip to content

Commit

Permalink
handle update secret
Browse files Browse the repository at this point in the history
Signed-off-by: tabVersion <[email protected]>
  • Loading branch information
tabVersion committed May 14, 2024
1 parent c6ddbab commit 800b919
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/frontend/src/catalog/root_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,25 @@ impl Catalog {
}
}

pub fn update_secret(&mut self, proto: &PbSecret) {
let database = self.get_database_mut(proto.database_id).unwrap();
let schema = database.get_schema_mut(proto.schema_id).unwrap();
let secret_id = SecretId::new(proto.id);
if schema.get_secret_by_id(&secret_id).is_some() {
schema.update_secret(proto);
} else {
// Enter this branch when schema is changed by `ALTER ... SET SCHEMA ...` statement.
schema.create_secret(proto);
database
.iter_schemas_mut()
.find(|schema| {
schema.id() != proto.schema_id && schema.get_secret_by_id(&secret_id).is_some()
})
.unwrap()
.drop_secret(secret_id);
}
}

pub fn drop_database(&mut self, db_id: DatabaseId) {
let name = self.db_name_by_id.remove(&db_id).unwrap();
let database = self.database_by_name.remove(&name).unwrap();
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/catalog/schema_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,10 @@ impl SchemaCatalog {
self.secret_by_name.get(secret_name)
}

pub fn get_secret_by_id(&self, secret_id: &SecretId) -> Option<&Arc<SecretCatalog>> {
self.secret_by_id.get(secret_id)
}

/// get all sources referencing the connection
pub fn get_source_ids_by_connection(
&self,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/handler/create_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub async fn handle_create_secret(
)
.into());
}
bail_not_implemented!()
bail_not_implemented!("hashicorp_vault backend is not implemented yet")
}
_ => {
return Err(ErrorCode::InvalidParameterValue(format!(
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/observer/observer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl FrontendObserverNode {
secret.schema_id,
SecretId::new(secret.id),
),
Operation::Update => unimplemented!(),
Operation::Update => catalog_guard.update_secret(secret),
_ => panic!("receive an unsupported notify {:?}", resp),
},
_ => unreachable!(),
Expand Down

0 comments on commit 800b919

Please sign in to comment.