Skip to content

fix(datastore): remove namespace from Key.String() (#10684)#10685

Closed
sgp wants to merge 4 commits intogoogleapis:mainfrom
pendo-io:datastore-unstring-namespace
Closed

fix(datastore): remove namespace from Key.String() (#10684)#10685
sgp wants to merge 4 commits intogoogleapis:mainfrom
pendo-io:datastore-unstring-namespace

Conversation

@sgp
Copy link
Copy Markdown
Contributor

@sgp sgp commented Aug 14, 2024

Datastore namespaces may be sensitive, and it's best not to emit them.

Provide a datastore.Key.StringWithNamespace() as an alternative, and use this version internally, which preserves the fix from #7829.

Datastore namespaces may be sensitive, and it's best not to emit
them.

Provide a `datastore.Key.StringWithNamespace()` as an alternative,
and use this version internally, which preserves the fix from
googleapis#7829.
@sgp sgp requested review from a team August 14, 2024 14:43
@google-cla
Copy link
Copy Markdown

google-cla bot commented Aug 14, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label bot added the api: datastore Issues related to the Datastore API. label Aug 14, 2024
@bhshkh
Copy link
Copy Markdown
Contributor

bhshkh commented Aug 23, 2024

Please create a bug describing the issue.

databasesStr, ok := os.LookupEnv(envDatabases)
if ok {
databaseIDs = append(databaseIDs, strings.Split(databasesStr, ",")...)
databaseIDs = strings.Split(databasesStr, ",")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Removing the append removes the default database from the list.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops. This was not intended to be committed; I had done this because testing in the default database wasn't easy without polluting a ton of stuff in existing projects here. Nice catch.

datastore/key.go Outdated

// marshal marshals the key's string representation to the buffer.
func (k *Key) marshal(b *bytes.Buffer) {
func (k *Key) marshal(b *bytes.Buffer, includeNamespace bool) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rename includeNamespace to includeSensitive.

datastore/key.go Outdated
}

// StringWithNamespace is identical to String(), but appends the namespace.
func (k *Key) StringWithNamespace() string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Better name for StringWithNamespace.
May be StringifyInternal or StringInternal or something else

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If it's truly meant to be "internal", then should we just make it non-exported and call it stringInternal?

datastore/key.go Outdated
return k._string(true)
}

func (k *Key) _string(includeNamespace bool) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lose the _
Using lowercase letters for unexported identifiers tends to be more readable and aligns with the overall Go coding style in this repository

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I nearly didn't do this, but redefining string as a func identifier when it clashes with a builtin type felt bad, too. I guess since it takes a receiver it's fine to call it Key.string, though. Will change.

@sgp
Copy link
Copy Markdown
Contributor Author

sgp commented Aug 27, 2024

Please create a bug describing the issue.

I did, didn't I? It's #10684.

@sgp
Copy link
Copy Markdown
Contributor Author

sgp commented Aug 27, 2024

I've addressed your comments, @bhshkh -- let me know what you think.

@bhshkh
Copy link
Copy Markdown
Contributor

bhshkh commented Sep 3, 2024

I've addressed your comments, @bhshkh -- let me know what you think.

Thanks! LGTM

@bhshkh bhshkh enabled auto-merge (squash) September 3, 2024 01:38
@bhshkh
Copy link
Copy Markdown
Contributor

bhshkh commented Sep 3, 2024

This branch is out-of-date with the base branch.
To minimize friction, consider setting 'Allow edits from maintainers' on the PR, which will enable project committers and automation to update your PR.
To allow edits, see point 4 at
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork#enabling-repository-maintainer-permissions-on-existing-pull-requests

@sgp
Copy link
Copy Markdown
Contributor Author

sgp commented Sep 3, 2024

@bhshkh --

To minimize friction, consider setting 'Allow edits from maintainers' on the PR, which will enable project committers and automation to update your PR.

Sadly, I created this fork from inside our organization, and apparently according to Github:

You cannot give push permissions to a fork owned by an organization.

I could close this PR, fork using my personal repository, and then recreate the PR there. That's a pain, and we would lose the conversation here.

In the meantime, can you force Kokoro to run so this will merge? Everything else has passed.

@sgp
Copy link
Copy Markdown
Contributor Author

sgp commented Sep 5, 2024

Ok, apparently this is a losing battle, as I cannot continually fight the progress of the monorepo changing every day. I'm going to close this PR and reopen it using a personal fork where I can give appropriate permissions.

@sgp sgp closed this Sep 5, 2024
auto-merge was automatically disabled September 5, 2024 14:48

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: datastore Issues related to the Datastore API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants