Skip to content

Commit

Permalink
Tables cleanup work (#6181)
Browse files Browse the repository at this point in the history
* conn and names key out

* all work except get set acl

* samples

* dqwd

* extra space

* record transactions, because test proxy

* tty

* clang and samples working , assets json

* fds

* samples , and remove APIs

* dsds

* acct name

* dsfds

* oopsie

* dasdas

* fdsfsd

* clangs

* account key for sas

* kjhdsakjhdkjashdjkwash

* dssfsd

* ggd

* Update sdk/tables/azure-data-tables/samples/CMakeLists.txt

Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>

* put back unused env in CI

* Update sdk/tables/azure-data-tables/src/table_clients.cpp

Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>

* Update sdk/tables/azure-data-tables/src/table_clients.cpp

Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>

* fdg

* fds

* update samples and readme

* sdjkfhsdkj

* Update sdk/tables/azure-data-tables/README.md

Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>

* Update sdk/tables/azure-data-tables/test/ut/table_client_test.hpp

Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>

* Update sdk/tables/azure-data-tables/test/ut/table_client_test.hpp

Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>

* update remove namespaces

---------

Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>
  • Loading branch information
gearama and antkmsft authored Nov 13, 2024
1 parent e7e4477 commit e6eaee7
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 553 deletions.
2 changes: 1 addition & 1 deletion sdk/tables/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/tables",
"Tag": "cpp/tables_cb42be8953"
"Tag": "cpp/tables_0b3363cab7"
}
10 changes: 6 additions & 4 deletions sdk/tables/azure-data-tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,16 @@ Two different clients are provided to interact with the various components of th

##### Creating and deleting a table

In order to Create/Delete a table we need to create a TablesClient first.
In order to Create/Delete a table we need to create a `TableServiceClient` first.

```cpp
#include <azure/data/tables.hpp>
...
using namespace Azure::Data::Tables;
const std::string TableName = "sample1";
...
auto tableServiceClient = TableServiceClient::CreateFromConnectionString(GetConnectionString());
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
auto tableServiceClient = Azure::Data::Tables::TableServiceClient(GetServiceUrl(), credential);

// create new table
tableServiceClient.CreateTable(TableName);
Expand Down Expand Up @@ -155,7 +156,7 @@ auto tableClient = tableServiceClient.GetTableClient(TableName);
```
N.B. Here we are obtaining the table client from the table service client using the credentials that were passed to the table service client.

##### Create a client with a connection string
##### Create a client with DefaultAzureCredentials
In order to Create/Update/Merge/Delete entities we need to create a TablesClient first.

```cpp
Expand All @@ -164,7 +165,8 @@ In order to Create/Update/Merge/Delete entities we need to create a TablesClient
using namespace Azure::Data::Tables;
const std::string TableName = "sample1";
...
auto tableClient = TableClient::CreateFromConnectionString(..., TableName);
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
auto tableServiceClient = Azure::Data::Tables::TableServiceClient(GetServiceUrl(), credential);
```
##### Entities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ namespace Azure { namespace Data { namespace Tables { namespace Sas {
Delete = 4,

/**
* @brief Indicates that Add is permitted.
* @brief Indicates that List is permitted.
*/
Add = 8,
List = 8,

/**
* @brief Indicates that List is permitted.
* @brief Indicates that Add is permitted.
*/
List = 16,
Add = 16,

/**
* @brief Indicates that Update is permitted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ namespace Azure { namespace Data { namespace Tables {
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const TableClientOptions& options = {});

/**
* @brief Initializes a new instance of tableClient.
*
* @param tableName The name of the table.
* @param credential The named key credential used to sign requests.
* @param url A url referencing the table that includes the name of the account and the name of
* @param options Optional client options that define the transport pipeline policies for
* authentication, retries, etc., that are applied to every request.
*/
explicit TableClient(
const std::string& tableName,
std::shared_ptr<Azure::Data::Tables::Credentials::NamedKeyCredential> credential,
std::string url,
const TableClientOptions& options = {});

