Skip to content

Commit

Permalink
[Tables] Track2 tables (#15276)
Browse files Browse the repository at this point in the history
* Initial generation of the aztables module (#14441)

* initial generation

* Update ci.yml

* Introduce internal/testFramework and test aztables with it (#14491)

* testFramework initial implementation

* sanitizer fixes (#14600)

* Progress on aztables (#14676)

* implement batch operations and all entity operations

* AsModels

* rename

* comments

* comment tweaks, options as pointer

* add EntityMapAsModel

* refactors to AddEntity

* update some code docs

* doc fixes

* doc fixes

* doc improvements

* rename testframework to recording

* move ci.yml

* ci path

* ci path

* [Tables] Update from testframework -> recording (#14888)

* Initial generation of the aztables module (#14441)

* initial generation

* Update ci.yml

* Introduce internal/testFramework and test aztables with it (#14491)

* testFramework initial implementation

* sanitizer fixes (#14600)

* Progress on aztables (#14676)

* implement batch operations and all entity operations

* AsModels

* rename

* comments

* comment tweaks, options as pointer

* add EntityMapAsModel

* refactors to AddEntity

* update some code docs

* doc fixes

* doc fixes

* doc improvements

* rename testframework to recording

* fixing tables to go from testframework -> recording

* renaming recordingInstance -> r

* file name change

Co-authored-by: Christopher Scott <chriss@microsoft.com>
Co-authored-by: catalinaperalta <catalinaperaltah@hotmail.com>

* [Tables] ci fix (#14956)

* [Tables] Add post-request validation of entity (#14960)

* adds a secondary validation if the entity doesnt have pk/rk

* creating an errors file just for handling errors

* removing extra line

* moving error to constants file, renaming constants file

* improving test

* [Tables] changing QueryOptions param to be a ptr (#14961)

* changing QueryOptions param to be a ptr

* feedback from catalina

* [Tables] linting Fixes (#15028)

* small fixes

* small fixes

* small fixes

* small fixes

* small fixes

* small fixes

* adding error checking to transactional batching

* adding error checking to test set up

* adding more error checking

* adding more error checking

* fixing two tests

* fixing error reporting

* fixing error reporting

* fixing error reporting

* fixing last lint failure

* [Tables] Adding swagger.md  (#15016)

* adding swagger

* updating swagger with autorest command

* more fixes

* fixing directive

* updating swagger.md

* fixed swagger

* fixing directive

* add dataplane flag

* updating swagger

* commented out tests, passes remaining

* addressing chris hamons feedback

* undoing changes

* undoing the rest of changes

* updating generated code

* formatting gen code

* more formatting corrections

* one last formatting correction

* [Tables] Add get/set access policy (#15027)

* adding a way to skip cosmos tests, adding access policies

* adding support for getting/setting access policies

* tests working

* does not work for multiple access policies

* adding post validation

* added error validation, note about possible issue

* set policy works

* removing table access policy file

* [Tables] Add GetStats, GetProperties, and SetProperties methods (#15112)

* adding GetProperties

* basic test of set properties

* added logging and metrics tests

* tests for setting service properties

* adding test for retention too long

* adding samples and docs

* [Tables] Add support for Entity struct (#15003)

* adding test for custom entity

* further

* starting access policy

* working for basic entity

* adding to test

* new generated code, removed one more test

* AddEntity now takes []bytes

* adding directive to change entity to []byte, changes to compile and be able to pass

* converting Value map[string]interface{} -> []byte in convenience layer

* paging works the same way now too

* fixing two tests, update complex and basic test entities, need to add type hints for int64/float64 types

* adding test for delete method, changed delete etag to be nil

* working test for merge

* Added Merge test

* fix up test query simple entity

* complex query test

* everything except for batch tests

* basic batch functionality

* fixing batch mixed test

* fixed last batch test

* added separate file for testing batch actions

* fixing query on table service client to take a pointer as well

* working on annotating entities

* fixing recordings

* working with odata annotations

* working test for using odata to annotate entity

* adding options to get

* working with embedded entity now too

* adding to entity, peeling off prints

* converted to a type

* first change to add EdmEntity type

* updated unmarshalling

* removing two files

* fix editLink

* removing sample

* cleaning up

* removing more code

* cleaning up

* formatting

* formatting

* [Tables] change Query to List (#15099)

* adding List methods

* moving helper to zt file

* improving docstrings

* changing all query methods to list

* updating docstrings

* [Tables] Update transactions method (#15125)

* adding test for custom entity

* further

* starting access policy

* working for basic entity

* adding to test

* new generated code, removed one more test

* AddEntity now takes []bytes

* adding directive to change entity to []byte, changes to compile and be able to pass

* converting Value map[string]interface{} -> []byte in convenience layer

* paging works the same way now too

* fixing two tests, update complex and basic test entities, need to add type hints for int64/float64 types

* adding test for delete method, changed delete etag to be nil

* working test for merge

* Added Merge test

* fix up test query simple entity

* complex query test

* everything except for batch tests

* basic batch functionality

* fixing batch mixed test

* fixed last batch test

* added separate file for testing batch actions

* fixing query on table service client to take a pointer as well

* working on annotating entities

* fixing recordings

* working with odata annotations

* working test for using odata to annotate entity

* adding options to get

* working with embedded entity now too

* adding to entity, peeling off prints

* converted to a type

* first change to add EdmEntity type

* updated unmarshalling

* removing two files

* fix editLink

* removing sample

* cleaning up

* removing more code

* cleaning up

* re-record and remove methods

* more cleanup

* formatting

* having issues with cosmos tests

* Adding Table suffix to Create, Delete, and List methods on service client (#15181)

* [Tables] Architect Feedback (#15196)

* architect feedback

* docstrings

* feedback

* fixing eng pipelines

* figuring out pipeline failure

* missing recording

* restore eng changes

* [EngSys] Test proxy (#15101)

* [Tables] Add authentication via SAS credential (#15256)

* changing recording to use test-proxy

* updating client and test proxy

* updated Transport Do to send actual request

* whitespace

* working implementation

* updating internal recording

* now I have a blank recording...

* cleaning up

* more clean up

* transport Do is repeating, proxy is not parsing URL correctly

* small changes

* adding a policy to do the same thing

* adding a second test for proxy and transport

* further progress with Jeff, switching to only using a policy right now

* cleaning up file

* cleaning up

* added more debugging, added two required headers that I was missing

* proxy working on a single test, need to convert all tests to test proxy

* cleaning up

* moved over successfully :)

* more helper functions

* working for a subtest functionality

* fixed up a service client test

* converting more service tests

* converted all service client tests

* converted table client tests

* fixed last two client tests

* entity test

* entity tests

* converting access policy tests

* all passing in record mode

* batch tests

* liveonly for batch tests

* adding a sanitizer and more methods for recording

* adding main method to start and stop the proxy automatically

* adding test proxy step to pipeline

* double dash on version arg

* need a better way to get userful error reporting

* explicitly running test-proxy in the background

* adjust the proxy start and install to be compatible with specific process

* dont run test proxy in background

* didnt remove an import

* header to proxy_test.go

* fixes for pipeline

* added loggin on accident

* use nohup on linux machines

* further simplify nohup usage

* there are no exes on windows

* fixing errors, passing in default env variable

* force background for linux task. may need another iteration to place it within the quotes

* fake aad credential

* clean up after test-proxy

* add print for record mode

* another different attempt at starting the proxy

* jobs apparently is an unrecognized command on our linux boxes

* correct dumb typo in run tests

* replace nuget install with docker

* working fake credentials for client delete entity test

* fixing fake credentials portion, passing locally

* trying an insecureskipverify transport

* debugging statements to find the cwd

* removing blank recording

* working implementation of sas

* working sas credential for account signature

* table sas is failing

* leverage proxy tool, not docker

* remove apostrophes

* moving recordings one directory up

* transitioning to using the sas written by storage team

* using storage methods

* copied storage code, sas needs to be appended in a different way

* changing directory for test-proxy to start from

* removing parenthesis

* adding steps for validating ssl

* switching to docker

* adding start server script

* working implementation if we can fix the prepending of 'recording' to the docker request finder

* big refactor, moving stuff into recording file, cleaning up proxy_test.go file

* last fixings

* convert back to docker. windows and linux images now present

* double condition

* moving configuration to a separate file. preparing for eng/common move

* tier 0 of trust. I don't expect this to work, but it's still worth a shot. maybe the devops agents do something differently

* update condition to use variable syntax

* guess I'm not using variables. removing

* call start-server.ps1

* adjust build-test and configure-proxy to run the docker container in context

* wrap in quotes for the container create. it's apparently a bad

* adjust the initialize call

* disable vet temporarily

* looking for cert file in env variable PROXY_CERT

* set proxy_cert environment variable to find that certificate

* changing to crt file

* use crt cert

* want to see errors

* powershell errors

* correcting how the volume binds to the windows container

* small modification for windows container

* finally got the magic sauce

* cleaning up to remove azcore from internal

* removing recordings that use vcr

* issue with the url creation

* persist query params correctly in azcore.JoinPaths

* removing print statements

* return root

* changing location of script

* forgot the stop command

* working table level sas implementation

* adding start/end rk/pk functionality

* removing print statements

* removing more non-tables code

* docstrings and removing storage only code

* making sas tests live only

* Fixing sas table name to be lowercase always, adding test to verify read only

* Fixing sas table name to be lowercase always, adding test to verify read only

* adding cosmos sas test

* fix for params

* apiview fixes

* fixing test

* undoing change

* updates

* error naming

* fixed service client, was adding percallpolicies twice

* simplification

* aligning with main

* converting from query pager to list pager for naming consistency

* updating objects for consistency

* jeffs feedback

* small fixes

* autorest.md changes

* fixing tablename

Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>

* fixing internal (#15315)

* Fixes2 (#15316)

Makes a fix to azcore in track2-tables branch

* [Tables] bump deps (#15350)

* Sync eng/common directory with azure-sdk-tools for PR 1912 (#15314)

* Attempt to purge all vaults, managed HSMs

Reverts #1910. Vaults and managed HSMs are automatically purged on their purge date. The point was to purge them daily to preserve capacity. The default purge date is +90 days.

* Add timeout and more logging

* Pass required -Resource

* Fix log message

* Ensure the $Resource is correctly captured

Added comment to new code explaining why, since ScriptBlock.GetNewClosure() is not working as expected.

* Add -ErrorAction to Receive-Job

Worked without terminating when run locally, but failed on the first error in the AzDO agent.

* Use $using:r instead of creating ScriptBlock

More idiomatic for passing ScriptBlocks to jobs.

* Resolve PR feedback

* Change default DeleteAfterHours to 120

Resolves #1917

* Use the Az cmdlets built-in -AsJob

Co-authored-by: Heath Stewart <heaths@microsoft.com>

* Fix query batch processing (#15319)

Co-authored-by: Wes Haggard <Wes.Haggard@microsoft.com>

* fix: three dots path not work in linux in build script (#15297)

* Release v56.3.0 1629350585 (#15323)

* Generated from specification/apimanagement/resource-manager/readme.md tag package-preview-2021-01 (commit hash: 30d1537f0c9aa49e6e04401b1d16f612b31231e7)

* Generated from specification/purview/resource-manager/readme.md tag package-2021-07-01 (commit hash: 30d1537f0c9aa49e6e04401b1d16f612b31231e7)

* v56.3.0

* fix

* Remove old unused update changelog script (#15326)

Co-authored-by: Wes Haggard <Wes.Haggard@microsoft.com>

* add clear output flag to build.ps1 (#15255)

* add clear output flag

* remove the path parameter and make sure the process-sdk function only runs in current directory

* change flag name

* [tools/generator] add automation and release command for track2 (#15271)

* [tools/generator] add automation and release command for track2

* add copyright and do gofmt

* Use semver to pump version, move git operation to repo package and fix some typo

* Add specfic version to release cmd, seperate package for automation and remove test config file

* add automation script and config for track2

* fix: three dots path not work in linux in build script

* fix: ln pwsh.exe to pwsh to run in linux

* fix: ignore dep check for go-git

* chore: label name change for track2

* fix: wrong package path result in empty git commit

* fix: repo addr replacement in autorest.md

* chore: move script to eng folder and change name

* fix: onboard generation need to replace NewClientMethod

* chore: change all naming from track2 to v2

* fix: add new build constraint

* fix: template compat with go 1.17 and change commit msg for release

* chore: add v2 to readme begin regex to support future change of `track2` naming

* chore: remove track2 naming

* fix: duplicated and wrong expression

* fix: add package title param to release cmd

* fix: ci

* Prevent ManagedIdentityCredential mutating GetToken arguments (#15331)

* [Azcore] bumps version of internal (#15347)

* bump internal to latest

* upgrading internal

* not the correct one

* changelog update

* [azidentity] bump azcore and internal dependencies (#15348)

* updating to latest core and identity

* trying to fix merge

* undoing changes to identity that should not be there

* more changes

* more changes

* removing a bunch more

* one last file

* formatting

* linting checks

* linting

* formatting

Co-authored-by: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com>
Co-authored-by: Heath Stewart <heaths@microsoft.com>
Co-authored-by: Wes Haggard <Wes.Haggard@microsoft.com>
Co-authored-by: tadelesh <tadelesh.shi@live.cn>
Co-authored-by: JiahuiPeng <46921893+804873052@users.noreply.github.com>
Co-authored-by: Arcturus <dapzhang@microsoft.com>
Co-authored-by: Charles Lowell <chlowe@microsoft.com>

* [Tables] connection string parser (#15187)

* adding conn str parser

* Basic conn str parser

* adding support for custom domains

* invalid tests

* adding self note

* Update sdk/tables/aztable/connection_string.go

Co-authored-by: Richard Park <51494936+richardpark-msft@users.noreply.github.com>

* Update sdk/tables/aztable/connection_string.go

Co-authored-by: Richard Park <51494936+richardpark-msft@users.noreply.github.com>

* improving testing

* finishing connection string portion

* formatting and improved error handling

* docstring addition for private method

* connection string error

* splitn instead of split

* sas comment

* updating proxy-server script

* configure proxy with hash of file, correct file location

* using certs in main

* trying download with no password

* trying without the pfx file altogether

* adding pfx portion back

* manual copy of testproxy to common

* using common

* fixing path

* adding trust ps1 script

* adding step to run proxy

* formatting and go mod x/net

* fixing for latest azcore

* fixing rqeuire

* removing eng stuff

* conn str

* running tests

* run tests = true

* adding build sourcesDir

* relative path

* fixing up path

* build-test

* moving byte array response inside table pager

* env var playing to fix ci lint

* changing package name

Co-authored-by: Richard Park <51494936+richardpark-msft@users.noreply.github.com>

* [Tables] simplify code space by moving generated to `internal` module (#15299)

* changing to internal package, everything except batching works

* back to working

* converting more things to private

* renamings

* still working, checkpoint

* most of tableclient done

* finished table client options/responses

* finished with service client

* cors rule done

* retentionpolicy

* retentionpolicy and cors

* last piece

* final comments

* updating with newest autorest

* formatting

* fixing go mod in internal package

* update versions

* flipping param order

* convert internal to a subpackage

* fixing telemetry and bumping go version

* updating proxy, adding test-resources.json file

* cert issues

* formatting and x/net

* fixing build-test

* correcting file path

* lint and formatting

* go fmt

* dropping coverage for internal

* updates from pre-arch board

* checking error

* doing scopes work in generated code

* linting

* removing old file

* consistent namings

* removing types and simplifying pageresponse for list entities

* formatting

* renames, removing Table prefix, removing TableTRansactionError

* fixed error type, placeholder while azcore is in PR

* running tests live, fixing one test, converting to always using shared key

* formatting

* linter

* fixing playback for storage

* fixing playback credential

* fixing serviceURL to expect tableName in service url

* moving update mode into options for update/insert entity

* return *Client from CreateTable method

* cleaning up structs

* flipping order of strings in conn str constructor

* renaming param of transactionAction from ETag -> IfMatch

* remove XMS prefix, change Value to Entities/Tables

* moving GetTableSASToken to Client struct

* making MinimalOdata the default, removing option to set it, new recordings

* renaming ETag -> IfMatch for Options

* formatting

* renaming file, adding version to constants.go file

* adding version

* updating to latest azcore

* updating autorest

* formatting

* updates for SAS

* fixing tests, fixing conn str parser

* formatting

* missing error check

* [Tables] Docs and cleanup (#15428)

* removing to library

* cleanup

* fixing two tests for live

* removing options, responses, and table_pagers files

* removing table_ prefix on files

* removing byte_array_response.go file

* fixing up two reponses, adding proper comments and fixing samples

* removing NewClientFromConnStr

* wrong 'to' library

* [Tables]Rename package (#15448)

<!--
Thank you for contributing to the Azure SDK for Go.

Please verify the following before submitting your PR, thank you!
-->

- [ ] The purpose of this PR is explained in this or a referenced issue.
- [ ] The PR does not update generated files.
   - These files are managed by the codegen framework at [Azure/autorest.go][].
- [ ] Tests are included and/or updated for code changes.
- [ ] Updates to [CHANGELOG.md][] are included.
- [ ] MIT license headers are included in each file.

[Azure/autorest.go]: https://github.com/Azure/autorest.go
[CHANGELOG.md]: https://github.com/Azure/azure-sdk-for-go/blob/main/CHANGELOG.md

* [Tables] Merging internal (#15451)

* updating

* formatting

Co-authored-by: Christopher Scott <chriss@microsoft.com>
Co-authored-by: catalinaperalta <catalinaperaltah@hotmail.com>
Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>
Co-authored-by: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com>
Co-authored-by: Heath Stewart <heaths@microsoft.com>
Co-authored-by: Wes Haggard <Wes.Haggard@microsoft.com>
Co-authored-by: tadelesh <tadelesh.shi@live.cn>
Co-authored-by: JiahuiPeng <46921893+804873052@users.noreply.github.com>
Co-authored-by: Arcturus <dapzhang@microsoft.com>
Co-authored-by: Charles Lowell <chlowe@microsoft.com>
Co-authored-by: Richard Park <51494936+richardpark-msft@users.noreply.github.com>
  • Loading branch information
12 people authored Sep 2, 2021
1 parent 19f00c3 commit 6fd8ceb
Show file tree
Hide file tree
Showing 96 changed files with 17,304 additions and 20 deletions.
6 changes: 5 additions & 1 deletion eng/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
},
{
"Name": "internal",
"CoverageGoal": 0.90
"CoverageGoal": 0.70
},
{
"Name": "data",
"CoverageGoal": 0.40
}
]
}
4 changes: 3 additions & 1 deletion eng/pipelines/templates/steps/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ steps:
- pwsh: ../eng/scripts/create_coverage.ps1 ${{parameters.ServiceDirectory}}
displayName: 'Generate Coverage XML'
workingDirectory: '${{parameters.GoWorkspace}}sdk'
env:
GO111MODULE: 'off'

- task: PublishTestResults@2
condition: succeededOrFailed()
Expand All @@ -86,4 +88,4 @@ steps:
codeCoverageTool: Cobertura
summaryFileLocation: '${{parameters.GoWorkspace}}sdk/${{parameters.ServiceDirectory}}/coverage.xml'
additionalCodeCoverageFiles: '${{parameters.GoWorkspace}}sdk/${{parameters.ServiceDirectory}}/coverage.html'
failIfCoverageEmpty: true
failIfCoverageEmpty: true
30 changes: 30 additions & 0 deletions sdk/data/autorest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Go

These settings apply only when `--go` is specified on the command line.

<!-- Original autorest command used by Chris Scott -->
<!-- autorest --use=@autorest/go@4.0.0-preview.20 https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/cosmos-db/data-plane/readme.md --tag=package-2019-02 --file-prefix="zz_generated_" --modelerfour.lenient-model-deduplication --license-header=MICROSOFT_MIT_NO_VERSION --output-folder=aztables --module=aztables --openapi-type="data-plane" --credential-scope=none -->

``` yaml
go: true
version: "^3.0.0"
input-file: https://github.com/Azure/azure-rest-api-specs/blob/d744b6bcb95ab4034832ded556dbbe58f4287c5b/specification/cosmos-db/data-plane/Microsoft.Tables/preview/2019-02-02/table.json
license-header: MICROSOFT_MIT_NO_VERSION
clear-output-folder: false
output-folder: aztables/internal
tag: package-2019-02
credential-scope: none
use: "@autorest/go@4.0.0-preview.27"
module-version: 0.1.0
security: "AADToken"
security-scopes: "https://storage.azure.com/.default"
modelerfour:
group-parameters: false
```
### Go multi-api
``` yaml $(go) && $(multiapi)
batch:
- tag: package-2019-02
```
4 changes: 4 additions & 0 deletions sdk/data/aztables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Release History

## v0.1.0 (09-07-2021)
* This is the initial release of the `aztables` library
21 changes: 21 additions & 0 deletions sdk/data/aztables/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
151 changes: 151 additions & 0 deletions sdk/data/aztables/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Azure Tables client library for Go

Azure Table storage is a service that stores large amounts of structured NoSQL data in the cloud, providing
a key/attribute store with a schema-less design.

Azure Cosmos DB provides a Table API for applications that are written for Azure Table storage that need premium capabilities like:

- Turnkey global distribution.
- Dedicated throughput worldwide.
- Single-digit millisecond latencies at the 99th percentile.
- Guaranteed high availability.
- Automatic secondary indexing.

The Azure Tables client library can seamlessly target either Azure Table storage or Azure Cosmos DB table service endpoints with no code changes.

## Getting started

### Install the package
Install the Azure Tables client library for Go :

### Prerequisites
* An [Azure subscription][azure_sub].
* An existing Azure storage account or Azure Cosmos DB database with Azure Table API specified.

If you need to create either of these, you can use the [Azure CLI][azure_cli].

#### Creating a storage account

Create a storage account `mystorageaccount` in resource group `MyResourceGroup`
in the subscription `MySubscription` in the West US region.


#### Creating a Cosmos DB

Create a Cosmos DB account `MyCosmosDBDatabaseAccount` in resource group `MyResourceGroup`
in the subscription `MySubscription` and a table named `MyTableName` in the account.


### Authenticate the Client

Learn more about options for authentication _(including Connection Strings, Shared Key, and Shared Key Signatures)_ in our samples.

## Key concepts

- `TableServiceClient` - Client that provides methods to interact at the Table Service level such as creating, listing, and deleting tables
- `TableClient` - Client that provides methods to interact at an table entity level such as creating, querying, and deleting entities within a table.
- `Table` - Tables store data as collections of entities.
- `Entity` - Entities are similar to rows. An entity has a primary key and a set of properties. A property is a name value pair, similar to a column.

Common uses of the Table service include:

- Storing TBs of structured data capable of serving web scale applications
- Storing datasets that don't require complex joins, foreign keys, or stored procedures and can be de-normalized for fast access
- Quickly querying data using a clustered index
### Create the Table service client

First, we need to construct a `TableServiceClient`.

### Create an Azure table
Next, we can create a new table.


### Get an Azure table
The set of existing Azure tables can be queries using an OData filter.


### Delete an Azure table

Individual tables can be deleted from the service.


### Create the Table client

To interact with table entities, we must first construct a `TableClient`.


### Add table entities

Let's define a new `TableEntity` so that we can add it to the table.

Using the `TableClient` we can now add our new entity to the table.


### Query table entities

To inspect the set of existing table entities, we can query the table using an OData filter.


If you prefer LINQ style query expressions, we can query the table using that syntax as well.


### Delete table entities

If we no longer need our new table entity, it can be deleted.


## Troubleshooting

When you interact with the Azure table library using the .NET SDK, errors returned by the service correspond to the same HTTP
status codes returned for [REST API][tables_rest] requests.

For example, if you try to create a table that already exists, a `409` error is returned, indicating "Conflict".


### Setting up console logging

The simplest way to see the logs is to enable the console logging.
To create an Azure SDK log listener that outputs messages to console use AzureEventSourceListener.CreateConsoleLogger method.


To learn more about other logging mechanisms see [here][logging].

## Next steps

Get started with our [Table samples][table_client_samples].

## Known Issues

A list of currently known issues relating to Cosmos DB table endpoints can be found [here](https://aka.ms/tablesknownissues).

## Contributing

This project welcomes contributions and suggestions. Most contributions require
you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution. For
details, visit [cla.microsoft.com][cla].

This project has adopted the [Microsoft Open Source Code of Conduct][coc].
For more information see the [Code of Conduct FAQ][coc_faq] or contact
[opencode@microsoft.com][coc_contact] with any additional questions or comments.

## Generating the client

From the tables dir:

autorest --use=@autorest/go@4.0.0-preview.20 https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/cosmos-db/data-plane/readme.md --tag=package-2019-02 --file-prefix="zz_generated_" --modelerfour.lenient-model-deduplication --license-header=MICROSOFT_MIT_NO_VERSION --output-folder=aztables --module=aztables --openapi-type="data-plane" --credential-scope=none

<!-- LINKS -->
[tables_rest]: https://docs.microsoft.com/rest/api/storageservices/table-service-rest-api
[azure_cli]: https://docs.microsoft.com/cli/azure
[azure_sub]: https://azure.microsoft.com/free/
[table_client_nuget_package]: https://www.nuget.org/packages?q=Azure.Data.Tables
[table_client_samples]: https://github\.com/Azure/azure-sdk-for-go
[table_client_src]: https://github\.com/Azure/azure-sdk-for-go
[logging]: https://github\.com/Azure/azure-sdk-for-go
[cla]: https://cla.microsoft.com
[coc]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:opencode@microsoft.com

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftables%2FAzure.Data.Tables%2FREADME.png)
151 changes: 151 additions & 0 deletions sdk/data/aztables/access_policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package aztables

import (
"strconv"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestSetEmptyAccessPolicy(t *testing.T) {
client, delete := initClientTest(t, "storage", true)
defer delete()

_, err := client.SetAccessPolicy(ctx, &SetAccessPolicyOptions{})
require.NoError(t, err)
}

func TestSetAccessPolicy(t *testing.T) {
client, delete := initClientTest(t, "storage", true)
defer delete()

start := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
expiration := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
permission := "r"
id := "1"

signedIdentifiers := make([]*SignedIdentifier, 0)

signedIdentifiers = append(signedIdentifiers, &SignedIdentifier{
AccessPolicy: &AccessPolicy{
Expiry: &expiration,
Start: &start,
Permission: &permission,
},
ID: &id,
})

param := SetAccessPolicyOptions{
TableACL: signedIdentifiers,
}

_, err := client.SetAccessPolicy(ctx, &param)
require.NoError(t, err)
}

func TestSetMultipleAccessPolicies(t *testing.T) {
client, delete := initClientTest(t, "storage", true)
defer delete()

id := "empty"

signedIdentifiers := make([]*SignedIdentifier, 0)
signedIdentifiers = append(signedIdentifiers, &SignedIdentifier{
ID: &id,
})

permission2 := "r"
id2 := "partial"

signedIdentifiers = append(signedIdentifiers, &SignedIdentifier{
ID: &id2,
AccessPolicy: &AccessPolicy{
Permission: &permission2,
},
})

id3 := "full"
permission3 := "r"
start := time.Date(2021, 6, 8, 2, 10, 9, 0, time.UTC)
expiry := time.Date(2021, 6, 8, 2, 10, 9, 0, time.UTC)

signedIdentifiers = append(signedIdentifiers, &SignedIdentifier{
ID: &id3,
AccessPolicy: &AccessPolicy{
Start: &start,
Expiry: &expiry,
Permission: &permission3,
},
})

param := SetAccessPolicyOptions{
TableACL: signedIdentifiers,
}

_, err := client.SetAccessPolicy(ctx, &param)
require.NoError(t, err)

// Make a Get to assert two access policies
resp, err := client.GetAccessPolicy(ctx, nil)
require.NoError(t, err)
require.Equal(t, len(resp.SignedIdentifiers), 3)
}

func TestSetTooManyAccessPolicies(t *testing.T) {
client, delete := initClientTest(t, "storage", true)
defer delete()

start := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
expiration := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
permission := "r"
id := "1"
signedIdentifiers := make([]*SignedIdentifier, 0)

for i := 0; i < 6; i++ {
expiration = time.Date(2024+i, 1, 1, 0, 0, 0, 0, time.UTC)
id = strconv.Itoa(i)

signedIdentifiers = append(signedIdentifiers, &SignedIdentifier{
AccessPolicy: &AccessPolicy{
Expiry: &expiration,
Start: &start,
Permission: &permission,
},
ID: &id,
})

}

param := SetAccessPolicyOptions{TableACL: signedIdentifiers}

_, err := client.SetAccessPolicy(ctx, &param)
require.NotNil(t, err, "Set access policy succeeded but should have failed")
require.Contains(t, err.Error(), errTooManyAccessPoliciesError.Error())
}

func TestSetNullAccessPolicy(t *testing.T) {
client, delete := initClientTest(t, "storage", true)
defer delete()

id := "null"

signedIdentifiers := make([]*SignedIdentifier, 0)
signedIdentifiers = append(signedIdentifiers, &SignedIdentifier{
ID: &id,
})

param := SetAccessPolicyOptions{
TableACL: signedIdentifiers,
}

_, err := client.SetAccessPolicy(ctx, &param)
require.NoError(t, err)

resp, err := client.GetAccessPolicy(ctx, nil)
require.NoError(t, err)
require.Equal(t, len(resp.SignedIdentifiers), 1)
}
Loading

0 comments on commit 6fd8ceb

Please sign in to comment.