Skip to content

Commit

Permalink
Add user-agent to mark access source
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Nov 4, 2024
1 parent 4938422 commit e2380cd
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ release: ## Create a new tag for release.
@echo "WARNING: This operation will create s version tag and push to github"
@set -e; \
read -p "Version? (provide the next x.y.z semver) : " TAG; \
chmod +x scripts/generate_version.sh; \
bash scripts/generate_version.sh $${TAG}; \
git checkout -b release-$${TAG}; \
echo "$${TAG}" > tosfs/VERSION; \
git log --pretty=format:"%h - %s (%an, %ad)" --date=short > HISTORY.md; \
poetry version $${TAG}; \
git add tosfs/VERSION HISTORY.md pyproject.toml; \
git add tosfs/version.py HISTORY.md pyproject.toml; \
git commit -m "release: version $${TAG} 🚀"; \
echo "creating git tag : $${TAG}"; \
git tag $${TAG}; \
Expand Down
85 changes: 85 additions & 0 deletions scripts/generate_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash

# This file is used to generate the annotation of package info that
# records the user, url, revision and timestamp.

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -e

unset LANG
unset LC_CTYPE

version=$1
if [ -z "$version" ]; then
version=$(poetry version -s)
fi

pushd .

bin=`dirname "$0"`
PROJECT_ROOT=`cd "$bin"/.. >/dev/null; pwd`

user=$(whoami | sed -n -e "s/\\\/\\\\\\\\/p")
if [ "$user" == "" ]
then
user=$(whoami)
fi
date=$(date)
cwd=$(pwd)

if [ -x "$(command -v git)" ]; then
revision=$(git log -1 --no-show-signature --pretty=format:"%H" || true)
repoUrl=$(git config --get remote.origin.url)
fi

if [ -z "${revision}" ]; then
echo "[WARN] revision info is empty! either we're not in VCS or VCS commands failed." >&2
revision="Unknown"
repoUrl="file://$cwd"
fi

popd

cat >"$PROJECT_ROOT/tosfs/version.py" <<EOF
# ByteDance Volcengine EMR, Copyright 2024.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generated by scripts/generate_version.sh
#
class Version:
version = "$version"
revision = "$revision"
user = "$user"
date = "$date"
repo_url = "$repoUrl"
EOF

7 changes: 7 additions & 0 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from tosfs.retry import INVALID_RANGE_CODE, retryable_func_executor
from tosfs.tag import BucketTagMgr
from tosfs.utils import find_bucket_key, get_brange
from tosfs.version import Version

logger = logging.getLogger("tosfs")

Expand Down Expand Up @@ -241,6 +242,12 @@ def __init__(
proxy_username=proxy_username,
proxy_password=proxy_password,
except100_continue_threshold=except100_continue_threshold,
user_agent_product_name="EMR",
user_agent_soft_name="TOSFS",
user_agent_soft_version=Version.version,
user_agent_customized_key_values={
"revision": Version.revision
}
)
if version_aware:
raise ValueError("Currently, version_aware is not supported.")
Expand Down
23 changes: 23 additions & 0 deletions tosfs/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ByteDance Volcengine EMR, Copyright 2024.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Generated by scripts/generate_version.sh
#
class Version:
version = "2024.10.2.dev0"
revision = "4938422a682119d7e82698708b0d1c3773cb1d34"
user = "bytedance"
date = "Mon Nov 4 19:45:22 CST 2024"
repo_url = "https://github.com/fsspec/tosfs.git"

0 comments on commit e2380cd

Please sign in to comment.