/**
* @brief Initializes a new instance of tableClient.
*
Expand All @@ -118,41 +103,6 @@ namespace Azure { namespace Data { namespace Tables {
const std::string& tableName,
const TableClientOptions& options = {});

/**
* @brief Initializes a new instance of tableClient.
*
* @param connectionString the connection string used to initialize.
* @param tableName The name of the table.
* @param options Optional client options that define the transport pipeline policies for
* authentication, retries, etc., that are applied to every request.
* @return TableClient.
*/
static TableClient CreateFromConnectionString(
const std::string& connectionString,
const std::string& tableName,
const TableClientOptions& options = {});

/**
* @brief Retrieves details about any stored access policies specified on the table that may be
* used with Shared Access Signatures.
*
* @param context for canceling long running operations.
* @return Get access policy result.
*/
Response<Models::TableAccessPolicy> GetAccessPolicy(Core::Context const& context = {});

/**
* @brief Sets stored access policies for the table that may be used with Shared Access
* Signatures.
*
* @param tableAccessPolicy The TableAccessPolicy to set.
* @param context for canceling long running operations.
* @return Set access policy result.
*/
Response<Models::SetTableAccessPolicyResult> SetAccessPolicy(
Models::TableAccessPolicy const& tableAccessPolicy,
Core::Context const& context = {});

/**
* @brief Add entity in a table.
*
Expand Down Expand Up @@ -236,14 +186,14 @@ namespace Azure { namespace Data { namespace Tables {
* @return Table entity.
*/
Response<Models::TableEntity> GetEntity(
const std::string& partitionKey,
const std::string& rowKey,
std::string const& partitionKey,
std::string const& rowKey,
Core::Context const& context = {});

/**
* @brief Submits a transaction.
*
* @param steps the transaction steps to execute.
* @param steps The transaction steps to execute.
* @param context for canceling long running operations.
* @return Submit transaction result.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,6 @@ namespace Azure { namespace Data { namespace Tables {
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const TableClientOptions& options = {});

/**
* @brief Initializes a new instance of tableClient.
*
* @param serviceUrl A url referencing the table that includes the name of the account and the
* name of the table.
* @param credential The named key credential used to sign requests.
* @param options Optional client options that define the transport pipeline policies for
* authentication, retries, etc., that are applied to every request.
*/
explicit TableServiceClient(
const std::string& serviceUrl,
std::shared_ptr<Azure::Data::Tables::Credentials::NamedKeyCredential> credential,
const TableClientOptions& options = {});

/**
* @brief Initializes a new instance of tableClient.
*
Expand All @@ -78,18 +64,6 @@ namespace Azure { namespace Data { namespace Tables {
std::shared_ptr<Azure::Data::Tables::Credentials::AzureSasCredential> credential,
const TableClientOptions& options = {});

/**
* @brief Initializes a new instance of tableClient.
*
* @param connectionString the connection string used to initialize.
* @param options Optional client options that define the transport pipeline policies for
* authentication, retries, etc., that are applied to every request.
* @return TableServiceClient.
*/
static TableServiceClient CreateFromConnectionString(
const std::string& connectionString,
const TableClientOptions& options = {});

/**
* @brief Creates a new table under the given account.
*
Expand Down Expand Up @@ -176,7 +150,6 @@ namespace Azure { namespace Data { namespace Tables {
private:
std::shared_ptr<Core::Http::_internal::HttpPipeline> m_pipeline;
std::shared_ptr<Core::Credentials::TokenCredential> m_tokenCredential;
std::shared_ptr<Azure::Data::Tables::Credentials::NamedKeyCredential> m_namedKeyCredential;
Core::Url m_url;
};
}}} // namespace Azure::Data::Tables
10 changes: 5 additions & 5 deletions sdk/tables/azure-data-tables/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ if(MSVC)
endif()

add_executable(tables-getting-started tables_getting_started.cpp )
target_link_libraries(tables-getting-started PRIVATE azure-data-tables get-env-helper)
target_link_libraries(tables-getting-started PRIVATE azure-data-tables azure-identity get-env-helper)
create_per_service_target_build_for_sample(tables tables-getting-started)
target_compile_definitions(tables-getting-started PRIVATE _azure_BUILDING_SAMPLES)

add_executable(tables_entity_operations tables_entity_operations.cpp)
target_link_libraries(tables_entity_operations PRIVATE azure-data-tables get-env-helper)
target_link_libraries(tables_entity_operations PRIVATE azure-data-tables azure-identity get-env-helper)
create_per_service_target_build_for_sample(tables tables_entity_operations)
target_compile_definitions(tables_entity_operations PRIVATE _azure_BUILDING_SAMPLES)

add_executable(tables_service_operations tables_service_operations.cpp)
target_link_libraries(tables_service_operations PRIVATE azure-data-tables get-env-helper)
target_link_libraries(tables_service_operations PRIVATE azure-data-tables azure-identity get-env-helper)
create_per_service_target_build_for_sample(tables tables_service_operations)
target_compile_definitions(tables_service_operations PRIVATE _azure_BUILDING_SAMPLES)

add_executable(tables_transactions_ok tables_transactions_ok.cpp)
target_link_libraries(tables_transactions_ok PRIVATE azure-data-tables get-env-helper)
target_link_libraries(tables_transactions_ok PRIVATE azure-data-tables azure-identity get-env-helper)
create_per_service_target_build_for_sample(tables tables_transactions_ok)
target_compile_definitions(tables_transactions_ok PRIVATE _azure_BUILDING_SAMPLES)

add_executable(tables_transactions_fail tables_transactions_fail.cpp)
target_link_libraries(tables_transactions_fail PRIVATE azure-data-tables get-env-helper)
target_link_libraries(tables_transactions_fail PRIVATE azure-data-tables azure-identity get-env-helper)
create_per_service_target_build_for_sample(tables tables_transactions_fail)
target_compile_definitions(tables_transactions_fail PRIVATE _azure_BUILDING_SAMPLES)
34 changes: 13 additions & 21 deletions sdk/tables/azure-data-tables/samples/tables_entity_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,28 @@
// Licensed under the MIT License.

#include <azure/data/tables.hpp>
#include <azure/identity.hpp>

#include <cstdio>
#include <iostream>
#include <stdexcept>
#include <thread>

using namespace Azure::Data::Tables;
using namespace Azure::Data::Tables::Models;
const std::string TableName = "table";

std::string GetConnectionString()
// The following environment variables must be set before running the sample.
// * ACCOUNT_NAME: The name of the storage account.
std::string GetAccountName() { return std::getenv("ACCOUNT_NAME"); }
std::string const GetServiceUrl()
{
const static std::string ConnectionString = "";

if (!ConnectionString.empty())
{
return ConnectionString;
}
const static std::string envConnectionString = std::getenv("STANDARD_STORAGE_CONNECTION_STRING");
if (!envConnectionString.empty())
{
return envConnectionString;
}
throw std::runtime_error("Cannot find connection string.");
return std::string{"https://" + GetAccountName() + ".table.core.windows.net/"};
}

int main()
{
auto tableServiceClient = TableServiceClient::CreateFromConnectionString(GetConnectionString());
auto tableClient = TableClient::CreateFromConnectionString(GetConnectionString(), TableName);
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
auto tableServiceClient = Azure::Data::Tables::TableServiceClient(GetServiceUrl(), credential);
auto tableClient = Azure::Data::Tables::TableClient(GetServiceUrl(), TableName, credential);

// create new table
tableServiceClient.CreateTable(TableName);
Expand All @@ -46,19 +38,19 @@ int main()
Azure::Data::Tables::Models::TableEntity entity;
entity.SetPartitionKey("P1");
entity.SetRowKey("R1");
entity.Properties["Name"] = TableEntityProperty("Azure");
entity.Properties["Product"] = TableEntityProperty("Tables");
entity.Properties["Name"] = Azure::Data::Tables::Models::TableEntityProperty("Azure");
entity.Properties["Product"] = Azure::Data::Tables::Models::TableEntityProperty("Tables");
// create new entity
auto response = tableClient.AddEntity(entity);

// update entity
std::cout << response.Value.ETag << std::endl;
entity.Properties["Product"] = TableEntityProperty("Tables2");
entity.Properties["Product"] = Azure::Data::Tables::Models::TableEntityProperty("Tables2");
auto updateResponse = tableClient.UpdateEntity(entity);
std::cout << updateResponse.Value.ETag << std::endl;

// merge entity
entity.Properties["Product"] = TableEntityProperty("Tables3");
entity.Properties["Product"] = Azure::Data::Tables::Models::TableEntityProperty("Tables3");
entity.SetETag(updateResponse.Value.ETag);
auto updateResponse2 = tableClient.MergeEntity(entity);

Expand Down
28 changes: 10 additions & 18 deletions sdk/tables/azure-data-tables/samples/tables_getting_started.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,26 @@
// Licensed under the MIT License.

#include <azure/data/tables.hpp>
#include <azure/identity.hpp>

#include <cstdio>
#include <iostream>
#include <stdexcept>
#include <thread>

std::string GetConnectionString()
{
const static std::string ConnectionString = "";

if (!ConnectionString.empty())
{
return ConnectionString;
}
const static std::string envConnectionString = std::getenv("STANDARD_STORAGE_CONNECTION_STRING");
if (!envConnectionString.empty())
{
return envConnectionString;
}
throw std::runtime_error("Cannot find connection string.");
}

using namespace Azure::Data::Tables;
const std::string TableName = "sample1";

// The following environment variables must be set before running the sample.
// * ACCOUNT_NAME: The name of the storage account.
std::string GetAccountName() { return std::getenv("ACCOUNT_NAME"); }
std::string const GetServiceUrl()
{
return std::string{"https://" + GetAccountName() + ".table.core.windows.net/"};
}
int main()
{
auto tableServiceClient = TableServiceClient::CreateFromConnectionString(GetConnectionString());
auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
auto tableServiceClient = Azure::Data::Tables::TableServiceClient(GetServiceUrl(), credential);

// create new table
tableServiceClient.CreateTable(TableName);
Expand Down
28 changes: 10 additions & 18 deletions sdk/tables/azure-data-tables/samples/tables_service_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,27 @@
// Licensed under the MIT License.

#include <azure/data/tables.hpp>
#include <azure/identity.hpp>

#include <cstdio>
#include <iostream>
#include <stdexcept>
#include <thread>

std::string GetConnectionString()
{
const static std::string ConnectionString = "";
const std::string TableName = "sample1";

if (!ConnectionString.empty())
{
return ConnectionString;
}
const static std::string envConnectionString = std::getenv("STANDARD_STORAGE_CONNECTION_STRING");
if (!envConnectionString.empty())
{
return envConnectionString;
}
throw std::runtime_error("Cannot find connection string.");
// The following environment variables must be set before running the sample.
// * ACCOUNT_NAME: The name of the storage account.
std::string GetAccountName() { return std::getenv("ACCOUNT_NAME"); }
std::string const GetServiceUrl()
{
return std::string{"https://" + GetAccountName() + ".table.core.windows.net/"};
}

using namespace Azure::Data::Tables;
const std::string TableName = "sample1";

int main()
{
auto tableServiceClient = TableServiceClient::CreateFromConnectionString(GetConnectionString());

auto credential = std::make_shared<Azure::Identity::DefaultAzureCredential>();
auto tableServiceClient = Azure::Data::Tables::TableServiceClient(GetServiceUrl(), credential);
// query tables
auto tables = tableServiceClient.QueryTables();

Expand Down
Loading

0 comments on commit e6eaee7

Please sign in to comment.